fixed acr

This commit is contained in:
Aman Singh 2022-08-02 09:26:23 +05:30
parent 23b0ed0baa
commit d96c3d05e8
2 changed files with 7 additions and 9 deletions

@ -26,7 +26,7 @@ const (
clientSecretKeyEnv string = "AZURE_CLIENT_SECRET"
tenantKeyEnv string = "AZURE_TENANT_ID"
certPathEnv string = "AZURE_CLIENT_CERTIFICATE_PATH"
dockerConfigPath string = "/kaniko/.docker/config.json"
dockerConfigPath string = "/kaniko/.docker"
defaultDigestFile string = "/kaniko/digest-file"
)
@ -296,7 +296,7 @@ func getACRToken(tenantId, clientId, clientSecret, cert, registry string) (strin
}
if clientSecret == "" && cert == "" {
return "", fmt.Errorf("one of client secert or cert should be defined")
return "", fmt.Errorf("one of client secret or cert should be defined")
}
// in case of authentication via cert
@ -311,6 +311,7 @@ func getACRToken(tenantId, clientId, clientSecret, cert, registry string) (strin
os.Setenv(clientIdEnv, clientId)
os.Setenv(clientSecretKeyEnv, clientSecret)
os.Setenv(tenantKeyEnv, tenantId)
os.Setenv(certPathEnv, ACRCertPath)
env, err := azidentity.NewEnvironmentCredential(nil)
if err != nil {
return "", errors.Wrap(err, "failed to get env credentials from azure")
@ -366,14 +367,10 @@ func fetchACRToken(tenantId, token, registry string) (string, error) {
return "", errors.New("failed to get refresh token from acr")
}
func setupACRCert(jsonKey string) error {
err := ioutil.WriteFile(ACRCertPath, []byte(jsonKey), 0644)
func setupACRCert(cert string) error {
err := ioutil.WriteFile(ACRCertPath, []byte(cert), 0644)
if err != nil {
return errors.Wrap(err, "failed to write ACR certificate")
}
err = os.Setenv(certPathEnv, ACRCertPath)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to set %s environment variable", certPathEnv))
}
return nil
}

@ -26,7 +26,8 @@ func CreateDockerCfgFile(username, password, registry, path string) error {
authBytes := []byte(fmt.Sprintf("%s:%s", username, password))
encodedString := base64.StdEncoding.EncodeToString(authBytes)
jsonBytes := []byte(fmt.Sprintf(`{"auths": {"%s": {"auth": "%s"}}}`, "https://"+registry, encodedString))
err = ioutil.WriteFile(path, jsonBytes, 0644)
filePath := path + "/config.json"
err = ioutil.WriteFile(filePath, jsonBytes, 0644)
if err != nil {
return errors.Wrap(err, "failed to create docker config file")
}