2015-03-18 01:31:20 +00:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
2018-01-19 07:43:36 +00:00
|
|
|
"context"
|
2017-10-23 21:15:56 +00:00
|
|
|
"fmt"
|
2017-01-18 00:40:21 +00:00
|
|
|
"reflect"
|
2017-02-16 23:20:11 +00:00
|
|
|
"strings"
|
2017-01-18 00:40:21 +00:00
|
|
|
|
2015-03-18 01:31:20 +00:00
|
|
|
"github.com/armon/go-radix"
|
2017-06-07 17:49:51 +00:00
|
|
|
"github.com/hashicorp/errwrap"
|
2017-10-23 21:15:56 +00:00
|
|
|
multierror "github.com/hashicorp/go-multierror"
|
|
|
|
"github.com/hashicorp/vault/helper/identity"
|
2017-03-03 22:50:55 +00:00
|
|
|
"github.com/hashicorp/vault/helper/strutil"
|
2015-03-18 01:31:20 +00:00
|
|
|
"github.com/hashicorp/vault/logical"
|
2018-05-18 20:33:49 +00:00
|
|
|
"github.com/mitchellh/copystructure"
|
2015-03-18 01:31:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ACL is used to wrap a set of policies to provide
|
|
|
|
// an efficient interface for access control.
|
|
|
|
type ACL struct {
|
2015-07-05 23:31:30 +00:00
|
|
|
// exactRules contains the path policies that are exact
|
|
|
|
exactRules *radix.Tree
|
|
|
|
|
|
|
|
// globRules contains the path policies that glob
|
|
|
|
globRules *radix.Tree
|
2015-03-18 01:31:20 +00:00
|
|
|
|
|
|
|
// root is enabled if the "root" named policy is present.
|
|
|
|
root bool
|
|
|
|
}
|
|
|
|
|
2017-10-23 20:42:56 +00:00
|
|
|
type PolicyCheckOpts struct {
|
|
|
|
RootPrivsRequired bool
|
|
|
|
Unauth bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type AuthResults struct {
|
2018-08-10 13:59:58 +00:00
|
|
|
ACLResults *ACLResults
|
|
|
|
Allowed bool
|
|
|
|
RootPrivs bool
|
|
|
|
DeniedError bool
|
|
|
|
Error *multierror.Error
|
2017-10-23 20:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ACLResults struct {
|
|
|
|
Allowed bool
|
|
|
|
RootPrivs bool
|
|
|
|
IsRoot bool
|
|
|
|
MFAMethods []string
|
|
|
|
}
|
|
|
|
|
2015-03-18 01:31:20 +00:00
|
|
|
// New is used to construct a policy based ACL from a set of policies.
|
|
|
|
func NewACL(policies []*Policy) (*ACL, error) {
|
|
|
|
// Initialize
|
|
|
|
a := &ACL{
|
2015-07-05 23:31:30 +00:00
|
|
|
exactRules: radix.New(),
|
|
|
|
globRules: radix.New(),
|
|
|
|
root: false,
|
2015-03-18 01:31:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inject each policy
|
|
|
|
for _, policy := range policies {
|
2015-03-24 22:49:17 +00:00
|
|
|
// Ignore a nil policy object
|
|
|
|
if policy == nil {
|
|
|
|
continue
|
|
|
|
}
|
2017-10-23 20:42:56 +00:00
|
|
|
|
|
|
|
switch policy.Type {
|
|
|
|
case PolicyTypeACL:
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unable to parse policy (wrong type)")
|
|
|
|
}
|
|
|
|
|
2015-03-18 01:31:20 +00:00
|
|
|
// Check if this is root
|
|
|
|
if policy.Name == "root" {
|
2018-08-21 20:12:23 +00:00
|
|
|
if len(policies) != 1 {
|
|
|
|
return nil, fmt.Errorf("other policies present along with root")
|
|
|
|
}
|
2015-03-18 01:31:20 +00:00
|
|
|
a.root = true
|
|
|
|
}
|
2018-08-21 20:12:23 +00:00
|
|
|
|
2016-01-07 20:10:05 +00:00
|
|
|
for _, pc := range policy.Paths {
|
2015-07-05 23:31:30 +00:00
|
|
|
// Check which tree to use
|
|
|
|
tree := a.exactRules
|
2016-01-07 20:10:05 +00:00
|
|
|
if pc.Glob {
|
2015-07-05 23:31:30 +00:00
|
|
|
tree = a.globRules
|
|
|
|
}
|
2016-10-22 01:38:05 +00:00
|
|
|
|
2015-03-18 01:31:20 +00:00
|
|
|
// Check for an existing policy
|
2016-01-07 20:10:05 +00:00
|
|
|
raw, ok := tree.Get(pc.Prefix)
|
2015-03-18 01:31:20 +00:00
|
|
|
if !ok {
|
2017-06-07 17:49:51 +00:00
|
|
|
clonedPerms, err := pc.Permissions.Clone()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errwrap.Wrapf("error cloning ACL permissions: {{err}}", err)
|
|
|
|
}
|
|
|
|
tree.Insert(pc.Prefix, clonedPerms)
|
2015-03-18 01:31:20 +00:00
|
|
|
continue
|
|
|
|
}
|
2016-10-28 19:33:50 +00:00
|
|
|
|
|
|
|
// these are the ones already in the tree
|
2017-10-23 20:42:56 +00:00
|
|
|
existingPerms := raw.(*ACLPermissions)
|
2016-01-07 20:10:05 +00:00
|
|
|
|
|
|
|
switch {
|
2016-12-07 02:14:15 +00:00
|
|
|
case existingPerms.CapabilitiesBitmap&DenyCapabilityInt > 0:
|
2016-01-07 20:10:05 +00:00
|
|
|
// If we are explicitly denied in the existing capability set,
|
|
|
|
// don't save anything else
|
2016-12-07 02:14:15 +00:00
|
|
|
continue
|
2016-01-07 20:10:05 +00:00
|
|
|
|
2016-10-09 22:39:58 +00:00
|
|
|
case pc.Permissions.CapabilitiesBitmap&DenyCapabilityInt > 0:
|
2016-01-07 20:10:05 +00:00
|
|
|
// If this new policy explicitly denies, only save the deny value
|
2017-06-07 17:49:51 +00:00
|
|
|
existingPerms.CapabilitiesBitmap = DenyCapabilityInt
|
|
|
|
existingPerms.AllowedParameters = nil
|
|
|
|
existingPerms.DeniedParameters = nil
|
2016-12-07 02:14:15 +00:00
|
|
|
goto INSERT
|
2015-03-18 01:31:20 +00:00
|
|
|
|
2016-01-07 20:10:05 +00:00
|
|
|
default:
|
|
|
|
// Insert the capabilities in this new policy into the existing
|
2016-03-03 18:37:51 +00:00
|
|
|
// value
|
2017-06-07 17:49:51 +00:00
|
|
|
existingPerms.CapabilitiesBitmap = existingPerms.CapabilitiesBitmap | pc.Permissions.CapabilitiesBitmap
|
2015-03-18 01:31:20 +00:00
|
|
|
}
|
2016-10-16 22:24:32 +00:00
|
|
|
|
2017-02-27 19:42:00 +00:00
|
|
|
// Note: In these stanzas, we're preferring minimum lifetimes. So
|
|
|
|
// we take the lesser of two specified max values, or we take the
|
|
|
|
// lesser of two specified min values, the idea being, allowing
|
|
|
|
// token lifetime to be minimum possible.
|
|
|
|
//
|
|
|
|
// If we have an existing max, and we either don't have a current
|
|
|
|
// max, or the current is greater than the previous, use the
|
|
|
|
// existing.
|
2017-06-07 17:49:51 +00:00
|
|
|
if pc.Permissions.MaxWrappingTTL > 0 &&
|
|
|
|
(existingPerms.MaxWrappingTTL == 0 ||
|
|
|
|
pc.Permissions.MaxWrappingTTL < existingPerms.MaxWrappingTTL) {
|
|
|
|
existingPerms.MaxWrappingTTL = pc.Permissions.MaxWrappingTTL
|
2017-02-27 19:42:00 +00:00
|
|
|
}
|
|
|
|
// If we have an existing min, and we either don't have a current
|
|
|
|
// min, or the current is greater than the previous, use the
|
|
|
|
// existing
|
2017-06-07 17:49:51 +00:00
|
|
|
if pc.Permissions.MinWrappingTTL > 0 &&
|
|
|
|
(existingPerms.MinWrappingTTL == 0 ||
|
|
|
|
pc.Permissions.MinWrappingTTL < existingPerms.MinWrappingTTL) {
|
|
|
|
existingPerms.MinWrappingTTL = pc.Permissions.MinWrappingTTL
|
2017-02-27 19:42:00 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 17:49:51 +00:00
|
|
|
if len(pc.Permissions.AllowedParameters) > 0 {
|
|
|
|
if existingPerms.AllowedParameters == nil {
|
2018-05-18 20:33:49 +00:00
|
|
|
clonedAllowed, err := copystructure.Copy(pc.Permissions.AllowedParameters)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
existingPerms.AllowedParameters = clonedAllowed.(map[string][]interface{})
|
2017-02-21 23:02:39 +00:00
|
|
|
} else {
|
2017-06-07 17:49:51 +00:00
|
|
|
for key, value := range pc.Permissions.AllowedParameters {
|
|
|
|
pcValue, ok := existingPerms.AllowedParameters[key]
|
2017-02-21 23:53:27 +00:00
|
|
|
// If an empty array exist it should overwrite any other
|
|
|
|
// value.
|
|
|
|
if len(value) == 0 || (ok && len(pcValue) == 0) {
|
2017-06-07 17:49:51 +00:00
|
|
|
existingPerms.AllowedParameters[key] = []interface{}{}
|
2017-02-21 23:53:27 +00:00
|
|
|
} else {
|
|
|
|
// Merge the two maps, appending values on key conflict.
|
2017-06-07 17:49:51 +00:00
|
|
|
existingPerms.AllowedParameters[key] = append(value, existingPerms.AllowedParameters[key]...)
|
2017-02-21 23:53:27 +00:00
|
|
|
}
|
2017-02-21 23:02:39 +00:00
|
|
|
}
|
2016-12-07 02:14:15 +00:00
|
|
|
}
|
2016-10-22 01:38:05 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 17:49:51 +00:00
|
|
|
if len(pc.Permissions.DeniedParameters) > 0 {
|
|
|
|
if existingPerms.DeniedParameters == nil {
|
2018-05-18 20:33:49 +00:00
|
|
|
clonedDenied, err := copystructure.Copy(pc.Permissions.DeniedParameters)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
existingPerms.DeniedParameters = clonedDenied.(map[string][]interface{})
|
2017-02-21 23:02:39 +00:00
|
|
|
} else {
|
2017-06-07 17:49:51 +00:00
|
|
|
for key, value := range pc.Permissions.DeniedParameters {
|
|
|
|
pcValue, ok := existingPerms.DeniedParameters[key]
|
2017-02-21 23:53:27 +00:00
|
|
|
// If an empty array exist it should overwrite any other
|
|
|
|
// value.
|
|
|
|
if len(value) == 0 || (ok && len(pcValue) == 0) {
|
2017-06-07 17:49:51 +00:00
|
|
|
existingPerms.DeniedParameters[key] = []interface{}{}
|
2017-02-21 23:53:27 +00:00
|
|
|
} else {
|
|
|
|
// Merge the two maps, appending values on key conflict.
|
2017-06-07 17:49:51 +00:00
|
|
|
existingPerms.DeniedParameters[key] = append(value, existingPerms.DeniedParameters[key]...)
|
2017-02-21 23:53:27 +00:00
|
|
|
}
|
2017-02-21 23:02:39 +00:00
|
|
|
}
|
2016-12-07 02:14:15 +00:00
|
|
|
}
|
2016-10-22 01:38:05 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 11:18:49 +00:00
|
|
|
if len(pc.Permissions.RequiredParameters) > 0 {
|
|
|
|
if len(existingPerms.RequiredParameters) == 0 {
|
|
|
|
existingPerms.RequiredParameters = pc.Permissions.RequiredParameters
|
|
|
|
} else {
|
|
|
|
for _, v := range pc.Permissions.RequiredParameters {
|
|
|
|
if !strutil.StrListContains(existingPerms.RequiredParameters, v) {
|
|
|
|
existingPerms.RequiredParameters = append(existingPerms.RequiredParameters, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-28 19:33:50 +00:00
|
|
|
INSERT:
|
2017-06-07 17:49:51 +00:00
|
|
|
tree.Insert(pc.Prefix, existingPerms)
|
2015-03-18 01:31:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return a, nil
|
|
|
|
}
|
|
|
|
|
2016-03-04 17:04:26 +00:00
|
|
|
func (a *ACL) Capabilities(path string) (pathCapabilities []string) {
|
|
|
|
// Fast-path root
|
|
|
|
if a.root {
|
2016-03-04 18:21:07 +00:00
|
|
|
return []string{RootCapability}
|
2016-03-04 17:04:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find an exact matching rule, look for glob if no match
|
|
|
|
var capabilities uint32
|
|
|
|
raw, ok := a.exactRules.Get(path)
|
2016-10-09 22:39:58 +00:00
|
|
|
|
2016-03-04 17:04:26 +00:00
|
|
|
if ok {
|
2017-10-23 20:42:56 +00:00
|
|
|
perm := raw.(*ACLPermissions)
|
2016-10-22 01:38:05 +00:00
|
|
|
capabilities = perm.CapabilitiesBitmap
|
2016-03-04 17:04:26 +00:00
|
|
|
goto CHECK
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find a glob rule, default deny if no match
|
|
|
|
_, raw, ok = a.globRules.LongestPrefix(path)
|
|
|
|
if !ok {
|
2016-03-04 18:21:07 +00:00
|
|
|
return []string{DenyCapability}
|
2016-03-04 17:04:26 +00:00
|
|
|
} else {
|
2017-10-23 20:42:56 +00:00
|
|
|
perm := raw.(*ACLPermissions)
|
2016-10-14 17:22:00 +00:00
|
|
|
capabilities = perm.CapabilitiesBitmap
|
2016-03-04 17:04:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CHECK:
|
|
|
|
if capabilities&SudoCapabilityInt > 0 {
|
|
|
|
pathCapabilities = append(pathCapabilities, SudoCapability)
|
|
|
|
}
|
|
|
|
if capabilities&ReadCapabilityInt > 0 {
|
|
|
|
pathCapabilities = append(pathCapabilities, ReadCapability)
|
|
|
|
}
|
|
|
|
if capabilities&ListCapabilityInt > 0 {
|
|
|
|
pathCapabilities = append(pathCapabilities, ListCapability)
|
|
|
|
}
|
|
|
|
if capabilities&UpdateCapabilityInt > 0 {
|
|
|
|
pathCapabilities = append(pathCapabilities, UpdateCapability)
|
|
|
|
}
|
|
|
|
if capabilities&DeleteCapabilityInt > 0 {
|
|
|
|
pathCapabilities = append(pathCapabilities, DeleteCapability)
|
|
|
|
}
|
|
|
|
if capabilities&CreateCapabilityInt > 0 {
|
|
|
|
pathCapabilities = append(pathCapabilities, CreateCapability)
|
|
|
|
}
|
2016-03-04 18:21:07 +00:00
|
|
|
|
|
|
|
// If "deny" is explicitly set or if the path has no capabilities at all,
|
|
|
|
// set the path capabilities to "deny"
|
|
|
|
if capabilities&DenyCapabilityInt > 0 || len(pathCapabilities) == 0 {
|
2016-03-04 17:04:26 +00:00
|
|
|
pathCapabilities = []string{DenyCapability}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-10-23 20:42:56 +00:00
|
|
|
// AllowOperation is used to check if the given operation is permitted.
|
|
|
|
func (a *ACL) AllowOperation(req *logical.Request) (ret *ACLResults) {
|
|
|
|
ret = new(ACLResults)
|
|
|
|
|
2015-03-18 01:31:20 +00:00
|
|
|
// Fast-path root
|
|
|
|
if a.root {
|
2017-10-23 20:42:56 +00:00
|
|
|
ret.Allowed = true
|
|
|
|
ret.RootPrivs = true
|
|
|
|
ret.IsRoot = true
|
|
|
|
return
|
2015-03-18 01:31:20 +00:00
|
|
|
}
|
2016-10-22 01:38:05 +00:00
|
|
|
op := req.Operation
|
|
|
|
path := req.Path
|
2016-10-09 22:39:58 +00:00
|
|
|
|
2016-01-07 20:10:05 +00:00
|
|
|
// Help is always allowed
|
|
|
|
if op == logical.HelpOperation {
|
2017-10-23 20:42:56 +00:00
|
|
|
ret.Allowed = true
|
|
|
|
return
|
2015-07-05 23:31:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-23 20:42:56 +00:00
|
|
|
var permissions *ACLPermissions
|
2016-10-22 04:12:02 +00:00
|
|
|
|
2015-07-05 23:31:30 +00:00
|
|
|
// Find an exact matching rule, look for glob if no match
|
2016-01-12 22:24:01 +00:00
|
|
|
var capabilities uint32
|
2015-07-05 23:31:30 +00:00
|
|
|
raw, ok := a.exactRules.Get(path)
|
2015-03-18 01:31:20 +00:00
|
|
|
if ok {
|
2017-10-23 20:42:56 +00:00
|
|
|
permissions = raw.(*ACLPermissions)
|
2016-10-22 04:12:02 +00:00
|
|
|
capabilities = permissions.CapabilitiesBitmap
|
2015-07-05 23:31:30 +00:00
|
|
|
goto CHECK
|
2015-03-18 01:31:20 +00:00
|
|
|
}
|
|
|
|
|
2015-07-05 23:31:30 +00:00
|
|
|
// Find a glob rule, default deny if no match
|
|
|
|
_, raw, ok = a.globRules.LongestPrefix(path)
|
|
|
|
if !ok {
|
2017-10-23 20:42:56 +00:00
|
|
|
return
|
2015-07-05 23:31:30 +00:00
|
|
|
} else {
|
2017-10-23 20:42:56 +00:00
|
|
|
permissions = raw.(*ACLPermissions)
|
2016-10-22 04:12:02 +00:00
|
|
|
capabilities = permissions.CapabilitiesBitmap
|
2015-07-05 23:31:30 +00:00
|
|
|
}
|
2015-03-18 01:31:20 +00:00
|
|
|
|
2015-07-05 23:31:30 +00:00
|
|
|
CHECK:
|
2015-03-18 01:31:20 +00:00
|
|
|
// Check if the minimum permissions are met
|
2016-01-07 20:10:05 +00:00
|
|
|
// If "deny" has been explicitly set, only deny will be in the map, so we
|
|
|
|
// only need to check for the existence of other values
|
2017-10-23 20:42:56 +00:00
|
|
|
ret.RootPrivs = capabilities&SudoCapabilityInt > 0
|
|
|
|
|
2016-10-10 18:21:25 +00:00
|
|
|
operationAllowed := false
|
2016-01-13 02:16:31 +00:00
|
|
|
switch op {
|
|
|
|
case logical.ReadOperation:
|
2016-10-10 18:21:25 +00:00
|
|
|
operationAllowed = capabilities&ReadCapabilityInt > 0
|
2016-01-13 02:16:31 +00:00
|
|
|
case logical.ListOperation:
|
2016-10-10 18:21:25 +00:00
|
|
|
operationAllowed = capabilities&ListCapabilityInt > 0
|
2016-01-13 02:16:31 +00:00
|
|
|
case logical.UpdateOperation:
|
2016-10-10 18:21:25 +00:00
|
|
|
operationAllowed = capabilities&UpdateCapabilityInt > 0
|
2016-01-13 02:16:31 +00:00
|
|
|
case logical.DeleteOperation:
|
2016-10-10 18:21:25 +00:00
|
|
|
operationAllowed = capabilities&DeleteCapabilityInt > 0
|
2016-01-13 02:16:31 +00:00
|
|
|
case logical.CreateOperation:
|
2016-10-10 18:21:25 +00:00
|
|
|
operationAllowed = capabilities&CreateCapabilityInt > 0
|
2016-01-12 22:10:48 +00:00
|
|
|
|
2017-02-16 06:13:18 +00:00
|
|
|
// These three re-use UpdateCapabilityInt since that's the most appropriate
|
|
|
|
// capability/operation mapping
|
2016-01-13 02:16:31 +00:00
|
|
|
case logical.RevokeOperation, logical.RenewOperation, logical.RollbackOperation:
|
2016-10-10 18:21:25 +00:00
|
|
|
operationAllowed = capabilities&UpdateCapabilityInt > 0
|
2016-01-12 22:10:48 +00:00
|
|
|
|
2016-01-12 22:08:10 +00:00
|
|
|
default:
|
2017-10-23 20:42:56 +00:00
|
|
|
return
|
2016-01-12 22:08:10 +00:00
|
|
|
}
|
2016-10-10 18:21:25 +00:00
|
|
|
|
|
|
|
if !operationAllowed {
|
2017-10-23 20:42:56 +00:00
|
|
|
return
|
2016-10-10 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
2017-02-27 19:42:00 +00:00
|
|
|
if permissions.MaxWrappingTTL > 0 {
|
|
|
|
if req.WrapInfo == nil || req.WrapInfo.TTL > permissions.MaxWrappingTTL {
|
2017-10-23 20:42:56 +00:00
|
|
|
return
|
2017-02-27 19:42:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if permissions.MinWrappingTTL > 0 {
|
|
|
|
if req.WrapInfo == nil || req.WrapInfo.TTL < permissions.MinWrappingTTL {
|
2017-10-23 20:42:56 +00:00
|
|
|
return
|
2017-02-27 19:42:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// This situation can happen because of merging, even though in a single
|
|
|
|
// path statement we check on ingress
|
|
|
|
if permissions.MinWrappingTTL != 0 &&
|
|
|
|
permissions.MaxWrappingTTL != 0 &&
|
|
|
|
permissions.MaxWrappingTTL < permissions.MinWrappingTTL {
|
2017-10-23 20:42:56 +00:00
|
|
|
return
|
2017-02-27 19:42:00 +00:00
|
|
|
}
|
|
|
|
|
2017-02-16 06:13:18 +00:00
|
|
|
// Only check parameter permissions for operations that can modify
|
|
|
|
// parameters.
|
2018-05-16 15:28:46 +00:00
|
|
|
if op == logical.ReadOperation || op == logical.UpdateOperation || op == logical.CreateOperation {
|
2017-11-02 11:18:49 +00:00
|
|
|
for _, parameter := range permissions.RequiredParameters {
|
|
|
|
if _, ok := req.Data[strings.ToLower(parameter)]; !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-21 23:02:39 +00:00
|
|
|
// If there are no data fields, allow
|
2017-02-16 23:20:11 +00:00
|
|
|
if len(req.Data) == 0 {
|
2017-10-23 20:42:56 +00:00
|
|
|
ret.Allowed = true
|
|
|
|
return
|
2017-02-16 23:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(permissions.DeniedParameters) == 0 {
|
|
|
|
goto ALLOWED_PARAMETERS
|
|
|
|
}
|
|
|
|
|
2016-10-22 01:38:05 +00:00
|
|
|
// Check if all parameters have been denied
|
2016-10-22 06:45:39 +00:00
|
|
|
if _, ok := permissions.DeniedParameters["*"]; ok {
|
2017-10-23 20:42:56 +00:00
|
|
|
return
|
2016-10-22 01:38:05 +00:00
|
|
|
}
|
2017-01-17 01:48:22 +00:00
|
|
|
|
|
|
|
for parameter, value := range req.Data {
|
2018-03-20 18:54:10 +00:00
|
|
|
// Check if parameter has been explicitly denied
|
2017-02-16 23:20:11 +00:00
|
|
|
if valueSlice, ok := permissions.DeniedParameters[strings.ToLower(parameter)]; ok {
|
2017-01-17 01:48:22 +00:00
|
|
|
// If the value exists in denied values slice, deny
|
2017-02-16 06:13:18 +00:00
|
|
|
if valueInParameterList(value, valueSlice) {
|
2017-10-23 20:42:56 +00:00
|
|
|
return
|
2017-02-16 06:13:18 +00:00
|
|
|
}
|
2016-10-22 01:38:05 +00:00
|
|
|
}
|
2017-02-16 23:20:11 +00:00
|
|
|
}
|
2017-01-17 01:48:22 +00:00
|
|
|
|
2017-02-16 23:20:11 +00:00
|
|
|
ALLOWED_PARAMETERS:
|
|
|
|
// If we don't have any allowed parameters set, allow
|
|
|
|
if len(permissions.AllowedParameters) == 0 {
|
2017-10-23 20:42:56 +00:00
|
|
|
ret.Allowed = true
|
|
|
|
return
|
2017-02-16 23:20:11 +00:00
|
|
|
}
|
2017-02-16 06:18:20 +00:00
|
|
|
|
2017-02-16 23:20:11 +00:00
|
|
|
_, allowedAll := permissions.AllowedParameters["*"]
|
|
|
|
if len(permissions.AllowedParameters) == 1 && allowedAll {
|
2017-10-23 20:42:56 +00:00
|
|
|
ret.Allowed = true
|
|
|
|
return
|
2017-02-16 23:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for parameter, value := range req.Data {
|
|
|
|
valueSlice, ok := permissions.AllowedParameters[strings.ToLower(parameter)]
|
|
|
|
// Requested parameter is not in allowed list
|
|
|
|
if !ok && !allowedAll {
|
2017-10-23 20:42:56 +00:00
|
|
|
return
|
2017-02-16 23:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the value doesn't exists in the allowed values slice,
|
|
|
|
// deny
|
|
|
|
if ok && !valueInParameterList(value, valueSlice) {
|
2017-10-23 20:42:56 +00:00
|
|
|
return
|
2016-10-22 01:38:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-10 18:21:25 +00:00
|
|
|
|
2017-10-23 20:42:56 +00:00
|
|
|
ret.Allowed = true
|
|
|
|
return
|
|
|
|
}
|
2018-06-08 21:24:27 +00:00
|
|
|
func (c *Core) performPolicyChecks(ctx context.Context, acl *ACL, te *logical.TokenEntry, req *logical.Request, inEntity *identity.Entity, opts *PolicyCheckOpts) (ret *AuthResults) {
|
2017-10-23 20:42:56 +00:00
|
|
|
ret = new(AuthResults)
|
|
|
|
|
|
|
|
// First, perform normal ACL checks if requested. The only time no ACL
|
|
|
|
// should be applied is if we are only processing EGPs against a login
|
|
|
|
// path in which case opts.Unauth will be set.
|
|
|
|
if acl != nil && !opts.Unauth {
|
|
|
|
ret.ACLResults = acl.AllowOperation(req)
|
|
|
|
ret.RootPrivs = ret.ACLResults.RootPrivs
|
|
|
|
// Root is always allowed; skip Sentinel/MFA checks
|
|
|
|
if ret.ACLResults.IsRoot {
|
|
|
|
//c.logger.Warn("policy: token is root, skipping checks")
|
|
|
|
ret.Allowed = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !ret.ACLResults.Allowed {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !ret.RootPrivs && opts.RootPrivsRequired {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.Allowed = true
|
|
|
|
return
|
2015-03-18 01:31:20 +00:00
|
|
|
}
|
2017-01-17 01:48:22 +00:00
|
|
|
|
|
|
|
func valueInParameterList(v interface{}, list []interface{}) bool {
|
2017-02-22 00:06:00 +00:00
|
|
|
// Empty list is equivalent to the item always existing in the list
|
2017-02-16 23:20:11 +00:00
|
|
|
if len(list) == 0 {
|
2017-01-17 01:48:22 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return valueInSlice(v, list)
|
|
|
|
}
|
|
|
|
|
|
|
|
func valueInSlice(v interface{}, list []interface{}) bool {
|
|
|
|
for _, el := range list {
|
2017-03-03 22:50:55 +00:00
|
|
|
if reflect.TypeOf(el).String() == "string" && reflect.TypeOf(v).String() == "string" {
|
|
|
|
item := el.(string)
|
|
|
|
val := v.(string)
|
|
|
|
|
|
|
|
if strutil.GlobbedStringsMatch(item, val) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
} else if reflect.DeepEqual(el, v) {
|
2017-01-17 01:48:22 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|