mirror of
https://github.com/docker/login-action.git
synced 2026-04-07 23:38:19 +01:00
Compare commits
8 Commits
f95fe26bb1
...
v3.7.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c94ce9fb46 | ||
|
|
8339c958ce | ||
|
|
c83e9320c8 | ||
|
|
b268aa57e3 | ||
|
|
a603229278 | ||
|
|
7567f92a74 | ||
|
|
0567fa5ae8 | ||
|
|
f6ef577545 |
59
README.md
59
README.md
@@ -25,6 +25,7 @@ ___
|
||||
* [Quay.io](#quayio)
|
||||
* [DigitalOcean](#digitalocean-container-registry)
|
||||
* [Authenticate to multiple registries](#authenticate-to-multiple-registries)
|
||||
* [Set scopes for the authentication token](#set-scopes-for-the-authentication-token)
|
||||
* [Customizing](#customizing)
|
||||
* [inputs](#inputs)
|
||||
* [Contributing](#contributing)
|
||||
@@ -527,8 +528,8 @@ jobs:
|
||||
```
|
||||
|
||||
You can also use the `registry-auth` input for raw authentication to
|
||||
registries, defined as YAML objects. Each object can contain `registry`,
|
||||
`username`, `password` and `ecr` keys similar to current inputs:
|
||||
registries, defined as YAML objects. Each object have the same attributes as
|
||||
current inputs (except `logout`):
|
||||
|
||||
> [!WARNING]
|
||||
> We don't recommend using this method, it's better to use the action multiple
|
||||
@@ -557,6 +558,60 @@ jobs:
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
### Set scopes for the authentication token
|
||||
|
||||
The `scope` input allows limiting registry credentials to a specific repository
|
||||
or namespace scope when building images with Buildx.
|
||||
|
||||
This is useful in GitHub Actions to avoid overriding the Docker Hub
|
||||
authentication token embedded in GitHub-hosted runners, which is used for
|
||||
pulling images without rate limits. By scoping credentials, you can
|
||||
authenticate only where needed (typically for pushing), while keeping
|
||||
unauthenticated pulls for base images.
|
||||
|
||||
When `scope` is set, credentials are written to the Buildx configuration
|
||||
instead of the global Docker configuration. This means:
|
||||
* Authentication applies only to the specified scope
|
||||
* The default Docker Hub credentials remain available for pulls
|
||||
* Credentials are used only by Buildx during the build
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Credentials written to the Buildx configuration are only accessible by Buildx.
|
||||
> They are not available to `docker pull`, `docker push`, or any other Docker
|
||||
> CLI commands outside Buildx.
|
||||
|
||||
> [!NOTE]
|
||||
> This feature requires Buildx version 0.31.0 or later.
|
||||
|
||||
```yaml
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: main
|
||||
|
||||
jobs:
|
||||
login:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Login to Docker Hub (scoped)
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ vars.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
scope: 'myorg/myimage@push'
|
||||
-
|
||||
name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
push: true
|
||||
tags: myorg/myimage:latest
|
||||
```
|
||||
|
||||
In this example, base images are pulled using the embedded GitHub-hosted runner
|
||||
credentials, while authenticated access is used only to push `myorg/myimage`.
|
||||
|
||||
## Customizing
|
||||
|
||||
### inputs
|
||||
|
||||
@@ -11,6 +11,7 @@ describe('isECR', () => {
|
||||
['876820548815.dkr.ecr.cn-north-1.amazonaws.com.cn', true],
|
||||
['390948362332.dkr.ecr.cn-northwest-1.amazonaws.com.cn', true],
|
||||
['012345678901.dkr-ecr.eu-north-1.on.aws', true],
|
||||
['012345678901.dkr.ecr.eusc-de-east-1.amazonaws.eu', true],
|
||||
['public.ecr.aws', true],
|
||||
['ecr-public.aws.com', true]
|
||||
])('given registry %p', async (registry, expected) => {
|
||||
@@ -26,6 +27,7 @@ describe('isPubECR', () => {
|
||||
['876820548815.dkr.ecr.cn-north-1.amazonaws.com.cn', false],
|
||||
['390948362332.dkr.ecr.cn-northwest-1.amazonaws.com.cn', false],
|
||||
['012345678901.dkr-ecr.eu-north-1.on.aws', false],
|
||||
['012345678901.dkr.ecr.eusc-de-east-1.amazonaws.eu', false],
|
||||
['public.ecr.aws', true],
|
||||
['ecr-public.aws.com', true]
|
||||
])('given registry %p', async (registry, expected) => {
|
||||
@@ -39,6 +41,7 @@ describe('getRegion', () => {
|
||||
['876820548815.dkr.ecr.cn-north-1.amazonaws.com.cn', 'cn-north-1'],
|
||||
['390948362332.dkr.ecr.cn-northwest-1.amazonaws.com.cn', 'cn-northwest-1'],
|
||||
['012345678901.dkr-ecr.eu-north-1.on.aws', 'eu-north-1'],
|
||||
['012345678901.dkr.ecr.eusc-de-east-1.amazonaws.eu', 'eusc-de-east-1'],
|
||||
['public.ecr.aws', 'us-east-1']
|
||||
])('given registry %p', async (registry, expected) => {
|
||||
expect(aws.getRegion(registry)).toEqual(expected);
|
||||
@@ -52,6 +55,7 @@ describe('getAccountIDs', () => {
|
||||
['012345678901.dkr.ecr.eu-west-3.amazonaws.com', '012345678901,012345678910,023456789012', ['012345678901', '012345678910', '023456789012']],
|
||||
['390948362332.dkr.ecr.cn-northwest-1.amazonaws.com.cn', '012345678910,023456789012', ['390948362332', '012345678910', '023456789012']],
|
||||
['876820548815.dkr-ecr.eu-north-1.on.aws', '012345678910,023456789012', ['876820548815', '012345678910', '023456789012']],
|
||||
['012345678901.dkr.ecr.eusc-de-east-1.amazonaws.eu', '012345678910,023456789012', ['012345678901', '012345678910', '023456789012']],
|
||||
['public.ecr.aws', undefined, []]
|
||||
])('given registry %p', async (registry, accountIDsEnv, expected) => {
|
||||
if (accountIDsEnv) {
|
||||
|
||||
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@@ -5,7 +5,7 @@ import {NodeHttpHandler} from '@smithy/node-http-handler';
|
||||
import {HttpProxyAgent} from 'http-proxy-agent';
|
||||
import {HttpsProxyAgent} from 'https-proxy-agent';
|
||||
|
||||
const ecrRegistryRegex = /^(([0-9]{12})\.(dkr\.ecr|dkr-ecr)\.(.+)\.(on\.aws|amazonaws\.com(.cn)?))(\/([^:]+)(:.+)?)?$/;
|
||||
const ecrRegistryRegex = /^(([0-9]{12})\.(dkr\.ecr|dkr-ecr)\.(.+)\.(on\.aws|amazonaws\.(com(.cn)?|eu)))(\/([^:]+)(:.+)?)?$/;
|
||||
const ecrPublicRegistryRegex = /public\.ecr\.aws|ecr-public\.aws\.com/;
|
||||
|
||||
export const isECR = (registry: string): boolean => {
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as core from '@actions/core';
|
||||
import * as yaml from 'js-yaml';
|
||||
|
||||
import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx';
|
||||
import {Util} from '@docker/actions-toolkit/lib/util';
|
||||
|
||||
export interface Inputs {
|
||||
registry: string;
|
||||
@@ -69,7 +70,7 @@ export function getAuthList(inputs: Inputs): Array<Auth> {
|
||||
}
|
||||
|
||||
export function scopeToConfigDir(registry: string, scope?: string): string {
|
||||
if (!scope || scope === '') {
|
||||
if (scopeDisabled() || !scope || scope === '') {
|
||||
return '';
|
||||
}
|
||||
let configDir = path.join(Buildx.configDir, 'config', registry === 'docker.io' ? 'registry-1.docker.io' : registry);
|
||||
@@ -80,3 +81,10 @@ export function scopeToConfigDir(registry: string, scope?: string): string {
|
||||
}
|
||||
return configDir;
|
||||
}
|
||||
|
||||
function scopeDisabled(): boolean {
|
||||
if (process.env.DOCKER_LOGIN_SCOPE_DISABLED) {
|
||||
return Util.parseBool(process.env.DOCKER_LOGIN_SCOPE_DISABLED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -56,9 +56,10 @@ export async function loginECR(registry: string, username: string, password: str
|
||||
|
||||
async function loginExec(registry: string, username: string, password: string, scope?: string): Promise<void> {
|
||||
let envs: {[key: string]: string} | undefined;
|
||||
if (scope && scope !== '') {
|
||||
const configDir = context.scopeToConfigDir(registry, scope);
|
||||
if (configDir !== '') {
|
||||
envs = Object.assign({}, process.env, {
|
||||
DOCKER_CONFIG: context.scopeToConfigDir(registry, scope)
|
||||
DOCKER_CONFIG: configDir
|
||||
}) as {
|
||||
[key: string]: string;
|
||||
};
|
||||
|
||||
@@ -6357,9 +6357,9 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"lodash@npm:^4.17.15":
|
||||
version: 4.17.21
|
||||
resolution: "lodash@npm:4.17.21"
|
||||
checksum: 10/c08619c038846ea6ac754abd6dd29d2568aa705feb69339e836dfa8d8b09abbb2f859371e86863eda41848221f9af43714491467b5b0299122431e202bb0c532
|
||||
version: 4.17.23
|
||||
resolution: "lodash@npm:4.17.23"
|
||||
checksum: 10/82504c88250f58da7a5a4289f57a4f759c44946c005dd232821c7688b5fcfbf4a6268f6a6cdde4b792c91edd2f3b5398c1d2a0998274432cff76def48735e233
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user