mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-29 14:41:09 +01:00
Audit: Add token's use count to audit response (#2437)
* audit: Added token_num_uses to audit response * Fixed jsonx tests * Revert logical auth to NumUses instead of TokenNumUses * s/TokenNumUses/NumUses * Audit: Add num uses to audit requests as well * Added RemainingUses to distinguish NumUses in audit requests
This commit is contained in:
parent
a4e41f6568
commit
3026b00da6
@ -105,6 +105,7 @@ func (f *AuditFormatter) FormatRequest(
|
|||||||
DisplayName: auth.DisplayName,
|
DisplayName: auth.DisplayName,
|
||||||
Policies: auth.Policies,
|
Policies: auth.Policies,
|
||||||
Metadata: auth.Metadata,
|
Metadata: auth.Metadata,
|
||||||
|
RemainingUses: req.ClientTokenRemainingUses,
|
||||||
},
|
},
|
||||||
|
|
||||||
Request: AuditRequest{
|
Request: AuditRequest{
|
||||||
@ -255,6 +256,7 @@ func (f *AuditFormatter) FormatResponse(
|
|||||||
DisplayName: resp.Auth.DisplayName,
|
DisplayName: resp.Auth.DisplayName,
|
||||||
Policies: resp.Auth.Policies,
|
Policies: resp.Auth.Policies,
|
||||||
Metadata: resp.Auth.Metadata,
|
Metadata: resp.Auth.Metadata,
|
||||||
|
NumUses: resp.Auth.NumUses,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,6 +369,8 @@ type AuditAuth struct {
|
|||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name"`
|
||||||
Policies []string `json:"policies"`
|
Policies []string `json:"policies"`
|
||||||
Metadata map[string]string `json:"metadata"`
|
Metadata map[string]string `json:"metadata"`
|
||||||
|
NumUses int `json:"num_uses,omitempty"`
|
||||||
|
RemainingUses int `json:"remaining_uses,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuditSecret struct {
|
type AuditSecret struct {
|
||||||
|
|||||||
@ -274,6 +274,7 @@ func requestAuth(core *vault.Core, r *http.Request, req *logical.Request) *logic
|
|||||||
te, err := core.LookupToken(v)
|
te, err := core.LookupToken(v)
|
||||||
if err == nil && te != nil {
|
if err == nil && te != nil {
|
||||||
req.ClientTokenAccessor = te.Accessor
|
req.ClientTokenAccessor = te.Accessor
|
||||||
|
req.ClientTokenRemainingUses = te.NumUses
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -85,6 +85,10 @@ type Request struct {
|
|||||||
// WrapInfo contains requested response wrapping parameters
|
// WrapInfo contains requested response wrapping parameters
|
||||||
WrapInfo *RequestWrapInfo `json:"wrap_info" structs:"wrap_info" mapstructure:"wrap_info"`
|
WrapInfo *RequestWrapInfo `json:"wrap_info" structs:"wrap_info" mapstructure:"wrap_info"`
|
||||||
|
|
||||||
|
// ClientTokenNumUses represents the allowed number of uses left on the
|
||||||
|
// token supplied
|
||||||
|
ClientTokenRemainingUses int `json:"client_token_remaining_uses" structs:"client_token_remaining_uses" mapstructure:"client_token_remaining_uses"`
|
||||||
|
|
||||||
// For replication, contains the last WAL on the remote side after handling
|
// For replication, contains the last WAL on the remote side after handling
|
||||||
// the request, used for best-effort avoidance of stale read-after-write
|
// the request, used for best-effort avoidance of stale read-after-write
|
||||||
lastRemoteWAL uint64
|
lastRemoteWAL uint64
|
||||||
|
|||||||
@ -444,6 +444,7 @@ func TestAuditBroker_LogResponse(t *testing.T) {
|
|||||||
b.Register("bar", a2, nil)
|
b.Register("bar", a2, nil)
|
||||||
|
|
||||||
auth := &logical.Auth{
|
auth := &logical.Auth{
|
||||||
|
NumUses: 10,
|
||||||
ClientToken: "foo",
|
ClientToken: "foo",
|
||||||
Policies: []string{"dev", "ops"},
|
Policies: []string{"dev", "ops"},
|
||||||
Metadata: map[string]string{
|
Metadata: map[string]string{
|
||||||
|
|||||||
@ -283,6 +283,10 @@ func (r *Router) routeCommon(req *logical.Request, existenceCheck bool) (*logica
|
|||||||
// Cache the identifier of the request
|
// Cache the identifier of the request
|
||||||
originalReqID := req.ID
|
originalReqID := req.ID
|
||||||
|
|
||||||
|
// Cache the client token's number of uses in the request
|
||||||
|
originalClientTokenRemainingUses := req.ClientTokenRemainingUses
|
||||||
|
req.ClientTokenRemainingUses = 0
|
||||||
|
|
||||||
// Cache the headers and hide them from backends
|
// Cache the headers and hide them from backends
|
||||||
headers := req.Headers
|
headers := req.Headers
|
||||||
req.Headers = nil
|
req.Headers = nil
|
||||||
@ -304,6 +308,7 @@ func (r *Router) routeCommon(req *logical.Request, existenceCheck bool) (*logica
|
|||||||
req.ID = originalReqID
|
req.ID = originalReqID
|
||||||
req.Storage = nil
|
req.Storage = nil
|
||||||
req.ClientToken = clientToken
|
req.ClientToken = clientToken
|
||||||
|
req.ClientTokenRemainingUses = originalClientTokenRemainingUses
|
||||||
req.WrapInfo = wrapInfo
|
req.WrapInfo = wrapInfo
|
||||||
req.Headers = headers
|
req.Headers = headers
|
||||||
// This is only set in one place, after routing, so should never be set
|
// This is only set in one place, after routing, so should never be set
|
||||||
|
|||||||
@ -1689,6 +1689,7 @@ func (ts *TokenStore) handleCreateCommon(
|
|||||||
|
|
||||||
// Generate the response
|
// Generate the response
|
||||||
resp.Auth = &logical.Auth{
|
resp.Auth = &logical.Auth{
|
||||||
|
NumUses: te.NumUses,
|
||||||
DisplayName: te.DisplayName,
|
DisplayName: te.DisplayName,
|
||||||
Policies: te.Policies,
|
Policies: te.Policies,
|
||||||
Metadata: te.Meta,
|
Metadata: te.Meta,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user