@@ -51,22 +51,35 @@ type pluginHooks struct {
51
51
type Config struct {
52
52
// A URL of Vault server. (e.g., https://vault.example.com:8443/)
53
53
VaultAddr string `hcl:"vault_addr" json:"vault_addr"`
54
+ // Name of the Vault namespace
55
+ Namespace string `hcl:"namespace" json:"namespace"`
54
56
55
57
// Configuration for the Token authentication method
56
58
TokenAuth * TokenAuthConfig `hcl:"token_auth" json:"token_auth,omitempty"`
57
-
58
- // Name of the Vault namespace
59
- Namespace string `hcl:"namespace" json:"namespace"`
59
+ // Configuration for the AppRole authentication method
60
+ AppRoleAuth * AppRoleAuthConfig `hcl:"approle_auth" json:"approle_auth,omitempty"`
60
61
61
62
// TODO: Support other auth methods
62
63
// TODO: Support client certificate and key
63
64
}
64
65
66
+ // TokenAuthConfig represents parameters for token auth method
65
67
type TokenAuthConfig struct {
66
68
// Token string to set into "X-Vault-Token" header
67
69
Token string `hcl:"token" json:"token"`
68
70
}
69
71
72
+ // AppRoleAuthConfig represents parameters for AppRole auth method.
73
+ type AppRoleAuthConfig struct {
74
+ // Name of the mount point where AppRole auth method is mounted. (e.g., /auth/<mount_point>/login)
75
+ // If the value is empty, use default mount point (/auth/approle)
76
+ AppRoleMountPoint string `hcl:"approle_auth_mount_point" json:"approle_auth_mount_point"`
77
+ // An identifier that selects the AppRole
78
+ RoleID string `hcl:"approle_id" json:"approle_id"`
79
+ // A credential that is required for login.
80
+ SecretID string `hcl:"approle_secret_id" json:"approle_secret_id"`
81
+ }
82
+
70
83
// Plugin is the main representation of this keymanager plugin
71
84
type Plugin struct {
72
85
keymanagerv1.UnsafeKeyManagerServer
@@ -138,11 +151,25 @@ func parseAuthMethod(config *Config) (AuthMethod, error) {
138
151
authMethod = TOKEN
139
152
}
140
153
154
+ if config .AppRoleAuth != nil {
155
+ if err := checkForAuthMethodConfigured (authMethod ); err != nil {
156
+ return 0 , err
157
+ }
158
+ authMethod = APPROLE
159
+ }
160
+
141
161
if authMethod != 0 {
142
162
return authMethod , nil
143
163
}
144
164
145
- return 0 , status .Error (codes .InvalidArgument , "must be configured one of these authentication method 'Token'" )
165
+ return 0 , status .Error (codes .InvalidArgument , "one of the available authentication methods must be configured: 'Token, AppRole'" )
166
+ }
167
+
168
+ func checkForAuthMethodConfigured (authMethod AuthMethod ) error {
169
+ if authMethod != 0 {
170
+ return status .Error (codes .InvalidArgument , "only one authentication method can be configured" )
171
+ }
172
+ return nil
146
173
}
147
174
148
175
func (p * Plugin ) genClientParams (method AuthMethod , config * Config ) (* ClientParams , error ) {
@@ -154,6 +181,10 @@ func (p *Plugin) genClientParams(method AuthMethod, config *Config) (*ClientPara
154
181
switch method {
155
182
case TOKEN :
156
183
cp .Token = p .getEnvOrDefault (envVaultToken , config .TokenAuth .Token )
184
+ case APPROLE :
185
+ cp .AppRoleAuthMountPoint = config .AppRoleAuth .AppRoleMountPoint
186
+ cp .AppRoleID = p .getEnvOrDefault (envVaultAppRoleID , config .AppRoleAuth .RoleID )
187
+ cp .AppRoleSecretID = p .getEnvOrDefault (envVaultAppRoleSecretID , config .AppRoleAuth .SecretID )
157
188
}
158
189
159
190
return cp , nil
0 commit comments