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

Read paths unmodified if KVv2 status check fails #1253

Merged
merged 1 commit into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dependency/vault_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ func (d *VaultReadQuery) readSecret(clients *ClientSet, opts *QueryOptions) (*ap
if d.isKVv2 == nil {
mountPath, isKVv2, err := isKVv2(vaultClient, d.rawPath)
if err != nil {
return nil, errors.Wrap(err, d.String())
}

if isKVv2 {
log.Printf("[WARN] %s: failed to check if %s is KVv2, assume not: %s", d, d.rawPath, err)
isKVv2 = false
d.secretPath = d.rawPath
} else if isKVv2 {
d.secretPath = addPrefixToVKVPath(d.rawPath, mountPath, "data")
} else {
d.secretPath = d.rawPath
Expand Down
62 changes: 62 additions & 0 deletions dependency/vault_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,68 @@ func TestVaultReadQuery_Fetch_PKI_Anonymous(t *testing.T) {
}
}

// TestVaultReadQuery_Fetch_NonSecrets asserts that vault.read can fetch a
// non-secret
func TestVaultReadQuery_Fetch_NonSecrets(t *testing.T) {
t.Parallel()

var err error

clients := testClients

vc := clients.Vault()

err = vc.Sys().EnableAuth("approle", "approle", "")
if err != nil {
t.Fatal(err)
}

_, err = vc.Logical().Write("auth/approle/role/my-approle", nil)
if err != nil {
t.Fatal(err)
}

// create restricted token
_, err = vc.Logical().Write("sys/policies/acl/operator",
map[string]interface{}{
"policy": `path "auth/approle/role/my-approle/role-id" { capabilities = ["read"] }`,
})
secret, err := vc.Auth().Token().Create(&api.TokenCreateRequest{
Policies: []string{"operator"},
})
if err != nil {
t.Fatal(err)
}

anonClient := NewClientSet()
anonClient.CreateVaultClient(&CreateVaultClientInput{
Address: vaultAddr,
Token: secret.Auth.ClientToken,
})
_, err = anonClient.vault.client.Auth().Token().LookupSelf()
if err != nil {
t.Fatal(err)
}

d, err := NewVaultReadQuery("auth/approle/role/my-approle/role-id")
if err != nil {
t.Fatal(err)
}

act, _, err := d.Fetch(anonClient, nil)
if err != nil {
t.Fatal(err)
}

sec, ok := act.(*Secret)
if !ok {
t.Fatalf("expected secret but found %v", reflect.TypeOf(act))
}
if _, ok := sec.Data["role_id"]; !ok {
t.Fatalf("expected to find role_id but found: %v", sec.Data)
}
}

func TestVaultReadQuery_String(t *testing.T) {
t.Parallel()

Expand Down