feat(relay): refuse to boot with --insecure-listen in production (#77)#82
Merged
Conversation
Adds the PYRYCODE_RELAY_PRODUCTION=1 contract and a boot-time check that returns ErrInsecureListenInProduction when production mode is on AND --insecure-listen is set. Wired into cmd/pyrycode-relay/main.go after flag-parse with structured remediation logging and exit 2. The env var is read via an injected getter so tests cover the matrix without mutating process env.
Contributor
Author
Code Review: #77Decision: PASS FindingsNone. SummaryClean additive change: new file Verified against the criteria:
Test, vet, and build are green locally. CI Ready to merge once remaining CI checks complete. |
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.
What
Adds a boot-time check that refuses to start the relay when
PYRYCODE_RELAY_PRODUCTION=1AND--insecure-listenis set. Defines thePYRYCODE_RELAY_PRODUCTIONcontract (exact\"1\"means on; anything else means off) as the canonical signal for production mode — sibling startup checks (#78) will reuse this.internal/relay/production.go— exportsIsProductionMode,CheckInsecureListenInProduction, and the sentinelErrInsecureListenInProduction.cmd/pyrycode-relay/main.goafter flag-parse, before any listener is started, with structured logging (env_var,fix) andos.Exit(2)to match the existing flag-validation guard.func(string) stringtest seam — never mutated process env.Issue
Closes #77.
Testing
internal/relay/production_test.gocovers:IsProductionModevalue matrix (8 cases, including the non-\"1\"rows that lock in the exact-match contract against futurestrconv.ParseBooldrift).CheckInsecureListenInProduction2×2 AC matrix.errors.Is.All tests pass under
go test -race ./...;go vet ./...clean; binary builds.Architecture compliance
Follows the spec at
docs/specs/architecture/77-refuse-insecure-listen-in-production.mdexactly: injected-getter seam (no process-env mutation), exact-string match (no truthy parsing), lazy read on every call, exit code 2, structured log fields named in the AC, noConfigstruct (premature abstraction). Mirrors theErrCacheDirInsecure(#9) sentinel pattern and thePYRYCODE_RELAY_SINGLE_INSTANCE(#39/#64) env-var shape. Per the security review's SHOULD FIX, the log line names the env var by name only — never logs its value.