2016-09-21 14:29:42 +00:00
|
|
|
package audit
|
|
|
|
|
|
|
|
import (
|
2018-03-08 19:21:11 +00:00
|
|
|
"context"
|
2016-09-21 14:29:42 +00:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2017-01-05 04:50:24 +00:00
|
|
|
"strings"
|
2016-09-21 14:29:42 +00:00
|
|
|
"time"
|
|
|
|
|
2017-01-05 04:50:24 +00:00
|
|
|
"github.com/SermoDigital/jose/jws"
|
2017-05-24 00:36:20 +00:00
|
|
|
"github.com/hashicorp/errwrap"
|
2018-09-18 03:03:00 +00:00
|
|
|
"github.com/hashicorp/vault/helper/namespace"
|
2017-05-24 00:36:20 +00:00
|
|
|
"github.com/hashicorp/vault/helper/salt"
|
2016-09-21 14:29:42 +00:00
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/mitchellh/copystructure"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AuditFormatWriter interface {
|
|
|
|
WriteRequest(io.Writer, *AuditRequestEntry) error
|
|
|
|
WriteResponse(io.Writer, *AuditResponseEntry) error
|
2018-03-08 19:21:11 +00:00
|
|
|
Salt(context.Context) (*salt.Salt, error)
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AuditFormatter implements the Formatter interface, and allows the underlying
|
|
|
|
// marshaller to be swapped out
|
|
|
|
type AuditFormatter struct {
|
|
|
|
AuditFormatWriter
|
|
|
|
}
|
|
|
|
|
2018-03-02 17:18:39 +00:00
|
|
|
var _ Formatter = (*AuditFormatter)(nil)
|
|
|
|
|
2018-03-08 19:21:11 +00:00
|
|
|
func (f *AuditFormatter) FormatRequest(ctx context.Context, w io.Writer, config FormatterConfig, in *LogInput) error {
|
2018-03-02 17:18:39 +00:00
|
|
|
if in == nil || in.Request == nil {
|
2017-02-16 18:09:53 +00:00
|
|
|
return fmt.Errorf("request to request-audit a nil request")
|
|
|
|
}
|
2016-09-21 14:29:42 +00:00
|
|
|
|
|
|
|
if w == nil {
|
|
|
|
return fmt.Errorf("writer for audit request is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.AuditFormatWriter == nil {
|
|
|
|
return fmt.Errorf("no format writer specified")
|
|
|
|
}
|
|
|
|
|
2018-03-08 19:21:11 +00:00
|
|
|
salt, err := f.Salt(ctx)
|
2017-05-24 00:36:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return errwrap.Wrapf("error fetching salt: {{err}}", err)
|
|
|
|
}
|
|
|
|
|
2018-03-02 17:18:39 +00:00
|
|
|
// Set these to the input values at first
|
|
|
|
auth := in.Auth
|
|
|
|
req := in.Request
|
|
|
|
|
2016-09-21 14:29:42 +00:00
|
|
|
if !config.Raw {
|
|
|
|
// Before we copy the structure we must nil out some data
|
|
|
|
// otherwise we will cause reflection to panic and die
|
2018-03-02 17:18:39 +00:00
|
|
|
if in.Request.Connection != nil && in.Request.Connection.ConnState != nil {
|
|
|
|
origState := in.Request.Connection.ConnState
|
|
|
|
in.Request.Connection.ConnState = nil
|
2016-09-21 14:29:42 +00:00
|
|
|
defer func() {
|
2018-03-02 17:18:39 +00:00
|
|
|
in.Request.Connection.ConnState = origState
|
2016-09-21 14:29:42 +00:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2017-02-16 18:09:53 +00:00
|
|
|
// Copy the auth structure
|
2018-03-02 17:18:39 +00:00
|
|
|
if in.Auth != nil {
|
|
|
|
cp, err := copystructure.Copy(in.Auth)
|
2017-02-16 18:09:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
auth = cp.(*logical.Auth)
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 17:18:39 +00:00
|
|
|
cp, err := copystructure.Copy(in.Request)
|
2016-09-21 14:29:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
req = cp.(*logical.Request)
|
|
|
|
|
|
|
|
// Hash any sensitive information
|
2017-02-16 18:09:53 +00:00
|
|
|
if auth != nil {
|
2017-06-05 22:04:31 +00:00
|
|
|
// Cache and restore accessor in the auth
|
|
|
|
var authAccessor string
|
|
|
|
if !config.HMACAccessor && auth.Accessor != "" {
|
|
|
|
authAccessor = auth.Accessor
|
|
|
|
}
|
2018-03-02 17:18:39 +00:00
|
|
|
if err := Hash(salt, auth, nil); err != nil {
|
2017-02-16 18:09:53 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-06-05 22:04:31 +00:00
|
|
|
if authAccessor != "" {
|
|
|
|
auth.Accessor = authAccessor
|
|
|
|
}
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
2016-10-29 21:01:49 +00:00
|
|
|
|
|
|
|
// Cache and restore accessor in the request
|
|
|
|
var clientTokenAccessor string
|
|
|
|
if !config.HMACAccessor && req != nil && req.ClientTokenAccessor != "" {
|
|
|
|
clientTokenAccessor = req.ClientTokenAccessor
|
|
|
|
}
|
2018-03-02 17:18:39 +00:00
|
|
|
if err := Hash(salt, req, in.NonHMACReqDataKeys); err != nil {
|
2016-09-21 14:29:42 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-10-29 21:01:49 +00:00
|
|
|
if clientTokenAccessor != "" {
|
|
|
|
req.ClientTokenAccessor = clientTokenAccessor
|
|
|
|
}
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If auth is nil, make an empty one
|
|
|
|
if auth == nil {
|
|
|
|
auth = new(logical.Auth)
|
|
|
|
}
|
|
|
|
var errString string
|
2018-03-02 17:18:39 +00:00
|
|
|
if in.OuterErr != nil {
|
|
|
|
errString = in.OuterErr.Error()
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
ns, err := namespace.FromContext(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-09-21 14:29:42 +00:00
|
|
|
reqEntry := &AuditRequestEntry{
|
|
|
|
Type: "request",
|
|
|
|
Error: errString,
|
|
|
|
|
|
|
|
Auth: AuditAuth{
|
2018-09-18 03:03:00 +00:00
|
|
|
ClientToken: auth.ClientToken,
|
|
|
|
Accessor: auth.Accessor,
|
|
|
|
DisplayName: auth.DisplayName,
|
|
|
|
Policies: auth.Policies,
|
|
|
|
TokenPolicies: auth.TokenPolicies,
|
|
|
|
IdentityPolicies: auth.IdentityPolicies,
|
|
|
|
ExternalNamespacePolicies: auth.ExternalNamespacePolicies,
|
|
|
|
Metadata: auth.Metadata,
|
|
|
|
EntityID: auth.EntityID,
|
|
|
|
RemainingUses: req.ClientTokenRemainingUses,
|
2016-09-21 14:29:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Request: AuditRequest{
|
2016-10-29 21:01:49 +00:00
|
|
|
ID: req.ID,
|
|
|
|
ClientToken: req.ClientToken,
|
|
|
|
ClientTokenAccessor: req.ClientTokenAccessor,
|
|
|
|
Operation: req.Operation,
|
2018-09-18 03:03:00 +00:00
|
|
|
Namespace: AuditNamespace{
|
|
|
|
ID: ns.ID,
|
|
|
|
Path: ns.Path,
|
|
|
|
},
|
|
|
|
Path: req.Path,
|
|
|
|
Data: req.Data,
|
|
|
|
PolicyOverride: req.PolicyOverride,
|
|
|
|
RemoteAddr: getRemoteAddr(req),
|
|
|
|
ReplicationCluster: req.ReplicationCluster,
|
|
|
|
Headers: req.Headers,
|
2016-09-21 14:29:42 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-01-05 04:50:24 +00:00
|
|
|
if req.WrapInfo != nil {
|
|
|
|
reqEntry.Request.WrapTTL = int(req.WrapInfo.TTL / time.Second)
|
|
|
|
}
|
|
|
|
|
2016-09-21 14:29:42 +00:00
|
|
|
if !config.OmitTime {
|
2017-11-07 23:09:54 +00:00
|
|
|
reqEntry.Time = time.Now().UTC().Format(time.RFC3339Nano)
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return f.AuditFormatWriter.WriteRequest(w, reqEntry)
|
|
|
|
}
|
|
|
|
|
2018-03-08 19:21:11 +00:00
|
|
|
func (f *AuditFormatter) FormatResponse(ctx context.Context, w io.Writer, config FormatterConfig, in *LogInput) error {
|
2018-03-02 17:18:39 +00:00
|
|
|
if in == nil || in.Request == nil {
|
2017-02-16 18:09:53 +00:00
|
|
|
return fmt.Errorf("request to response-audit a nil request")
|
|
|
|
}
|
2016-09-21 14:29:42 +00:00
|
|
|
|
|
|
|
if w == nil {
|
|
|
|
return fmt.Errorf("writer for audit request is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.AuditFormatWriter == nil {
|
|
|
|
return fmt.Errorf("no format writer specified")
|
|
|
|
}
|
|
|
|
|
2018-03-08 19:21:11 +00:00
|
|
|
salt, err := f.Salt(ctx)
|
2017-05-24 00:36:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return errwrap.Wrapf("error fetching salt: {{err}}", err)
|
|
|
|
}
|
|
|
|
|
2018-03-02 17:18:39 +00:00
|
|
|
// Set these to the input values at first
|
|
|
|
auth := in.Auth
|
|
|
|
req := in.Request
|
|
|
|
resp := in.Response
|
|
|
|
|
2016-09-21 14:29:42 +00:00
|
|
|
if !config.Raw {
|
|
|
|
// Before we copy the structure we must nil out some data
|
|
|
|
// otherwise we will cause reflection to panic and die
|
2018-03-02 17:18:39 +00:00
|
|
|
if in.Request.Connection != nil && in.Request.Connection.ConnState != nil {
|
|
|
|
origState := in.Request.Connection.ConnState
|
|
|
|
in.Request.Connection.ConnState = nil
|
2016-09-21 14:29:42 +00:00
|
|
|
defer func() {
|
2018-03-02 17:18:39 +00:00
|
|
|
in.Request.Connection.ConnState = origState
|
2016-09-21 14:29:42 +00:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2017-02-16 18:09:53 +00:00
|
|
|
// Copy the auth structure
|
2018-03-02 17:18:39 +00:00
|
|
|
if in.Auth != nil {
|
|
|
|
cp, err := copystructure.Copy(in.Auth)
|
2017-02-16 18:09:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
auth = cp.(*logical.Auth)
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 17:18:39 +00:00
|
|
|
cp, err := copystructure.Copy(in.Request)
|
2016-09-21 14:29:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
req = cp.(*logical.Request)
|
|
|
|
|
2018-03-02 17:18:39 +00:00
|
|
|
if in.Response != nil {
|
|
|
|
cp, err := copystructure.Copy(in.Response)
|
2017-02-16 18:09:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
resp = cp.(*logical.Response)
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hash any sensitive information
|
|
|
|
|
|
|
|
// Cache and restore accessor in the auth
|
2017-02-16 18:09:53 +00:00
|
|
|
if auth != nil {
|
|
|
|
var accessor string
|
|
|
|
if !config.HMACAccessor && auth.Accessor != "" {
|
|
|
|
accessor = auth.Accessor
|
|
|
|
}
|
2018-03-02 17:18:39 +00:00
|
|
|
if err := Hash(salt, auth, nil); err != nil {
|
2017-02-16 18:09:53 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if accessor != "" {
|
|
|
|
auth.Accessor = accessor
|
|
|
|
}
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
2016-10-29 21:01:49 +00:00
|
|
|
// Cache and restore accessor in the request
|
|
|
|
var clientTokenAccessor string
|
|
|
|
if !config.HMACAccessor && req != nil && req.ClientTokenAccessor != "" {
|
|
|
|
clientTokenAccessor = req.ClientTokenAccessor
|
|
|
|
}
|
2018-03-02 17:18:39 +00:00
|
|
|
if err := Hash(salt, req, in.NonHMACReqDataKeys); err != nil {
|
2016-09-21 14:29:42 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-10-29 21:01:49 +00:00
|
|
|
if clientTokenAccessor != "" {
|
|
|
|
req.ClientTokenAccessor = clientTokenAccessor
|
|
|
|
}
|
2016-09-21 14:29:42 +00:00
|
|
|
|
|
|
|
// Cache and restore accessor in the response
|
2017-02-16 18:09:53 +00:00
|
|
|
if resp != nil {
|
2017-11-13 20:31:32 +00:00
|
|
|
var accessor, wrappedAccessor, wrappingAccessor string
|
2017-02-16 18:09:53 +00:00
|
|
|
if !config.HMACAccessor && resp != nil && resp.Auth != nil && resp.Auth.Accessor != "" {
|
|
|
|
accessor = resp.Auth.Accessor
|
|
|
|
}
|
|
|
|
if !config.HMACAccessor && resp != nil && resp.WrapInfo != nil && resp.WrapInfo.WrappedAccessor != "" {
|
|
|
|
wrappedAccessor = resp.WrapInfo.WrappedAccessor
|
2017-11-13 20:31:32 +00:00
|
|
|
wrappingAccessor = resp.WrapInfo.Accessor
|
2017-02-16 18:09:53 +00:00
|
|
|
}
|
2018-03-02 17:18:39 +00:00
|
|
|
if err := Hash(salt, resp, in.NonHMACRespDataKeys); err != nil {
|
2017-02-16 18:09:53 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if accessor != "" {
|
|
|
|
resp.Auth.Accessor = accessor
|
|
|
|
}
|
|
|
|
if wrappedAccessor != "" {
|
|
|
|
resp.WrapInfo.WrappedAccessor = wrappedAccessor
|
|
|
|
}
|
2017-11-13 20:31:32 +00:00
|
|
|
if wrappingAccessor != "" {
|
|
|
|
resp.WrapInfo.Accessor = wrappingAccessor
|
|
|
|
}
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If things are nil, make empty to avoid panics
|
|
|
|
if auth == nil {
|
|
|
|
auth = new(logical.Auth)
|
|
|
|
}
|
|
|
|
if resp == nil {
|
|
|
|
resp = new(logical.Response)
|
|
|
|
}
|
|
|
|
var errString string
|
2018-03-02 17:18:39 +00:00
|
|
|
if in.OuterErr != nil {
|
|
|
|
errString = in.OuterErr.Error()
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
ns, err := namespace.FromContext(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-09-21 14:29:42 +00:00
|
|
|
var respAuth *AuditAuth
|
|
|
|
if resp.Auth != nil {
|
|
|
|
respAuth = &AuditAuth{
|
2018-09-18 03:03:00 +00:00
|
|
|
ClientToken: resp.Auth.ClientToken,
|
|
|
|
Accessor: resp.Auth.Accessor,
|
|
|
|
DisplayName: resp.Auth.DisplayName,
|
|
|
|
Policies: resp.Auth.Policies,
|
|
|
|
TokenPolicies: resp.Auth.TokenPolicies,
|
|
|
|
IdentityPolicies: resp.Auth.IdentityPolicies,
|
|
|
|
ExternalNamespacePolicies: resp.Auth.ExternalNamespacePolicies,
|
|
|
|
Metadata: resp.Auth.Metadata,
|
|
|
|
NumUses: resp.Auth.NumUses,
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var respSecret *AuditSecret
|
|
|
|
if resp.Secret != nil {
|
|
|
|
respSecret = &AuditSecret{
|
|
|
|
LeaseID: resp.Secret.LeaseID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-04 21:44:03 +00:00
|
|
|
var respWrapInfo *AuditResponseWrapInfo
|
2016-09-21 14:29:42 +00:00
|
|
|
if resp.WrapInfo != nil {
|
2017-01-05 04:50:24 +00:00
|
|
|
token := resp.WrapInfo.Token
|
|
|
|
if jwtToken := parseVaultTokenFromJWT(token); jwtToken != nil {
|
|
|
|
token = *jwtToken
|
|
|
|
}
|
2017-01-04 21:44:03 +00:00
|
|
|
respWrapInfo = &AuditResponseWrapInfo{
|
2016-09-21 14:29:42 +00:00
|
|
|
TTL: int(resp.WrapInfo.TTL / time.Second),
|
2017-01-05 04:50:24 +00:00
|
|
|
Token: token,
|
2017-11-13 20:31:32 +00:00
|
|
|
Accessor: resp.WrapInfo.Accessor,
|
2018-03-29 21:49:21 +00:00
|
|
|
CreationTime: resp.WrapInfo.CreationTime.UTC().Format(time.RFC3339Nano),
|
2017-08-02 22:28:58 +00:00
|
|
|
CreationPath: resp.WrapInfo.CreationPath,
|
2016-09-21 14:29:42 +00:00
|
|
|
WrappedAccessor: resp.WrapInfo.WrappedAccessor,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
respEntry := &AuditResponseEntry{
|
|
|
|
Type: "response",
|
|
|
|
Error: errString,
|
|
|
|
Auth: AuditAuth{
|
2018-09-18 03:03:00 +00:00
|
|
|
DisplayName: auth.DisplayName,
|
|
|
|
Policies: auth.Policies,
|
|
|
|
TokenPolicies: auth.TokenPolicies,
|
|
|
|
IdentityPolicies: auth.IdentityPolicies,
|
|
|
|
ExternalNamespacePolicies: auth.ExternalNamespacePolicies,
|
|
|
|
Metadata: auth.Metadata,
|
|
|
|
ClientToken: auth.ClientToken,
|
|
|
|
Accessor: auth.Accessor,
|
|
|
|
RemainingUses: req.ClientTokenRemainingUses,
|
|
|
|
EntityID: auth.EntityID,
|
2016-09-21 14:29:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Request: AuditRequest{
|
2016-10-29 21:01:49 +00:00
|
|
|
ID: req.ID,
|
|
|
|
ClientToken: req.ClientToken,
|
|
|
|
ClientTokenAccessor: req.ClientTokenAccessor,
|
|
|
|
Operation: req.Operation,
|
2018-09-18 03:03:00 +00:00
|
|
|
Namespace: AuditNamespace{
|
|
|
|
ID: ns.ID,
|
|
|
|
Path: ns.Path,
|
|
|
|
},
|
|
|
|
Path: req.Path,
|
|
|
|
Data: req.Data,
|
|
|
|
PolicyOverride: req.PolicyOverride,
|
|
|
|
RemoteAddr: getRemoteAddr(req),
|
|
|
|
ReplicationCluster: req.ReplicationCluster,
|
|
|
|
Headers: req.Headers,
|
2016-09-21 14:29:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Response: AuditResponse{
|
|
|
|
Auth: respAuth,
|
|
|
|
Secret: respSecret,
|
|
|
|
Data: resp.Data,
|
|
|
|
Redirect: resp.Redirect,
|
|
|
|
WrapInfo: respWrapInfo,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-01-05 04:50:24 +00:00
|
|
|
if req.WrapInfo != nil {
|
|
|
|
respEntry.Request.WrapTTL = int(req.WrapInfo.TTL / time.Second)
|
|
|
|
}
|
|
|
|
|
2016-09-21 14:29:42 +00:00
|
|
|
if !config.OmitTime {
|
2017-11-07 23:09:54 +00:00
|
|
|
respEntry.Time = time.Now().UTC().Format(time.RFC3339Nano)
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return f.AuditFormatWriter.WriteResponse(w, respEntry)
|
|
|
|
}
|
|
|
|
|
2018-03-02 17:18:39 +00:00
|
|
|
// AuditRequestEntry is the structure of a request audit log entry in Audit.
|
2016-09-21 14:29:42 +00:00
|
|
|
type AuditRequestEntry struct {
|
|
|
|
Time string `json:"time,omitempty"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Auth AuditAuth `json:"auth"`
|
|
|
|
Request AuditRequest `json:"request"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// AuditResponseEntry is the structure of a response audit log entry in Audit.
|
|
|
|
type AuditResponseEntry struct {
|
|
|
|
Time string `json:"time,omitempty"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Auth AuditAuth `json:"auth"`
|
|
|
|
Request AuditRequest `json:"request"`
|
|
|
|
Response AuditResponse `json:"response"`
|
2017-02-16 18:09:53 +00:00
|
|
|
Error string `json:"error"`
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type AuditRequest struct {
|
2016-10-29 21:01:49 +00:00
|
|
|
ID string `json:"id"`
|
2017-02-16 18:09:53 +00:00
|
|
|
ReplicationCluster string `json:"replication_cluster,omitempty"`
|
2016-10-29 21:01:49 +00:00
|
|
|
Operation logical.Operation `json:"operation"`
|
|
|
|
ClientToken string `json:"client_token"`
|
|
|
|
ClientTokenAccessor string `json:"client_token_accessor"`
|
2018-09-18 03:03:00 +00:00
|
|
|
Namespace AuditNamespace `json:"namespace"`
|
2016-10-29 21:01:49 +00:00
|
|
|
Path string `json:"path"`
|
|
|
|
Data map[string]interface{} `json:"data"`
|
2017-10-23 20:52:56 +00:00
|
|
|
PolicyOverride bool `json:"policy_override"`
|
2016-10-29 21:01:49 +00:00
|
|
|
RemoteAddr string `json:"remote_address"`
|
2017-01-05 04:50:24 +00:00
|
|
|
WrapTTL int `json:"wrap_ttl"`
|
2017-02-02 19:49:20 +00:00
|
|
|
Headers map[string][]string `json:"headers"`
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type AuditResponse struct {
|
|
|
|
Auth *AuditAuth `json:"auth,omitempty"`
|
2016-09-29 19:03:47 +00:00
|
|
|
Secret *AuditSecret `json:"secret,omitempty"`
|
|
|
|
Data map[string]interface{} `json:"data,omitempty"`
|
|
|
|
Redirect string `json:"redirect,omitempty"`
|
2017-01-04 21:44:03 +00:00
|
|
|
WrapInfo *AuditResponseWrapInfo `json:"wrap_info,omitempty"`
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type AuditAuth struct {
|
2018-09-18 03:03:00 +00:00
|
|
|
ClientToken string `json:"client_token"`
|
|
|
|
Accessor string `json:"accessor"`
|
|
|
|
DisplayName string `json:"display_name"`
|
|
|
|
Policies []string `json:"policies"`
|
|
|
|
TokenPolicies []string `json:"token_policies,omitempty"`
|
|
|
|
IdentityPolicies []string `json:"identity_policies,omitempty"`
|
|
|
|
ExternalNamespacePolicies map[string][]string `json:"external_namespace_policies,omitempty"`
|
|
|
|
Metadata map[string]string `json:"metadata"`
|
|
|
|
NumUses int `json:"num_uses,omitempty"`
|
|
|
|
RemainingUses int `json:"remaining_uses,omitempty"`
|
|
|
|
EntityID string `json:"entity_id"`
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type AuditSecret struct {
|
|
|
|
LeaseID string `json:"lease_id"`
|
|
|
|
}
|
|
|
|
|
2017-01-04 21:44:03 +00:00
|
|
|
type AuditResponseWrapInfo struct {
|
2016-09-23 16:32:07 +00:00
|
|
|
TTL int `json:"ttl"`
|
|
|
|
Token string `json:"token"`
|
2017-11-13 20:31:32 +00:00
|
|
|
Accessor string `json:"accessor"`
|
2016-09-23 16:32:07 +00:00
|
|
|
CreationTime string `json:"creation_time"`
|
2017-08-02 22:28:58 +00:00
|
|
|
CreationPath string `json:"creation_path"`
|
2016-09-23 16:32:07 +00:00
|
|
|
WrappedAccessor string `json:"wrapped_accessor,omitempty"`
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
type AuditNamespace struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Path string `json:"path"`
|
|
|
|
}
|
|
|
|
|
2016-09-21 14:29:42 +00:00
|
|
|
// getRemoteAddr safely gets the remote address avoiding a nil pointer
|
|
|
|
func getRemoteAddr(req *logical.Request) string {
|
|
|
|
if req != nil && req.Connection != nil {
|
|
|
|
return req.Connection.RemoteAddr
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
2017-01-05 04:50:24 +00:00
|
|
|
|
|
|
|
// parseVaultTokenFromJWT returns a string iff the token was a JWT and we could
|
|
|
|
// extract the original token ID from inside
|
|
|
|
func parseVaultTokenFromJWT(token string) *string {
|
|
|
|
if strings.Count(token, ".") != 2 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
wt, err := jws.ParseJWT([]byte(token))
|
|
|
|
if err != nil || wt == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
result, _ := wt.Claims().JWTID()
|
|
|
|
|
|
|
|
return &result
|
|
|
|
}
|