Skip to content

feat(sts): send RFC 8707 resource and audience on token exchange (Python)#2107

Open
QuentinBisson wants to merge 1 commit into
kagent-dev:mainfrom
QuentinBisson:feat/sts-resource-indicator-py
Open

feat(sts): send RFC 8707 resource and audience on token exchange (Python)#2107
QuentinBisson wants to merge 1 commit into
kagent-dev:mainfrom
QuentinBisson:feat/sts-resource-indicator-py

Conversation

@QuentinBisson

Copy link
Copy Markdown
Contributor

What

The Python ADK token-propagation plugin (agentsts-adk) called
exchange_token without resource or audience, so an issued token could
not be scoped to a specific backend. This wires two optional inputs through:

  • KAGENT_TOKEN_RESOURCE — RFC 8707 resource indicator (the target backend).
  • KAGENT_TOKEN_AUDIENCE — RFC 8693 audience, for STS servers that key on it.

ADKTokenPropagationPlugin now accepts resource/audience; the CLI reads
them from the environment in create_sts_integration. Unset values are
omitted from the request, so behaviour is unchanged when neither is set.

Why

Without a resource/audience, the STS returns a token whose audience is not the
MCP backend, so audience-validating backends reject it. RFC 8707 is the
standard way to scope an exchanged token to its intended resource. The
exchange_token API already accepted resource/audience; only the plugin
call site and the configuration plumbing were missing.

Notes

The Python token-propagation plugin omitted resource/audience on every STS
token exchange, so issued tokens could not be scoped to a target backend.
Accept resource/audience on ADKTokenPropagationPlugin, read them from
KAGENT_TOKEN_RESOURCE / KAGENT_TOKEN_AUDIENCE in the CLI, and pass them to
exchange_token. Unset values are omitted, so behaviour is unchanged by default.

Signed-off-by: QuentinBisson <quentin@giantswarm.io>
@QuentinBisson QuentinBisson force-pushed the feat/sts-resource-indicator-py branch from fe47397 to 22b87f8 Compare June 29, 2026 09:45
@QuentinBisson QuentinBisson marked this pull request as ready for review June 29, 2026 10:22
@QuentinBisson QuentinBisson requested a review from EItanya as a code owner June 29, 2026 10:22
Copilot AI review requested due to automatic review settings June 29, 2026 10:22

Copilot AI 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.

Pull request overview

Wires optional RFC 8707 resource and RFC 8693 audience parameters through the Python ADK STS token-propagation path so exchanged tokens can be scoped to the intended backend, while preserving existing behavior when unset.

Changes:

  • Read KAGENT_TOKEN_RESOURCE / KAGENT_TOKEN_AUDIENCE from the environment in the Python ADK CLI and pass them into the STS token-propagation plugin.
  • Extend ADKTokenPropagationPlugin to accept resource/audience and forward them to STSIntegrationBase.exchange_token.
  • Add/adjust tests to verify resource/audience forwarding and to account for the new kwargs on exchange calls.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
python/packages/kagent-adk/src/kagent/adk/cli.py Reads optional env vars and passes resource/audience into ADKTokenPropagationPlugin.
python/packages/agentsts-adk/src/agentsts/adk/_base.py Adds resource/audience configuration to the plugin and forwards them on token exchange.
python/packages/agentsts-adk/tests/test_adk_integration.py Updates existing assertions and adds coverage verifying forwarding of resource/audience.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Comment on lines +28 to +29
token_resource = os.getenv("KAGENT_TOKEN_RESOURCE") or None
token_audience = os.getenv("KAGENT_TOKEN_AUDIENCE") or None

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.

Can you please rename these KAGENT_STS_* so it's more clear what they belong to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants