Skip to content

fix(dir): refuse a negative policy refresh_interval at load - #2496

Merged
tkircsi merged 2 commits into
agntcy:mainfrom
sarankumar1325:fix/refuse-negative-policy-refresh-interval
Nov 12, 2026
Merged

tkircsi merged 2 commits into
agntcy:mainfrom
sarankumar1325:fix/refuse-negative-policy-refresh-interval

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor

Fixes #2466.

policy.Config.Validate() already refuses a negative refresh_interval, but no loader calls it, so refresh_interval: -5s loads without complaint. Resolver.Current() treats age >= interval as stale, so a negative interval makes every enforcement stale and a request starts a refresh each time.

Change

Of the two options in the issue, this takes refuse, and keeps it narrow:

  • server/policy/config: the negative check moves into ValidateRefreshInterval(). Validate() still calls it, so its behaviour doesn't change.
  • server/config.LoadConfig and the daemon's loadConfig call ValidateRefreshInterval() after unmarshal. A negative value now stops the start with the existing message (policy: refresh_interval must not be negative).
  • The rest of Validate() (lists, name uniqueness) is not wired into the loaders. That's the broader behaviour change the issue warns about, so configurations that load today still load.
  • The reconciler loader is unchanged. It doesn't bind refresh_interval and has no gate (see the comment in reconciler/config/config_test.go).
  • GetRefreshInterval() still treats only 0 as unset. A negative value no longer gets past the loaders, so nothing gets silently swapped for the default.

Tests

  • server/config: TestLoadConfig_RefusesANegativePolicyRefreshInterval (DIRECTORY_SERVER_POLICY_REFRESH_INTERVAL=-5s). It fails without the loader change.
  • cli/cmd/daemon: the same case for DIRECTORY_DAEMON_SERVER_POLICY_REFRESH_INTERVAL with the file that carries the policies.
  • server/policy/config: TestValidateRefreshInterval (unset, positive, negative).

go test ./config/ ./policy/config/ (server) and go test ./cmd/daemon/ (cli) pass.

policy.Config.Validate already refused a negative refresh_interval, but no
loader called it, so the server and daemon started with an interval that
made every enforcement stale on arrival and refreshed on each request.

Split the check into ValidateRefreshInterval and call it from the server
and daemon loaders after unmarshal. The rest of Validate is not wired in,
so configurations that load today keep loading. The reconciler does not
bind refresh_interval (it has no gate) and is unchanged.

Fixes agntcy#2466

Signed-off-by: sarankumar1325 <[email protected]>
@sarankumar1325
sarankumar1325 requested a review from a team as a code owner November 11, 2026 04:49
@github-actions github-actions Bot added the size/S Denotes a PR that changes 50-199 lines label Nov 11, 2026
ramizpolic
ramizpolic previously approved these changes 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

✅ All modified and coverable lines are covered by tests.

📢 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 a conflict with the base branch Nov 11, 2026
@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 a conflict with the base branch Nov 11, 2026
…-policy-refresh-interval

Signed-off-by: sarankumar1325 <[email protected]>

# Conflicts:
#	cli/cmd/daemon/config_fileonly_test.go

@tkircsi tkircsi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thanks @sarankumar1325 !

@tkircsi
tkircsi added this pull request to the merge queue Nov 12, 2026
Merged via the queue into agntcy:main with commit a0735ec Nov 12, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 50-199 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: A negative policy refresh_interval is accepted and makes every enforcement stale on arrival

3 participants