OpenID Connect
OpenID Connect (OIDC) allows you to establish a more secure trust relationship between Semaphore and cloud providers such as AWS or Google Cloud.
Overview
Semaphore users traditionally use secrets to inject credentials or API keys in jobs that need to interact with cloud providers. Every time the CI pipeline needs to deploy an application or fetch resources from a Docker registry or S3 bucket, we need to supply a secret to authorize Semaphore to access your cloud.
These long-lived credentials present a challenge to maintain security or face exposure to security threats. Access and usage of these secrets need to be carefully monitored. Secrets need to be regularly rotated and the provided access rights on the cloud should follow the principle of least privilege.
OpenID Connect (OIDC) provides an alternative way to interact with the cloud. Instead of secrets, OIDC uses short-lived access tokens that do not require secret maintenance.
How to configure OpenID Connect
This section explains how to connect OpenID to your cloud provider.
AWS
To connect to Amazon Web Services (AWS) from Semaphore using OpenID Connect, you will need to perform the following steps.
Step 1: Create identity provider
-
Log in to the AWS IAM Console
-
Under Access management, select Identity providers
-
Press Add provider
-
Select OpenID connect
-
In Provider URL and Audience type your organization URL, e.g.
https://my-org.semaphoreci.com -
Press Add provider

Step 2: Configure a role and trust policy
-
Log in to the AWS IAM Console
-
Under Access management, select Roles
-
Press Create role
-
Select Web identity
-
Under Identity provider and Audience, select the provider you created in Step 1
-
Press Next
-
Choose the permissions you want this role to have. This typically involves selecting a policy that allows access to the AWS resources your pipelines need. For example, if your pipelines need access to S3, you might choose the
AmazonS3FullAccesspolicy. -
Press Next
-
Type the Role name and an optional description
-
Press Create role

Next, edit the trust policy as follows:
- Select the newly created Role by name. You may need to use the search box to locate it
- Select the Trust relationships tab
- Press Edit trust policy
- Edit the
Conditionsection (see below for details) - Press Update policy
The trust policy uses JSON to configure what projects and branches can access the resources assigned to this role.
- Use
StringEqualsto define specific projects and branches - Use
StringLiketo match projects and branches using a pattern - You can combine
StringEqualsandStringLikein the sameCondition
The following example shows how to grant permissions to:
- organization:
my-org - project id:
936a5312-a3b8-4921-8b3f-2cec8baac574 - repository:
web - branch:
main
"Condition": {
"StringEquals": {
"my-org.semaphoreci.com:aud": "https://my-org.semaphoreci.com",
"my-org.semaphoreci.com:sub": "org:my-org:project:936a5312-a3b8-4921-8b3f-2cec8baac574:repo:web:ref_type:branch:ref:refs/heads/main"
}
}
The next example shows how to grant permissions to:
- organization
my-org - project id
936a5312-a3b8-4921-8b3f-2cec8baac574 - repository
web - all branches
"Condition": {
"StringLike": {
"<org-url>.semaphoreci.com:sub":
"org:<org-url>:project:936a5312-a3b8-4921-8b3f-2cec8baac574:repo:web:ref_type:branch:ref:refs/heads/*",
},
}
Step 3: Use OIDC in your Semaphore pipelines
You can now use OIDC to access your AWS resources from any of your pipelines.
In order authenticate with AWS add these commands to the Semaphore job that needs access.
export ROLE_ARN="YOUR_AWS_ROLE_NAME"
export SESSION_NAME="semaphore-job-${SEMAPHORE_JOB_ID}"
export CREDENTIALS=$(aws sts assume-role-with-web-identity --role-arn $ROLE_ARN --role-session-name $SESSION_NAME --web-identity-token $SEMAPHORE_OIDC_TOKEN)
export AWS_ACCESS_KEY_ID=$(echo $CREDENTIALS | jq -r '.Credentials.AccessKeyId')
export AWS_SESSION_TOKEN=$(echo $CREDENTIALS | jq -r '.Credentials.SessionToken')
export AWS_SECRET_ACCESS_KEY=$(echo $CREDENTIALS | jq -r '.Credentials.SecretAccessKey')
Replace YOUR_AWS_ROLE_NAME with the Role you created in Step 2