Repository navigation
fix: keep local env files out of builds - #68
Conversation
.gitignore ignored every .env* file, the committed .env.example included, so edits to the example could be missed. Ignore all env files except .env.example. Refs #53 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fail the Lint job if an env file other than .env.example is committed, or if local env files in the build context would be copied into the Docker image, so a gap in .gitignore or .dockerignore can't go unnoticed. Refs #53 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Say that .env.example is the only committed env file, that all settings are read on the server at runtime, that the image holds no env files and takes no build settings, and how to pass settings to a container. Replace the stale VITE_HOST_URI note and fix the link to the deployment guide. Closes #53 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build the check image from a git archive of HEAD instead of the checkout, so that the dummy env files can't overwrite or delete real ones when the step is run locally. Match only .env and .env.* names when looking for committed env files, and drop --no-cache. Refs #53 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the README note and leave the details to the deployment guide. Say that Docker keeps quotes in --env-file values, and that NODE_ENV and the Secure cookie flag are fixed at build time, not at runtime. Refs #53 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reviewer's GuideConfigurationUpdate Git and Docker ignore rules so only the top-level
DocumentationExplain how environment settings are supplied at runtime and which settings are public, while correcting the development-origin and production-cookie guidance.
TestsAdd CI checks that reject committed env files other than the top-level example and verify local env files are excluded from the Docker build context.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path=".github/workflows/checks.yml" line_range="30" />
<code_context>
+ # only `.env.example` may be committed; settings come in at runtime
+ - name: Check that no env files are committed
+ run: |
+ tracked="$(git ls-files | grep -E '(^|/)\.env(\..*)?$' | grep -vE '(^|/)\.env\.example$' || true)"
+ if [ -n "$tracked" ]; then
+ echo "::error::Env files must not be committed: ${tracked}"
</code_context>
<issue_to_address>
**Lint fails on dev**
When the workflow runs on `dev` while `.env.production` remains tracked, `git ls-files` puts `.env.production` in `tracked`, so the guard exits 1 and the Lint job fails, blocking dependent checks and PRs targeting `dev`.
Remove the tracked `.env.production` from `dev` or reconcile the check with that branch's existing file.
</issue_to_address>
### Comment 2
<location path=".github/workflows/checks.yml" line_range="30" />
<code_context>
+ # only `.env.example` may be committed; settings come in at runtime
+ - name: Check that no env files are committed
+ run: |
+ tracked="$(git ls-files | grep -E '(^|/)\.env(\..*)?$' | grep -vE '(^|/)\.env\.example$' || true)"
+ if [ -n "$tracked" ]; then
+ echo "::error::Env files must not be committed: ${tracked}"
</code_context>
<issue_to_address>
**Nested example secrets enter image**
When a nested `.env.example` contains secrets or deployment settings, the `tracked` filter accepts `.env.example` at any depth, and the Docker build-context check also ignores that basename, so CI accepts the file and `COPY . .` puts it in the image.
Make the `.env.example` exception root-only in the tracked-file check and the build-context rules.
Also at `.github/workflows/checks.yml:50`.
</issue_to_address>
### Comment 3
<location path="docs/deployment.md" line_range="116" />
<code_context>
+- Docker: `docker run --env-file krini.env ...`, with `krini.env` kept outside the repository and the build context. Docker reads plain `KEY=value` lines and doesn't strip quotes, so write `PRIVACY_CONTROLLER=Example Institute, Example City`, not `PRIVACY_CONTROLLER="..."`.
+- Kubernetes or OpenShift: a `ConfigMap` for the non-secret settings and a `Secret` for `OIDC_CLIENT_SECRET`, referenced with `envFrom` or `env[].valueFrom` in the deployment.
+
+Changing a setting needs a restart, not a new image. Krini uses no `NEXT_PUBLIC_*` variables, so no setting is sent to the browser; never put a secret into one.
+
### Production Considerations
</code_context>
<issue_to_address>
**Public settings are described as private**
When a user follows the deployment guide’s statement literally, `login-redirect` puts `OIDC_CLIENT_ID`, `OIDC_REDIRECT_URI`, and `OIDC_SCOPE` in the redirect URL, and `/privacy` renders `PRIVACY_*` values into HTML, so the blanket claim that no setting is sent to the browser is false.
Clarify that server settings are not bundled into client-side JavaScript, while identifying the public settings intentionally exposed through redirects and rendered pages.
</issue_to_address>
### Comment 4
<location path=".github/workflows/checks.yml" line_range="44" />
<code_context>
+ context="$(mktemp -d)"
+ git archive HEAD | tar -x -C "${context}"
+ mkdir -p "${context}/env-check"
+ for file in .env .env.local .env.production env-check/.env env-check/.env.local; do
+ touch "${context}/${file}"
+ done
</code_context>
<issue_to_address>
**Uncovered env variants pass check**
When `.dockerignore` is narrowed to allow an env-file variant missing from the fixture list, the fixture loop creates only the listed filenames, so the Docker build check passes without testing the newly allowed variant; `COPY . .` can then include a real file with that name in the image.
Extend the fixtures to cover the env-file variants the ignore rules are intended to exclude.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: .github/workflows/checks.yml:30, .github/workflows/checks.yml:30, .github/workflows/checks.yml:44
Restrict the .env.example exception in .gitignore, .dockerignore and both CI checks to the top-level file, so a nested .env.example can't slip into the repository or the image. Let the image check cover more env file variants at the top level and in a subdirectory. Say in the deployment guide which settings are public by design and reach the browser (OIDC client ID, redirect URI and scope, privacy notice details), as opposed to being built into client code. Refs #53 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@AnonymousXC this is ready for your review (see #53). Feel free to merge as is, ask for changes, or adjust it yourself. |
Brings in the CI workflow (#60) and the env file checks (#68). The README note on the login host keeps the wording of this PR and adds where to set the two variables. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Issue #53 was written for the old Vite app. On
staging(the Next.js rewrite) most of it is already in place, so this PR closes the remaining gaps and adds a check so they stay closed:.dockerignorealready excludes**/.envand**/.env.*,*.pemand*.key, and has no inline comments. Its.env.exampleexception now applies to the top-level file only..gitignoreignored.env*including the committed.env.example; it now un-ignores the top-level/.env.example.stagingis.env.example. (.env.productionfrom the Vite app is still tracked ondev, see below.)NEXT_PUBLIC_*variables andnext.config.tshas noenvkey. Allprocess.envreads are in route handlers, server components andsrc/lib/privacy.ts, so no setting is built into the client bundle (some, like the OIDC client ID and the privacy notice details, are public by design and reach the browser through the login redirect and rendered pages; the docs say so).NODE_ENVis the exception that is fixed at build time (next build), which the docs now say..env.exampleis committed. The other builds a throwaway busybox image from agit archive HEADcopy of the repository with dummy.env,.env.localand.env.{development,production,test}[.local]files at the top level and in a subdirectory, plus a nested.env.example, and fails if any of them would be in the Docker build context (the Dockerfile copies the context withCOPY . .).docs/deployment.mdsay that.env.exampleis the only committed env file, that settings are read on the server at runtime and are passed to the container at start (Docker--env-file, Kubernetes/OpenShift ConfigMap + Secret), that no setting is built into client code, and which settings are public by design. Also replaced the staleVITE_HOST_URInote, fixed the link todocs/deployment.md(wasdocs/DEPLOYMENT.md), and corrected theNODE_ENV/Securecookie lines.Note on Git history (please check)
stagingtracks no env file except.env.example, butdev(the old Vite app) still tracks.env.production, and it stays in the Git history of the repository either way. I did not read it or any other env file. The maintainer should check whether any value in it (or in older env files in the history) was a secret, and rotate it if so. The new CI check would flag.env.productionon any branch that still tracks it, such asdev.How it was verified
Locally, with Bun 1.2.21:
bun run lint: passed.bun run test:coverage: 12 files, 117 tests passed.bun run build: passed.git archiveof the branch: passed; it fails as expected with**/.env.*removed from.dockerignore, and with the.env.exampleexception widened to any depth.origin/devit would flag.env.production.CI on 61810a7: all checks pass (Lint with both new steps, Test, Build, End-to-end tests, Sourcery, Vercel). On the first push, the
Vercel – krinipreview of theelixir-cloud-aaiVercel team failed, as it did on #64 and #65; it passed on the second push.Declined review findings
.dockerignoreas the real build in seconds, without installing dependencies; the README and the step say "build context", not "image".busybox:1.37isn't tracked by Dependabot: accepted as is; it is a pinned test helper that only runsfind.devis unaffected; a branch that still tracks an env file should fail this check.Open questions
None.
Closes #53
🤖 Generated with Claude Code
Summary by Sourcery
Keep local environment files out of version control and Docker build contexts while documenting runtime configuration and validating these safeguards in CI.
Bug Fixes:
Enhancements:
CI:
.env.exampleand verify Docker build contexts exclude environment files.Documentation:
.env.exampleas the only committed environment file and explain runtime configuration for Docker, Kubernetes, and OpenShift deployments.