@@ -3,7 +3,6 @@ package internal
33import (
44 "errors"
55 "fmt"
6- rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
76 "os"
87 "sync"
98 "time"
@@ -56,12 +55,12 @@ var (
5655 SecretClientCreationError error
5756)
5857
59- func GetSecretStoreClient (vaultSpec * rabbitmqv1beta1. VaultSpec ) (SecretStoreClient , error ) {
60- createSecretStoreClientOnce .Do (InitializeClient (vaultSpec ))
58+ func GetSecretStoreClient () (SecretStoreClient , error ) {
59+ createSecretStoreClientOnce .Do (InitializeClient ())
6160 return SecretClient , SecretClientCreationError
6261}
6362
64- func InitializeClient (vaultSpec * rabbitmqv1beta1. VaultSpec ) func () {
63+ func InitializeClient () func () {
6564 return func () {
6665 // VAULT_ADDR environment variable will be the address that pod uses to communicate with Vault.
6766 config := vault .DefaultConfig () // modify for more granular configuration
@@ -71,7 +70,7 @@ func InitializeClient(vaultSpec *rabbitmqv1beta1.VaultSpec) func() {
7170 return
7271 }
7372
74- go renewToken (vaultClient , vaultSpec , FirstLoginAttemptResultCh )
73+ go renewToken (vaultClient , FirstLoginAttemptResultCh )
7574 err = <- FirstLoginAttemptResultCh
7675 if err != nil {
7776 SecretClientCreationError = fmt .Errorf ("unable to login to Vault: %w" , err )
@@ -152,33 +151,31 @@ func availableKeys(m map[string]interface{}) []string {
152151 return result
153152}
154153
155- func login (vaultClient * vault.Client , vaultSpec * rabbitmqv1beta1. VaultSpec ) (* vault.Secret , error ) {
154+ func login (vaultClient * vault.Client ) (* vault.Secret , error ) {
156155 logger := ctrl .LoggerFrom (nil )
157156
158- var annotations = vaultSpec .Annotations
159- if annotations ["vault.hashicorp.com/namespace" ] != "" {
160- vaultClient .SetNamespace (annotations ["vault.hashicorp.com/namespace" ])
161- }
162-
163157 jwt , err := ReadServiceAccountTokenFunc ()
164158 if err != nil {
165159 return nil , fmt .Errorf ("unable to read file containing service account token: %w" , err )
166160 }
167161
168- loginAuthPath := defaultAuthPath
169- annotations = vaultSpec .Annotations
170- if annotations ["vault.hashicorp.com/auth-path" ] != "" {
171- loginAuthPath = annotations ["vault.hashicorp.com/auth-path" ]
162+ vaultNamespace := os .Getenv ("OPERATOR_VAULT_NAMESPACE" )
163+ if vaultNamespace != "" {
164+ vaultClient .SetNamespace (vaultNamespace )
165+ }
166+
167+ loginAuthPath := os .Getenv ("OPERATOR_VAULT_AUTH_PATH" )
168+ if loginAuthPath == "" {
169+ loginAuthPath = defaultAuthPath
172170 }
173171
174172 role := os .Getenv ("OPERATOR_VAULT_ROLE" )
175173 if role == "" {
176174 role = defaultVaultRole
177- logger .Info ("Authenticating to Vault using default role value because OPERATOR_VAULT_ROLE env var is not set" , "vault role" , role )
178- } else {
179- logger .Info ("Authenticating to Vault using role set from OPERATOR_VAULT_ROLE env var" , "vault role" , role )
180175 }
181176
177+ logger .Info ("Authenticating to Vault" , "vault role" , role , "vault namespace" , vaultNamespace , "vault auth path" , loginAuthPath )
178+
182179 vaultSecret , err := ReadVaultClientSecretFunc (vaultClient , string (jwt ), role , loginAuthPath )
183180 if err != nil {
184181 return nil , fmt .Errorf ("unable to obtain Vault client secret: %w" , err )
@@ -192,12 +189,12 @@ func login(vaultClient *vault.Client, vaultSpec *rabbitmqv1beta1.VaultSpec) (*va
192189 return vaultSecret , nil
193190}
194191
195- func renewToken (client * vault.Client , vaultSpec * rabbitmqv1beta1. VaultSpec , initialLoginErrorCh chan <- error ) {
192+ func renewToken (client * vault.Client , initialLoginErrorCh chan <- error ) {
196193 logger := ctrl .LoggerFrom (nil )
197194 sentFirstLoginAttemptErr := false
198195
199196 for {
200- vaultLoginResp , err := login (client , vaultSpec )
197+ vaultLoginResp , err := login (client )
201198 if err != nil {
202199 logger .Error (err , "unable to authenticate to Vault server" )
203200 }
0 commit comments