credentialFile: an embedded string placeholder is refused, but the egress proxy substitutes sentinels as substrings #1508

Closed
opened 2026-10-27 13:40:41 +00:00 by sam · 1 comment
Owner

Found while reviewing archie-core-egkf.14, which merged the scopes and primaryApiKey rendering.

egkf.14 refuses a value placeholder embedded in a larger string ("must be a field's whole value"), calling it a fail-closed reading of a shape the spec does not define. egkf.13 had accepted that shape ("whole value or inside a larger string").

The refusal is not required by the mechanism it protects. The egress proxy substitutes the sentinel as a SUBSTRING, not as an exact value:

  • internal/infrastructure/egress/oauth.go:129 gates on headerCarries(r.Header, rule.sentinels.AccessToken);
  • :145 replaces with strings.ReplaceAll(v, rule.sentinels.AccessToken, current.AccessToken);
  • :165-171 does the same for the refresh token in the body via bytes.Contains / bytes.ReplaceAll.
    So "Bearer {{.AccessToken}}" renders to a sentinel that the proxy still finds and swaps, and the container never sees a real token either way.

Decide: restore embedding for the STRING placeholders (AccessToken, RefreshToken, PrimaryApiKey), where the proxy supports it and egkf.13 supported it; and keep the refusal for the TYPED ones ({{.Scopes}}, an array), where embedding is genuinely ill-defined because the leaf has no string form. That is a narrower, better-grounded rule than refusing both.

Evidence to keep: the proxy's substring semantics above, and egkf.14's test that pins the current refusal so a change is deliberate.


Imported from beads archie-core-pa4q · GitHub #1386 · type task · priority P3 · created 2026-09-29

Found while reviewing archie-core-egkf.14, which merged the scopes and primaryApiKey rendering. egkf.14 refuses a value placeholder embedded in a larger string ("must be a field's whole value"), calling it a fail-closed reading of a shape the spec does not define. egkf.13 had accepted that shape ("whole value or inside a larger string"). The refusal is not required by the mechanism it protects. The egress proxy substitutes the sentinel as a SUBSTRING, not as an exact value: - internal/infrastructure/egress/oauth.go:129 gates on headerCarries(r.Header, rule.sentinels.AccessToken); - :145 replaces with strings.ReplaceAll(v, rule.sentinels.AccessToken, current.AccessToken); - :165-171 does the same for the refresh token in the body via bytes.Contains / bytes.ReplaceAll. So "Bearer {{.AccessToken}}" renders to a sentinel that the proxy still finds and swaps, and the container never sees a real token either way. Decide: restore embedding for the STRING placeholders (AccessToken, RefreshToken, PrimaryApiKey), where the proxy supports it and egkf.13 supported it; and keep the refusal for the TYPED ones ({{.Scopes}}, an array), where embedding is genuinely ill-defined because the leaf has no string form. That is a narrower, better-grounded rule than refusing both. Evidence to keep: the proxy's substring semantics above, and egkf.14's test that pins the current refusal so a change is deliberate. --- _Imported from beads `archie-core-pa4q` · GitHub #1386 · type task · priority P3 · created 2026-09-29_
sam added the lowtask labels 2026-10-27 13:40:41 +00:00
sam self-assigned this 2026-10-27 13:40:41 +00:00
Author
Owner

Triaged: no code change is needed for this. No code change: the rule the issue asks for is already the shipped rule for the placeholders the proxy actually substring-substitutes.

Embedding is not refused for AccessToken/RefreshToken. internal/infrastructure/kit/credential_file.go:99 runs spliceSentinels on every non-exact string leaf, and :135-147 replaces {{.AccessToken}} and {{.RefreshToken}} inside a larger string, so "Bearer {{.AccessToken}}" renders to "Bearer <sentinel>" today. egkf.14 refuses only the typed/omitted leaves, not the token ones.

What is refused is {{.ExpiresAt}}, {{.Scopes}}, {{.PrimaryApiKey}} embedded (credential_file.go:155-166). {{.Scopes}} is the array the issue wants refused; {{.ExpiresAt}} is an int64 epoch-ms (:37-40), so it belongs with the typed ones too, not the string ones.

The proxy evidence in the issue checks out, and matches the code above: headerCarries uses strings.Contains (egress/oauth.go:300-309), injectOAuth ReplaceAlls every header value (oauth.go:148-152), interceptOAuth does bytes.Contains/bytes.ReplaceAll on the token body (oauth.go:168-172).

The one residual ask — embedding {{.PrimaryApiKey}} — is not a value placeholder here. credential_file.go:18-20 and :61-63 treat it as the spec's omission marker and drop the enclosing key. It also is not substring-substituted by the proxy: API keys are injected by overwriting the header from the Kit's own rule (egress/credentials.go:113, r.Header.Set(rule.header, fmt.Sprintf(rule.format, secret))) under a single shared sentinel constant (credentials.go:18, SentinelEnv at :118-128). A sentinel spliced into a file string would reach upstream literally unless the Kit's inject rule names the same header, so restoring that embedding would not do what the issue expects.

Not verified: the sandbox-kit-spec/v3 v3.0.0-m.8 source (go.mod:78) — outside this worktree. The omit-marker reading of {{.PrimaryApiKey}} rests on the in-repo comment at credential_file.go:18-19, not on the spec text.

The evidence the issue asks to keep does not exist. No test covers credential_file.go: kit_test.go has three tests, and its only credential-file fixture (kit_test.go:196) uses a whole-value {{.AccessToken}} and asserts only that the file is present (:207-213). Nothing pins the "must be a field's whole value" refusal, so egkf.14's pinning test was never committed in this tree.

Follow-up not started: add the missing pins — embedded AccessToken/RefreshToken accepted with the sentinel spliced in, embedded Scopes/ExpiresAt/PrimaryApiKey refused. If the operator instead wants {{.PrimaryApiKey}} treated as a rendered string rather than an omission marker, that is a spec question to settle before code, not a defect.

Triaged: no code change is needed for this. No code change: the rule the issue asks for is already the shipped rule for the placeholders the proxy actually substring-substitutes. **Embedding is not refused for AccessToken/RefreshToken.** `internal/infrastructure/kit/credential_file.go:99` runs `spliceSentinels` on every non-exact string leaf, and `:135-147` replaces `{{.AccessToken}}` and `{{.RefreshToken}}` inside a larger string, so `"Bearer {{.AccessToken}}"` renders to `"Bearer <sentinel>"` today. egkf.14 refuses only the typed/omitted leaves, not the token ones. **What is refused** is `{{.ExpiresAt}}`, `{{.Scopes}}`, `{{.PrimaryApiKey}}` embedded (`credential_file.go:155-166`). `{{.Scopes}}` is the array the issue wants refused; `{{.ExpiresAt}}` is an int64 epoch-ms (`:37-40`), so it belongs with the typed ones too, not the string ones. **The proxy evidence in the issue checks out**, and matches the code above: `headerCarries` uses `strings.Contains` (`egress/oauth.go:300-309`), `injectOAuth` `ReplaceAll`s every header value (`oauth.go:148-152`), `interceptOAuth` does `bytes.Contains`/`bytes.ReplaceAll` on the token body (`oauth.go:168-172`). **The one residual ask — embedding `{{.PrimaryApiKey}}` — is not a value placeholder here.** `credential_file.go:18-20` and `:61-63` treat it as the spec's omission marker and drop the enclosing key. It also is not substring-substituted by the proxy: API keys are injected by overwriting the header from the Kit's own rule (`egress/credentials.go:113`, `r.Header.Set(rule.header, fmt.Sprintf(rule.format, secret))`) under a single shared sentinel constant (`credentials.go:18`, `SentinelEnv` at `:118-128`). A sentinel spliced into a file string would reach upstream literally unless the Kit's inject rule names the same header, so restoring that embedding would not do what the issue expects. **Not verified:** the `sandbox-kit-spec/v3 v3.0.0-m.8` source (`go.mod:78`) — outside this worktree. The omit-marker reading of `{{.PrimaryApiKey}}` rests on the in-repo comment at `credential_file.go:18-19`, not on the spec text. **The evidence the issue asks to keep does not exist.** No test covers `credential_file.go`: `kit_test.go` has three tests, and its only credential-file fixture (`kit_test.go:196`) uses a whole-value `{{.AccessToken}}` and asserts only that the file is present (`:207-213`). Nothing pins the `"must be a field's whole value"` refusal, so egkf.14's pinning test was never committed in this tree. Follow-up not started: add the missing pins — embedded AccessToken/RefreshToken accepted with the sentinel spliced in, embedded Scopes/ExpiresAt/PrimaryApiKey refused. If the operator instead wants `{{.PrimaryApiKey}}` treated as a rendered string rather than an omission marker, that is a spec question to settle before code, not a defect.
sam closed this issue 2026-11-08 12:12:10 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: sam/archie#1508