Skip to content

Commit

Permalink
use auth for acrs only
Browse files Browse the repository at this point in the history
  • Loading branch information
abhilashjoseph committed Nov 10, 2023
1 parent 49cc1bf commit 5a546e0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
5 changes: 5 additions & 0 deletions pkg/azure/credentialprovider/acr.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func (c CloudConfigCredentialProvider) GetAcrCredentials(image string) (k8sCrede
Password: "",
}

if !c.IsAcrRegistry(image) {
klog.V(4).Info("image not from acr, returning empty credentials")
return cred, nil
}

if c.config.UseManagedIdentityExtension {
klog.V(4).Info("using managed identity for acr credentials")
loginServer := parseACRLoginServerFromImage(image, c.environment)
Expand Down
36 changes: 25 additions & 11 deletions pkg/docker/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,31 @@ func getContainerRegistryRemoteOptions(ctx context.Context, client kubernetes.In
return nil, fmt.Errorf("cannot fetch acr credentials: %w", err)
}

sec := []corev1.Secret{ //{
*dockerCfgSecretType.Create(container.Namespace, "secret", registry, authn.AuthConfig{
Username: dockerConfigEntry.Username, Password: dockerConfigEntry.Password,
}),
}
*authChain, err = k8schain.NewFromPullSecrets(
ctx,
sec,
)
if err != nil {
return nil, err
if dockerConfigEntry.Username != "" {

sec := []corev1.Secret{ //{
*dockerCfgSecretType.Create(container.Namespace, "secret", registry, authn.AuthConfig{
Username: dockerConfigEntry.Username, Password: dockerConfigEntry.Password,
}),
}
*authChain, err = k8schain.NewFromPullSecrets(
ctx,
sec,
)
if err != nil {
return nil, err
}
} else {
*authChain, err = k8schain.New(
ctx,
client,
k8schain.Options{
Namespace: container.Namespace,
ServiceAccountName: container.ServiceAccountName},
)
if err != nil {
return nil, err
}
}

default:
Expand Down

0 comments on commit 5a546e0

Please sign in to comment.