Skip to content
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

Allow users to enable the default registry #504

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ A community-maintained package is available in the [Alpine Linux aports Reposito
```bash
$ apk add docker-credential-ecr-login
```
> [!NOTE]
> [!NOTE]
> Badge only shows edge, check [repository](https://pkgs.alpinelinux.org/packages?name=docker-credential-ecr-login) for stable releases or add `--repository=http://dl-cdn.alpinelinux.org/alpine/edge/community`

Once you have installed the credential helper, see the
Expand Down Expand Up @@ -219,7 +219,7 @@ contents of your `~/.docker/config.json` file to be:
This configures the Docker daemon to use the credential helper for all Amazon
ECR registries.

The Amazon ECR Docker Credential Helper can be used alongside your existing docker login authentication tokens:
The Amazon ECR Docker Credential Helper can be used alongside your existing docker login authentication tokens:

```json
{
Expand Down Expand Up @@ -293,6 +293,7 @@ The credentials must have a policy applied that
| AWS_ECR_DISABLE_CACHE | true | Disables the local file auth cache if set to a non-empty value |
| AWS_ECR_CACHE_DIR | ~/.ecr | Specifies the local file auth cache directory location |
| AWS_ECR_IGNORE_CREDS_STORAGE | true | Ignore calls to docker login or logout and pretend they succeeded |
| AWS_ECR_USE_DEFAULT_REGISTRY | true | Uses the default registry when the provided one cannot be parsed |

## Usage

Expand Down Expand Up @@ -335,7 +336,7 @@ If you test any experimental feaures, you can give feedback via the feature's tr
* Suggested improvements

Experimental features are incomplete in design and implementation. Backwards incompatible
changes may be introduced at any time or support dropped entirely. Therefore experimental
changes may be introduced at any time or support dropped entirely. Therefore experimental
features are **not recommended** for use in production environments.

## Security disclosures
Expand Down
15 changes: 13 additions & 2 deletions ecr-login/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/base64"
"fmt"
"net/url"
"os"
"regexp"
"strings"
"time"
Expand All @@ -37,7 +38,10 @@ const (
ecrPublicEndpoint = proxyEndpointScheme + ecrPublicName
)

var ecrPattern = regexp.MustCompile(`^(\d{12})\.dkr\.ecr(\-fips)?\.([a-zA-Z0-9][a-zA-Z0-9-_]*)\.(amazonaws\.com(\.cn)?|sc2s\.sgov\.gov|c2s\.ic\.gov|cloud\.adc-e\.uk|csp\.hci\.ic\.gov)$`)
var (
ecrPattern = regexp.MustCompile(`^(\d{12})\.dkr\.ecr(\-fips)?\.([a-zA-Z0-9][a-zA-Z0-9-_]*)\.(amazonaws\.com(\.cn)?|sc2s\.sgov\.gov|c2s\.ic\.gov|cloud\.adc-e\.uk|csp\.hci\.ic\.gov)$`)
ecrUseDefaultRegistry = os.Getenv("AWS_ECR_USE_DEFAULT_REGISTRY")
)

type Service string

Expand Down Expand Up @@ -69,7 +73,14 @@ func ExtractRegistry(input string) (*Registry, error) {
}, nil
}
matches := ecrPattern.FindStringSubmatch(serverURL.Hostname())
if len(matches) == 0 {
if len(matches) == 0 && ecrUseDefaultRegistry != "" {
return &Registry{
Service: ServiceECR,
ID: "",
FIPS: false,
Region: "",
}, nil
} else if len(matches) == 0 {
return nil, fmt.Errorf(programName + " can only be used with Amazon Elastic Container Registry.")
} else if len(matches) < 3 {
return nil, fmt.Errorf("%q is not a valid repository URI for Amazon Elastic Container Registry.", input)
Expand Down