Skip to content

fix: keep local env files out of builds - #68

Merged
AnonymousXC merged 7 commits into
stagingfrom
fix/53-env-files-staging
Nov 13, 2026
Merged

AnonymousXC merged 7 commits into
stagingfrom
fix/53-env-files-staging

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

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:

  • .dockerignore already excludes **/.env and **/.env.*, *.pem and *.key, and has no inline comments. Its .env.example exception now applies to the top-level file only.
  • .gitignore ignored .env* including the committed .env.example; it now un-ignores the top-level /.env.example.
  • The only committed env file on staging is .env.example. (.env.production from the Vite app is still tracked on dev, see below.)
  • The app reads no NEXT_PUBLIC_* variables and next.config.ts has no env key. All process.env reads are in route handlers, server components and src/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_ENV is the exception that is fixed at build time (next build), which the docs now say.
  • CI (Lint job): two new steps. One fails if an env file other than the top-level .env.example is committed. The other builds a throwaway busybox image from a git archive HEAD copy of the repository with dummy .env, .env.local and .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 with COPY . .).
  • Docs: README and docs/deployment.md say that .env.example is 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 stale VITE_HOST_URI note, fixed the link to docs/deployment.md (was docs/DEPLOYMENT.md), and corrected the NODE_ENV/Secure cookie lines.

Note on Git history (please check)

staging tracks no env file except .env.example, but dev (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.production on any branch that still tracks it, such as dev.

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.
  • The image check, run locally against a git archive of the branch: passed; it fails as expected with **/.env.* removed from .dockerignore, and with the .env.example exception widened to any depth.
  • The tracked-file check: passes on this branch; on origin/dev it would flag .env.production.
  • End-to-end tests: not run locally (unchanged code; CI runs them).

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 – krini preview of the elixir-cloud-aai Vercel team failed, as it did on #64 and #65; it passed on the second push.

Declined review findings

  • Build the real Dockerfile in the check instead of a throwaway image: declined, the throwaway image checks the same context and .dockerignore as the real build in seconds, without installing dependencies; the README and the step say "build context", not "image".
  • busybox:1.37 isn't tracked by Dependabot: accepted as is; it is a pinned test helper that only runs find.
  • Sourcery, "Lint fails on dev": intended. Each branch runs its own workflow, so dev is 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:

  • Prevent local and environment-specific files from being committed or included in Docker build contexts.

Enhancements:

  • Clarify that runtime configuration is supplied to containers and that client-visible settings are limited to values intentionally exposed by the application.
  • Correct environment-variable, deployment, and production cookie documentation for the Next.js application.

CI:

  • Add CI checks that reject tracked environment files other than the top-level .env.example and verify Docker build contexts exclude environment files.

Documentation:

  • Document .env.example as the only committed environment file and explain runtime configuration for Docker, Kubernetes, and OpenShift deployments.

uniqueg and others added 5 commits November 13, 2026 16:29
.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]>
@uniqueg uniqueg self-assigned this Nov 13, 2026
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
krini Ready Ready Preview Nov 13, 2026 5:27pm UTC

@sourcery-ai

sourcery-ai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Configuration

Update Git and Docker ignore rules so only the top-level .env.example is allowed while other local environment files stay out of the repository and build context.

  • .dockerignore L4
  • .gitignore L36-38

Documentation

Explain how environment settings are supplied at runtime and which settings are public, while correcting the development-origin and production-cookie guidance.

  • README.md L38, L45, L102-104
  • docs/deployment.md L212-221, L233-234

Tests

Add 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.

  • .github/workflows/ci.yml L109-142

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@uniqueg
uniqueg marked this pull request as ready for review November 13, 2026 15:47

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread .github/workflows/checks.yml Resolved
Comment thread .github/workflows/checks.yml Resolved
Comment thread docs/deployment.md Resolved
Comment thread .github/workflows/checks.yml Resolved
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]>
@vercel
vercel Bot temporarily deployed to Preview – krini November 13, 2026 16:08 Inactive

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

@uniqueg

uniqueg commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

@AnonymousXC this is ready for your review (see #53). Feel free to merge as is, ask for changes, or adjust it yourself.

@vercel
vercel Bot temporarily deployed to Preview – krini November 13, 2026 17:27 Inactive
@AnonymousXC
AnonymousXC merged commit afaab0a into staging Nov 13, 2026
25 checks passed
@AnonymousXC
AnonymousXC deleted the fix/53-env-files-staging branch November 14, 2026 05:50
uniqueg added a commit that referenced this pull request Nov 14, 2026
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]>

This branch was previously deployed

1 inactive deployment
Preview – krini — f8d7b8f3 Deployed Nov 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants