Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vault CLI makes request to incorrect URL when namespace is both provided as argument and part of the path #12675

Closed
kmehkeri opened this issue Sep 29, 2021 · 0 comments · Fixed by #12720
Labels
bug Used to indicate a potential bug namespace secret/kv

Comments

@kmehkeri
Copy link

Describe the bug
Namespace documentation states that namespace can be treated as part of the path. This works fine with HTTP API, but CLI makes request to incorrect URL when namespace is both provided as argument and part of the path.

To Reproduce

# Setup
vault namespace create dev
vault namespace create -namespace=dev myapp
vault secrets enable -version=2 -namespace=/dev/myapp -path=secrets kv
vault kv put -namespace=/dev/myapp secrets/examplePath foo=APPsecret

# Check that HTTP API works; all below requests return the same result
export VAULT_ADDR=...
export VAULT_TOKEN=...
curl -H "X-Vault-Token: $VAULT_TOKEN" -H "X-Vault-Namespace: " -X GET $VAULT_ADDR/v1/dev/myapp/secrets/data/examplePath
curl -H "X-Vault-Token: $VAULT_TOKEN" -H "X-Vault-Namespace: dev" -X GET $VAULT_ADDR/v1/myapp/secrets/data/examplePath
curl -H "X-Vault-Token: $VAULT_TOKEN" -H "X-Vault-Namespace: dev/myapp" -X GET $VAULT_ADDR/v1/secrets/data/examplePath

# Check CLI
vault kv get -field foo -namespace= dev/myapp/secrets/examplePath  # APPsecret
vault kv get -field foo -namespace=/dev myapp/secrets/examplePath  # No value found at dev/myapp/secrets/data/myapp/secrets/examplePath
vault kv get -field foo -namespace=/dev/myapp secrets/examplePath  # APPsecret

Expected behavior
Command vault kv get -field foo -namespace=/dev myapp/secrets/examplePath should work and return the secret. That is, CLI should call dev/myapp/secrets/data/examplePath instead of dev/myapp/secrets/data/myapp/secrets/examplePath.

Environment:

  • Vault Server Version (retrieve with vault status): 1.8.2+ent
  • Vault CLI Version (retrieve with vault version): v1.8.2+ent (bf22e1eb262e59f08bb8a1374dc726ab93830178)
  • Server Operating System/Architecture: Windows 10 / 5.4.72-microsoft-standard-WSL2

Vault server configuration file(s):

(empty)

Additional context
n/a

@hghaf099 hghaf099 added namespace secret/kv bug Used to indicate a potential bug labels Oct 1, 2021
hghaf099 added a commit that referenced this issue Oct 4, 2021
hghaf099 added a commit that referenced this issue Oct 22, 2021
* CLI makes request to incorrect URL when namespace is both provided as argument and part of the path
fixes #12675

* adding change log

* removing a switch and addressing a possibility of out of bound index
qk4l pushed a commit to qk4l/vault that referenced this issue Feb 4, 2022
…corp#12720)

* CLI makes request to incorrect URL when namespace is both provided as argument and part of the path
fixes hashicorp#12675

* adding change log

* removing a switch and addressing a possibility of out of bound index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Used to indicate a potential bug namespace secret/kv
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants