Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a unique SECRET_KEY_FILE when deploying a new django instance (ref: build_suite.sh) #531

Merged
merged 18 commits into from
Apr 28, 2023

Conversation

wlorenzetti
Copy link
Member

Closes: #523

@wlorenzetti wlorenzetti added feature New feature or request python Pull requests that update Python code labels Apr 19, 2023
@wlorenzetti wlorenzetti self-assigned this Apr 19, 2023
@Raruto Raruto changed the title Generete e newone django SECRET_KEY on new G3W-SUITE deploy. Generate a unique SECRET_KEY_FILE when deploying a new django instance (ref: build_suite.sh) Apr 20, 2023

# Read SECRET_KEY from SECRET_KEY_FILE environment variable
try:
with open(os.getenv('SECRET_KEY_FILE', '/shared-volume/.secret_key')) as f:
Copy link
Contributor

@Raruto Raruto Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to know, have you also considered this other topic? Manage sensitive data with Docker secrets (related to: g3w-suite/g3w-suite-docker#71)

When you deploy, Docker mounts a file under /run/secrets/<secret_name> in the services. These files are never persisted in disk, but are managed in memory.

If I'm not mistaken, within the compose file, it's possible to use the secrets: attribute without enable a "swarm" mode.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but in this way if someone want deploy it by classic way (without docker), can do it, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Raruto I think we can merge it, do you approve it?

@Raruto Raruto added config Anything related to configuration files and removed feature New feature or request python Pull requests that update Python code labels Apr 24, 2023
Comment on lines 28 to 33

echo "Create unique django SECRET_KEY"
SECRET_KEY=$(python3 -c "from django.core.management.utils import get_random_secret_key;sk=get_random_secret_key();print (sk)")
touch ${BUILD_DONE_FILE}
echo ${SECRET_KEY} >> ${SECRET_KEY_FILE}

Copy link
Contributor

@Raruto Raruto Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this inside a dedicated management command? --> Distributing Django projects with unique SECRET_KEYs

Is it feasible to run these such of commands in a pre-installation phase?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can move the code inside a dedicated management command, as inside the stackoverflow solution you which you mentioned, but I prefer to leave the file containing the secret key as a hidden file instead of a .py module.

What do you mean with

pre-installation phase

build_suite.sh is just in a pre-installation phase, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, I don't know if we can run the manage.py commands before a django project is installed / created.

It's just a doubt, since I don't exactly know the whole flow..

Copy link
Member Author

@wlorenzetti wlorenzetti Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I just try it on a new docker deploy and it works fine.

@wlorenzetti wlorenzetti marked this pull request as ready for review April 28, 2023 09:59
@wlorenzetti wlorenzetti requested a review from Raruto April 28, 2023 10:00
@wlorenzetti wlorenzetti added this to the v3.6 milestone Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config Anything related to configuration files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unsafe SECRET_KEY ?
2 participants