2015-03-15 20:52:43 +00:00
|
|
|
package logical
|
|
|
|
|
2015-03-15 21:53:41 +00:00
|
|
|
import (
|
2015-03-31 03:55:01 +00:00
|
|
|
"fmt"
|
2017-10-23 20:42:56 +00:00
|
|
|
"strings"
|
2016-05-02 02:39:45 +00:00
|
|
|
"time"
|
2015-03-15 21:53:41 +00:00
|
|
|
)
|
|
|
|
|
2017-01-04 21:44:03 +00:00
|
|
|
// RequestWrapInfo is a struct that stores information about desired response
|
2017-11-09 15:32:49 +00:00
|
|
|
// and seal wrapping behavior
|
2017-01-04 21:44:03 +00:00
|
|
|
type RequestWrapInfo struct {
|
|
|
|
// Setting to non-zero specifies that the response should be wrapped.
|
|
|
|
// Specifies the desired TTL of the wrapping token.
|
2017-10-23 20:42:56 +00:00
|
|
|
TTL time.Duration `json:"ttl" structs:"ttl" mapstructure:"ttl" sentinel:""`
|
2017-01-04 21:44:03 +00:00
|
|
|
|
|
|
|
// The format to use for the wrapped response; if not specified it's a bare
|
|
|
|
// token
|
2017-10-23 20:42:56 +00:00
|
|
|
Format string `json:"format" structs:"format" mapstructure:"format" sentinel:""`
|
2017-11-09 15:32:49 +00:00
|
|
|
|
|
|
|
// A flag to conforming backends that data for a given request should be
|
|
|
|
// seal wrapped
|
|
|
|
SealWrap bool `json:"seal_wrap" structs:"seal_wrap" mapstructure:"seal_wrap" sentinel:""`
|
2017-01-04 21:44:03 +00:00
|
|
|
}
|
|
|
|
|
2017-10-23 20:42:56 +00:00
|
|
|
func (r *RequestWrapInfo) SentinelGet(key string) (interface{}, error) {
|
|
|
|
if r == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
switch key {
|
|
|
|
case "ttl":
|
|
|
|
return r.TTL, nil
|
|
|
|
case "ttl_seconds":
|
|
|
|
return int64(r.TTL.Seconds()), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2017-11-13 20:31:32 +00:00
|
|
|
func (r *RequestWrapInfo) SentinelKeys() []string {
|
|
|
|
return []string{
|
|
|
|
"ttl",
|
|
|
|
"ttl_seconds",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 20:42:56 +00:00
|
|
|
// Request is a struct that stores the parameters and context of a request
|
|
|
|
// being made to Vault. It is used to abstract the details of the higher level
|
|
|
|
// request protocol from the handlers.
|
|
|
|
//
|
|
|
|
// Note: Many of these have Sentinel disabled because they are values populated
|
|
|
|
// by the router after policy checks; the token namespace would be the right
|
|
|
|
// place to access them via Sentinel
|
2015-03-15 20:52:43 +00:00
|
|
|
type Request struct {
|
2018-09-18 03:03:00 +00:00
|
|
|
entReq
|
|
|
|
|
2016-07-24 01:46:28 +00:00
|
|
|
// Id is the uuid associated with each request
|
2017-10-23 20:42:56 +00:00
|
|
|
ID string `json:"id" structs:"id" mapstructure:"id" sentinel:""`
|
2016-07-24 01:46:28 +00:00
|
|
|
|
2017-02-16 18:09:53 +00:00
|
|
|
// If set, the name given to the replication secondary where this request
|
|
|
|
// originated
|
2017-10-23 20:42:56 +00:00
|
|
|
ReplicationCluster string `json:"replication_cluster" structs:"replication_cluster" mapstructure:"replication_cluster" sentinel:""`
|
2017-02-16 18:09:53 +00:00
|
|
|
|
2015-03-15 20:52:43 +00:00
|
|
|
// Operation is the requested operation type
|
2016-07-24 01:46:28 +00:00
|
|
|
Operation Operation `json:"operation" structs:"operation" mapstructure:"operation"`
|
2015-03-15 20:52:43 +00:00
|
|
|
|
|
|
|
// Path is the part of the request path not consumed by the
|
|
|
|
// routing. As an example, if the original request path is "prod/aws/foo"
|
|
|
|
// and the AWS logical backend is mounted at "prod/aws/", then the
|
|
|
|
// final path is "foo" since the mount prefix is trimmed.
|
2017-10-23 20:42:56 +00:00
|
|
|
Path string `json:"path" structs:"path" mapstructure:"path" sentinel:""`
|
2015-03-15 20:52:43 +00:00
|
|
|
|
|
|
|
// Request data is an opaque map that must have string keys.
|
2016-07-24 01:46:28 +00:00
|
|
|
Data map[string]interface{} `json:"map" structs:"data" mapstructure:"data"`
|
2015-03-15 20:52:43 +00:00
|
|
|
|
|
|
|
// Storage can be used to durably store and retrieve state.
|
2017-10-23 20:42:56 +00:00
|
|
|
Storage Storage `json:"-" sentinel:""`
|
2015-03-19 22:11:42 +00:00
|
|
|
|
|
|
|
// Secret will be non-nil only for Revoke and Renew operations
|
|
|
|
// to represent the secret that was returned prior.
|
2017-10-23 20:42:56 +00:00
|
|
|
Secret *Secret `json:"secret" structs:"secret" mapstructure:"secret" sentinel:""`
|
2015-03-24 18:09:25 +00:00
|
|
|
|
2015-04-09 21:21:06 +00:00
|
|
|
// Auth will be non-nil only for Renew operations
|
|
|
|
// to represent the auth that was returned prior.
|
2017-10-23 20:42:56 +00:00
|
|
|
Auth *Auth `json:"auth" structs:"auth" mapstructure:"auth" sentinel:""`
|
2015-04-09 21:21:06 +00:00
|
|
|
|
2017-02-02 19:49:20 +00:00
|
|
|
// Headers will contain the http headers from the request. This value will
|
|
|
|
// be used in the audit broker to ensure we are auditing only the allowed
|
|
|
|
// headers.
|
2017-10-23 20:42:56 +00:00
|
|
|
Headers map[string][]string `json:"headers" structs:"headers" mapstructure:"headers" sentinel:""`
|
2017-02-02 19:49:20 +00:00
|
|
|
|
2015-03-30 21:23:32 +00:00
|
|
|
// Connection will be non-nil only for credential providers to
|
|
|
|
// inspect the connection information and potentially use it for
|
|
|
|
// authentication/protection.
|
2016-07-24 01:46:28 +00:00
|
|
|
Connection *Connection `json:"connection" structs:"connection" mapstructure:"connection"`
|
2015-03-30 21:23:32 +00:00
|
|
|
|
2015-03-24 18:09:25 +00:00
|
|
|
// ClientToken is provided to the core so that the identity
|
2015-04-15 20:56:42 +00:00
|
|
|
// can be verified and ACLs applied. This value is passed
|
|
|
|
// through to the logical backends but after being salted and
|
|
|
|
// hashed.
|
2017-10-23 20:42:56 +00:00
|
|
|
ClientToken string `json:"client_token" structs:"client_token" mapstructure:"client_token" sentinel:""`
|
2015-04-15 20:56:42 +00:00
|
|
|
|
2016-10-29 21:01:49 +00:00
|
|
|
// ClientTokenAccessor is provided to the core so that the it can get
|
|
|
|
// logged as part of request audit logging.
|
2017-10-23 20:42:56 +00:00
|
|
|
ClientTokenAccessor string `json:"client_token_accessor" structs:"client_token_accessor" mapstructure:"client_token_accessor" sentinel:""`
|
2016-10-29 21:01:49 +00:00
|
|
|
|
2015-04-15 20:56:42 +00:00
|
|
|
// DisplayName is provided to the logical backend to help associate
|
|
|
|
// dynamic secrets with the source entity. This is not a sensitive
|
|
|
|
// name, but is useful for operators.
|
2017-10-23 20:42:56 +00:00
|
|
|
DisplayName string `json:"display_name" structs:"display_name" mapstructure:"display_name" sentinel:""`
|
2015-05-27 18:46:42 +00:00
|
|
|
|
|
|
|
// MountPoint is provided so that a logical backend can generate
|
|
|
|
// paths relative to itself. The `Path` is effectively the client
|
|
|
|
// request path with the MountPoint trimmed off.
|
2017-10-23 20:42:56 +00:00
|
|
|
MountPoint string `json:"mount_point" structs:"mount_point" mapstructure:"mount_point" sentinel:""`
|
2016-05-02 02:39:45 +00:00
|
|
|
|
2017-04-24 19:15:50 +00:00
|
|
|
// MountType is provided so that a logical backend can make decisions
|
|
|
|
// based on the specific mount type (e.g., if a mount type has different
|
|
|
|
// aliases, generating different defaults depending on the alias)
|
2017-10-23 20:42:56 +00:00
|
|
|
MountType string `json:"mount_type" structs:"mount_type" mapstructure:"mount_type" sentinel:""`
|
2017-04-24 19:15:50 +00:00
|
|
|
|
2017-10-11 17:21:20 +00:00
|
|
|
// MountAccessor is provided so that identities returned by the authentication
|
|
|
|
// backends can be tied to the mount it belongs to.
|
2017-10-23 20:42:56 +00:00
|
|
|
MountAccessor string `json:"mount_accessor" structs:"mount_accessor" mapstructure:"mount_accessor" sentinel:""`
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2017-01-04 21:44:03 +00:00
|
|
|
// WrapInfo contains requested response wrapping parameters
|
2017-10-23 20:42:56 +00:00
|
|
|
WrapInfo *RequestWrapInfo `json:"wrap_info" structs:"wrap_info" mapstructure:"wrap_info" sentinel:""`
|
2017-03-01 17:39:42 +00:00
|
|
|
|
2017-03-09 01:05:23 +00:00
|
|
|
// ClientTokenRemainingUses represents the allowed number of uses left on the
|
2017-03-08 22:36:50 +00:00
|
|
|
// token supplied
|
|
|
|
ClientTokenRemainingUses int `json:"client_token_remaining_uses" structs:"client_token_remaining_uses" mapstructure:"client_token_remaining_uses"`
|
|
|
|
|
2017-10-11 17:21:20 +00:00
|
|
|
// EntityID is the identity of the caller extracted out of the token used
|
|
|
|
// to make this request
|
2017-10-23 20:42:56 +00:00
|
|
|
EntityID string `json:"entity_id" structs:"entity_id" mapstructure:"entity_id" sentinel:""`
|
|
|
|
|
|
|
|
// PolicyOverride indicates that the requestor wishes to override
|
|
|
|
// soft-mandatory Sentinel policies
|
|
|
|
PolicyOverride bool `json:"policy_override" structs:"policy_override" mapstructure:"policy_override"`
|
|
|
|
|
|
|
|
// Whether the request is unauthenticated, as in, had no client token
|
|
|
|
// attached. Useful in some situations where the client token is not made
|
|
|
|
// accessible.
|
|
|
|
Unauthenticated bool `json:"unauthenticated" structs:"unauthenticated" mapstructure:"unauthenticated"`
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
// MFACreds holds the parsed MFA information supplied over the API as part of
|
|
|
|
// X-Vault-MFA header
|
|
|
|
MFACreds MFACreds `json:"mfa_creds" structs:"mfa_creds" mapstructure:"mfa_creds" sentinel:""`
|
|
|
|
|
2018-06-08 21:24:27 +00:00
|
|
|
// Cached token entry. This avoids another lookup in request handling when
|
|
|
|
// we've already looked it up at http handling time. Note that this token
|
|
|
|
// has not been "used", as in it will not properly take into account use
|
|
|
|
// count limitations. As a result this field should only ever be used for
|
|
|
|
// transport to a function that would otherwise do a lookup and then
|
|
|
|
// properly use the token.
|
|
|
|
tokenEntry *TokenEntry
|
|
|
|
|
2017-03-01 17:39:42 +00:00
|
|
|
// For replication, contains the last WAL on the remote side after handling
|
|
|
|
// the request, used for best-effort avoidance of stale read-after-write
|
2018-04-10 23:11:44 +00:00
|
|
|
lastRemoteWAL uint64
|
2015-03-15 20:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get returns a data field and guards for nil Data
|
|
|
|
func (r *Request) Get(key string) interface{} {
|
|
|
|
if r.Data == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return r.Data[key]
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetString returns a data field as a string
|
|
|
|
func (r *Request) GetString(key string) string {
|
|
|
|
raw := r.Get(key)
|
|
|
|
s, _ := raw.(string)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2015-03-31 03:55:01 +00:00
|
|
|
func (r *Request) GoString() string {
|
|
|
|
return fmt.Sprintf("*%#v", *r)
|
|
|
|
}
|
|
|
|
|
2017-10-23 20:42:56 +00:00
|
|
|
func (r *Request) SentinelGet(key string) (interface{}, error) {
|
|
|
|
switch key {
|
|
|
|
case "path":
|
|
|
|
// Sanitize it here so that it's consistent in policies
|
|
|
|
return strings.TrimPrefix(r.Path, "/"), nil
|
|
|
|
|
|
|
|
case "wrapping", "wrap_info":
|
|
|
|
// If the pointer is nil accessing the wrap info is considered
|
|
|
|
// "undefined" so this allows us to instead discover a TTL of zero
|
|
|
|
if r.WrapInfo == nil {
|
|
|
|
return &RequestWrapInfo{}, nil
|
|
|
|
}
|
|
|
|
return r.WrapInfo, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2017-11-13 20:31:32 +00:00
|
|
|
func (r *Request) SentinelKeys() []string {
|
|
|
|
return []string{
|
|
|
|
"path",
|
|
|
|
"wrapping",
|
|
|
|
"wrap_info",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-01 17:39:42 +00:00
|
|
|
func (r *Request) LastRemoteWAL() uint64 {
|
|
|
|
return r.lastRemoteWAL
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) SetLastRemoteWAL(last uint64) {
|
|
|
|
r.lastRemoteWAL = last
|
|
|
|
}
|
|
|
|
|
2018-06-08 21:24:27 +00:00
|
|
|
func (r *Request) TokenEntry() *TokenEntry {
|
|
|
|
return r.tokenEntry
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) SetTokenEntry(te *TokenEntry) {
|
|
|
|
r.tokenEntry = te
|
|
|
|
}
|
|
|
|
|
2015-03-19 19:20:25 +00:00
|
|
|
// RenewRequest creates the structure of the renew request.
|
2017-12-14 22:03:11 +00:00
|
|
|
func RenewRequest(path string, secret *Secret, data map[string]interface{}) *Request {
|
2015-03-19 19:20:25 +00:00
|
|
|
return &Request{
|
|
|
|
Operation: RenewOperation,
|
|
|
|
Path: path,
|
2015-03-19 22:11:42 +00:00
|
|
|
Data: data,
|
|
|
|
Secret: secret,
|
2015-03-19 19:20:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-11 21:46:09 +00:00
|
|
|
// RenewAuthRequest creates the structure of the renew request for an auth.
|
2017-12-14 22:03:11 +00:00
|
|
|
func RenewAuthRequest(path string, auth *Auth, data map[string]interface{}) *Request {
|
2015-04-11 21:46:09 +00:00
|
|
|
return &Request{
|
|
|
|
Operation: RenewOperation,
|
|
|
|
Path: path,
|
|
|
|
Data: data,
|
|
|
|
Auth: auth,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-19 19:20:25 +00:00
|
|
|
// RevokeRequest creates the structure of the revoke request.
|
2017-12-14 22:03:11 +00:00
|
|
|
func RevokeRequest(path string, secret *Secret, data map[string]interface{}) *Request {
|
2015-03-19 19:20:25 +00:00
|
|
|
return &Request{
|
|
|
|
Operation: RevokeOperation,
|
|
|
|
Path: path,
|
2015-03-19 22:11:42 +00:00
|
|
|
Data: data,
|
|
|
|
Secret: secret,
|
2015-03-19 19:20:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-20 16:20:55 +00:00
|
|
|
// RollbackRequest creates the structure of the revoke request.
|
|
|
|
func RollbackRequest(path string) *Request {
|
|
|
|
return &Request{
|
|
|
|
Operation: RollbackOperation,
|
|
|
|
Path: path,
|
2015-03-21 10:18:33 +00:00
|
|
|
Data: make(map[string]interface{}),
|
2015-03-20 16:20:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-15 20:52:43 +00:00
|
|
|
// Operation is an enum that is used to specify the type
|
|
|
|
// of request being made
|
|
|
|
type Operation string
|
|
|
|
|
|
|
|
const (
|
2015-03-19 18:41:41 +00:00
|
|
|
// The operations below are called per path
|
2017-10-04 17:35:05 +00:00
|
|
|
CreateOperation Operation = "create"
|
|
|
|
ReadOperation = "read"
|
|
|
|
UpdateOperation = "update"
|
|
|
|
DeleteOperation = "delete"
|
|
|
|
ListOperation = "list"
|
|
|
|
HelpOperation = "help"
|
|
|
|
AliasLookaheadOperation = "alias-lookahead"
|
2015-03-19 18:41:41 +00:00
|
|
|
|
|
|
|
// The operations below are called globally, the path is less relevant.
|
|
|
|
RevokeOperation Operation = "revoke"
|
2015-03-17 23:16:04 +00:00
|
|
|
RenewOperation = "renew"
|
|
|
|
RollbackOperation = "rollback"
|
2015-03-15 20:52:43 +00:00
|
|
|
)
|
2018-09-18 03:03:00 +00:00
|
|
|
|
|
|
|
type MFACreds map[string][]string
|