Skip to content

chore: clone config.env in genEnv to prevent shared-object mutation#2981

Open
joonas wants to merge 1 commit intodefenseunicorns:mainfrom
joonas:fix/environment-mutates-shared-config-env
Open

chore: clone config.env in genEnv to prevent shared-object mutation#2981
joonas wants to merge 1 commit intodefenseunicorns:mainfrom
joonas:fix/environment-mutates-shared-config-env

Conversation

@joonas
Copy link
Copy Markdown
Member

@joonas joonas commented Mar 1, 2026

Description

genEnv deleted config.env["PEPR_WATCH_MODE"] directly from the caller's ModuleConfig reference. Since the same config object is passed twice (once for the admission deployment and once for the watcher deployment) the first call permanently removed the key. Any code reading config.env after the first genEnv call would no longer see PEPR_WATCH_MODE.

Shallow-clone config.env into a local cfg object and delete the key from the clone instead. This preserves the original config while still preventing a user-supplied PEPR_WATCH_MODE from overriding the programmatic value controlled by the watchMode parameter.

Both regression tests assert config.env identity via snapshot comparison rather than checking genEnv return values. The def object always supplies PEPR_WATCH_MODE from the watchMode parameter, so output-based assertions pass even with the mutation bug present. Existing tests already cover output correctness for each mode.

End to End Test:
(See Pepr Excellent Examples)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Other (security config, docs update, etc)

Checklist before merging

@joonas joonas requested a review from a team as a code owner March 1, 2026 05:21
@github-project-automation github-project-automation bot moved this to 👀 In review in Pepr Project Board Mar 2, 2026
@cmwylie19 cmwylie19 changed the title fix: clone config.env in genEnv to prevent shared-object mutation chore: clone config.env in genEnv to prevent shared-object mutation Mar 2, 2026
`genEnv` deleted `config.env["PEPR_WATCH_MODE"]` directly from the
caller's `ModuleConfig` reference. Since the same config object is
passed twice (once for the admission deployment and once for the
watcher deployment) the first call permanently removed the key.
Any code reading `config.env` after the first `genEnv` call would
no longer see `PEPR_WATCH_MODE`.

Shallow-clone `config.env` into a local `cfg` object and delete
the key from the clone instead. This preserves the original config
while still preventing a user-supplied `PEPR_WATCH_MODE` from
overriding the programmatic value controlled by the `watchMode`
parameter.

Both regression tests assert `config.env` identity via snapshot
comparison rather than checking `genEnv` return values. The `def`
object always supplies `PEPR_WATCH_MODE` from the `watchMode`
parameter, so output-based assertions pass even with the mutation
bug present. Existing tests already cover output correctness for each mode.

Signed-off-by: Joonas Bergius <joonas@defenseunicorns.com>
@samayer12 samayer12 force-pushed the fix/environment-mutates-shared-config-env branch from d9479f9 to bcdf37e Compare March 17, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

2 participants