Skip to content

fix(dir): refuse an environment variable over any configuration block - #2497

Merged
ramizpolic merged 1 commit into
agntcy:mainfrom
sarankumar1325:fix/refuse-env-over-config-block
Nov 11, 2026
Merged

ramizpolic merged 1 commit into
agntcy:mainfrom
sarankumar1325:fix/refuse-env-over-config-block

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor

Fixes #2464

What

A variable for a non-leaf key, like DIRECTORY_DAEMON_RECONCILER, replaced every setting under that block, even when it was set but empty. With the reconciler block emptied, policy_evaluation.enabled went back to its false default. The daemon then started, produced no verdicts, and served every record while its read gate was configured.

As the issue suggests, this is a general rule rather than more entries in the #2462 list:

  • New env.CheckBlocks(prefix, keys) in utils/env. It works out the blocks from the leaf keys the loader already holds (v.AllKeys() after the config is read). Each proper prefix of a key counts as a block. It then refuses any <PREFIX>_<BLOCK> variable that is present in the environment, empty or not, and names it. If a leaf happens to map to the same variable name as a block, the leaf wins.
  • The apiserver, the standalone reconciler and the daemon loaders call it right after the existing CheckFileOnly, so the policy-specific messages from [Bug]: An environment variable for a policy list silently empties it, and the node starts enforcing nothing #2462 are unchanged.
  • A short note in dir-content-policy-enforcement.md.

I left the second idea in the issue (refuse to start when policies are configured but policy_evaluation.enabled is off) out of this PR. It changes a default behaviour, and maintainers may want to decide on it separately.

Tests

  • utils/env: blocks_test.go covers refusal for nested and top-level blocks ("" and "x"), settings still accepted, another prefix ignored, and a leaf that shares a block's variable name.
  • cli/cmd/daemon: TestLoadConfig_RefusesAVariableOverAnyBlock (DIRECTORY_DAEMON_RECONCILER, ..._RECONCILER_POLICY_EVALUATION, DIRECTORY_DAEMON_SERVER) fails without the loader change. TestLoadConfig_AcceptsASettingUnderABlock checks that a leaf setting still works.
  • reconciler/config: RECONCILER_POLICY_EVALUATION is refused.
  • go test passes in utils ./env, cli ./cmd/daemon, server ./config and reconciler ./config. golangci-lint run reports 0 issues on utils/env and cli/cmd/daemon.

A variable over a non-leaf key, such as DIRECTORY_DAEMON_RECONCILER, replaced
every setting under it, even when empty. The daemon then started with policy
evaluation off and served every record despite its configured gate.

Each loader now derives the blocks from the keys viper already holds and
refuses a variable set for one, naming it.

Fixes agntcy#2464

Signed-off-by: sarankumar1325 <[email protected]>
@sarankumar1325
sarankumar1325 requested a review from a team as a code owner November 11, 2026 05:18
@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Nov 11, 2026

@ramizpolic ramizpolic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@codecov

codecov Bot commented Nov 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/config/config.go 50.0% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@ramizpolic
ramizpolic added this pull request to the merge queue Nov 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 11, 2026
@ramizpolic
ramizpolic added this pull request to the merge queue Nov 11, 2026
Merged via the queue into agntcy:main with commit 2d1c96a Nov 11, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 200-999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: An environment variable over a parent block empties it, and a daemon starts serving everything with its gate configured

2 participants