Skip to content

Commit

Permalink
Fix the consul secret backends renewal revocation problem
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnayak authored and jefferai committed May 27, 2016
1 parent 62d2d07 commit c6fb200
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion builtin/logical/consul/path_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func (b *backend) pathTokenRead(
// Use the helper to create the secret
s := b.Secret(SecretTokenType).Response(map[string]interface{}{
"token": token,
}, nil)
}, map[string]interface{}{
"token": token,
})
s.Secret.TTL = result.Lease

return s, nil
Expand Down
9 changes: 8 additions & 1 deletion builtin/logical/consul/secret_token.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package consul

import (
"fmt"

"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
Expand Down Expand Up @@ -37,7 +39,12 @@ func secretTokenRevoke(
return logical.ErrorResponse(err.Error()), nil
}

_, err = c.ACL().Destroy(d.Get("token").(string), nil)
tokenRaw, ok := req.Secret.InternalData["token"]
if !ok {
return nil, fmt.Errorf("secret is missing internal data: token")
}

_, err = c.ACL().Destroy(tokenRaw.(string), nil)
if err != nil {
return logical.ErrorResponse(err.Error()), nil
}
Expand Down
10 changes: 5 additions & 5 deletions vault/expiration.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,10 @@ func (m *ExpirationManager) revokeEntry(le *leaseEntry) error {
}

// Handle standard revocation via backends
_, err := m.router.Route(logical.RevokeRequest(
resp, err := m.router.Route(logical.RevokeRequest(
le.Path, le.Secret, le.Data))
if err != nil {
return fmt.Errorf("failed to revoke entry: %v", err)
if err != nil || (resp != nil && resp.IsError()) {
return fmt.Errorf("failed to revoke entry: resp:%#v err:%s", resp, err)
}
return nil
}
Expand All @@ -579,8 +579,8 @@ func (m *ExpirationManager) renewEntry(le *leaseEntry, increment time.Duration)

req := logical.RenewRequest(le.Path, &secret, le.Data)
resp, err := m.router.Route(req)
if err != nil {
return nil, fmt.Errorf("failed to renew entry: %v", err)
if err != nil || (resp != nil && resp.IsError()) {
return nil, fmt.Errorf("failed to renew entry: resp:%#v err:%s", resp, err)
}
return resp, nil
}
Expand Down

0 comments on commit c6fb200

Please sign in to comment.