-
Notifications
You must be signed in to change notification settings - Fork 68.8k
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
411ad22
1791b9b
6559ae5
bc657ad
18f1857
addecea
dcaf739
4e2c9f3
2cef39a
762690f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -47,7 +47,7 @@ To use OIDC with Docker, establish a trust relationship between {% data variable | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## 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/oidc-action`](https://github.com/docker/oidc-action) and [`docker/login-action`](https://github.com/docker/login-action) actions. | ||||||||||||||||||||||||||
| 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. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -64,17 +64,12 @@ jobs: | |||||||||||||||||||||||||
| - name: Check out repository | ||||||||||||||||||||||||||
| uses: {% data reusables.actions.action-checkout %} | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - 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@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4 | ||||||||||||||||||||||||||
| - name: Sign in to Docker Hub with OIDC | ||||||||||||||||||||||||||
| uses: docker/login-action@abd2ef45e78c5afb21d64d4ca52ee8550d9572c7 # v4.5.1 | ||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||
| username: YOUR_DOCKER_ORG | ||||||||||||||||||||||||||
| password: {% raw %}${{ steps.docker-oidc.outputs.token }}{% endraw %} | ||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||
| DOCKERHUB_OIDC_CONNECTIONID: YOUR_CONNECTION_ID | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - name: Build and push | ||||||||||||||||||||||||||
| uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 | ||||||||||||||||||||||||||
|
|
@@ -86,8 +81,35 @@ jobs: | |||||||||||||||||||||||||
| ### 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/oidc-action` exchanges the {% data variables.product.prodname_dotcom %} OIDC token for a short-lived Docker access token based on your connection's rulesets. | ||||||||||||||||||||||||||
| * The `docker/login-action` uses the token output to authenticate with Docker Hub. The `username` field should be your Docker organization name. | ||||||||||||||||||||||||||
| * 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: | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This content suggests using the token for API calls or custom authentication. However, the pinned
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. going to remove this section altogether |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```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 | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved in 4e2c9f3. |
||||||||||||||||||||||||||
| password: {% raw %}${{ steps.docker-oidc.outputs.token }}{% endraw %} | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Subject claim matching | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same note here about
DOCKERHUB_OIDC_CONNECTIONIDusing underscores vs hyphens.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line only references the literal
DOCKERHUB_OIDC_CONNECTIONIDenv var name, not a placeholder, so there's nothing to change here specifically — the actual fix is the placeholder hyphenation applied below in the second example, resolved in 4e2c9f3.