Skip to content

Commit

Permalink
Only set the namespace if the env var isn't present (#1519) (#10556)
Browse files Browse the repository at this point in the history
  • Loading branch information
raskchanky authored Dec 14, 2020
1 parent 89fa827 commit a9191bc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
22 changes: 22 additions & 0 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,28 @@ func NewClient(c *Config) (*Client, error) {
return client, nil
}

func (c *Client) CloneConfig() *Config {
c.modifyLock.RLock()
defer c.modifyLock.RUnlock()

newConfig := DefaultConfig()
newConfig.Address = c.config.Address
newConfig.AgentAddress = c.config.AgentAddress
newConfig.MaxRetries = c.config.MaxRetries
newConfig.Timeout = c.config.Timeout
newConfig.Backoff = c.config.Backoff
newConfig.CheckRetry = c.config.CheckRetry
newConfig.Limiter = c.config.Limiter
newConfig.OutputCurlString = c.config.OutputCurlString
newConfig.SRVLookup = c.config.SRVLookup

// we specifically want a _copy_ of the client here, not a pointer to the original one
newClient := *c.config.HttpClient
newConfig.HttpClient = &newClient

return newConfig
}

// Sets the address of Vault in the client. The format of address should be
// "<Scheme>://<Host>:<Port>". Setting this on a client will override the
// value of VAULT_ADDR environment variable.
Expand Down
3 changes: 3 additions & 0 deletions changelog/10556.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
agent: Only set the namespace if the VAULT_NAMESPACE env var isn't present
```
3 changes: 0 additions & 3 deletions changelog/_1519.txt

This file was deleted.

8 changes: 5 additions & 3 deletions command/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,11 @@ func (c *AgentCommand) Run(args []string) int {

// Check if a default namespace has been set
mountPath := config.AutoAuth.Method.MountPath
if config.AutoAuth.Method.Namespace != "" {
namespace = config.AutoAuth.Method.Namespace
mountPath = path.Join(namespace, mountPath)
if cns := config.AutoAuth.Method.Namespace; cns != "" {
// Only set this value if the env var is empty, otherwise we end up with a nested namespace
if ens := os.Getenv(api.EnvVaultNamespace); ens == "" {
mountPath = path.Join(cns, mountPath)
}
}

authConfig := &auth.AuthConfig{
Expand Down
22 changes: 22 additions & 0 deletions vendor/github.com/hashicorp/vault/api/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a9191bc

Please sign in to comment.