Skip to content

fix(auth): support STS session token in sso-setup / publish discovery step - #139

Merged
innsd merged 1 commit into
volcengine:mainfrom
jdp-just-does-projects:fix/sso-setup-session-token
Jul 14, 2026
Merged

fix(auth): support STS session token in sso-setup / publish discovery step#139
innsd merged 1 commit into
volcengine:mainfrom
jdp-just-does-projects:fix/sso-setup-session-token

Conversation

@jdp-just-does-projects

Copy link
Copy Markdown
Contributor

Problem

Running agentkit auth admin sso-setup (or agentkit auth admin publish) with temporary STS credentials (VOLCENGINE_ACCESS_KEY / VOLCENGINE_SECRET_KEY / VOLCENGINE_SESSION_TOKEN) fails at the final "publish discovery doc to TOS" step:

TosServerError: 403 InvalidAccessKeyId
The Access Key Id you provided does not exist in our records.

All earlier provisioning steps (UserPool, CLI client, OIDC provider, STS role, ...) succeed because OpenApiClient (agentkit/auth/_openapi.py) already reads VOLCENGINE_SESSION_TOKEN and includes it in the SigV4 signature. But publish_discovery() in agentkit/auth/admin.py builds the TOS client with only AK/SK:

client = tos.TosClientV2(ak, sk, endpoint, coords.region)   # session token dropped

A temporary access key is invalid without its session token, so TOS rejects the request.

Fix

Three small changes to agentkit/auth/admin.py:

  1. publish_discovery() gains a session_token parameter with an env fallback (VOLCENGINE_SESSION_TOKEN), mirroring the existing AK/SK handling.
  2. The token is passed to the TOS SDK via security_token:
    client = tos.TosClientV2(ak, sk, endpoint, coords.region, security_token=token)
  3. sso_setup() forwards session_token=api.token, so the publish step uses the same credentials as the provisioning steps.

The env fallback also fixes agentkit auth admin publish, which calls publish_discovery without explicit credential arguments. Fully backward compatible: with long-lived AK/SK the token is None and behavior is unchanged.

Verification

With temporary credentials configured, a read-only head_bucket call against the affected bucket (agentkit-cli-<account_id>) using the same AK/SK:

  • without session token (pre-fix behavior): TosServerError 403, matching the original failure;
  • with session token (post-fix behavior): succeeds.

After the fix, re-running sso-setup completes; the command is idempotent and reuses previously created resources, only finishing the failed publish step.

Related observation (not addressed here)

create_bucket errors are treated as "bucket already exists" when the message contains Exist/exist. The auth error message "...does not exist in our records" matches that keyword, so the create_bucket failure was silently swallowed and only surfaced at put_object. Worth hardening separately by matching error codes (BucketAlreadyExists / BucketAlreadyOwnedByYou) instead of message keywords.

🤖 Generated with Claude Code

When agentkit auth admin sso-setup / publish is run with temporary
credentials (VOLCENGINE_ACCESS_KEY / VOLCENGINE_SECRET_KEY /
VOLCENGINE_SESSION_TOKEN), every OpenAPI-based provisioning step
succeeds, but publish_discovery() constructs the TOS client with only
AK/SK and drops the session token. A temporary AK without its session
token is invalid, so TOS rejects the request with 403 InvalidAccessKeyId.

Fix by threading the session token through:
- publish_discovery() accepts a session_token parameter with the same
  VOLCENGINE_SESSION_TOKEN env fallback used for AK/SK, and passes it
  to tos.TosClientV2 via security_token.
- sso_setup() forwards session_token=api.token so the publish step uses
  the same credentials as the earlier provisioning steps.

Backward compatible: with long-lived AK/SK the token is None and
behavior is unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@innsd
innsd merged commit 57bc06e into volcengine:main Jul 14, 2026
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