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

chore: make secret key configurable and reorganize settings #668

Merged
merged 5 commits into from
Jun 16, 2023

Conversation

oleobal
Copy link
Collaborator

@oleobal oleobal commented Jun 5, 2023

Description

Rename some files and variables to be a bit clearer. Reorganize the settings to lower the size of common.py. Split off CORS and OIDC settings into their own category of settings (mods) because they change settings from common and therefore must be applied afterwards.

Add two new configuration options:SECRET_KEY_PATH and SECRET_KEY_LOAD_AND_STORE

Inline gen_secret_key.py

This is a backwards compatible prerequisite PR to: #657

Checklist

  • changelog was updated with notable changes
  • documentation was updated

@oleobal oleobal requested a review from a team as a code owner June 5, 2023 15:51
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jun 5, 2023
@oleobal oleobal mentioned this pull request Jun 5, 2023
2 tasks
@thbcmlowk
Copy link
Contributor

How about moving JWT related statements into a dedicated module?

Benefits:

  • Lighter commons
  • Encouraging method extraction for "get secret key" part

Disclaimer:

  • Not sure on the global backend impact
  • Probably out of this PR scope

@oleobal
Copy link
Collaborator Author

oleobal commented Jun 8, 2023

@thbcmlowk

How about moving JWT related statements into a dedicated module?

Why not, I think that would fit under this PR. I didn't think of it because our settings files are usually a bit bigger than this but really splitting settings/common.py might be a good idea.

@oleobal oleobal force-pushed the chore/jwt-key branch 2 times, most recently from de28649 to a85ecd8 Compare June 12, 2023 16:28
@oleobal oleobal force-pushed the chore/jwt-key branch 6 times, most recently from de9e301 to 5fcdb66 Compare June 13, 2023 15:10
@oleobal oleobal changed the title chore: make JWT key configurable chore: make secret key configurable Jun 13, 2023
@oleobal oleobal force-pushed the chore/jwt-key branch 3 times, most recently from d481f20 to aad6230 Compare June 13, 2023 15:20
@oleobal oleobal changed the title chore: make secret key configurable chore: make secret key configurable and reorganize settings Jun 13, 2023
@oleobal
Copy link
Collaborator Author

oleobal commented Jun 13, 2023

/e2e

@Owlfred
Copy link

Owlfred commented Jun 13, 2023

End to end tests: ✔️ SUCCESS

@@ -1,11 +1,11 @@
import os

from .. import common
from .utils import to_bool
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@SdgJlbl SdgJlbl left a comment

Choose a reason for hiding this comment

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

Thanks for the PR 👍
We should wait for the end of the release before merging

Signed-off-by: Olivier Léobal <olivier.leobal@owkin.com>
Signed-off-by: Olivier Léobal <olivier.leobal@owkin.com>
Signed-off-by: Olivier Léobal <olivier.leobal@owkin.com>
Signed-off-by: Olivier Léobal <olivier.leobal@owkin.com>
Signed-off-by: Olivier Léobal <olivier.leobal@owkin.com>
@oleobal oleobal merged commit 41d6d09 into main Jun 16, 2023
@oleobal oleobal deleted the chore/jwt-key branch June 16, 2023 13:54
@oleobal
Copy link
Collaborator Author

oleobal commented Jun 19, 2023

/e2e --tests sdk,frontend

@Owlfred
Copy link

Owlfred commented Jun 19, 2023

End to end tests: ❌ FAILURE

Jobs status:

  • Tests Benchmark: ⏭️
  • Tests Distributed:
  • Tests Standalone:

“Success is not final; failure is not fatal: It is the courage to continue that counts.” ―- Winston S. Churchill

oleobal added a commit that referenced this pull request Jun 20, 2023
@oleobal oleobal mentioned this pull request Jun 20, 2023
2 tasks
oleobal added a commit that referenced this pull request Jun 20, 2023
…668)"

This reverts commit 41d6d09.

Refs: 41d6d09
Signed-off-by: Olivier Léobal <olivier.leobal@owkin.com>
oleobal added a commit that referenced this pull request Jun 26, 2023
#676)

#668 added a new `SECRET_KEY_LOAD_AND_STORE` boolean setting in the
backend. If `SECRET_KEY_LOAD_AND_STORE` is false, then the `SECRET_KEY`
is generated at startup and not stored. If it is true, the program tries
reading it from `SECRET_KEY_PATH`, and if that fails generate a new one
and write it there.

The intent was to allow configuring components that use the same
settings as the backend server not to write the `SECRET_KEY` on the file
system, because this eases configuration in production.

In #668 this was set to `False` by default. However to match the pre-668
behavior you'd need to set it to `True` by default.

Possibly we could get rid of this setting instead and just write the key
every time.

I don't know _why_ frontend authentication on k8s breaks when this
setting is set to `false`. The `SECRET_KEY` is used for signing JWTs, so
presumably at some point Django is restarted and so previously generated
JWTs aren't valid anymore.. But JWTs are requested (and therefore
generated) right before they're needed, so that's weird.

---

#668 also moved the file containing this line:

```python
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
```

without updating it, which broke paths


Co-authored-by: Guilhem Barthés <guilhem.barthes@owkin.com>
Signed-off-by: Olivier Léobal <olivier.leobal@owkin.com>
@thbcmlowk thbcmlowk mentioned this pull request Jun 27, 2023
thbcmlowk added a commit that referenced this pull request Jun 30, 2023
##
[0.39.0](https://github.com/Substra/substra-backend/releases/tag/0.39.0)
2023-06-27

### Added

- New `SECRET_KEY_PATH` and `SECRET_KEY_LOAD_AND_STORE` environment
variables ([#668](#668))

Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com>
oleobal added a commit that referenced this pull request Aug 14, 2023
Writing on the root filesystem fails when `readOnlyRootFilesystem` is
set, which is the case in some environments, such as OpenShift. This PR
fixes this.

Since `SECRET_KEY` is now stored in a secret, it should also mostly fix "Given token is not valid for any token type" errors, which were due to application restart where `SECRET_KEY` was regenerated and users had to refresh their tokens (which were signed with the old `SECRET_KEY`)

Reverts many changes from #668

Fixes FL-1000

Signed-off-by: Olivier Léobal <olivier.leobal@owkin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants