@@ -16,60 +16,76 @@ type RegistryCredentials struct {
16
16
Password string `yaml:"-" json:"-" mapstructure:"password"`
17
17
// IMPORTANT: do not show the token in any YAML/JSON output (sensitive information)
18
18
Token string `yaml:"-" json:"-" mapstructure:"token"`
19
+
20
+ TLSCert string `yaml:"tls-cert,omitempty" json:"tls-cert,omitempty" mapstructure:"tls-cert"`
21
+ TLSKey string `yaml:"tls-key,omitempty" json:"tls-key,omitempty" mapstructure:"tls-key"`
19
22
}
20
23
21
24
type registry struct {
22
25
InsecureSkipTLSVerify bool `yaml:"insecure-skip-tls-verify" json:"insecure-skip-tls-verify" mapstructure:"insecure-skip-tls-verify"`
23
26
InsecureUseHTTP bool `yaml:"insecure-use-http" json:"insecure-use-http" mapstructure:"insecure-use-http"`
24
27
Auth []RegistryCredentials `yaml:"auth" json:"auth" mapstructure:"auth"`
28
+ CACert string `yaml:"ca-cert" json:"ca-cert" mapstructure:"ca-cert"`
25
29
}
26
30
27
31
func (cfg registry ) loadDefaultValues (v * viper.Viper ) {
28
32
v .SetDefault ("registry.insecure-skip-tls-verify" , false )
29
33
v .SetDefault ("registry.insecure-use-http" , false )
30
34
v .SetDefault ("registry.auth" , []RegistryCredentials {})
35
+ v .SetDefault ("registry.ca-cert" , "" )
31
36
}
32
37
33
38
//nolint:unparam
34
39
func (cfg * registry ) parseConfigValues () error {
35
40
// there may be additional credentials provided by env var that should be appended to the set of credentials
36
- authority , username , password , token :=
41
+ authority , username , password , token , tlsCert , tlsKey :=
37
42
os .Getenv ("GRYPE_REGISTRY_AUTH_AUTHORITY" ),
38
43
os .Getenv ("GRYPE_REGISTRY_AUTH_USERNAME" ),
39
44
os .Getenv ("GRYPE_REGISTRY_AUTH_PASSWORD" ),
40
- os .Getenv ("GRYPE_REGISTRY_AUTH_TOKEN" )
45
+ os .Getenv ("GRYPE_REGISTRY_AUTH_TOKEN" ),
46
+ os .Getenv ("GRYPE_REGISTRY_AUTH_TLS_CERT" ),
47
+ os .Getenv ("GRYPE_REGISTRY_AUTH_TLS_KEY" )
41
48
42
- if hasNonEmptyCredentials (username , password , token ) {
49
+ if hasNonEmptyCredentials (username , password , token , tlsCert , tlsKey ) {
43
50
// note: we prepend the credentials such that the environment variables take precedence over on-disk configuration.
44
51
cfg .Auth = append ([]RegistryCredentials {
45
52
{
46
53
Authority : authority ,
47
54
Username : username ,
48
55
Password : password ,
49
56
Token : token ,
57
+ TLSCert : tlsCert ,
58
+ TLSKey : tlsKey ,
50
59
},
51
60
}, cfg .Auth ... )
52
61
}
53
62
return nil
54
63
}
55
64
56
- func hasNonEmptyCredentials (username , password , token string ) bool {
57
- return password != "" && username != "" || token != ""
65
+ func hasNonEmptyCredentials (username , password , token , tlsCert , tlsKey string ) bool {
66
+ hasUserPass := username != "" && password != ""
67
+ hasToken := token != ""
68
+ hasTLSMaterial := tlsCert != "" && tlsKey != ""
69
+ return hasUserPass || hasToken || hasTLSMaterial
58
70
}
59
71
60
72
func (cfg * registry ) ToOptions () * image.RegistryOptions {
61
73
var auth = make ([]image.RegistryCredentials , len (cfg .Auth ))
62
74
for i , a := range cfg .Auth {
63
75
auth [i ] = image.RegistryCredentials {
64
- Authority : a .Authority ,
65
- Username : a .Username ,
66
- Password : a .Password ,
67
- Token : a .Token ,
76
+ Authority : a .Authority ,
77
+ Username : a .Username ,
78
+ Password : a .Password ,
79
+ Token : a .Token ,
80
+ ClientCert : a .TLSCert ,
81
+ ClientKey : a .TLSKey ,
68
82
}
69
83
}
84
+
70
85
return & image.RegistryOptions {
71
86
InsecureSkipTLSVerify : cfg .InsecureSkipTLSVerify ,
72
87
InsecureUseHTTP : cfg .InsecureUseHTTP ,
73
88
Credentials : auth ,
89
+ CAFileOrDir : cfg .CACert ,
74
90
}
75
91
}
0 commit comments