Skip to content

Commit f1b4e37

Browse files
authored
Merge pull request #2376 from lizardruss/acr-auth-fix
fix: skip /auth call for ACR registries
2 parents 8913da3 + f18ecf8 commit f1b4e37

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

pkg/devspace/build/builder/docker/docker.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import (
44
"context"
55
"encoding/base64"
66
"encoding/json"
7-
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
8-
"github.com/loft-sh/devspace/pkg/devspace/kubectl"
9-
command2 "github.com/loft-sh/loft-util/pkg/command"
10-
"github.com/sirupsen/logrus"
117
"io"
128
"os"
139
"path/filepath"
1410
"strings"
1511

12+
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
13+
"github.com/loft-sh/devspace/pkg/devspace/kubectl"
14+
command2 "github.com/loft-sh/loft-util/pkg/command"
15+
"github.com/sirupsen/logrus"
16+
1617
"github.com/docker/cli/cli/streams"
1718
"github.com/loft-sh/devspace/pkg/devspace/build/builder/restart"
1819

@@ -112,13 +113,21 @@ func (b *Builder) BuildImage(ctx devspacecontext.Context, contextPath, dockerfil
112113

113114
// Authenticate
114115
if !b.skipPush && !b.helper.ImageConf.SkipPush {
115-
ctx.Log().Info("Authenticating (" + displayRegistryURL + ")...")
116-
_, err = b.Authenticate(ctx.Context())
117-
if err != nil {
118-
return errors.Errorf("Error during image registry authentication: %v", err)
119-
}
116+
if pullsecrets.IsAzureContainerRegistry(registryURL) {
117+
ctx.Log().Warn("Using an Azure Container Registry(ACR), skipping authentication. You may need to refresh your credentials by running 'az acr login'")
118+
b.authConfig, err = b.client.GetAuthConfig(ctx.Context(), registryURL, true)
119+
if err != nil {
120+
return err
121+
}
122+
} else {
123+
ctx.Log().Info("Authenticating (" + displayRegistryURL + ")...")
124+
_, err = b.Authenticate(ctx.Context())
125+
if err != nil {
126+
return errors.Errorf("Error during image registry authentication: %v", err)
127+
}
120128

121-
ctx.Log().Done("Authentication successful (" + displayRegistryURL + ")")
129+
ctx.Log().Done("Authentication successful (" + displayRegistryURL + ")")
130+
}
122131
}
123132

124133
// Buildoptions

pkg/devspace/pullsecrets/init.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package pullsecrets
22

33
import (
4-
"strings"
54
"time"
65

76
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
@@ -19,6 +18,8 @@ import (
1918
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2019
)
2120

21+
const AzureContainerRegistryUsername = "00000000-0000-0000-0000-000000000000"
22+
2223
func (r *client) EnsurePullSecret(ctx devspacecontext.Context, dockerClient docker.Client, namespace, registryURL string) error {
2324
pullSecret := &latest.PullSecretConfig{Registry: registryURL}
2425

@@ -175,8 +176,8 @@ func (r *client) createPullSecret(ctx devspacecontext.Context, dockerClient dock
175176

176177
// Handle Azure Container Registry (ACR) when credentials helper does not provide a username
177178
// https://learn.microsoft.com/en-us/azure/container-registry/container-registry-authentication?tabs=azure-cli#az-acr-login-with---expose-token
178-
if username == "" && strings.HasSuffix(authConfig.ServerAddress, "azurecr.io") {
179-
username = "00000000-0000-0000-0000-000000000000"
179+
if username == "" && IsAzureContainerRegistry(authConfig.ServerAddress) {
180+
username = AzureContainerRegistryUsername
180181
}
181182
}
182183
}

pkg/devspace/pullsecrets/util.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package pullsecrets
22

33
import (
4+
"strings"
5+
46
"github.com/docker/distribution/reference"
57
dockerregistry "github.com/docker/docker/registry"
68
)
@@ -23,3 +25,7 @@ func GetRegistryFromImageName(imageName string) (string, error) {
2325

2426
return repoInfo.Index.Name, nil
2527
}
28+
29+
func IsAzureContainerRegistry(serverAddress string) bool {
30+
return strings.HasSuffix(serverAddress, "azurecr.io")
31+
}

0 commit comments

Comments
 (0)