fix(security): reject unsafe production credentials - #9
Merged
astaxie merged 1 commit intoJul 21, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a safer bootstrap and startup path by adding a dedicated TOKENHUB_BOOTSTRAP_ADMIN_PASSWORD, wiring TOKENHUB_ENV through runtime entrypoints, and enforcing credential strength checks for non-development environments before the backend opens the database or starts serving traffic.
Changes:
- Add
TOKENHUB_BOOTSTRAP_ADMIN_PASSWORDand thread config through seeding/bootstrap paths so the initialadminpassword is configurable. - Add
Config.ValidateForStartup()and call it on startup to reject placeholder/weak secrets outside dev/local/test. - Propagate new env vars through
start.shand Docker Compose, and update EN/zh-CN/ja deployment docs accordingly.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| start.sh | Adds TOKENHUB_ENV, TOKENHUB_BOOTSTRAP_ADMIN_PASSWORD, and TOKENHUB_SECRET_KEY defaults and passes them to the backend process. |
| README.md | Updates quickstart guidance to replace placeholders and documents the new bootstrap password behavior. |
| README.zh-CN.md | Same as README.md for zh-CN. |
| README.ja.md | Same as README.md for ja. |
| docs/deployment.md | Documents the new bootstrap password variable and the non-dev startup validation behavior. |
| docs/zh-CN/deployment.md | Same as docs/deployment.md for zh-CN. |
| docs/ja/deployment.md | Same as docs/deployment.md for ja. |
| deploy/docker-compose.yml | Passes TOKENHUB_ENV and the new bootstrap password into the backend container environment. |
| deploy/.env.example | Adds TOKENHUB_BOOTSTRAP_ADMIN_PASSWORD placeholder to the deployment env template. |
| backend/internal/server/seed.go | Introduces *WithConfig seeding/bootstrap functions and uses configured bootstrap password. |
| backend/internal/server/http_test.go | Adds a regression test ensuring the configured bootstrap password is used instead of the hard-coded default. |
| backend/internal/server/config.go | Extends config with environment + bootstrap password and adds startup validation for non-dev environments. |
| backend/internal/server/config_test.go | Adds tests covering production rejection, production acceptance, and retaining dev defaults. |
| backend/cmd/tokenhub/main.go | Validates config before opening the store or starting the HTTP server; uses *WithConfig seeding/bootstrap. |
| backend/.env.example | Adds dev defaults for TOKENHUB_BOOTSTRAP_ADMIN_PASSWORD and TOKENHUB_SECRET_KEY. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+38
to
+42
| environment := strings.ToLower(strings.TrimSpace(c.Environment)) | ||
| switch environment { | ||
| case "", "dev", "development", "local", "test": | ||
| return nil | ||
| } |
legendtkl
force-pushed
the
agent/secure-production-bootstrap
branch
from
July 21, 2026 16:08
ecf471e to
c75b0fd
Compare
Comment on lines
23
to
+27
| func ConfigFromEnv() Config { | ||
| return Config{ | ||
| Environment: getenv("TOKENHUB_ENV", "dev"), | ||
| AdminToken: getenv("TOKENHUB_ADMIN_TOKEN", "dev_admin_token"), | ||
| BootstrapAdminPassword: getenv("TOKENHUB_BOOTSTRAP_ADMIN_PASSWORD", "admin123456"), |
Comment on lines
+592
to
+594
| store := NewMemoryStore() | ||
| config := ConfigFromEnv() | ||
| config.BootstrapAdminPassword = "configured-bootstrap-password" |
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 changed
TOKENHUB_BOOTSTRAP_ADMIN_PASSWORDand use it when creating the initial administratordev,development,local, andteststart.shand Docker ComposeWhy
Production Compose currently exposes known placeholder tokens and a hard-coded
admin123456password unless operators remember to replace them. The backend also ignoresTOKENHUB_ENV, so there is no runtime safety net.Impact
Production and staging deployments now fail fast with the names of unsafe variables. Existing development workflows continue to work without extra setup. Operators choose the initial administrator password explicitly before first startup.
Validation
go vet ./...git diff --check