Upstream Authentication
Applies to
Gatewayruntime for API, AI, and MCP gateways
Hosting
Managed EdgeManaged DedicatedSelf-Hosted

Upstream AWS Federated Auth Policy

Authenticate to AWS upstreams with no stored AWS keys using Workload Identity Federation. This policy exchanges Zuplo's ambient OIDC identity for an IAM role's short-lived temporary credentials via STS AssumeRoleWithWebIdentity, and makes them available to the AWS Lambda handler and to custom code, which sign upstream requests with AWS Signature Version 4.

With this policy, you'll benefit from:

  • No Long-Lived Secrets: No AWS access keys are stored anywhere — the gateway proves its identity with a short-lived, audience-bound OIDC token
  • Least Privilege: Assume a specific IAM role whose trust policy accepts only the Zuplo environments you list, by their subject (sub) and audience
  • Automatic Token Management: Temporary credentials are cached in memory and refreshed before they expire
  • Reusable Credentials: Resolve credentials once and use them from the AWS Lambda handler or your own code via AwsClient.fromContext(context)

To set this up you configure an IAM OIDC identity provider that trusts Zuplo's issuer, and an IAM role whose trust policy permits AssumeRoleWithWebIdentity for that provider only when the token's subject and audience match your environment.

Beta

This policy is in beta. You can use it today, but it may change in non-backward compatible ways before the final release.

Enterprise Feature

This policy is only available as part of our enterprise plans. It's free to try only any plan for development only purposes. If you would like to use this in production reach out to us: sales@zuplo.com

Configuration

The configuration shows how to configure the policy in the 'policies.json' document.

JSONconfig/policies.json
{ "name": "my-upstream-aws-federated-auth-inbound-policy", "policyType": "upstream-aws-federated-auth-inbound", "handler": { "export": "UpstreamAwsFederatedAuthInboundPolicy", "module": "$import(@zuplo/runtime)", "options": { "region": "us-east-1", "roleArn": "arn:aws:iam::123456789012:role/zuplo-gateway" } } }

Policy Configuration

  • name <string> - The name of your policy instance. This is used as a reference in your routes.
  • policyType <string> - The identifier of the policy. This is used by the Zuplo UI. Value should be upstream-aws-federated-auth-inbound.
  • handler.export <string> - The name of the exported type. Value should be UpstreamAwsFederatedAuthInboundPolicy.
  • handler.module <string> - The module containing the policy. Value should be $import(@zuplo/runtime).
  • handler.options <object> - The options for this policy. See Policy Options below.

Policy Options

The options for this policy are specified below. All properties are optional unless specifically marked as required.

  • roleArn (required) <string> - The IAM role to assume with STS AssumeRoleWithWebIdentity. The role's trust policy must trust the Zuplo OIDC identity provider and require both the token's subject ('sub' claim) and audience ('aud' claim).
  • region (required) <string> - The AWS region used for the STS endpoint and as the default signing region for consumers of the resolved credentials.
  • audience <string> - The audience ('aud' claim) of the Zuplo-issued OIDC token. Must match a client ID configured on the IAM OIDC identity provider. Defaults to "sts.amazonaws.com".
  • roleSessionName <string> - The STS role session name recorded in AWS CloudTrail. Must match the pattern [\w+=,.@-]64. Defaults to "zuplo-gateway".
  • durationSeconds <number> - The lifetime in seconds of the temporary credentials requested from STS (900-43200). The assumed role's maximum session duration may further limit this value. Defaults to 3600.
  • stsEndpoint <string> - Overrides the STS endpoint URL. Only needed for non-standard partitions such as AWS GovCloud or AWS China.
  • tokenRetries <number> - The number of times to retry fetching temporary credentials in the event of a failure. Defaults to 3.
  • expirationOffsetSeconds <number> - The number of seconds before credential expiration at which cached credentials are discarded and refreshed. Defaults to 300.

Using the Policy

Overview

The Upstream AWS Federated Auth policy obtains AWS credentials without storing any AWS keys. It exchanges Zuplo's ambient OIDC identity token for an IAM role's short-lived temporary credentials using STS AssumeRoleWithWebIdentity, then registers those credentials on the request context.

Like the upstream-aws-service-auth policy, it does not add an Authorization header itself — AWS Signature Version 4 signs the exact final request, which is only known inside the handler. The AWS Lambda handler and your own code read the resolved credentials and sign the requests they build.

AWS setup

  1. Create an IAM OIDC identity provider with the provider URL https://dev.zuplo.com/v1/client-auth/auth_o8PUdhKxSTOiB794GWPwLQCD. Set the audience (client ID) to the value you use for the audience option (default sts.amazonaws.com).
  2. Find the subject (sub claim) of each Zuplo environment that needs the role. See Find your environment's subject.
  3. Create an IAM role whose trust policy allows sts:AssumeRoleWithWebIdentity for that provider, with conditions on both the token's audience (aud) and subject (sub). See Trust policy.
  4. Grant the role only the permissions the gateway needs (for example execute-api:Invoke or lambda:InvokeFunction).

Trust policy

Important Security Step

Require both the aud and the sub condition in the role's trust policy. The sub condition limits the role to the Zuplo environments you list.

The condition keys are the provider URL without https://, followed by :aud or :sub. Replace the account ID and the example subject with your own values. If you set the policy's audience option, replace sts.amazonaws.com in the aud condition with the same value.

JSONCode
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::123456789012:oidc-provider/dev.zuplo.com/v1/client-auth/auth_o8PUdhKxSTOiB794GWPwLQCD" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "dev.zuplo.com/v1/client-auth/auth_o8PUdhKxSTOiB794GWPwLQCD:aud": "sts.amazonaws.com", "dev.zuplo.com/v1/client-auth/auth_o8PUdhKxSTOiB794GWPwLQCD:sub": [ "atcl_ExampleSubject0000000000" ] } } } ] }

To let more than one environment assume the role (for example production and a preview branch), list each environment's subject in the sub array.

Find your environment's subject

The sub claim of the Zuplo Identity Token is the unique identity of one environment, for example atcl_ExampleSubject0000000000. It stays the same across deployments of that environment. Each environment has its own subject, so a new environment, such as a new preview branch, needs its subject added to the trust policy.

To read the subject, deploy a handler like the following to the environment, call it once, and copy the sub value from the logs. Remove the handler afterwards.

TypeScriptCode
import { ZuploContext, ZuploRequest, ZuploServices } from "@zuplo/runtime"; export default async function (request: ZuploRequest, context: ZuploContext) { const token = await ZuploServices.getIDToken(context, { audience: "sts.amazonaws.com", }); const payload = token.split(".")[1].replace(/-/g, "+").replace(/_/g, "/"); const { sub, deployment } = JSON.parse(atob(payload)); context.log.info({ sub, deployment }); return new Response(null, { status: 204 }); }

Using the credentials

With the AWS Lambda handler

JSONCode
{ "paths": { "/lambda/{path}*": { "x-zuplo-route": { "handler": { "export": "awsLambdaHandler", "module": "$import(@zuplo/runtime)", "options": { "region": "us-east-1", "functionName": "my-function" } }, "policies": { "inbound": ["upstream-aws-federated-auth"] } } } } }

With custom code

TypeScriptCode
import { AwsClient } from "@zuplo/runtime/aws"; import { ZuploContext, ZuploRequest } from "@zuplo/runtime"; export default async function (request: ZuploRequest, context: ZuploContext) { const aws = AwsClient.fromContext(context, { service: "execute-api", region: "us-east-1", }); return aws.fetch( "https://abc123.execute-api.us-east-1.amazonaws.com/prod/orders", ); }

Configuration

JSONCode
{ "name": "upstream-aws-federated-auth", "policyType": "upstream-aws-federated-auth", "handler": { "export": "UpstreamAwsFederatedAuthInboundPolicy", "module": "$import(@zuplo/runtime)", "options": { "roleArn": "arn:aws:iam::123456789012:role/zuplo-gateway", "region": "us-east-1" } } }

Read more about how policies work

Last modified on