Skip to content

feat: allow short-term bearer tokens for opencode bedrock user - #16

Merged
xnoto merged 1 commit into
mainfrom
feat/bedrock-bearer-token
Aug 25, 2026
Merged

feat: allow short-term bearer tokens for opencode bedrock user#16
xnoto merged 1 commit into
mainfrom
feat/bedrock-bearer-token

Conversation

@xnoto

@xnoto xnoto commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Flex/Priority service tiers for Claude models are only selectable via service_tier in the Anthropic Messages API surface on bedrock-runtime (/anthropic/v1/messages). That surface authenticates with Bedrock API keys (bearer tokens), not SigV4 — InvokeModel/Converse reject non-Standard tiers for Anthropic models (verified empirically in us-west-2/us-east-1/us-east-2).

This adds bedrock:CallWithBearerToken so the opencode-bedrock user can use short-term (12h, client-side presigned, permission-inheriting) bearer tokens, hardened with bedrock:bearerTokenType = SHORT_TERM so long-term API keys remain forbidden.

Validation

  • make test — all canonical pre-commit hooks pass
  • Additive IAM statement only; CI plan authoritative

Post-merge test plan: presign a short-term token from the user's credentials and call /anthropic/v1/messages with \"service_tier\": \"flex\" on Opus 4.6; the response echoes the served tier.

The Anthropic Messages API surface on bedrock-runtime is the only one
that accepts service_tier (flex/priority) for Claude models, and it
authenticates with Bedrock API keys rather than SigV4. Short-term
tokens are presigned client-side from the user's credentials and
inherit its permissions; the bedrock:bearerTokenType=SHORT_TERM
condition keeps long-term API keys forbidden.
@xnoto
xnoto requested a review from a team as a code owner August 25, 2026 23:08
@github-actions

Copy link
Copy Markdown

OpenTofu Plan

OpenTofu will perform the following actions:

  # aws_iam_user_policy.bedrock_opencode will be updated in-place
  ~ resource "aws_iam_user_policy" "bedrock_opencode" {
        id     = "opencode-bedrock:bedrock-invoke"
        name   = "bedrock-invoke"
      ~ policy = jsonencode(
          ~ {
              ~ Statement = [
                    # (3 unchanged elements hidden)
                    {
                        Action   = [
                            "bedrock:ListModelInvocationJobs",
                        ]
                        Effect   = "Allow"
                        Resource = "*"
                        Sid      = "ListBatchJobs"
                    },
                  ~ {
                      ~ Action    = [
                          - "aws-marketplace:ViewSubscriptions",
                          - "aws-marketplace:Subscribe",
                          + "bedrock:CallWithBearerToken",
                        ]
                      ~ Condition = {
                          ~ StringEquals = {
                              - "aws:CalledViaLast"       = "bedrock.amazonaws.com"
                              + "bedrock:bearerTokenType" = "SHORT_TERM"
                            }
                        }
                      ~ Sid       = "MarketplaceModelSubscription" -> "AllowShortTermBearerToken"
                        # (2 unchanged attributes hidden)
                    },
                  ~ {
                      ~ Action    = [
                          - "s3:GetObject",
                          - "s3:PutObject",
                          - "s3:ListBucket",
                          + "aws-marketplace:ViewSubscriptions",
                          + "aws-marketplace:Subscribe",
                        ]
                      + Condition = {
                          + StringEquals = {
                              + "aws:CalledViaLast" = "bedrock.amazonaws.com"
                            }
                        }
                      ~ Resource  = [
                          - "arn:aws:s3:::mitw-bedrock-batch",
                          - "arn:aws:s3:::mitw-bedrock-batch/*",
                        ] -> "*"
                      ~ Sid       = "BatchDataS3Access" -> "MarketplaceModelSubscription"
                        # (1 unchanged attribute hidden)
                    },
                  - {
                      - Action    = [
                          - "iam:PassRole",
                        ]
                      - Condition = {
                          - StringEquals = {
                              - "iam:PassedToService" = "bedrock.amazonaws.com"
                            }
                        }
                      - Effect    = "Allow"
                      - Resource  = "arn:aws:iam::332355796717:role/bedrock-batch-inference"
                      - Sid       = "PassBatchServiceRole"
                    },
                  + {
                      + Action   = [
                          + "s3:GetObject",
                          + "s3:PutObject",
                          + "s3:ListBucket",
                        ]
                      + Effect   = "Allow"
                      + Resource = [
                          + "arn:aws:s3:::mitw-bedrock-batch",
                          + "arn:aws:s3:::mitw-bedrock-batch/*",
                        ]
                      + Sid      = "BatchDataS3Access"
                    },
                  + {
                      + Action    = [
                          + "iam:PassRole",
                        ]
                      + Condition = {
                          + StringEquals = {
                              + "iam:PassedToService" = "bedrock.amazonaws.com"
                            }
                        }
                      + Effect    = "Allow"
                      + Resource  = "arn:aws:iam::332355796717:role/bedrock-batch-inference"
                      + Sid       = "PassBatchServiceRole"
                    },
                ]
                # (1 unchanged attribute hidden)
            }
        )
        # (1 unchanged attribute hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

@xnoto
xnoto merged commit 025d92b into main Aug 25, 2026
4 checks passed
@xnoto
xnoto deleted the feat/bedrock-bearer-token branch August 25, 2026 23:11
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.

1 participant