mirror of
https://github.com/docker/login-action.git
synced 2026-07-25 14:17:57 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b472f5b276 | |||
| abd2ef45e7 | |||
| d49d3a9839 | |||
| b58b17c30b | |||
| be646c21ce | |||
| d77c059cb9 |
@@ -173,6 +173,27 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
username: ${{ vars.DOCKERHUB_OIDC_USERNAME }}
|
username: ${{ vars.DOCKERHUB_OIDC_USERNAME }}
|
||||||
|
|
||||||
|
registry-auth-oidc:
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
id-token: write
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
-
|
||||||
|
name: Login to registries
|
||||||
|
uses: ./
|
||||||
|
env:
|
||||||
|
DOCKERHUB_OIDC_CONNECTIONID: ${{ vars.DOCKERHUB_OIDC_CONNECTIONID }}
|
||||||
|
with:
|
||||||
|
registry-auth: |
|
||||||
|
- username: ${{ vars.DOCKERHUB_OIDC_USERNAME }}
|
||||||
|
- registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
ecr:
|
ecr:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
|
|||||||
@@ -648,6 +648,38 @@ jobs:
|
|||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Docker Hub OIDC can also be used with `registry-auth`. Grant `id-token: write`,
|
||||||
|
set `DOCKERHUB_OIDC_CONNECTIONID`, pass the Docker Hub organization name as
|
||||||
|
`username`, and omit `password` for the Docker Hub object:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: ci
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: main
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
login:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Login to registries
|
||||||
|
uses: docker/login-action@v4
|
||||||
|
env:
|
||||||
|
DOCKERHUB_OIDC_CONNECTIONID: ${{ vars.DOCKERHUB_OIDC_CONNECTIONID }}
|
||||||
|
with:
|
||||||
|
registry-auth: |
|
||||||
|
- username: ${{ vars.DOCKERHUB_ORGANIZATION }}
|
||||||
|
- registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
### Set scopes for the authentication token
|
### Set scopes for the authentication token
|
||||||
|
|
||||||
The `scope` input allows limiting registry credentials to a specific repository
|
The `scope` input allows limiting registry credentials to a specific repository
|
||||||
|
|||||||
@@ -54,6 +54,25 @@ test('getAuthList skips secret masking when registry-auth password is absent', a
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getAuthList supports password-less Docker Hub registry-auth for OIDC', async () => {
|
||||||
|
const [auth] = getAuthList({
|
||||||
|
registry: '',
|
||||||
|
username: '',
|
||||||
|
password: '',
|
||||||
|
scope: '',
|
||||||
|
ecr: '',
|
||||||
|
logout: true,
|
||||||
|
registryAuth: '- username: docker-org\n'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(auth).toMatchObject({
|
||||||
|
registry: 'docker.io',
|
||||||
|
username: 'docker-org',
|
||||||
|
password: undefined,
|
||||||
|
ecr: 'auto'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('getAuthList masks registry-auth password when present', async () => {
|
test('getAuthList masks registry-auth password when present', async () => {
|
||||||
const stdoutWriteSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
|
const stdoutWriteSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
|
||||||
getAuthList({
|
getAuthList({
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
import {expect, test, vi} from 'vitest';
|
import {afterEach, expect, test, vi} from 'vitest';
|
||||||
|
|
||||||
import {Docker} from '@docker/actions-toolkit/lib/docker/docker.js';
|
import {Docker} from '@docker/actions-toolkit/lib/docker/docker.js';
|
||||||
|
|
||||||
import {loginStandard, logout} from '../src/docker.js';
|
import {login, loginStandard, logout} from '../src/docker.js';
|
||||||
|
import * as dockerhub from '../src/dockerhub.js';
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
delete process.env.DOCKERHUB_OIDC_CONNECTIONID;
|
||||||
|
});
|
||||||
|
|
||||||
test('loginStandard calls exec', async () => {
|
test('loginStandard calls exec', async () => {
|
||||||
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
||||||
@@ -32,6 +38,37 @@ test('loginStandard calls exec', async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('login exchanges Docker Hub OIDC token for password-less auth', async () => {
|
||||||
|
process.env.DOCKERHUB_OIDC_CONNECTIONID = '123e4567-e89b-42d3-a456-426614174000';
|
||||||
|
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
||||||
|
return {
|
||||||
|
exitCode: 0,
|
||||||
|
stdout: '',
|
||||||
|
stderr: ''
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const oidcSpy = vi.spyOn(dockerhub, 'getOIDCToken').mockResolvedValue({
|
||||||
|
username: 'docker-org',
|
||||||
|
token: 'hub-token'
|
||||||
|
});
|
||||||
|
|
||||||
|
await login({
|
||||||
|
registry: 'docker.io',
|
||||||
|
username: 'docker-org',
|
||||||
|
password: '',
|
||||||
|
scope: '',
|
||||||
|
ecr: 'auto',
|
||||||
|
configDir: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(oidcSpy).toHaveBeenCalledWith('docker.io', 'docker-org');
|
||||||
|
expect(execSpy).toHaveBeenCalledWith(['login', '--password-stdin', '--username', 'docker-org', 'docker.io'], {
|
||||||
|
input: Buffer.from('hub-token'),
|
||||||
|
silent: true,
|
||||||
|
ignoreReturnCode: true
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('logout calls exec', async () => {
|
test('logout calls exec', async () => {
|
||||||
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
||||||
return {
|
return {
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+3
-3
File diff suppressed because one or more lines are too long
+2
-5
@@ -12,17 +12,14 @@ interface OIDCTokenResponse {
|
|||||||
access_token: string;
|
access_token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const registries = new Set(['', 'docker.io', 'registry-1.docker.io', 'registry-1-stage.docker.io', 'dhi.io']);
|
||||||
const defaultExpiresIn = 300;
|
const defaultExpiresIn = 300;
|
||||||
const minExpiresIn = 300;
|
const minExpiresIn = 300;
|
||||||
const maxExpiresIn = 3600;
|
const maxExpiresIn = 3600;
|
||||||
const maxRetries = 5;
|
const maxRetries = 5;
|
||||||
|
|
||||||
export const isDockerHubOIDC = (registry: string, password: string): boolean => {
|
export const isDockerHubOIDC = (registry: string, password: string): boolean => {
|
||||||
return process.env.DOCKERHUB_OIDC_CONNECTIONID !== undefined && !password && isDockerHubRegistry(registry);
|
return process.env.DOCKERHUB_OIDC_CONNECTIONID !== undefined && !password && registries.has(registry);
|
||||||
};
|
|
||||||
|
|
||||||
const isDockerHubRegistry = (registry: string): boolean => {
|
|
||||||
return registry === '' || registry === 'docker.io' || registry === 'registry-1.docker.io' || registry === 'registry-1-stage.docker.io';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getOIDCToken = async (registry: string, username: string): Promise<LoginCredentials> => {
|
export const getOIDCToken = async (registry: string, username: string): Promise<LoginCredentials> => {
|
||||||
|
|||||||
@@ -4853,12 +4853,12 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"nanoid@npm:^3.3.11":
|
"nanoid@npm:^3.3.16":
|
||||||
version: 3.3.11
|
version: 3.3.16
|
||||||
resolution: "nanoid@npm:3.3.11"
|
resolution: "nanoid@npm:3.3.16"
|
||||||
bin:
|
bin:
|
||||||
nanoid: bin/nanoid.cjs
|
nanoid: bin/nanoid.cjs
|
||||||
checksum: 10/73b5afe5975a307aaa3c95dfe3334c52cdf9ae71518176895229b8d65ab0d1c0417dd081426134eb7571c055720428ea5d57c645138161e7d10df80815527c48
|
checksum: 10/8004af92b5541af1dbd23b69845b5026f777d5b7ef07163cea1837aae86e052ced8b383cecbf8a4f1b5e77ae207df96dc45e16b9e0fa3c4b761d085f1e42851b
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -5281,13 +5281,13 @@ __metadata:
|
|||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"postcss@npm:^8.5.6":
|
"postcss@npm:^8.5.6":
|
||||||
version: 8.5.10
|
version: 8.5.22
|
||||||
resolution: "postcss@npm:8.5.10"
|
resolution: "postcss@npm:8.5.22"
|
||||||
dependencies:
|
dependencies:
|
||||||
nanoid: "npm:^3.3.11"
|
nanoid: "npm:^3.3.16"
|
||||||
picocolors: "npm:^1.1.1"
|
picocolors: "npm:^1.1.1"
|
||||||
source-map-js: "npm:^1.2.1"
|
source-map-js: "npm:^1.2.1"
|
||||||
checksum: 10/7eac6169e535b63c8412e94d4f6047fc23efa3e9dde804b541940043c831b25f1cd867d83cd2c4371ad2450c8abcb42c208aa25668c1f0f3650d7f72faf711a8
|
checksum: 10/7944444f267f2d94c7caeed66f3da56d5b947bd4a7e57a166a5161af25c6006dd73f40e2a1a6822f3d7fccc2fa005778c03058368eb7efca1b5038aec55abd14
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user