Authenticate AWS workloads with workload identity federation
AWS outbound identity federation lets an IAM role request a signed JWT from AWS STS. A workload running as that role, such as an EC2 instance, an ECS task, or a Lambda function, can exchange the JWT for a short-lived Limrun access token. No Limrun API key is stored in AWS.
Before you start
You need:
- The
adminrole in your Limrun organization. - Permission to change your AWS account's IAM settings and the workload's role policy.
- The AWS CLI on the machine where you run the setup commands.
Enable outbound identity federation
Each AWS account has its own issuer, so you enable the feature once per account and copy the issuer from AWS:
aws iam enable-outbound-web-identity-federation
aws iam get-outbound-web-identity-federation-infoThe second command prints IssuerIdentifier, a URL like https://EXAMPLE.tokens.sts.global.api.aws. Copy it exactly. Disabling and enabling the feature again gives the account new signing keys.
Then allow the workload's IAM role to request tokens by adding sts:GetWebIdentityToken to its policy. AWS also offers the condition key sts:IdentityTokenAudience if you want to limit the role to the audience limrun.
Create the provider
Your account's issuer signs only for your account, but any role in the account that may call sts:GetWebIdentityToken can get a token. The provider condition limits trust to the role that should reach Limrun.
-
Open console.limrun.com, go to Settings, then Workload identity federation, and click the + button next to Identity providers.
-
In Issuer, choose Amazon Web Services (AWS).
-
Enter a provider name and paste the
IssuerIdentifieras the Issuer URL. The preset adds the signing keys at/.well-known/jwks.jsonunder the issuer. -
Keep Token audience as
limrun. -
In Provider condition (CEL), replace
ACCOUNT_IDandROLE_NAMEwith your account ID and the workload's role:assertion.sub == 'arn:aws:iam::ACCOUNT_ID:role/ROLE_NAME'AWS puts the requesting role's ARN in
sub. Runaws sts get-caller-identity --query Account --output textto print your account ID. -
Click Create provider.
Create a binding
-
In the provider's card, click the + button next to Bindings.
-
Enter a name and a Claim condition (CEL). The provider condition already selects the role, so
trueadmits it. AWS puts its other claims, such asaws_accountandsource_region, inside an object namedhttps://sts.amazonaws.com/, so read them by index:assertion['https://sts.amazonaws.com/'].source_region == 'us-east-1' -
Enter the permissions the workload needs, one per line, such as
xcode:*:all. -
Click Create binding, expand Setup, and copy the binding ID.
Use the token in the workload
Request tokens from a regional STS endpoint; the global endpoint doesn't serve them. AWS tokens last 300 seconds unless you set --duration-seconds, up to 3,600, and a Limrun access token never outlives its source token. This script keeps a fresh token in a file, which the CLI reads again whenever it renews:
export AWS_REGION=us-east-1
export LIMRUN_WORKLOAD_IDENTITY_BINDING_ID=binding_REPLACE_WITH_BINDING_ID
export LIMRUN_WORKLOAD_IDENTITY_TOKEN_FILE=/tmp/limrun.jwt
refresh() {
aws sts get-web-identity-token \
--region "$AWS_REGION" \
--endpoint-url "https://sts.$AWS_REGION.amazonaws.com" \
--audience limrun \
--signing-algorithm RS256 \
--duration-seconds 900 \
--query WebIdentityToken --output text > "$LIMRUN_WORKLOAD_IDENTITY_TOKEN_FILE.tmp"
mv "$LIMRUN_WORKLOAD_IDENTITY_TOKEN_FILE.tmp" "$LIMRUN_WORKLOAD_IDENTITY_TOKEN_FILE"
}
refresh
(while sleep 600; do refresh; done) &
lim whoami--audience limrun must match the provider's audience. --signing-algorithm accepts RS256 or ES384, and Limrun verifies both. Writing to a temporary file and renaming it means the CLI never reads a half-written token. lim whoami prints your organization and the binding's permissions.
In code, call the STS GetWebIdentityToken API from a token function instead of running a background loop. With the TypeScript SDK, pass a function that returns the WebIdentityToken field as workloadToken. The Python SDK's workload_token and the Go SDK's TokenSource work the same way.
Things to know
- The
audclaim can be a list.--audienceaccepts several values. Limrun admits the token when one of them matches the provider's audience. - A token can't outlive the caller's session. AWS refuses a duration longer than the role session that requests it.
See AWS outbound identity federation and its token claims for the AWS side.
Let AWS workloads call Limrun with tokens from AWS outbound identity federation instead of a stored API key.
Was this guide helpful?