Repository navigation
Use supplied JWT_SECRET_KEY instead of always generating a random one - #520
Merged
Merged
Conversation
The --jwt-secret callback discarded the value resolved from the option or JWT_SECRET_KEY and always substituted a freshly generated key, so every API process signed tokens with its own key. Tokens were rejected by other replicas and invalidated on restart. Only generate a key when none is supplied, and warn on stderr when that happens. Fixes #519. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MfKrZ874H9yYqThyTNK88t
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #520 +/- ##
==========================================
+ Coverage 80.94% 80.99% +0.05%
==========================================
Files 31 31
Lines 4932 4935 +3
==========================================
+ Hits 3992 3997 +5
+ Misses 940 938 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MfKrZ874H9yYqThyTNK88t
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.
Fixes #519.
Summary
alchemiscale apiandalchemiscale compute apidiscarded theJWT_SECRET_KEY/--jwt-secretthey were given: the option'sgenerate_secret_keycallback ignoredvalueand always returned a freshly generated key, which then overrode the environment settings viadependency_overrides. Every API process therefore signed tokens with its own private key, so tokens failed with401on other replicas and were invalidated on every restart.Changes
alchemiscale/cli.py: the callback now passes through a supplied secret and only generates a random key when none is given. When it does generate one, it prints a warning to stderr, so a deployment missing the key no longer fails silently. Removed the stale "CONSIDER GENERATING…" comments in bothapicommands, since this now implements that behaviour. Updated the--jwt-secrethelp text.alchemiscale/tests/integration/test_cli.py: tests that a secret supplied by option or env var is used unchanged with no warning, and that with no secret a warning is printed and each invocation gets a different random key.docs/deployment.rst: note thatJWT_SECRET_KEYmust be set and shared across all API processes.news/issue-519.rst: changelog fragment.Testing
I couldn't run the full test suite here because the conda-only dependencies (openff) weren't available. Instead, I ran the
jwt_paramscallback throughCliRunnerwith those imports stubbed out:--jwt-secret abc→abcJWT_SECRET_KEY=fromenv→fromenvblack --checkpasses on the changed files. CI needs to run the new tests intest_cli.py.Generated by Claude Code