Skip to content

fix(cli): prefer user/api audience for mixed-aud JWTs#2828

Open
SergioChan wants to merge 1 commit intochainloop-dev:mainfrom
SergioChan:fix-2812-token-audience-priority
Open

fix(cli): prefer user/api audience for mixed-aud JWTs#2828
SergioChan wants to merge 1 commit intochainloop-dev:mainfrom
SergioChan:fix-2812-token-audience-priority

Conversation

@SergioChan
Copy link

Summary

  • handle JWT aud claims as an ordered set instead of trusting the first item in an array
  • prioritize api-token-auth.chainloop and user-auth.chainloop ahead of generic chainloop when multiple audiences are present
  • add a regression test for mixed-audience user tokens (["chainloop", "user-auth.chainloop"]) so user identity is selected instead of issuer fallback

Testing

  • go test ./app/cli/internal/token

Related

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

@SergioChan SergioChan force-pushed the fix-2812-token-audience-priority branch from b3a0ca9 to 5885882 Compare March 9, 2026 20:26
@SergioChan
Copy link
Author

Thanks for the checks — I force-pushed an amended commit with DCO sign-off so the DCO status should now pass.

No functional code changes were introduced in this push.

@migmartri
Copy link
Member

Thanks for the contribution

Could you elaborate on what was the root cause of the problem?

Thanks

@SergioChan
Copy link
Author

Thanks for the detailed review feedback 鈥?I鈥檓 working through the requested updates and will post a focused patch (or direct answers) shortly.

1 similar comment
@SergioChan
Copy link
Author

Thanks for the detailed review feedback 鈥?I鈥檓 working through the requested updates and will post a focused patch (or direct answers) shortly.

@SergioChan
Copy link
Author

Thanks for asking — root cause was in the CLI audience selection logic, not tmux itself.

Before this patch, we effectively trusted the first value when aud was an array. For affected user tokens the audience list can be mixed, e.g. ["chainloop", "user-auth.chainloop"], where the generic chainloop value may appear before the specific auth audience.

That caused the CLI to classify the token via the generic audience path and then fall back to issuer resolution (cp.chainloop), which is where the issuer not found: cp.chainloop error came from.

The fix changes audience handling to treat aud as a set and apply explicit priority (api-token-auth.chainloop / user-auth.chainloop before generic chainloop) so mixed-audience user tokens are classified correctly.

@migmartri
Copy link
Member

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@Piskoo
Copy link
Collaborator

Piskoo commented Mar 18, 2026

The issue mentions a possible race condition between tmux sessions affecting the local config. Does this fix address the root cause? Consider adding a negative case for a multi-audience token where none match the known audiences (["unknown1", "unknown2"] → returns nil).

@SergioChan
Copy link
Author

Good callout — thank you.

Short answer: this PR addresses the audience-selection bug in mixed-aud tokens (which surfaced as the issuer not found: cp.chainloop behavior), not tmux session coordination itself.

I’ll add the negative multi-audience case you suggested ([unknown1, unknown2] -> nil) and push an update.

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.

ERR failed to load issuer: authorization error: issuer not found: cp.chainloop

3 participants