mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2026-02-03 04:09:29 -05:00
fix: Authentication to ECR public (#690)
Originally proposed by @achille-roussel in https://github.com/kreuzwerker/terraform-provider-docker/pull/666
This commit is contained in:
parent
dacb5dfe73
commit
4a46383d4c
4 changed files with 22 additions and 4 deletions
|
|
@ -41,8 +41,12 @@ func normalizeECRPasswordForDockerCLIUsage(password string) string {
|
|||
return password[4:]
|
||||
}
|
||||
|
||||
func isECRPublicRepositoryURL(url string) bool {
|
||||
return url == "public.ecr.aws"
|
||||
}
|
||||
|
||||
func isECRRepositoryURL(url string) bool {
|
||||
if url == "public.ecr.aws" {
|
||||
if isECRPublicRepositoryURL(url) {
|
||||
return true
|
||||
}
|
||||
// Regexp is based on the ecr urls shown in https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html
|
||||
|
|
|
|||
|
|
@ -4,8 +4,16 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestIsECRRepositoryURL(t *testing.T) {
|
||||
func TestIsECRPublicRepositoryURL(t *testing.T) {
|
||||
if !isECRPublicRepositoryURL("public.ecr.aws") {
|
||||
t.Fatalf("Expected true")
|
||||
}
|
||||
if isECRPublicRepositoryURL("public.ecr.aws.com") {
|
||||
t.Fatalf("Expected false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsECRRepositoryURL(t *testing.T) {
|
||||
if !isECRRepositoryURL("2385929435838.dkr.ecr.eu-central-1.amazonaws.com") {
|
||||
t.Fatalf("Expected true")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,10 @@ func getImageDigest(registry string, registryWithProtocol string, image, tag, us
|
|||
if registry != "ghcr.io" && !isECRRepositoryURL(registry) && !isAzureCRRepositoryURL(registry) && registry != "gcr.io" {
|
||||
req.SetBasicAuth(username, password)
|
||||
} else {
|
||||
if isECRRepositoryURL(registry) {
|
||||
if isECRPublicRepositoryURL(registry) {
|
||||
password = normalizeECRPasswordForHTTPUsage(password)
|
||||
req.Header.Add("Authorization", "Bearer "+password)
|
||||
} else if isECRRepositoryURL(registry) {
|
||||
password = normalizeECRPasswordForHTTPUsage(password)
|
||||
req.Header.Add("Authorization", "Basic "+password)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -270,7 +270,10 @@ func deleteDockerRegistryImage(pushOpts internalPushImageOptions, registryWithPr
|
|||
if pushOpts.Registry != "ghcr.io" && !isECRRepositoryURL(pushOpts.Registry) && !isAzureCRRepositoryURL(pushOpts.Registry) && pushOpts.Registry != "gcr.io" {
|
||||
req.SetBasicAuth(username, password)
|
||||
} else {
|
||||
if isECRRepositoryURL(pushOpts.Registry) {
|
||||
if isECRPublicRepositoryURL(pushOpts.Registry) {
|
||||
password = normalizeECRPasswordForHTTPUsage(password)
|
||||
req.Header.Add("Authorization", "Bearer "+password)
|
||||
} else if isECRRepositoryURL(pushOpts.Registry) {
|
||||
password = normalizeECRPasswordForHTTPUsage(password)
|
||||
req.Header.Add("Authorization", "Basic "+password)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue