Skip to content

Commit

Permalink
feat(datasource/docker): Enable additional authentication mechansim f…
Browse files Browse the repository at this point in the history
…or private ECR repositories (#30053)
  • Loading branch information
super-mcgin committed Jul 7, 2024
1 parent a1708c0 commit 06349b9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
23 changes: 23 additions & 0 deletions docs/usage/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ module.exports = {

#### AWS ECR (Amazon Web Services Elastic Container Registry)

#### Using access key id & secret

Renovate can authenticate with AWS ECR using AWS access key id & secret as the username & password, for example:

```json
Expand All @@ -254,6 +256,27 @@ Renovate can authenticate with AWS ECR using AWS access key id & secret as the u
}
```

##### Using `get-login-password`

Renovate can also authenticate with AWS ECR using the output from the `aws ecr get-login-password` command as outlined in
the [AWS documentation](https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html#registry-auth-token).
To make use of this authentication mechanism, specify the username as `AWS`:

```json
{
"hostRules": [
{
"hostType": "docker",
"matchHost": "12345612312.dkr.ecr.us-east-1.amazonaws.com",
"username": "AWS",
"encrypted": {
"password": "w...A"
}
}
]
}
```

#### Google Container Registry / Google Artifact Registry

##### Using Application Default Credentials / Workload Identity (Self-Hosted only)
Expand Down
10 changes: 9 additions & 1 deletion lib/modules/datasource/docker/ecr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ export async function getECRAuthToken(
opts: HostRule,
): Promise<string | null> {
const config: ECRClientConfig = { region };
if (opts.username && opts.password) {
if (opts.username === `AWS` && opts.password) {
logger.trace(
`AWS user specified, encoding basic auth credentials for ECR registry`,
);
return Buffer.from(`AWS:${opts.password}`).toString('base64');
} else if (opts.username && opts.password) {
logger.trace(
`Using AWS accessKey to get Authorization token for ECR registry`,
);
config.credentials = {
accessKeyId: opts.username,
secretAccessKey: opts.password,
Expand Down
27 changes: 27 additions & 0 deletions lib/modules/datasource/docker/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,33 @@ describe('modules/datasource/docker/index', () => {
expect(res).toBeNull();
});

it('supports ECR authentication for private repositories', async () => {
httpMock
.scope(amazonUrl)
.get('/')
.reply(401, '', {
'www-authenticate': 'Basic realm="My Private Docker Registry Server"',
})
.head('/node/manifests/some-tag')
.matchHeader('authorization', 'Basic QVdTOnNvbWUtcGFzc3dvcmQ=')
.reply(200, '', { 'docker-content-digest': 'some-digest' });

hostRules.find.mockReturnValue({
username: 'AWS',
password: 'some-password',
});

const res = await getDigest(
{
datasource: 'docker',
packageName: '123456789.dkr.ecr.us-east-1.amazonaws.com/node',
},
'some-tag',
);

expect(res).toBe('some-digest');
});

it('supports Google ADC authentication for gcr', async () => {
httpMock
.scope(gcrUrl)
Expand Down

0 comments on commit 06349b9

Please sign in to comment.