Amazon Web Services (AWS)
This page describes Spacelift's native integration with AWS, which allows users to generate short-lived credentials for runs and tasks orchestrated by Spacelift.
Last updated
Was this helpful?
This page describes Spacelift's native integration with AWS, which allows users to generate short-lived credentials for runs and tasks orchestrated by Spacelift.
Last updated
Was this helpful?
The AWS integration allows either Spacelift or to automatically in your AWS account, and in the process, generate a set of temporary credentials. These credentials are then exposed as during the run/task that takes place on the particular Spacelift stack that the integration is attached to.
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_SECURITY_TOKEN
AWS_SESSION_TOKEN
This is enough for both the and/or to generate a fully authenticated AWS session without further configuration. However, you will likely need to select one of the available regions with the former.
To utilize the AWS integration you'll need to setup at least one cloud integration, and then attach that integration to any stack(s) that you'd like to have utilize that integration. Please follow the for more information on this process.
When setting up a Spacelift AWS Cloud Integration you'll need to specify the ARN of an IAM Role to use. This role, will need to have its Trust Policy configured, to allow Spacelift to assume the role and generate temporary credentials.
When completing the role assumption, Spacelift will pass extra information in the ExternalId
attribute, allowing you to optionally add additional layers of security to your role.
External ID Format:
<spacelift-account-name>@<integration-id>@<stack-slug>@<read|write>
<spacelift-account-name>
The name of the Spacelift account that initiated the role assumption.
<integration-id>
The ID of the AWS Cloud Integration that initiated the role assumption.
<stack-slug>
The slug of the stack that the AWS Cloud integration is attached to, that initiated the role assumption.
<read|write>
This will either be set to read
or write
based upon the event occurring that has initiated the role assumption.
Planning: Utilizes read
Applying: Utilizes write
Pre-Requisites:
Ability to create IAM Roles in your AWS account.
Admin access to your Spacelift account.
Navigate to AWS IAM
Within your AWS account, navigate to AWS IAM and click the Create role button.
Here's the format of a custom trust policy statement you can use, that allows any stack within your Spacelift account to use this IAM Role:
Knowing the format of the external id passed by Spacelift, users can further secure their IAM Role trust policies if they desire a deeper level of granular security.
For example, users may wish to lock down an IAM Role, to only be used by a specific stack (e.g. stack-a
in their Spacelift account example
). In such a case, they could add the stack-slug into their Trust Policy like so:
Configure Role Permissions
Next, you need to attach at least one IAM Policy to your IAM Role to provide it with sufficient permissions to deploy any resources that your IaC code defines.
Create IAM Role
Once you have your IAM Role's trust policy and IAM Policies configured, you can finish creating the role. Take a note of the IAM Role ARN, as you'll need this when setting up the integration in Spacelift in the next section.
Now that you have an IAM Role created, navigate to the Cloud Integration page from the Spacelift navigation sidebar.
Click the button to begin the creation of your first integration.
When creating an integration, you'll immediately notice that you need to specify two required fields: Name and Role ARN. Give the integration a name of your choosing, and paste in the ARN of the IAM Role that we just created.
When assuming the role on private workers, the process is straightforward: you provide the IAM role to assume, and, optionally, an external ID.
Note that we have no way of validating whether your worker has the ability to assume the said role. You will need to trigger a job to verify that.
Now that you've created the integration, we need to attach it to the Spacelift Stack that you wish to use this integration.
Navigate to Chosen Stack
This part's up to you - navigate to a stack that you wish to attach the integration you just created to.
Navigate to Settings of the Stack
Select the Integrations Tab
Select the AWS Integration Option, and Select your Integration
Read indicates that this integration will be used during read phases of runs (for example, plans).
Write indicates that this integration will be used during write phases of runs (for example, applies).
If the Cloud Integration has the "Assume Role on Worker" setting disabled, Spacelift will verify the role assumption as soon as you click the attach button.
Here's a little example of what that might look like to create a Cloud Integration programmatically:
Assuming role and generating credentials on the private worker is perfectly safe. Those credentials are never leaked to us in any shape or form. Hence, the rest of this section discusses the trust relationship established between the Spacelift account and your AWS account for the purpose of dynamically generating short-lived credentials. So, how safe is that?
Probably safer than storing static credentials in your stack environment. Unlike user keys that you'd normally have to use, role credentials are dynamically created and short-lived. We use the default expiration which is 1 hour, and do not store them anywhere. Leaking them accidentally through the logs is not an option either because we mask AWS credentials.
Let's have a look at a CloudTrail event showing an IAM role being created by what seems to be a Spacelift run:
01DSJ63P40BAZY4VW8BXXG7M4K
is indeed a run ID we can then trace back even further:
OK, we get it. Using everyone's favorite Inception meme:
First things first - before proceeding, you'll want to have an within your AWS account that we will be configuring this cloud integration to use.
Next, we want to configure the for the role to allow Spacelift to assume the role.
For Terraform users that are managing their own state file, don't forget to give your role sufficient permissions to access your state (Terraform documents the permissions required for S3-managed state , and for DynamoDB state locking ).
When creating your role in AWS, you'll need to ensure the role has a trust policy that allows Spacelift to assume the role to generate temporary credentials for runs, assuming you are following this guide, you should have configured this in the .
This somewhat counterintuitive extra check is to prevent against malicious takeover of your account by someone who happens to know your AWS account ID, which isn't all that secret, really. The security vulnerability we're addressing here is known as the .
You can also use the in order to create an AWS Cloud integration from an , including the trust relationship. Note that in order to do that, your administrative stack will require AWS credentials itself, and ones powerful enough to be able to deal with IAM.
Please always refer to the for the most up-to-date documentation.
The most tangible safety feature of the AWS integration is the breadcrumb trail it leaves in . Every resource change can be mapped to an individual Terraform or whose ID automatically becomes the username as the API call with that ID as RoleSessionName
. In conjunction with AWS tools like , it can be a very powerful compliance tool.
Indeed, AWS Terraform provider allows you to , effectively doing the same thing over again. This approach is especially useful if you want to control resources in multiple AWS accounts from a single Spacelift stack. This is totally fine - in IAM, roles can assume other roles, though what you need to do on your end is set up the trust relationship between the role you have Spacelift assume and the role for each provider instance to assume. But let's face it - at this level of sophistication, you sure know what you're doing.
One bit you might not want to miss though, is the guaranteed ability to map the change to a particular or that we described in the . One way of fixing that would be to use the TF_VAR_spacelift_run_id
available to each Spacelift workflow. Conveniently, it's already a , so a setup like this should do the trick: