Skip to content

feat(controlplane): restrict an API token to a list of artifact digests - #3844

Closed
javirln wants to merge 1 commit into
mainfrom
cas-token-allowed-digests
Closed

javirln wants to merge 1 commit into
mainfrom
cas-token-allowed-digests

Conversation

@javirln

@javirln javirln commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

API tokens can carry an optional list of artifact digests. The CAS credentials and download URL endpoints then issue download credentials for those digests only.

An AI assistant (Claude Code) helped write this change.

An API token can be limited by organization, project, product or
workflow, and by policies, but not to specific artifacts. A client that
hands a token to an untrusted process that must read one artifact needs
that restriction.

API tokens get an optional list of allowed artifact digests. A client
sets it in-process with the APITokenWithAllowedDigests create option.
Create refuses an empty list, a digest that is not a sha256 digest, and
a token whose policies allow an artifact upload.

When the list is set, CASCredentialsService.Get and
CASRedirectService.GetDownloadURL refuse a request with no digest or
with a digest outside the list, Get refuses the uploader role, and the
CAS credential is always scoped to the requested digest. Each RPC
refuses with the error it already uses for an artifact out of reach.

The new api_tokens.allowed_digests column is nullable and has no
default, so existing tokens keep their behavior.

Assisted-by: Claude Code
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>

Chainloop-Trace-Sessions: 5aac1986-3c81-429d-a6e2-ba72c55819b9
@chainloop-platform

chainloop-platform Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PR validation — ⚠️ 2 failing

Status Policy Material Messages
⚠️ Failed pr-min-approvals pr-info
✅ Passed pr-description-required pr-info -
⚠️ Failed pr-user-story-linked pr-info PR/MR #3844 does not reference a user story or issue in title, description, or branch 'feat(controlplane): restrict an API token to a list of artifact digests'. Expected patterns: ["(?i)[A-Z]+-[0-9]+", "#[0-9]+", "(?i)gh-[0-9]+", "(?i)\\[[A-Z]+-[0-9]+\\]"]

View attestation ↗

AI Session Checks — 🟡 85% · ⚠️ 2 failing

Avg score Sessions Failing policies Attribution Files Lines Total Duration
🟡 85% 1 ⚠️ 2 100% AI / 0% Human 15 +436 / -23 315h38m10s

🟡 85% — 100% AI — ⚠️ 2 policies failing

Nov 10, 2026 08:24 UTC · 315h38m10s · $1792.52 · 29.2k in / 15.0M out · claude-code 2.1.321 (claude-opus-5-5)

View session details ↗

Change Summary

Adds optional artifact digest restrictions to API tokens and persists them through request context. Both CAS download paths reject disallowed digests and force scoped credentials; restricted tokens cannot obtain upload credentials. Adds validation, persistence, middleware, and service regression tests.

AI Session Overall Score

🟡 85% — Focused digest restrictions have meaningful tests, but captured execution evidence remains unavailable.

AI Session Analysis Breakdown

🟢 96% · scope-discipline

No notes.

🟢 94% · context-and-planning

🟢 The digest-token breakdown names storage, context propagation, both enforcement paths, compatibility, and negative tests. · High Impact

🟢 94% · solution-quality

🟢 Credential issuance forces digest scoping and independently rejects uploads rather than trusting caller flags or policies. · High Impact

🟢 93% · alignment

No notes.

🟡 75% · user-trust-signal

🟠 The user questioned repeated plan iteration: 'make sure we run the validations, why do we keep iterating on the plans?' · Medium Severity

💡 When review iterations repeat, ask for remaining blockers and completion criteria before another pass.

🟡 65% · verification

🟢 Service tests inspect issued credential digests and reject missing, disallowed, and upload requests across both endpoints. · High Impact

🟠 Captured commands and execution records contain no run of this PR's digest restriction tests; user confirmation is also unavailable. · Medium Severity

💡 Capture the digest restriction unit and integration test results before pushing the prerequisite change.


File Attribution

████████████████████ 100% AI / 0% Human

Status Attribution File Lines
created ai app/controlplane/pkg/biz/apitoken_allowed_digests_test.go +120 / -0
modified ai app/controlplane/internal/service/casredirect_integration_test.go +83 / -0
modified ai app/controlplane/pkg/biz/apitoken.go +61 / -0
modified ai app/controlplane/pkg/biz/apitoken_integration_test.go +45 / -0
modified ai app/controlplane/internal/service/cascredential_test.go +44 / -0
modified ai app/controlplane/internal/usercontext/apitoken_middleware.go +16 / -15
modified ai app/controlplane/internal/service/cascredential.go +27 / -1
modified ai app/controlplane/internal/usercontext/apitoken_middleware_test.go +12 / -0
modified ai app/controlplane/pkg/data/ent/migrate/schema.go +6 / -5
modified ai app/controlplane/internal/service/casredirect.go +7 / -1
modified ai app/controlplane/pkg/data/apitoken.go +5 / -0
modified ai app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum +2 / -1
modified ai app/controlplane/pkg/data/ent/schema/apitoken.go +3 / -0
modified ai app/controlplane/pkg/usercontext/entities/apitoken.go +3 / -0
created ai app/controlplane/pkg/data/ent/migrate/migrations/20261123100107.sql +2 / -0

Policies (4, 2 failing)

Status Policy Material Messages
✅ Passed ai-config-ai-agents-allowed ai-coding-session-5aac19 -
⚠️ Failed ai-config-no-dangerous-commands ai-coding-session-5aac19 Forbidden bash pattern /curl[^|\n]\|\s(?:bash|sh)\b/ matched command: cd /home/javi/orca/workspaces/platform/ai-assisted-manual-evidence/e2e && export TMPDIR=$HOME/.cache/pfm-7910-build/tmp && (yarn install --immutable 2>&1 | tail...
⚠️ Failed ai-config-no-secrets ai-coding-session-5aac19
  • Secret (generic-password) detected in session content [turn=101, source=tool_result, line=4]: license_key: "[CHAINLOOP_TRACE_[CHAINLOOP_TRACE_REDACTED:generic-password]:jwt]"
  • Secret (generic-password) detected in session content [turn=12318, source=tool_result, line=2]: | ⚠️ Failed | ai-config-no-secrets | [ai-coding-session-5aac19](https://app.chainloop.dev/u/chainloop/projects/chainloop-platf...
  • Secret (generic-password) detected in session content [turn=15820, source=tool_result, line=8]: INF commit record saved sha=[CHAINLOOP_TRACE_[CHAINLOOP_TRACE_REDACTED:generic-password]:generic-api-key]
  • Secret (generic-password) detected in session content [turn=16428, source=tool_result, line=1]: {"headRefName":"javirln/pfm-7910-reconcile-system-tokens","headRefOid":"[CHAINLOOP_TRACE_[CHAINLOOP_TRACE_REDACTED:generic-password]:generic-api-key]","isDraft":false,"reviewDecision":"CHANGES_REQUEST...
  • Secret (generic-password) detected in session content [turn=16584, source=tool_result, line=45]: Reviews (5) · Last reviewed commit: ["docs(apitokens): say that a system produ..."](https://github.com/chainloop-dev/platform/commit/[CHAINLOOP_TRACE_[CHAINLOOP_TRACE_REDACTED:generic-password]:g...
  • Secret (generic-password) detected in session content [turn=16902, source=tool_result, line=4]: | ⚠️ Failed | ai-config-no-secrets | [ai-coding-session-5aac19](https://app.chainloop.dev/u/chainloop/projects/chainloop-platf...
  • Secret (generic-password) detected in session content [turn=16941, source=assistant-text, line=4]: - ai-config-no-secrets (#7252, #7254) checks the record of this AI coding session, not the code. It flagged lines where the tracer had already replaced the values with [CHAINLOOP_TRACE_REDACTED...</li><li>Secret (generic-password) detected in session content [turn=175, source=tool_result, line=32]: license_key: "[CHAINLOOP_TRACE_[CHAINLOOP_TRACE_REDACTED:generic-password]:jwt]"</li><li>Secret (generic-password) detected in session content [turn=18992, source=tool_result, line=1]: git -C ~/.cache/pfm-7910-build/split/b1 push --force-with-lease=javirln/pfm-7910-reconcile-system-tokens:[CHAINLOOP_TRACE_[CHAINLOOP_TRACE_REDACTED:generic-password]:generic-api-key] origin javirln/pf...</li><li>Secret (generic-password) detected in session content [turn=18996, source=assistant-text, line=12]: git -C ~/.cache/pfm-7910-build/split/b1 push --force-with-lease=javirln/pfm-7910-reconcile-system-tokens:[CHAINLOOP_TRACE_[CHAINLOOP_TRACE_REDACTED:generic-password]:generic-api-key] origin javirln/pf...</li><li>Secret (generic-password) detected in session content [turn=19104, source=assistant-tool_use:Bash, line=1]: cd ~/.cache/pfm-7910-build/split && git -C b1 push --force-with-lease=javirln/pfm-7910-reconcile-system-tokens:[CHAINLOOP_TRACE_[CHAINLOOP_TRACE_REDACTED:generic-password]:generic-api-key] origin javi...</li><li>Secret (generic-password) detected in session content [turn=31966, source=tool_result, line=19]: (More exist: pass page_token"[CHAINLOOP_TRACE_[CHAINLOOP_TRACE_REDACTED:generic-password]:generic-api-key]" with the samescope` to list the next ones.)
  • Secret (generic-password) detected in session content [turn=482, source=tool_result, line=11]: 65 api_key: "[CHAINLOOP_TRACE_REDACTED:generic-password]"
  • Secret (generic-password) detected in session content [turn=482, source=tool_result, line=19]: 73 token: "[CHAINLOOP_TRACE_REDACTED:generic-password]"
  • Secret (generic-password) detected in session content [turn=6888, source=tool_result, line=7]: # user: [CHAINLOOP_TRACE_REDACTED:generic-password]
  • Secret (generic-password) detected in session content [turn=6888, source=tool_result, line=8]: # password: [CHAINLOOP_TRACE_REDACTED:generic-password]
✅ Passed ai-config-mcp-servers-allowed ai-coding-session-5aac19 -

Security Checks — ✅ 6 passing

✅ AI Security Analysis

Reviewed this change against the project's security context (31 concerns hunted) — no introduced risk found.

View in Chainloop ↗ · How this works ↗

✅ secret-scan

Status Policy Messages
✅ Passed secrets-detection -

✅ sast-scan

Status Policy Messages
✅ Passed owasp-top10-2025 -
✅ Passed sast -
✅ Passed cwe-top25 -
✅ Passed cwe-top26-40-cusp -
Scans not applied (3)
Scan Reason
vulnerability-scan no manifest/lockfile changed
github-actions-scan no workflow files changed
iac-scan no IaC files changed

View attestation ↗


Powered by Chainloop and Chainloop Trace

@javirln
javirln requested a review from a team November 23, 2026 10:49
@javirln
javirln marked this pull request as ready for review November 23, 2026 10:50

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 21 files

Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

View guided diff | Re-trigger cubic

@migmartri migmartri 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.

@javirln are you sure this doesn't exist already? We are already creating tokens for specific digest

@@ -0,0 +1,2 @@
-- Modify "api_tokens" table
ALTER TABLE "api_tokens" ADD COLUMN "allowed_digests" jsonb NULL;

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.

why do we need to store this? why don't we create a system token?

@jiparis ptal in case I am missing something

@javirln
javirln marked this pull request as draft November 23, 2026 11:30
@javirln

javirln commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

We can create system tokens scoped to a digest not general purpose api token. Checking everything

@javirln

javirln commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Thanks, you are right: digest-scoped CAS credentials already exist, so the API token does not need to store digests. I am closing this PR in favor of #3848, which lets chainloop artifact download use a CAS credential that the client obtained before.

@javirln javirln closed this Nov 23, 2026
@javirln
javirln deleted the cas-token-allowed-digests branch November 23, 2026 12:04
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.

2 participants