Compare commits

..

17 Commits

Author SHA1 Message Date
Aman Singh 648478377d addressed comments 2022-08-01 20:59:21 +05:30
Aman Singh 8d244528bc fixed dockerfile 2022-08-01 19:25:24 +05:30
Aman Singh 032be851de addressed comments 2022-08-01 19:22:48 +05:30
Aman Singh 2a15df4bd0 fixed error handeling 2022-08-01 18:25:50 +05:30
Aman Singh edde153446 addressed pr review comments 2022-08-01 18:13:58 +05:30
Aman Singh c32ed28951 addressed pr review comments 2022-08-01 18:12:07 +05:30
Aman Singh 83dc0a47c8 fixed go.mod and go.sum 2022-08-01 13:27:50 +05:30
Aman Singh 2a96f08569 moved code to an external file 2022-08-01 13:25:49 +05:30
Aman Singh 40b88e559f fixed push code 2022-08-01 13:10:57 +05:30
Aman Singh 42860e1bf6 fixed drone.yml 2022-08-01 12:55:51 +05:30
Aman Singh 261458b664 fixed base image 2022-08-01 12:49:29 +05:30
Aman Singh 62904766db addressed pr comments 2022-08-01 12:34:34 +05:30
Aman Singh fdf1104358 addressed pr comments 2022-08-01 12:33:00 +05:30
Aman Singh 39ca5e4471 added dockerfile 2022-08-01 12:04:26 +05:30
Aman Singh bb4c34c632 fixed cert support 2022-08-01 11:32:27 +05:30
Aman Singh 97101432f6 added drone yaml 2022-08-01 10:45:36 +05:30
Aman Singh 08b3a85089 Added acr integration 2022-08-01 10:44:47 +05:30
3 changed files with 15 additions and 25 deletions
-1
View File
@@ -2,4 +2,3 @@ release
coverage.out
vendor
.idea
.vscode
+14 -22
View File
@@ -2,7 +2,6 @@ package main
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
@@ -27,7 +26,7 @@ const (
clientSecretKeyEnv string = "AZURE_CLIENT_SECRET"
tenantKeyEnv string = "AZURE_TENANT_ID"
certPathEnv string = "AZURE_CLIENT_CERTIFICATE_PATH"
dockerConfigPath string = "/kaniko/.docker"
dockerConfigPath string = "/kaniko/.docker/config.json"
defaultDigestFile string = "/kaniko/digest-file"
)
@@ -131,7 +130,7 @@ func main() {
},
cli.StringFlag{
Name: "client-cert",
Usage: "Azure client certificate encoded in base64 format",
Usage: "Azure client certificate",
EnvVar: "CLIENT_CERTIFICATE",
},
cli.StringFlag{
@@ -297,7 +296,7 @@ func getACRToken(tenantId, clientId, clientSecret, cert, registry string) (strin
}
if clientSecret == "" && cert == "" {
return "", fmt.Errorf("one of client secret or cert should be defined")
return "", fmt.Errorf("one of client secert or cert should be defined")
}
// in case of authentication via cert
@@ -308,22 +307,15 @@ func getACRToken(tenantId, clientId, clientSecret, cert, registry string) (strin
}
}
if err := os.Setenv(clientIdEnv, clientId); err != nil {
return "", errors.Wrap(err, "failed to set env variable client Id")
}
if err := os.Setenv(clientSecretKeyEnv, clientSecret); err != nil {
return "", errors.Wrap(err, "failed to set env variable client secret")
}
if err := os.Setenv(tenantKeyEnv, tenantId); err != nil {
return "", errors.Wrap(err, "failed to set env variable tenant Id")
}
if err := os.Setenv(certPathEnv, ACRCertPath); err != nil {
return "", errors.Wrap(err, "failed to set env variable cert path")
}
// TODO check for presence of file as well.
os.Setenv(clientIdEnv, clientId)
os.Setenv(clientSecretKeyEnv, clientSecret)
os.Setenv(tenantKeyEnv, tenantId)
env, err := azidentity.NewEnvironmentCredential(nil)
if err != nil {
return "", errors.Wrap(err, "failed to get env credentials from azure")
}
policy := policy.TokenRequestOptions{
Scopes: []string{"https://management.azure.com/.default"},
}
@@ -374,14 +366,14 @@ func fetchACRToken(tenantId, token, registry string) (string, error) {
return "", errors.New("failed to get refresh token from acr")
}
func setupACRCert(cert string) error {
decoded, err := base64.StdEncoding.DecodeString(cert)
if err != nil {
return errors.Wrap(err, "failed to base64 decode ACR certificate")
}
err = ioutil.WriteFile(ACRCertPath, []byte(decoded), 0644)
func setupACRCert(jsonKey string) error {
err := ioutil.WriteFile(ACRCertPath, []byte(jsonKey), 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
}
+1 -2
View File
@@ -26,8 +26,7 @@ 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))
filePath := path + "/config.json"
err = ioutil.WriteFile(filePath, jsonBytes, 0644)
err = ioutil.WriteFile(path, jsonBytes, 0644)
if err != nil {
return errors.Wrap(err, "failed to create docker config file")
}