-
Notifications
You must be signed in to change notification settings - Fork 68.1k
Add OIDC in Docker guide for GitHub Actions deployments #45243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gmondello
wants to merge
7
commits into
github:main
Choose a base branch
from
gmondello:add-oidc-in-docker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+141
−0
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
411ad22
Add OIDC in Docker guide for GitHub Actions deployments
gmondello 1791b9b
Use immutable SHA refs for all GitHub Actions in workflow example
gmondello 6559ae5
Address all Copilot review feedback
gmondello bc657ad
Replace literal 'personal access tokens' with Liquid variable
gmondello 18f1857
Replace Docker Hub with Docker where scope is broader than registry
gmondello addecea
Lead with single-step OIDC login, move two-step to advanced section
gmondello dcaf739
Update content/actions/how-tos/secure-your-work/security-harden-deplo…
gmondello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
.../actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-docker.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| --- | ||
| title: Configuring OpenID Connect in Docker | ||
| shortTitle: OIDC in Docker | ||
| intro: Use OpenID Connect within your workflows to authenticate with Docker without storing long-lived credentials. | ||
| versions: | ||
| fpt: '*' | ||
| ghec: '*' | ||
| contentType: how-tos | ||
| category: | ||
| - Secure your workflows | ||
| --- | ||
|
|
||
| ## Overview | ||
|
|
||
| OpenID Connect (OIDC) allows your {% data variables.product.prodname_actions %} workflows to authenticate with [Docker](https://www.docker.com/) to access Docker Hub and Docker Build Cloud without storing Docker passwords, {% data variables.product.pat_generic_plural %}, or organization access tokens (OATs) in {% data variables.product.company_short %}. | ||
|
|
||
| Instead of managing long-lived credentials, you configure a trust relationship between your {% data variables.product.prodname_dotcom %} organization and your Docker organization. When a workflow runs, {% data variables.product.prodname_dotcom %} issues a short-lived OIDC token that Docker validates against your configured rulesets, then issues a scoped access token for the workflow. | ||
|
|
||
| This guide gives an overview of how to configure Docker to trust {% data variables.product.prodname_dotcom %}'s OIDC as a federated identity, and demonstrates how to use this configuration in a {% data variables.product.prodname_actions %} workflow. | ||
|
|
||
| For more information, see [OIDC connections](https://docs.docker.com/enterprise/security/oidc-connections/) in the Docker documentation. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| {% data reusables.actions.oidc-link-to-intro %} | ||
|
|
||
| {% data reusables.actions.oidc-security-notice %} | ||
|
|
||
| {% data reusables.actions.oidc-on-ghecom %} | ||
|
|
||
| * You must have a Docker Business or Docker Team subscription. | ||
| * You must be an organization owner or editor in your Docker organization. | ||
| * You should plan which repositories, branches, and workflows need access to Docker, and configure rulesets accordingly. | ||
|
|
||
| ## Adding the identity provider to Docker | ||
|
|
||
| To use OIDC with Docker, establish a trust relationship between {% data variables.product.prodname_actions %} and Docker by creating an OIDC connection. For more information about this process, see [Create and manage OIDC connections](https://docs.docker.com/enterprise/security/oidc-connections/create-manage/) in the Docker documentation. | ||
|
|
||
| 1. Sign in to [Docker Home](https://app.docker.com/) and navigate to your organization. | ||
| 1. Go to **Identity & auth** > **OIDC connections**. | ||
| 1. Select **Create OIDC connection**. | ||
| 1. Configure at least one ruleset to define which {% data variables.product.prodname_dotcom %} repositories, branches, or workflows can authenticate. Each ruleset specifies: | ||
| * **Rules**: Conditions matched against OIDC token claims (repository, branch, workflow path). Wildcard patterns like `repo:my-org/*` are supported. | ||
| * **Resources**: Docker Hub repositories or Docker Build Cloud projects the workflow can access. | ||
| * **Scopes**: Permission levels (`read`, `write`). | ||
| 1. Save the connection and copy the **connection ID** for use in your workflow. | ||
|
|
||
| ## Updating your {% data variables.product.prodname_actions %} workflow | ||
|
|
||
| Once you have created an OIDC connection in Docker, update your workflow to authenticate using the [`docker/login-action`](https://github.com/docker/login-action) action. | ||
|
|
||
| The following example uses the placeholder `YOUR_CONNECTION_ID` for the connection ID you copied from Docker, and `YOUR_DOCKER_ORG` for your Docker organization name. | ||
|
|
||
| ```yaml | ||
|
gmondello marked this conversation as resolved.
|
||
| {% data reusables.actions.actions-not-certified-by-github-comment %} | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check out repository | ||
| uses: {% data reusables.actions.action-checkout %} | ||
|
|
||
| - name: Sign in to Docker Hub with OIDC | ||
| uses: docker/login-action@abd2ef45e78c5afb21d64d4ca52ee8550d9572c7 # v4.5.1 | ||
| with: | ||
| username: YOUR_DOCKER_ORG | ||
| env: | ||
| DOCKERHUB_OIDC_CONNECTIONID: YOUR_CONNECTION_ID | ||
|
|
||
| - name: Build and push | ||
| uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 | ||
| with: | ||
| push: true | ||
| tags: YOUR_DOCKER_ORG/my-image:latest | ||
| ``` | ||
|
|
||
| ### Key workflow settings | ||
|
|
||
| * **`permissions.id-token: write`** is required so that {% data variables.product.prodname_dotcom %} can issue an OIDC token for the workflow. | ||
| * The `docker/login-action` handles the OIDC token exchange and Docker login in a single step when `DOCKERHUB_OIDC_CONNECTIONID` is set and `password` is omitted. | ||
| * The `username` field should be your Docker organization name. | ||
|
|
||
| ### Using the token as an output | ||
|
|
||
| If your workflow needs the Docker access token as a separate output (for example, for API calls or custom authentication flows), use [`docker/oidc-action`](https://github.com/docker/oidc-action) to perform the token exchange explicitly: | ||
|
|
||
| ```yaml | ||
| {% data reusables.actions.actions-not-certified-by-github-comment %} | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Get Docker OIDC token | ||
| id: docker-oidc | ||
| uses: docker/oidc-action@3f002d200df5620744c973221788e401898c6f86 # v1 | ||
| with: | ||
| connection_id: YOUR_CONNECTION_ID | ||
|
|
||
| - name: Sign in to Docker Hub | ||
| uses: docker/login-action@abd2ef45e78c5afb21d64d4ca52ee8550d9572c7 # v4.5.1 | ||
| with: | ||
| username: YOUR_DOCKER_ORG | ||
| password: {% raw %}${{ steps.docker-oidc.outputs.token }}{% endraw %} | ||
| ``` | ||
|
|
||
| ### Subject claim matching | ||
|
|
||
| Docker evaluates the `sub` claim from the {% data variables.product.prodname_dotcom %} OIDC token against the rulesets you configured. The default subject claim format is: | ||
|
|
||
| ```text | ||
| repo:<owner>/<repo>:ref:refs/heads/<branch> | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > Repositories created or renamed after July 15, 2026 use immutable owner and repository identifiers in the subject claim, for example: `repo:octocat@123456/my-repo@456789:ref:refs/heads/main`. For more information, see [AUTOTITLE](/actions/concepts/security/openid-connect). | ||
|
|
||
| Different workflow triggers produce different subject claims. For example: | ||
|
|
||
| | Trigger | Subject claim format | | ||
| |---------|---------------------| | ||
| | Branch push | `repo:my-org/my-repo:ref:refs/heads/main` | | ||
| | Pull request | `repo:my-org/my-repo:pull_request` | | ||
| | Tag | `repo:my-org/my-repo:ref:refs/tags/v1.0` | | ||
| | Environment | `repo:my-org/my-repo:environment:production` | | ||
|
|
||
| You can use wildcard patterns in your rulesets to match multiple repositories or branches. For example, `repo:my-org/*` matches all repositories in your organization. | ||
|
gmondello marked this conversation as resolved.
|
||
|
|
||
| For more information, see [Rulesets and subject claims](https://docs.docker.com/enterprise/security/oidc-connections/rulesets-claims/) in the Docker documentation. | ||
|
|
||
| ## Further reading | ||
|
|
||
| * [AUTOTITLE](/actions/concepts/security/openid-connect) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.