Skip to content

Commit addecea

Browse files
committed
Lead with single-step OIDC login, move two-step to advanced section
login-action v4.5.1 now handles OIDC token exchange natively when DOCKERHUB_OIDC_CONNECTIONID is set. This is simpler for the common case. The two-step flow using docker/oidc-action is preserved for workflows that need the token as a separate output.
1 parent 18f1857 commit addecea

1 file changed

Lines changed: 34 additions & 12 deletions

File tree

  • content/actions/how-tos/secure-your-work/security-harden-deployments

content/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-docker.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ To use OIDC with Docker, establish a trust relationship between {% data variable
4747

4848
## Updating your {% data variables.product.prodname_actions %} workflow
4949

50-
Once you have created an OIDC connection in Docker, update your workflow to authenticate using the [`docker/oidc-action`](https://github.com/docker/oidc-action) and [`docker/login-action`](https://github.com/docker/login-action) actions.
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.
5151

5252
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.
5353

@@ -64,17 +64,12 @@ jobs:
6464
- name: Check out repository
6565
uses: {% data reusables.actions.action-checkout %}
6666

67-
- name: Get Docker OIDC token
68-
id: docker-oidc
69-
uses: docker/oidc-action@3f002d200df5620744c973221788e401898c6f86 # v1
70-
with:
71-
connection_id: YOUR_CONNECTION_ID
72-
73-
- name: Sign in to Docker Hub
74-
uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4
67+
- name: Sign in to Docker Hub with OIDC
68+
uses: docker/login-action@abd2ef45e78c5afb21d64d4ca52ee8550d9572c7 # v4.5.1
7569
with:
7670
username: YOUR_DOCKER_ORG
77-
password: {% raw %}${{ steps.docker-oidc.outputs.token }}{% endraw %}
71+
env:
72+
DOCKERHUB_OIDC_CONNECTIONID: YOUR_CONNECTION_ID
7873

7974
- name: Build and push
8075
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
@@ -86,8 +81,35 @@ jobs:
8681
### Key workflow settings
8782
8883
* **`permissions.id-token: write`** is required so that {% data variables.product.prodname_dotcom %} can issue an OIDC token for the workflow.
89-
* The `docker/oidc-action` exchanges the {% data variables.product.prodname_dotcom %} OIDC token for a short-lived Docker access token based on your connection's rulesets.
90-
* The `docker/login-action` uses the token output to authenticate with Docker Hub. The `username` field should be your Docker organization name.
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+
### Using the token as an output
88+
89+
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:
90+
91+
```yaml
92+
{% data reusables.actions.actions-not-certified-by-github-comment %}
93+
permissions:
94+
id-token: write
95+
contents: read
96+
97+
jobs:
98+
build:
99+
runs-on: ubuntu-latest
100+
steps:
101+
- name: Get Docker OIDC token
102+
id: docker-oidc
103+
uses: docker/oidc-action@3f002d200df5620744c973221788e401898c6f86 # v1
104+
with:
105+
connection_id: YOUR_CONNECTION_ID
106+
107+
- name: Sign in to Docker Hub
108+
uses: docker/login-action@abd2ef45e78c5afb21d64d4ca52ee8550d9572c7 # v4.5.1
109+
with:
110+
username: YOUR_DOCKER_ORG
111+
password: {% raw %}${{ steps.docker-oidc.outputs.token }}{% endraw %}
112+
```
91113

92114
### Subject claim matching
93115

0 commit comments

Comments
 (0)