fix: don't report success when JWT secret generation fails - #47
Open
pucedoteth wants to merge 1 commit into
Open
fix: don't report success when JWT secret generation fails#47pucedoteth wants to merge 1 commit into
pucedoteth wants to merge 1 commit into
Conversation
The jwt-generator entrypoint ends in `|| exit 0`:
[ ! -s /shared/jwtsecret.key ] && openssl rand -hex 32 | tr -d '\n' > /shared/jwtsecret.key || exit 0
The `||` is reached in two different situations: when the key already exists,
which is the intended no-op, and when the key was missing but generating it
failed. A full disk or an unwritable /shared both take the second path and the
container still exits 0:
$ sh -c "[ ! -s ./ro/jwtsecret.key ] && openssl rand -hex 32 | tr -d '\n' > ./ro/jwtsecret.key || exit 0"
sh: ./ro/jwtsecret.key: Permission denied
exit code: 0
key present: NO
service_completed_successfully is then satisfied, and both clients start against
an absent secret — the state the `-s` test was added to prevent, arrived at from
the other direction. reth and op-node fail on authrpc some seconds later, far
from the cause.
Generate into a temp file, check it is non-empty, and move it into place under
`set -e`, so a failed generation exits non-zero and never leaves a partial
secret where a reader could pick it up.
Behaviour is unchanged on every path that works today: an existing key is left
alone, a missing or empty one is (re)generated as 64 hex characters with no
trailing newline.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
The bug
The
jwt-generatorentrypoint ends in|| exit 0:The
||branch is reached in two different situations: when the key already exists — the intended no-op — and when the key was missing but generating it failed. A full disk or an unwritable/sharedtakes the second path, and the container still exits 0:service_completed_successfullyis then satisfied, so both clients start against an absent secret and fail on authrpc some seconds later, far from the cause.That is the same end state the
-stest in "regenerate empty JWT secrets" was added to prevent — reached from the other direction. The check catches a secret that is empty on arrival; this path creates one that is absent on departure.The fix
Generate into a temp file, verify it is non-empty, then move it into place, under
set -e. A failed generation now exits non-zero, and no partial secret is ever visible at the real path for a reader that races the writer.Switched to exec form so the script is readable rather than one long folded line.
Test plan
No test harness in the repo, so I extracted the script exactly as YAML hands it to the container (
yaml.safe_load(...)['services']['jwt-generator']['entrypoint'][2]) and ran it against a real filesystem, with/shared/jwtsecret.keyrepointed at a temp path:Format is preserved — 64 hex characters, no trailing newline — and no
.tmpfile is left behind in any case. The same four cases againstmaingive exit 0 for the unwritable directory with no key produced.One note:
[ -s ... ]is used rather thanset -o pipefail, since the pipeline's status istr's, notopenssl's. Ifopensslfailed whiletrsucceeded, an empty file would be written with status 0 — checking the temp file covers that too, and does not depend onpipefailbeing available in the image's shell.