Skip to content

collectors: resolve the scoped grant before the environment (OPS-1120) [ZC:   WW.3.S] - #2091

Merged
jaywedgeworth22 merged 4 commits into
mainfrom
zc/ops-1120-token-provenance
Nov 25, 2026
Merged

jaywedgeworth22 merged 4 commits into
mainfrom
zc/ops-1120-token-provenance

Conversation

@jaywedgeworth22

@jaywedgeworth22 jaywedgeworth22 commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Fixes OPS-1120 is not claimed here: those two sites keep the issue open.  Refs OPS-1120.

Resolves collector ingest tokens store-first for OPS-1120. resolveCollectorToken now consults this consumer's scoped Infisical binding before the environment for each name in order, so a reviewed grant cannot lose to a value merely present in the environment. Environment values shaped like an Infisical service token are refused outside COLLECTOR_STRICT_INJECTED_SECRETS=1, because the synchronous resolver cannot prove the grant from metadata; static producer app bearers continue to work from the host bootstrap store when the scoped store has no answer. Strict injected-secrets mode skips the runtime lookup entirely, and deferred store failures are rethrown only when no name yields a value. Docs in AGENTS.md updated with provenance order. Tests added in scripts/__tests__/resolve-collector-token.test.mjs covering store-first precedence, environment fallback, service-token refusal/allowance, strict-mode bypass of lookup, and deferred failure handling, and the file was added to the collectors Vitest config. Test execution, deployment, and runtime verification are unverified. Open automated review findings remain unresolved: strict-mode bypass of service-token shape refusal, and whitespace-padded strict flag silently disabling strict mode.


Resolves collector ingest token via scoped store grant before environment fallback for OPS-1120. Environment values remain trimmed fallback only when the store has no usable value.

Behavior

  • A service-token-shaped environment value is refused for that name without blocking later candidates; the refusal is raised only when no candidate yields a usable value. Strict injected-secrets mode treats a whitespace-padded flag as strict and continues to skip runtime lookup.

Tests

  • Added coverage that a refused first name still allows a valid later candidate to resolve. Added coverage that a padded strict flag stays strict and that store-first precedence with trimmed environment fallback holds. Run results, deployment verification, and unresolved risks were not provided in the changes reviewed. Automated code review reported no issues in the reviewed changes.

Summary

Updates collector token resolution to check the scoped secret-store grant before the environment (OPS-1120). Lookup failures are now tracked separately from environment shape refusals, so a scoped-read infrastructure error outranks a shape refusal and all refused candidate names are reported together when no usable value resolves.

Changes

  • Keeps store-first precedence for collector tokens while preserving strict-injected handling.
  • Defers environment service-token shape refusals per candidate instead of keeping only the first.
  • Throws the deferred scoped-read failure first when no candidate resolves; otherwise throws one error naming every refused variable.
  • Adds tests covering multi-name refusal reporting and scoped-read failure precedence.

Verification

Tests added but no run results, deployment, or runtime verification were reported in the provided context. Automated code review reported no issues. Operational behavior beyond the added unit coverage remains unverified.

@linear-code

linear-code Bot commented Nov 25, 2026

Copy link
Copy Markdown

OPS-1120

@jaywedgeworth22

Copy link
Copy Markdown
Member Author

@kody start-review
[ZC:   WW.3.S]
Head a4dfd05 on zc/ops-1120-token-provenance (base main).

Reorders resolveCollectorToken to store-first, refuses service-token-shaped environment values outside strict-injected mode, and wires the previously-unrun resolve-collector-token suite into the collectors vitest config. No token values or secrets in the diff.

@jaywedgeworth22
jaywedgeworth22 enabled auto-merge (squash) November 25, 2026 10:22
@kody-ai

kody-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ✅

Access your configuration settings here.

​

@github-actions
github-actions Bot disabled auto-merge November 25, 2026 10:23
@kody-ai

kody-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Automatic approval held

Kody's assessment:

Risk was identified in this PR.

@kody-ai

This comment has been minimized.

`resolveCollectorToken` read the environment first and returned immediately, so a value
sitting in the environment beat the reviewed Infisical grant and nothing proved where it
came from.  It now asks the consumer's scoped Infisical binding first, per name, and
consults the environment only for a name the store did not answer.

An environment value shaped like an Infisical service token (`st.<id>.<secret>`) is now
refused outside `COLLECTOR_STRICT_INJECTED_SECRETS=1`, because this synchronous resolver
cannot read that token's own metadata to prove whose narrow grant it is.  Strict-injected
mode is a delivery channel (the injector already read the store), so it is exempt.  The documented static producer tokens (`<PRODUCER>_INGEST_TOKEN`, `USAGE_INGEST_TOKEN`) are
app bearers rather than Infisical grants and keep resolving from the host bootstrap store;
a production smoke test over the server collector env resolved every producer name unchanged.

Also wires `scripts/__tests__/resolve-collector-token.test.mjs` into the collectors vitest
config.  That suite existed but no runner included it (the main config excludes
`scripts/__tests__/**` and the collectors config listed three other files), so the token
precedence contract it pins had been gating nothing.  Its service-token fixture is built
at runtime so no token-shaped literal enters the tree.
@jaywedgeworth22
jaywedgeworth22 force-pushed the zc/ops-1120-token-provenance branch from d80c56e to b4db6db Compare November 25, 2026 10:26
@jaywedgeworth22

Copy link
Copy Markdown
Member Author

@kody start-review
[ZC:   WW.3.S]
Head b4db6db on zc/ops-1120-token-provenance (base main), squashed after the fixture fix so the scanner range carries no token-shaped literal.

Store-first resolveCollectorToken, service-token-shaped env refusal outside strict-injected mode, and the previously-unrun resolve-collector-token suite wired into the collectors vitest config. Docs: AGENTS.md provenance line.

@jaywedgeworth22
jaywedgeworth22 enabled auto-merge (squash) November 25, 2026 10:27
@github-actions
github-actions Bot disabled auto-merge November 25, 2026 10:28
kody-ai[bot]
kody-ai Bot previously requested changes Nov 25, 2026

@kody-ai kody-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.

Found critical issues please review the requested changes

Kody takes this request back once the findings above are resolved.

…d name

Review findings on the store-first change.  Two fixture cases in
`scripts/__tests__/run-session-token-collector.fixture.mjs` still asserted the old
environment-first contract and failed under `test:collector-runtime`; they now assert the
store value wins and that the environment is trimmed and returned only after the store
answers empty.

A refused service-token-shaped environment value is now deferred instead of thrown at once,
so one poisoned candidate name cannot block a valid `USAGE_INGEST_TOKEN` under a later name;
the refusal is raised only when no name yields a usable value.
@kody-ai

This comment has been minimized.

`COLLECTOR_STRICT_INJECTED_SECRETS` was compared with exact `=== "1"`, so a padded
value silently dropped the process into the non-strict path: extra scoped reads and a
spurious shape refusal.  It is trimmed like the token values now, with a test.
@jaywedgeworth22

Copy link
Copy Markdown
Member Author

@kody start-review
[ZC:   WW.3.S]
Head 443aca2 on zc/ops-1120-token-provenance (base main) after triaging the previous findings.

Two fixed (runtime fixture store-first assertions; deferred refusal so a poisoned name cannot block a valid later candidate) and one more fixed since (whitespace-padded COLLECTOR_STRICT_INJECTED_SECRETS now trimmed). The performance and env-control findings are declined with reasons in their threads. Suites: 120 vitest + 75 fixture checks.

@jaywedgeworth22
jaywedgeworth22 enabled auto-merge (squash) November 25, 2026 10:37
@github-actions
github-actions Bot disabled auto-merge November 25, 2026 10:37
@kody-ai

This comment has been minimized.

@kody-ai
kody-ai Bot dismissed their stale review November 25, 2026 10:43

The critical findings behind this request are resolved.

`deferredFailure ??=` kept only the first deferred error, so a second refused name or a
scoped-read failure behind a shape refusal was silently dropped and diagnosing took one run
per problem.  The resolver now keeps the two kinds apart: a failed scoped read is thrown
in preference to a shape refusal because it is the more actionable error, and when no value
resolves the refusal names every refused candidate at once.
@jaywedgeworth22

Copy link
Copy Markdown
Member Author

@kody start-review
[ZC:   WW.3.S]
Head 939f69c on zc/ops-1120-token-provenance (base main).

Last finding fixed: deferred failures are now kept in two slots, a scoped-read failure outranks a shape refusal, and every refused name is named at once. All threads resolved. Suites: 122 vitest + 75 fixture checks.

@jaywedgeworth22
jaywedgeworth22 enabled auto-merge (squash) November 25, 2026 14:27
@kody-ai

kody-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ✅

Access your configuration settings here.

​

@github-actions
github-actions Bot disabled auto-merge November 25, 2026 14:28
@jaywedgeworth22
jaywedgeworth22 enabled auto-merge (squash) November 25, 2026 14:37
@github-actions
github-actions Bot disabled auto-merge November 25, 2026 14:37
@jaywedgeworth22
jaywedgeworth22 merged commit 6dc0b8b into main Nov 25, 2026
24 checks passed
@jaywedgeworth22
jaywedgeworth22 deleted the zc/ops-1120-token-provenance branch November 25, 2026 14:43
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.

1 participant