Spacelift OIDC AWS is how a stack assumes an IAM role from a token Spacelift mints for that run, so the stack environment can stop holding an AWS access key. The token is on the run already, in SPACELIFT_OIDC_TOKEN and in the file /mnt/workspace/spacelift.oidc. The AWS provider reads the file and calls AssumeRoleWithWebIdentity. When plan and apply both succeed that way, the static key is removed from the stack. A plan that is green because the key is still in the environment has not cut over.
Rutagon builds that cutover per stack, then per account the stack can touch. The client keeps Spacelift. We change the trust, the provider block, and the secret. Spacelift documents the token, including a one-hour lifetime and availability on paid accounts, in OpenID Connect for AWS. A tier that does not issue the token cannot finish this cutover, and we stop there rather than inventing a key rotation schedule and calling it federation.
Spacelift OIDC AWS role trust
The issuer is the account hostname, for example https://demo.app.spacelift.io. A self-hosted installation uses its own hostname. The IAM OIDC provider URL is that issuer. The audience is the hostname without the scheme, demo.app.spacelift.io, which is what the token's aud claim carries. This is a different audience from the sts.amazonaws.com value other CI systems request. Copying a GitHub trust policy and only changing the provider host will fail the audience check.
AWS can match the standard claims on this token. The claim that expresses space, stack, run type, and scope is sub. Custom claims such as spaceId and callerId are real fields on the token, and they are the wrong knob for an IAM condition, because IAM's OIDC trust matching uses the standard subject. Spacelift's default subject looks like this:
space:<space_id>:(stack|module):<id>:run_type:<run_type>:scope:<read|write> Proposed runs get scope:read. Tracked, testing, and destroy runs, and tasks, get scope:write. A tracked run on a stack that is not set to autodeploy is the exception Spacelift documents: read during plan, write during apply. That split is the control. The plan role's trust lists subjects that end in scope:read. The apply role's trust lists subjects that end in scope:write. One role whose subject wildcard swallows both scopes lets the plan phase hold apply permissions whenever the run's scope is broader than you thought.
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::111122223333:oidc-provider/demo.app.spacelift.io"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"demo.app.spacelift.io:aud": "demo.app.spacelift.io",
"demo.app.spacelift.io:sub": [
"space:SPACE_ID:stack:STACK_ID:run_type:TRACKED:scope:write",
"space:SPACE_ID:stack:STACK_ID:run_type:DESTROY:scope:write"
]
}
}
} StringEquals on the full subject avoids a wildcard. AWS rejects overly permissive wildcards on this condition key unless the wildcard is preceded by a solid run of characters, and a pattern that starts with * or puts * too early fails role save. An end-wildcard such as space:SPACE_ID:stack:STACK_ID* does save, and it also matches scope:read. We use it only on a read role where matching every run type is intentional. Tasks carry scope:write. A write trust that includes run_type:TASK lets a task on that stack assume the apply role and run whatever the task command is. If tasks are not a deploy path, omit TASK from the write role.
Session tags are optional and useful. The stack label feature:aws_oidc_session_tagging tells Spacelift to pass run, stack, and space as transitive session tags. The trust policy then also allows sts:TagSession. CloudTrail shows which stack assumed the role without decoding the token. We turn the label on once the assume works without it, so a tagging failure is not confused with a bad subject.
Provider, backend, and the static key
The Terraform AWS provider block points at the role and the token file. No access key belongs in that block or in the stack's environment.
provider "aws" {
assume_role_with_web_identity {
role_arn = var.aws_role_arn
web_identity_token_file = "/mnt/workspace/spacelift.oidc"
}
} The state backend is a second credential. A provider that assumes a role while the backend still uses an access key from the environment has moved half of the secret. We read the backend configuration as part of the cutover. If that backend can assume a role with the same token file, it does. If it still requires a static key, the key remains a finding with an owner, and we do not describe the stack as keyless. The sibling pattern on Terraform Cloud, where the dynamic credential is issued by a different issuer, is Terraform Cloud dynamic credentials. Pulumi's version of the same AWS exchange is Pulumi OIDC for AWS.
Prove it on one stack. A proposed run assumes the read role and cannot assume the write role. A tracked apply assumes the write role. CloudTrail shows AssumeRoleWithWebIdentity and the session tags if you enabled them. The stack environment no longer contains AWS_ACCESS_KEY_ID. Then the next stack. Shared modules that run in Spacelift are in the list, because a module run has a subject with module in the caller position, and a trust policy that only names stack will deny it. That denial is correct until you add the module subject on purpose.
Revoke in order. Remove the key from the stack environment after the clean runs. Deactivate it. Confirm CloudTrail. Delete it. While the overlap lasts, the key is sealed and unmounted, available to put back on one stack if a subject mismatch blocks an apply you cannot delay. After deletion, rollback is a trust-policy fix, not a key someone saved locally. A second AWS account that the stack assumes into needs the same OIDC provider and its own role. The first account's role does not travel.
What we file, and what we refuse
The evidence pack is the provider host, the role ARNs, the trust policies, the stack ids that ran clean, and the deactivation time of the old key. The GRC platform you already run gets that pack. A screenshot of the Spacelift AWS integration page, without the trust policy, does not show the subject restriction. An integration that uses a static key and an external id is a different feature. External-id integrations can stay for a vendor that cannot do OIDC. They are not this cutover, and we do not relabel them as workload identity.
This is security automation on the infrastructure tool you already use. Rutagon runs its own infrastructure applies through short-lived federation, including the applies that maintain a production SaaS platform. The client's stacks still need their own trust policies. Our pipeline is not their evidence.
Frequently Asked Questions
What is the audience on a Spacelift token for AWS?
The hostname of the Spacelift account, such as demo.app.spacelift.io, with no scheme. The issuer URL includes https://. The IAM condition key and the aud claim do not. Using sts.amazonaws.com as the audience, which is correct for several other CI systems, fails this assume.
Why are there two roles for one stack?
Plan and apply do not have the same scope. Proposed runs, and the plan phase of a tracked run that waits for approval, carry scope:read. Apply carries scope:write. A read role and a write role keep the plan from holding apply permissions. Tasks also carry write scope, so the write role should list TASK only when a task is allowed to change the account.
Do custom claims like spaceId work in the IAM trust policy?
Use sub. Spacelift puts space, stack or module, run type, and scope into the subject string, and IAM matches that standard claim. spaceId and callerId are on the token for other consumers. A trust policy written against those custom names will not constrain the assume the way the author intended.
When is the static AWS key actually deleted?
After every stack and module that used it has a clean run that does not read it, including the state backend. Deactivate, watch CloudTrail for that key id, then delete. A green plan that still has AWS_ACCESS_KEY_ID in the environment is still on the key.
Talk to us about your credential elimination pilot. Contact Rutagon at rutagon.com/contact, 907-841-8407, or contact@rutagon.com.