Skip to content

Commit dbd0547

Browse files
gmondelloakristenclaudeCopilotmchammer01
authored
Add OIDC in Docker guide for GitHub Actions deployments (#45243)
Co-authored-by: Alexa Kristensen <81787716+akristen@users.noreply.github.com> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: mc <42146119+mchammer01@users.noreply.github.com> Co-authored-by: subatoi <32935794+subatoi@users.noreply.github.com>
1 parent 484d6ea commit dbd0547

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

‎content/actions/how-tos/secure-your-work/security-harden-deployments/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ versions:
1313
children:
1414
- /oidc-in-aws
1515
- /oidc-in-azure
16+
- /oidc-in-docker
1617
- /oidc-in-google-cloud-platform
1718
- /oidc-in-hashicorp-vault
1819
- /oidc-in-jfrog
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
title: Configuring OpenID Connect in Docker
3+
shortTitle: OIDC in Docker
4+
intro: Use OpenID Connect within your workflows to authenticate with Docker without storing long-lived credentials.
5+
versions:
6+
fpt: '*'
7+
ghec: '*'
8+
contentType: how-tos
9+
category:
10+
- Secure your workflows
11+
---
12+
13+
## Overview
14+
15+
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 %}.
16+
17+
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.
18+
19+
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.
20+
21+
For more information, see [OIDC connections](https://docs.docker.com/enterprise/security/oidc-connections/) in the Docker documentation.
22+
23+
## Prerequisites
24+
25+
{% data reusables.actions.oidc-link-to-intro %}
26+
27+
{% data reusables.actions.oidc-security-notice %}
28+
29+
{% data reusables.actions.oidc-on-ghecom %}
30+
31+
* Your Docker organization must use Docker Business, Docker Team, or Docker Hardened Images, or be enrolled in the Docker Sponsored Open Source Program.
32+
* You must be an organization owner or editor in your Docker organization.
33+
* You must plan which repositories, branches, and workflows need access to Docker, and configure rulesets accordingly.
34+
35+
## Adding the identity provider to Docker
36+
37+
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/security/authentication/oidc-connections/create-manage/) in the Docker documentation.
38+
39+
1. Sign in to [Docker Home](https://app.docker.com/) and navigate to your organization.
40+
1. Go to **Identity & auth** > **OIDC connections**.
41+
1. Select **Create OIDC connection**.
42+
1. Configure at least one ruleset to define which {% data variables.product.prodname_dotcom %} repositories, branches, or workflows can authenticate. Each ruleset specifies:
43+
* **Rules**: Conditions matched against OIDC token claims (repository, branch, workflow path). Wildcard patterns like `repo:my-org/*` are supported.
44+
* **Resources**: Docker Hub repositories or Docker Build Cloud projects the workflow can access.
45+
* **Scopes**: Permission levels (`read`, `write`).
46+
1. Save the connection and copy the **connection ID** for use in your workflow.
47+
48+
## Updating your {% data variables.product.prodname_actions %} workflow
49+
50+
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.
51+
52+
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.
53+
54+
```yaml
55+
{% data reusables.actions.actions-not-certified-by-github-comment %}
56+
permissions:
57+
id-token: write
58+
contents: read
59+
60+
jobs:
61+
build:
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Check out repository
65+
uses: {% data reusables.actions.action-checkout %}
66+
67+
- name: Sign in to Docker Hub with OIDC
68+
uses: docker/login-action@abd2ef45e78c5afb21d64d4ca52ee8550d9572c7 # v4.5.1
69+
with:
70+
username: YOUR-DOCKER-ORG
71+
env:
72+
DOCKERHUB_OIDC_CONNECTIONID: YOUR-CONNECTION-ID
73+
74+
- name: Build and push
75+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
76+
with:
77+
push: true
78+
tags: YOUR-DOCKER-ORG/my-image:latest
79+
```
80+
81+
### Key workflow settings
82+
83+
* **`permissions.id-token: write`** is required so that {% data variables.product.prodname_dotcom %} can issue an OIDC token for the workflow.
84+
* 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.
85+
* The `username` field should be your Docker organization name.
86+
87+
### Subject claim matching
88+
89+
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:
90+
91+
```text
92+
repo:<owner>/<repo>:ref:refs/heads/<branch>
93+
```
94+
95+
> [!NOTE]
96+
> Repositories created after July 15, 2026, and repository renames or transfers after that date, use an immutable default OIDC `sub` claim that includes owner and repository IDs. Existing repositories keep the previous format unless they opt in. For more information, see [AUTOTITLE](/actions/reference/security/oidc#immutable-subject-claims).
97+
98+
Different workflow triggers produce different subject claims. For example:
99+
100+
| Trigger | Subject claim format |
101+
|---------|---------------------|
102+
| Branch push | `repo:my-org/my-repo:ref:refs/heads/main` |
103+
| Pull request | `repo:my-org/my-repo:pull_request` |
104+
| Tag | `repo:my-org/my-repo:ref:refs/tags/v1.0` |
105+
| Environment | `repo:my-org/my-repo:environment:production` |
106+
107+
You can use wildcard patterns in your rulesets to match multiple repositories or branches. For legacy subject claims, `repo:my-org/*` matches all repositories in the organization. For immutable subject claims, use `repo:my-org@OWNER-ID/*`; if the organization contains repositories using both formats, configure both patterns.
108+
109+
For more information, see [Rulesets and subject claims](https://docs.docker.com/security/authentication/oidc-connections/rulesets-claims/) in the Docker documentation.

0 commit comments

Comments
 (0)