@@ -21,17 +21,19 @@ import (
21
21
// TODO: Delete everything that is unused in here
22
22
23
23
const (
24
- envVaultAddr = "VAULT_ADDR"
25
- envVaultToken = "VAULT_TOKEN"
26
- envVaultClientCert = "VAULT_CLIENT_CERT"
27
- envVaultClientKey = "VAULT_CLIENT_KEY"
28
- envVaultCACert = "VAULT_CACERT"
29
- envVaultAppRoleID = "VAULT_APPROLE_ID"
30
- envVaultAppRoleSecretID = "VAULT_APPROLE_SECRET_ID" // #nosec G101
31
- envVaultNamespace = "VAULT_NAMESPACE"
24
+ envVaultAddr = "VAULT_ADDR"
25
+ envVaultToken = "VAULT_TOKEN"
26
+ envVaultClientCert = "VAULT_CLIENT_CERT"
27
+ envVaultClientKey = "VAULT_CLIENT_KEY"
28
+ envVaultCACert = "VAULT_CACERT"
29
+ envVaultAppRoleID = "VAULT_APPROLE_ID"
30
+ envVaultAppRoleSecretID = "VAULT_APPROLE_SECRET_ID" // #nosec G101
31
+ envVaultNamespace = "VAULT_NAMESPACE"
32
+ envVaultTransitEnginePath = "VAULT_TRANSIT_ENGINE_PATH"
32
33
33
34
defaultCertMountPoint = "cert"
34
35
defaultPKIMountPoint = "pki"
36
+ defaultTransitEnginePath = "transit"
35
37
defaultAppRoleMountPoint = "approle"
36
38
defaultK8sMountPoint = "kubernetes"
37
39
)
@@ -93,6 +95,8 @@ type ClientParams struct {
93
95
MaxRetries * int
94
96
// Name of the Vault namespace
95
97
Namespace string
98
+ // TransitEnginePath specifies the path to the transit engine to perform key operations.
99
+ TransitEnginePath string
96
100
}
97
101
98
102
type Client struct {
@@ -110,6 +114,7 @@ func NewClientConfig(cp *ClientParams, logger hclog.Logger) (*ClientConfig, erro
110
114
AppRoleAuthMountPoint : defaultAppRoleMountPoint ,
111
115
K8sAuthMountPoint : defaultK8sMountPoint ,
112
116
PKIMountPoint : defaultPKIMountPoint ,
117
+ TransitEnginePath : defaultTransitEnginePath ,
113
118
}
114
119
if err := mergo .Merge (cp , defaultParams ); err != nil {
115
120
return nil , status .Errorf (codes .Internal , "unable to merge client params: %v" , err )
@@ -370,15 +375,13 @@ func (c *Client) CreateKey(ctx context.Context, spireKeyID string, keyType Trans
370
375
}
371
376
372
377
// TODO: Handle errors here such as key already exists
373
- // TODO: Make the transit engine path configurable
374
- _ , err := c .vaultClient .Logical ().WriteWithContext (ctx , fmt .Sprintf ("/transit/keys/%s" , spireKeyID ), arguments )
378
+ _ , err := c .vaultClient .Logical ().WriteWithContext (ctx , fmt .Sprintf ("/%s/keys/%s" , c .clientParams .TransitEnginePath , spireKeyID ), arguments )
375
379
return err
376
380
}
377
381
378
382
func (c * Client ) GetKey (ctx context.Context , spireKeyID string ) (string , error ) {
379
383
// TODO: Handle errors here
380
- // TODO: Make the transit engine path configurable
381
- res , err := c .vaultClient .Logical ().ReadWithContext (ctx , fmt .Sprintf ("/transit/keys/%s" , spireKeyID ))
384
+ res , err := c .vaultClient .Logical ().ReadWithContext (ctx , fmt .Sprintf ("/%s/keys/%s" , c .clientParams .TransitEnginePath , spireKeyID ))
382
385
if err != nil {
383
386
return "" , err
384
387
}
@@ -428,8 +431,7 @@ func (c *Client) SignData(ctx context.Context, spireKeyID string, data []byte, h
428
431
}
429
432
430
433
// TODO: Handle errors here
431
- // TODO: Make the transit engine path configurable
432
- sigResp , err := c .vaultClient .Logical ().WriteWithContext (ctx , fmt .Sprintf ("/transit/sign/%s/%s" , spireKeyID , hashAlgo ), body )
434
+ sigResp , err := c .vaultClient .Logical ().WriteWithContext (ctx , fmt .Sprintf ("/%s/sign/%s/%s" , c .clientParams .TransitEnginePath , spireKeyID , hashAlgo ), body )
433
435
if err != nil {
434
436
return nil , status .Errorf (codes .Internal , "transit engine sign call failed: %v" , err )
435
437
}
0 commit comments