Repository navigation
fix: stop hardcoding the Flask SECRET_KEY in the bookshelf samples - #630
Open
angelcaamal wants to merge 1 commit into
Open
angelcaamal wants to merge 1 commit into
angelcaamal wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes the hardcoded Flask
SECRET_KEY = 'secret'from the two bookshelf samples. Flask signs session cookies with this key, so a value published in the repository lets anyone forge session cookies.Changes
GKE bookshelf (
optional-kubernetes-engine/)config.py: read the key from theFLASK_SECRET_KEYenvironment variable, with no default, so the app fails at startup instead of running with a predictable key.bookshelf-frontend.yaml,bookshelf-worker.yaml: injectFLASK_SECRET_KEYfrom a Kubernetes Secret (bookshelf-secrets).README.md,Makefile: add a step and acreate-secrettarget that generate a random key and create that Secret.make deploynow runs it first.conftest.py(new): set a randomFLASK_SECRET_KEYfor test runs sotests/conftest.pycan still importconfig.App Engine bookshelf (
bookshelf/)main.py: useFLASK_SECRET_KEYwhen it is set; otherwise generate a random key for the process. The session here only carries flashed messages, andapp.yamlhas no way to supply a key, so this keeps the tutorial deployable without extra configuration.Behavior changes
FLASK_SECRET_KEYis set. Existing deployments need thebookshelf-secretsSecret before updating, and local runs need the variable exported.FLASK_SECRET_KEYis not set, sessions don't survive restarts and aren't shared between instances or workers, so a flashed message can be lost.Internal bug: b/586645246