mirror of
https://github.com/drone/drone-kaniko.git
synced 2026-06-26 16:03:13 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 648478377d | |||
| 8d244528bc | |||
| 032be851de | |||
| 2a15df4bd0 | |||
| edde153446 | |||
| c32ed28951 | |||
| 83dc0a47c8 | |||
| 2a96f08569 | |||
| 40b88e559f | |||
| 42860e1bf6 | |||
| 261458b664 | |||
| 62904766db | |||
| fdf1104358 | |||
| 39ca5e4471 | |||
| bb4c34c632 | |||
| 97101432f6 | |||
| 08b3a85089 |
@@ -2,4 +2,3 @@ release
|
||||
coverage.out
|
||||
vendor
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
+14
-22
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user