mirror of
https://github.com/docker/login-action.git
synced 2026-08-07 11:14:18 +08:00
Compare commits
2 Commits
dockerhub-
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9b180b02b | ||
|
|
45e208d066 |
@@ -757,10 +757,10 @@ The following inputs can be used as `step.with` keys:
|
|||||||
|
|
||||||
The following environment variables can be set as `step.env` keys:
|
The following environment variables can be set as `step.env` keys:
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|-------------------------------|--------|---------|----------------------------------------------------------------------------------------------------|
|
|-------------------------------|--------|---------|-----------------------------------------------------------------------------|
|
||||||
| `DOCKERHUB_OIDC_CONNECTIONID` | String | | Docker Hub OIDC connection ID. Required for Docker Hub OIDC login |
|
| `DOCKERHUB_OIDC_CONNECTIONID` | String | | Docker Hub OIDC connection ID. Required for Docker Hub OIDC login |
|
||||||
| `DOCKERHUB_OIDC_EXPIREIN` | Number | `300` | Docker Hub OIDC token lifetime in seconds. Must be between `300` (5 minutes) and `21600` (6 hours) |
|
| `DOCKERHUB_OIDC_EXPIREIN` | Number | `300` | Docker Hub OIDC token lifetime in seconds. Must be between `300` and `3600` |
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {beforeEach, describe, expect, test, vi} from 'vitest';
|
|||||||
import * as dockerhub from '../src/dockerhub.js';
|
import * as dockerhub from '../src/dockerhub.js';
|
||||||
|
|
||||||
vi.mock('@actions/core', () => ({
|
vi.mock('@actions/core', () => ({
|
||||||
debug: vi.fn(),
|
|
||||||
getIDToken: vi.fn(),
|
getIDToken: vi.fn(),
|
||||||
info: vi.fn(),
|
info: vi.fn(),
|
||||||
setSecret: vi.fn()
|
setSecret: vi.fn()
|
||||||
@@ -84,22 +83,13 @@ describe('getOIDCToken', () => {
|
|||||||
expect(body.get('connection_id')).toBe(validConnectionID);
|
expect(body.get('connection_id')).toBe(validConnectionID);
|
||||||
expect(body.get('expires_in')).toBe('300');
|
expect(body.get('expires_in')).toBe('300');
|
||||||
expect(setSecretMock).toHaveBeenCalledWith('hub-token');
|
expect(setSecretMock).toHaveBeenCalledWith('hub-token');
|
||||||
expect(core.info).toHaveBeenCalledWith('Docker Hub OIDC detected for docker.io');
|
|
||||||
expect(core.info).toHaveBeenCalledWith('Retrieving GitHub OIDC token for Docker Hub');
|
|
||||||
expect(core.info).toHaveBeenCalledWith('Exchanging GitHub OIDC token for Docker Hub token');
|
|
||||||
expect(core.info).toHaveBeenCalledWith('Docker Hub OIDC token exchange succeeded');
|
|
||||||
expect(core.debug).toHaveBeenCalledWith('Docker Hub OIDC token audience: https://identity.docker.com');
|
|
||||||
expect(core.debug).toHaveBeenCalledWith('Docker Hub OIDC token expiration: 300s');
|
|
||||||
expect(core.debug).toHaveBeenCalledWith('Sending Docker Hub OIDC token request to https://identity.docker.com/oauth/token');
|
|
||||||
expect(core.debug).toHaveBeenCalledWith('Docker Hub OIDC token request returned status code 200');
|
|
||||||
expect(core.debug).toHaveBeenCalledWith('Docker Hub OIDC token response status code: 200');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('uses custom token expiration', async () => {
|
test('uses custom token expiration', async () => {
|
||||||
process.env.DOCKERHUB_OIDC_EXPIREIN = '21600';
|
process.env.DOCKERHUB_OIDC_EXPIREIN = '900';
|
||||||
await dockerhub.getOIDCToken('docker.io', 'dbowie');
|
await dockerhub.getOIDCToken('docker.io', 'dbowie');
|
||||||
const body = new URLSearchParams(postSpy.mock.calls[0][1]);
|
const body = new URLSearchParams(postSpy.mock.calls[0][1]);
|
||||||
expect(body.get('expires_in')).toBe('21600');
|
expect(body.get('expires_in')).toBe('900');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('uses stage identity host for stage registry', async () => {
|
test('uses stage identity host for stage registry', async () => {
|
||||||
@@ -122,9 +112,9 @@ describe('getOIDCToken', () => {
|
|||||||
expect(postSpy).not.toHaveBeenCalled();
|
expect(postSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test.each(['not-a-number', '299', '21601'])('validates token expiration %p', async expiresIn => {
|
test.each(['not-a-number', '299', '3601'])('validates token expiration %p', async expiresIn => {
|
||||||
process.env.DOCKERHUB_OIDC_EXPIREIN = expiresIn;
|
process.env.DOCKERHUB_OIDC_EXPIREIN = expiresIn;
|
||||||
await expect(dockerhub.getOIDCToken('docker.io', 'dbowie')).rejects.toThrow(`Invalid DOCKERHUB_OIDC_EXPIREIN: ${expiresIn}. Must be between 300 and 21600`);
|
await expect(dockerhub.getOIDCToken('docker.io', 'dbowie')).rejects.toThrow(`Invalid DOCKERHUB_OIDC_EXPIREIN: ${expiresIn}. Must be between 300 and 3600`);
|
||||||
expect(getIDTokenMock).not.toHaveBeenCalled();
|
expect(getIDTokenMock).not.toHaveBeenCalled();
|
||||||
expect(postSpy).not.toHaveBeenCalled();
|
expect(postSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|||||||
202
dist/index.cjs
generated
vendored
202
dist/index.cjs
generated
vendored
File diff suppressed because one or more lines are too long
6
dist/index.cjs.map
generated
vendored
6
dist/index.cjs.map
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/licenses.txt
generated
vendored
2
dist/licenses.txt
generated
vendored
@@ -2399,7 +2399,7 @@ SOFTWARE.
|
|||||||
The following npm packages may be included in this product:
|
The following npm packages may be included in this product:
|
||||||
|
|
||||||
- js-yaml@5.2.1
|
- js-yaml@5.2.1
|
||||||
- js-yaml@5.2.2
|
- js-yaml@5.2.3
|
||||||
|
|
||||||
These packages each contain the following license:
|
These packages each contain the following license:
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
"@docker/actions-toolkit": "^0.94.0",
|
"@docker/actions-toolkit": "^0.94.0",
|
||||||
"http-proxy-agent": "^9.1.0",
|
"http-proxy-agent": "^9.1.0",
|
||||||
"https-proxy-agent": "^9.1.0",
|
"https-proxy-agent": "^9.1.0",
|
||||||
"js-yaml": "^5.2.2",
|
"js-yaml": "^5.2.3",
|
||||||
"uuid": "^14.0.1"
|
"uuid": "^14.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ interface OIDCTokenResponse {
|
|||||||
const registries = new Set(['', 'docker.io', 'registry-1.docker.io', 'registry-1-stage.docker.io', 'dhi.io']);
|
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 = 21600;
|
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 => {
|
||||||
@@ -35,10 +35,6 @@ export const getOIDCToken = async (registry: string, username: string): Promise<
|
|||||||
const expiresIn = getExpiresIn();
|
const expiresIn = getExpiresIn();
|
||||||
const identityHost = registry === 'registry-1-stage.docker.io' ? 'identity-stage.docker.com' : 'identity.docker.com';
|
const identityHost = registry === 'registry-1-stage.docker.io' ? 'identity-stage.docker.com' : 'identity.docker.com';
|
||||||
const audience = `https://${identityHost}`;
|
const audience = `https://${identityHost}`;
|
||||||
core.info(`Docker Hub OIDC detected for ${registry || 'docker.io'}`);
|
|
||||||
core.debug(`Docker Hub OIDC token audience: ${audience}`);
|
|
||||||
core.debug(`Docker Hub OIDC token expiration: ${expiresIn}s`);
|
|
||||||
core.info(`Retrieving GitHub OIDC token for Docker Hub`);
|
|
||||||
const idToken = await core.getIDToken(audience);
|
const idToken = await core.getIDToken(audience);
|
||||||
const http: httpm.HttpClient = new httpm.HttpClient('github.com/docker/login-action', [], {
|
const http: httpm.HttpClient = new httpm.HttpClient('github.com/docker/login-action', [], {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -53,12 +49,10 @@ export const getOIDCToken = async (registry: string, username: string): Promise<
|
|||||||
data.set('connection_id', connectionID);
|
data.set('connection_id', connectionID);
|
||||||
data.set('expires_in', expiresIn.toString());
|
data.set('expires_in', expiresIn.toString());
|
||||||
|
|
||||||
core.info(`Exchanging GitHub OIDC token for Docker Hub token`);
|
|
||||||
const resp = await postWithRetry(http, `https://${identityHost}/oauth/token`, data.toString());
|
const resp = await postWithRetry(http, `https://${identityHost}/oauth/token`, data.toString());
|
||||||
|
|
||||||
const tokenResp = <OIDCTokenResponse>JSON.parse(await handleResponse(resp));
|
const tokenResp = <OIDCTokenResponse>JSON.parse(await handleResponse(resp));
|
||||||
core.setSecret(tokenResp.access_token);
|
core.setSecret(tokenResp.access_token);
|
||||||
core.info(`Docker Hub OIDC token exchange succeeded`);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
username,
|
username,
|
||||||
@@ -76,20 +70,16 @@ const getExpiresIn = (): number => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const postWithRetry = async (http: httpm.HttpClient, url: string, data: string): Promise<httpm.HttpClientResponse> => {
|
const postWithRetry = async (http: httpm.HttpClient, url: string, data: string): Promise<httpm.HttpClientResponse> => {
|
||||||
core.debug(`Sending Docker Hub OIDC token request to ${url}`);
|
|
||||||
let resp = await http.post(url, data);
|
let resp = await http.post(url, data);
|
||||||
core.debug(`Docker Hub OIDC token request returned status code ${resp.message.statusCode || HttpCodes.InternalServerError}`);
|
|
||||||
for (let attempt = 0; (resp.message.statusCode || HttpCodes.InternalServerError) === HttpCodes.TooManyRequests && attempt < maxRetries; attempt++) {
|
for (let attempt = 0; (resp.message.statusCode || HttpCodes.InternalServerError) === HttpCodes.TooManyRequests && attempt < maxRetries; attempt++) {
|
||||||
const delay = parseRetryAfter(resp.message.headers['retry-after']);
|
const delay = parseRetryAfter(resp.message.headers['retry-after']);
|
||||||
if (delay === null) {
|
if (delay === null) {
|
||||||
core.debug(`Docker Hub OIDC token request rate limited without retry-after header`);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
await resp.readBody();
|
await resp.readBody();
|
||||||
core.info(`Docker Hub OIDC token request rate limited, retrying in ${delay}ms (attempt ${attempt + 1}/${maxRetries})`);
|
core.info(`Docker Hub OIDC token request rate limited, retrying in ${delay}ms (attempt ${attempt + 1}/${maxRetries})`);
|
||||||
await new Promise(resolve => setTimeout(resolve, delay));
|
await new Promise(resolve => setTimeout(resolve, delay));
|
||||||
resp = await http.post(url, data);
|
resp = await http.post(url, data);
|
||||||
core.debug(`Docker Hub OIDC token request returned status code ${resp.message.statusCode || HttpCodes.InternalServerError}`);
|
|
||||||
}
|
}
|
||||||
return resp;
|
return resp;
|
||||||
};
|
};
|
||||||
@@ -111,7 +101,6 @@ const parseRetryAfter = (value: string | string[] | undefined): number | null =>
|
|||||||
const handleResponse = async (resp: httpm.HttpClientResponse): Promise<string> => {
|
const handleResponse = async (resp: httpm.HttpClientResponse): Promise<string> => {
|
||||||
const body = await resp.readBody();
|
const body = await resp.readBody();
|
||||||
const statusCode = resp.message.statusCode || HttpCodes.InternalServerError;
|
const statusCode = resp.message.statusCode || HttpCodes.InternalServerError;
|
||||||
core.debug(`Docker Hub OIDC token response status code: ${statusCode}`);
|
|
||||||
if (statusCode < HttpCodes.OK || statusCode >= HttpCodes.MultipleChoices) {
|
if (statusCode < HttpCodes.OK || statusCode >= HttpCodes.MultipleChoices) {
|
||||||
throw parseError(statusCode, body);
|
throw parseError(statusCode, body);
|
||||||
}
|
}
|
||||||
|
|||||||
10
yarn.lock
10
yarn.lock
@@ -3174,7 +3174,7 @@ __metadata:
|
|||||||
globals: "npm:^17.3.0"
|
globals: "npm:^17.3.0"
|
||||||
http-proxy-agent: "npm:^9.1.0"
|
http-proxy-agent: "npm:^9.1.0"
|
||||||
https-proxy-agent: "npm:^9.1.0"
|
https-proxy-agent: "npm:^9.1.0"
|
||||||
js-yaml: "npm:^5.2.2"
|
js-yaml: "npm:^5.2.3"
|
||||||
prettier: "npm:^3.8.1"
|
prettier: "npm:^3.8.1"
|
||||||
typescript: "npm:^5.9.3"
|
typescript: "npm:^5.9.3"
|
||||||
uuid: "npm:^14.0.1"
|
uuid: "npm:^14.0.1"
|
||||||
@@ -4357,14 +4357,14 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"js-yaml@npm:^5.2.2":
|
"js-yaml@npm:^5.2.3":
|
||||||
version: 5.2.2
|
version: 5.2.3
|
||||||
resolution: "js-yaml@npm:5.2.2"
|
resolution: "js-yaml@npm:5.2.3"
|
||||||
dependencies:
|
dependencies:
|
||||||
argparse: "npm:^2.0.1"
|
argparse: "npm:^2.0.1"
|
||||||
bin:
|
bin:
|
||||||
js-yaml: bin/js-yaml.mjs
|
js-yaml: bin/js-yaml.mjs
|
||||||
checksum: 10/2b4c2933af12c97e1c4894a4f27fe9b06dab70a64a96bb50624b4429bef6bf11008bde20d868bce52a36784473314efc30078ba6025b58cf7537961e23b1ae9c
|
checksum: 10/5d2562f2d7e7bc51bd678b43d2dbc3965129ac854222c794157369c8904d249cfc78325dff8fc64becb505a2506242548c54c8fa50cdb24554bb1a557e460004
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user