OIDC Integration with AWS
Ona can connect environments to AWS using Ona support for OpenID Connect, which allows environments to retrieve AWS access credentials without using static credentials or environment variables. In this authentication flow, an IAM role is created in an external AWS account, accessible through thegitpod
command in Ona. The generated JWT token includes claims about the environment and its owner, and is exchanged with AWS for an STS token. That STS token is associated with an IAM role and inherits any access granted to that role. Access control configuration is the responsibility of the AWS account owner/administrator.
Step 1: Create an “AWS Identity Provider” resource
To connect Ona to AWS, you need to create an “IAM identity provider” to establish a trust relationship between your AWS account and Ona. Ona supports OpenID Connect (OIDC), so follow AWS’s guide here to create an OIDC identity provider.- Configure the URL of the identity provider to:
https://app.gitpod.io
- The client ID / Audience should be set to:
sts.amazonaws.com
Note: AddRead more:/.well-known/openid-configuration
to the end of the identity provider’s URL to see the provider’s publicly available configuration document and metadata:https://app.gitpod.io/.well-known/openid-configuration
- [AWS docs] Identity providers and federation
- [AWS docs] Creating OpenID Connect (OIDC) identity providers
Step 2: Create an AWS role with a trust policy
Now that your AWS account is set up to trust Ona, you need to create an AWS IAM role that can be assumed by the Ona environment user. You can restrict who has access to the assumed role based on claims in your Ona environment JWT token.Info: We strongly recommend you adhere to the principle of least privilege, and ensure that only relevant environments and users can assume your AWS role.
Note: You can inspect the claims that will be sent to AWS by runningTo adjust the IAM role trust policy to restrict which environments can assume the role, you can define condition keys using the name of the OIDC provider (created in step 1, e.g.gitpod idp token --decode --audience sts.amazonaws.com
inside an Ona environment. Pay attention to thesub
claim containing the organization, project, and environment information.
app.gitpod.io
) followed by the claim (:aud
, :sub
, etc.). The examples below show how this works. Read more about these OIDC condition keys here.
Here are some examples restricting who can assume the role depending on the sub
key contents:
This example shows that only environments created within a specific organization can assume this role:
Step 3: Assume the AWS role to retrieve the AWS credentials
Note: The following assumes that your environment has the AWS CLI installed so that it can call aws sts assume-role-with-web-identity
.
You can either call the AWS CLI assume-role
command manually, or use the helper command within the gitpod
CLI, gitpod idp login aws
which will automatically update your AWS CLI credentials file.
The token expiry can be customized using --duration-seconds=<token-expiry-in-seconds>
, this configuration option exactly matches the --duration-seconds
configuration option offered by AWS CLI. The default is 3600
seconds. Note, to use a longer expiry your AWS Administrator must allow for longer sessions.
You can can run the following to assume the role and retrieve secrets from AWS Secrets Manager, or you can extend your Automation to authenticate with AWS automatically on startup.
Troubleshooting
Usegitpod idp token --decode --audience sts.amazonaws.com
to print your environment JWT token. Ensure that any claims against the sub
match the trust policy in AWS.