Repository navigation
fix(config): never generate a secret the staging/prod validators reject - #948
Merged
Merged
Conversation
generateSecureRandom returned base64url text straight from the random source. About 1 draw in 50,000 (24 chars) to 25,000 (44 chars) contains a blocked substring (test, admin, hasura, 12345, change-me ...), so a fresh staging/prod project got a POSTGRES_PASSWORD or admin secret that validatePasswords refused (E400), after build had already persisted it to .env.secrets. TestSurfaceIdentity hit this on the arm runner (build --plan). Discard a draw that matches insecurePatterns or a placeholder and take the next bytes of the source. A seeded source (plan and apply) skips the same draw both times, so they still agree. A source stuck on a blocked value errors after 32 draws instead of looping.
acamarata
force-pushed
the
fix/flaky-tests-wave6
branch
from
October 25, 2026 20:03
92ac349 to
677785b
Compare
Collaborator
Author
|
Rebased onto origin/main (9 commits behind) and force-pushed (677785b). Full |
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.
Root cause (product bug, not a test race)
TestSurfaceIdentityfailed on the arm runner inbuild --plan(staging fixture) withPOSTGRES_PASSWORD contains insecure pattern(E400, run 40198819060).config.generateSecureRandomreturned raw base64url text, so a random draw sometimes spells one ofinsecurePatterns(test,admin,hasura,12345,secret, ...). In staging/prodvalidatePasswordsthen rejects a value the CLI itself just generated. Build persists generated secrets to.env.secretsbefore it validates, so a real firstnself buildin staging could leave a project permanently failing with E400.Measured on the unfixed generator, 5,000,000 draws each: 107 rejected at 24 chars (POSTGRES_PASSWORD), 138 at 32, 195 at 44 (admin secret, JWT key). About 1 in 10,000 fresh staging/prod projects, and the surface test builds several.
Fix
generateSecureRandomdiscards a draw that matchesinsecurePatternsor a placeholder and takes the next bytes of the source. A seeded source (plan and apply share one stream) skips the same draw both times, so they still agree. A source stuck on a blocked value errors after 32 draws.Evidence
TestGenerateSecureRandomSkipsBlockedPatterns(5 blocked prefixes x 24/44 chars),...SkipIsDeterministic,...StuckSourceErrors. Before the fix: 2 of the 3 fail (the generated value isxxTeStxxAAAA...); after: all pass, also with-race.go test ./internal/build/... ./internal/config/... ./cmd/commands/: 5595 passed.TestSurfaceIdentity -count=15after the fix: pass. This is a sanity check only, at 1 in 10,000 it cannot prove the flake gone; the forced-draw tests do.