2014-08-06 22:08:17 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/armon/go-radix"
|
2017-09-14 19:31:01 +00:00
|
|
|
"github.com/hashicorp/consul/sentinel"
|
2014-08-06 22:08:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2014-08-12 22:09:01 +00:00
|
|
|
// allowAll is a singleton policy which allows all
|
|
|
|
// non-management actions
|
2018-10-19 16:04:07 +00:00
|
|
|
allowAll Authorizer
|
2014-08-06 22:08:17 +00:00
|
|
|
|
|
|
|
// denyAll is a singleton policy which denies all actions
|
2018-10-19 16:04:07 +00:00
|
|
|
denyAll Authorizer
|
2014-08-12 22:09:01 +00:00
|
|
|
|
|
|
|
// manageAll is a singleton policy which allows all
|
|
|
|
// actions, including management
|
2018-10-19 16:04:07 +00:00
|
|
|
manageAll Authorizer
|
2014-08-06 22:08:17 +00:00
|
|
|
)
|
|
|
|
|
2017-09-14 19:31:01 +00:00
|
|
|
// DefaultPolicyEnforcementLevel will be used if the user leaves the level
|
|
|
|
// blank when configuring an ACL.
|
|
|
|
const DefaultPolicyEnforcementLevel = "hard-mandatory"
|
|
|
|
|
2014-08-06 22:08:17 +00:00
|
|
|
func init() {
|
|
|
|
// Setup the singletons
|
2018-10-19 16:04:07 +00:00
|
|
|
allowAll = &StaticAuthorizer{
|
2014-08-12 22:09:01 +00:00
|
|
|
allowManage: false,
|
|
|
|
defaultAllow: true,
|
|
|
|
}
|
2018-10-19 16:04:07 +00:00
|
|
|
denyAll = &StaticAuthorizer{
|
2014-08-12 22:09:01 +00:00
|
|
|
allowManage: false,
|
|
|
|
defaultAllow: false,
|
|
|
|
}
|
2018-10-19 16:04:07 +00:00
|
|
|
manageAll = &StaticAuthorizer{
|
2014-08-12 22:09:01 +00:00
|
|
|
allowManage: true,
|
|
|
|
defaultAllow: true,
|
|
|
|
}
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// Authorizer is the interface for policy enforcement.
|
|
|
|
type Authorizer interface {
|
|
|
|
// ACLRead checks for permission to list all the ACLs
|
|
|
|
ACLRead() bool
|
2016-12-02 04:31:50 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// ACLWrite checks for permission to manipulate ACLs
|
|
|
|
ACLWrite() bool
|
2016-12-02 04:31:50 +00:00
|
|
|
|
2016-12-13 07:05:11 +00:00
|
|
|
// AgentRead checks for permission to read from agent endpoints for a
|
|
|
|
// given node.
|
|
|
|
AgentRead(string) bool
|
|
|
|
|
|
|
|
// AgentWrite checks for permission to make changes via agent endpoints
|
|
|
|
// for a given node.
|
|
|
|
AgentWrite(string) bool
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// EventRead determines if a specific event can be queried.
|
|
|
|
EventRead(string) bool
|
|
|
|
|
|
|
|
// EventWrite determines if a specific event may be fired.
|
|
|
|
EventWrite(string) bool
|
|
|
|
|
2018-03-27 17:08:20 +00:00
|
|
|
// IntentionDefaultAllow determines the default authorized behavior
|
2018-03-26 01:50:05 +00:00
|
|
|
// when no intentions match a Connect request.
|
2018-03-27 17:08:20 +00:00
|
|
|
IntentionDefaultAllow() bool
|
2018-03-26 01:50:05 +00:00
|
|
|
|
2018-03-04 08:38:04 +00:00
|
|
|
// IntentionRead determines if a specific intention can be read.
|
|
|
|
IntentionRead(string) bool
|
|
|
|
|
|
|
|
// IntentionWrite determines if a specific intention can be
|
|
|
|
// created, modified, or deleted.
|
|
|
|
IntentionWrite(string) bool
|
|
|
|
|
2017-10-02 22:10:21 +00:00
|
|
|
// KeyList checks for permission to list keys under a prefix
|
|
|
|
KeyList(string) bool
|
|
|
|
|
2014-08-14 22:53:02 +00:00
|
|
|
// KeyRead checks for permission to read a given key
|
2014-08-06 22:08:17 +00:00
|
|
|
KeyRead(string) bool
|
2014-08-14 22:53:02 +00:00
|
|
|
|
|
|
|
// KeyWrite checks for permission to write a given key
|
2017-09-14 19:31:01 +00:00
|
|
|
KeyWrite(string, sentinel.ScopeFn) bool
|
2014-08-14 22:53:02 +00:00
|
|
|
|
|
|
|
// KeyWritePrefix checks for permission to write to an
|
|
|
|
// entire key prefix. This means there must be no sub-policies
|
|
|
|
// that deny a write.
|
|
|
|
KeyWritePrefix(string) bool
|
|
|
|
|
2015-07-07 00:28:09 +00:00
|
|
|
// KeyringRead determines if the encryption keyring used in
|
|
|
|
// the gossip layer can be read.
|
|
|
|
KeyringRead() bool
|
|
|
|
|
|
|
|
// KeyringWrite determines if the keyring can be manipulated
|
|
|
|
KeyringWrite() bool
|
|
|
|
|
2016-12-07 04:05:15 +00:00
|
|
|
// NodeRead checks for permission to read (discover) a given node.
|
|
|
|
NodeRead(string) bool
|
|
|
|
|
|
|
|
// NodeWrite checks for permission to create or update (register) a
|
|
|
|
// given node.
|
2017-09-14 19:31:01 +00:00
|
|
|
NodeWrite(string, sentinel.ScopeFn) bool
|
2016-12-07 04:05:15 +00:00
|
|
|
|
2016-08-30 02:09:57 +00:00
|
|
|
// OperatorRead determines if the read-only Consul operator functions
|
|
|
|
// can be used.
|
|
|
|
OperatorRead() bool
|
|
|
|
|
|
|
|
// OperatorWrite determines if the state-changing Consul operator
|
|
|
|
// functions can be used.
|
|
|
|
OperatorWrite() bool
|
|
|
|
|
2018-03-19 16:56:00 +00:00
|
|
|
// PreparedQueryRead determines if a specific prepared query can be read
|
2016-12-02 04:31:50 +00:00
|
|
|
// to show its contents (this is not used for execution).
|
|
|
|
PreparedQueryRead(string) bool
|
2014-08-14 22:53:02 +00:00
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// PreparedQueryWrite determines if a specific prepared query can be
|
|
|
|
// created, modified, or deleted.
|
|
|
|
PreparedQueryWrite(string) bool
|
|
|
|
|
|
|
|
// ServiceRead checks for permission to read a given service
|
|
|
|
ServiceRead(string) bool
|
|
|
|
|
2016-12-07 04:05:15 +00:00
|
|
|
// ServiceWrite checks for permission to create or update a given
|
|
|
|
// service
|
2017-09-14 19:31:01 +00:00
|
|
|
ServiceWrite(string, sentinel.ScopeFn) bool
|
2016-10-26 02:20:24 +00:00
|
|
|
|
2016-12-13 04:20:28 +00:00
|
|
|
// SessionRead checks for permission to read sessions for a given node.
|
|
|
|
SessionRead(string) bool
|
|
|
|
|
|
|
|
// SessionWrite checks for permission to create sessions for a given
|
|
|
|
// node.
|
|
|
|
SessionWrite(string) bool
|
|
|
|
|
2016-10-26 02:20:24 +00:00
|
|
|
// Snapshot checks for permission to take and restore snapshots.
|
|
|
|
Snapshot() bool
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// StaticAuthorizer is used to implement a base ACL policy. It either
|
2014-08-06 22:08:17 +00:00
|
|
|
// allows or denies all requests. This can be used as a parent
|
|
|
|
// ACL to act in a blacklist or whitelist mode.
|
2018-10-19 16:04:07 +00:00
|
|
|
type StaticAuthorizer struct {
|
2014-08-12 22:09:01 +00:00
|
|
|
allowManage bool
|
2014-08-06 22:08:17 +00:00
|
|
|
defaultAllow bool
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) ACLRead() bool {
|
2016-12-02 04:31:50 +00:00
|
|
|
return s.allowManage
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) ACLWrite() bool {
|
2016-12-02 04:31:50 +00:00
|
|
|
return s.allowManage
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) AgentRead(string) bool {
|
2016-12-13 07:05:11 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) AgentWrite(string) bool {
|
2016-12-13 07:05:11 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) EventRead(string) bool {
|
2014-08-14 22:53:02 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) EventWrite(string) bool {
|
2014-12-01 03:33:46 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) IntentionDefaultAllow() bool {
|
2018-03-26 01:50:05 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) IntentionRead(string) bool {
|
2018-03-04 08:38:04 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) IntentionWrite(string) bool {
|
2018-03-04 08:38:04 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) KeyRead(string) bool {
|
2014-12-01 03:33:46 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) KeyList(string) bool {
|
2017-10-02 22:10:21 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) KeyWrite(string, sentinel.ScopeFn) bool {
|
2015-06-18 01:56:29 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) KeyWritePrefix(string) bool {
|
2015-06-18 01:56:29 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) KeyringRead() bool {
|
2015-07-07 00:28:09 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) KeyringWrite() bool {
|
2015-07-07 00:28:09 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) NodeRead(string) bool {
|
2016-12-07 04:05:15 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) NodeWrite(string, sentinel.ScopeFn) bool {
|
2016-12-07 04:05:15 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) OperatorRead() bool {
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
return s.defaultAllow
|
2014-08-12 22:09:01 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) OperatorWrite() bool {
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
return s.defaultAllow
|
2014-08-12 22:09:01 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) PreparedQueryRead(string) bool {
|
2016-08-30 02:09:57 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) PreparedQueryWrite(string) bool {
|
2016-08-30 02:09:57 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) ServiceRead(string) bool {
|
2016-12-02 04:31:50 +00:00
|
|
|
return s.defaultAllow
|
2015-11-04 23:16:21 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) ServiceWrite(string, sentinel.ScopeFn) bool {
|
2016-12-02 04:31:50 +00:00
|
|
|
return s.defaultAllow
|
2015-11-04 23:16:21 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) SessionRead(string) bool {
|
2016-12-13 04:20:28 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) SessionWrite(string) bool {
|
2016-12-13 04:20:28 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func (s *StaticAuthorizer) Snapshot() bool {
|
2016-10-26 02:20:24 +00:00
|
|
|
return s.allowManage
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// AllowAll returns an Authorizer that allows all operations
|
|
|
|
func AllowAll() Authorizer {
|
2014-08-06 22:08:17 +00:00
|
|
|
return allowAll
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// DenyAll returns an Authorizer that denies all operations
|
|
|
|
func DenyAll() Authorizer {
|
2014-08-06 22:08:17 +00:00
|
|
|
return denyAll
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// ManageAll returns an Authorizer that can manage all resources
|
|
|
|
func ManageAll() Authorizer {
|
2014-08-12 22:09:01 +00:00
|
|
|
return manageAll
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// RootAuthorizer returns a possible Authorizer if the ID matches a root policy
|
|
|
|
func RootAuthorizer(id string) Authorizer {
|
2014-08-12 17:35:27 +00:00
|
|
|
switch id {
|
|
|
|
case "allow":
|
|
|
|
return allowAll
|
|
|
|
case "deny":
|
|
|
|
return denyAll
|
2014-08-12 22:09:01 +00:00
|
|
|
case "manage":
|
|
|
|
return manageAll
|
2014-08-12 17:35:27 +00:00
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// RulePolicy binds a regular ACL policy along with an optional piece of
|
2017-09-14 19:31:01 +00:00
|
|
|
// code to execute.
|
2018-10-19 16:04:07 +00:00
|
|
|
type RulePolicy struct {
|
2017-09-14 19:31:01 +00:00
|
|
|
// aclPolicy is used for simple acl rules(allow/deny/manage)
|
|
|
|
aclPolicy string
|
|
|
|
|
|
|
|
// sentinelPolicy has the code part of a policy
|
|
|
|
sentinelPolicy Sentinel
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// PolicyAuthorizer is used to wrap a set of ACL policies to provide
|
|
|
|
// the Authorizer interface.
|
|
|
|
//
|
|
|
|
type PolicyAuthorizer struct {
|
2014-08-06 22:08:17 +00:00
|
|
|
// parent is used to resolve policy if we have
|
|
|
|
// no matching rule.
|
2018-10-19 16:04:07 +00:00
|
|
|
parent Authorizer
|
2014-08-06 22:08:17 +00:00
|
|
|
|
2017-09-14 19:31:01 +00:00
|
|
|
// sentinel is an interface for validating and executing sentinel code
|
|
|
|
// policies.
|
|
|
|
sentinel sentinel.Evaluator
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// aclRule contains the acl management policy.
|
|
|
|
aclRule string
|
|
|
|
|
|
|
|
// agentRules contain the exact-match agent policies
|
2016-12-13 07:05:11 +00:00
|
|
|
agentRules *radix.Tree
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// intentionRules contains the service intention exact-match policies
|
2018-03-04 08:38:04 +00:00
|
|
|
intentionRules *radix.Tree
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// keyRules contains the key exact-match policies
|
2014-08-11 05:01:03 +00:00
|
|
|
keyRules *radix.Tree
|
2014-12-01 03:33:46 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// nodeRules contains the node exact-match policies
|
2016-12-07 04:05:15 +00:00
|
|
|
nodeRules *radix.Tree
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// serviceRules contains the service exact-match policies
|
2015-05-05 06:25:19 +00:00
|
|
|
serviceRules *radix.Tree
|
2015-06-18 01:56:29 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// sessionRules contains the session exact-match policies
|
2016-12-13 04:20:28 +00:00
|
|
|
sessionRules *radix.Tree
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// eventRules contains the user event exact-match policies
|
2015-06-18 01:56:29 +00:00
|
|
|
eventRules *radix.Tree
|
2015-07-07 00:28:09 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// preparedQueryRules contains the prepared query exact-match policies
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
preparedQueryRules *radix.Tree
|
|
|
|
|
2016-08-30 02:09:57 +00:00
|
|
|
// keyringRule contains the keyring policies. The keyring has
|
2015-09-15 12:22:08 +00:00
|
|
|
// a very simple yes/no without prefix matching, so here we
|
2015-07-07 00:28:09 +00:00
|
|
|
// don't need to use a radix tree.
|
2015-07-07 16:45:38 +00:00
|
|
|
keyringRule string
|
2016-08-30 02:09:57 +00:00
|
|
|
|
|
|
|
// operatorRule contains the operator policies.
|
|
|
|
operatorRule string
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// policyAuthorizerRadixLeaf is used as the main
|
|
|
|
// structure for storing in the radix.Tree's within the
|
|
|
|
// PolicyAuthorizer
|
|
|
|
type policyAuthorizerRadixLeaf struct {
|
|
|
|
exact interface{}
|
|
|
|
prefix interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// getPolicy first attempts to get an exact match for the segment from the "exact" tree and then falls
|
|
|
|
// back to getting the policy for the longest prefix from the "prefix" tree
|
|
|
|
func getPolicy(segment string, tree *radix.Tree) (policy interface{}, found bool) {
|
|
|
|
found = false
|
|
|
|
|
|
|
|
tree.WalkPath(segment, func(path string, leaf interface{}) bool {
|
|
|
|
policies := leaf.(*policyAuthorizerRadixLeaf)
|
|
|
|
if policies.exact != nil && path == segment {
|
|
|
|
found = true
|
|
|
|
policy = policies.exact
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if policies.prefix != nil {
|
|
|
|
found = true
|
|
|
|
policy = policies.prefix
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func insertPolicyIntoRadix(segment string, tree *radix.Tree, exactPolicy interface{}, prefixPolicy interface{}) {
|
|
|
|
leaf, found := tree.Get(segment)
|
|
|
|
if found {
|
|
|
|
policy := leaf.(*policyAuthorizerRadixLeaf)
|
|
|
|
if exactPolicy != nil {
|
|
|
|
policy.exact = exactPolicy
|
|
|
|
}
|
|
|
|
if prefixPolicy != nil {
|
|
|
|
policy.prefix = prefixPolicy
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
policy := &policyAuthorizerRadixLeaf{exact: exactPolicy, prefix: prefixPolicy}
|
|
|
|
tree.Insert(segment, policy)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-24 20:21:56 +00:00
|
|
|
func enforce(rule string, requiredPermission string) (allow, recurse bool) {
|
|
|
|
switch rule {
|
|
|
|
case PolicyWrite:
|
|
|
|
// grants read, list and write permissions
|
|
|
|
return true, false
|
|
|
|
case PolicyList:
|
|
|
|
// grants read and list permissions
|
|
|
|
if requiredPermission == PolicyList || requiredPermission == PolicyRead {
|
|
|
|
return true, false
|
|
|
|
} else {
|
|
|
|
return false, false
|
|
|
|
}
|
|
|
|
case PolicyRead:
|
|
|
|
// grants just read permissions
|
|
|
|
if requiredPermission == PolicyRead {
|
|
|
|
return true, false
|
|
|
|
} else {
|
|
|
|
return false, false
|
|
|
|
}
|
|
|
|
case PolicyDeny:
|
|
|
|
// explicit denial - do not recurse
|
|
|
|
return false, false
|
|
|
|
default:
|
|
|
|
// need to recurse as there was no specific policy set
|
|
|
|
return false, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// NewPolicyAuthorizer is used to construct a policy based ACL from a set of policies
|
2014-08-06 22:08:17 +00:00
|
|
|
// and a parent policy to resolve missing cases.
|
2018-10-19 16:04:07 +00:00
|
|
|
func NewPolicyAuthorizer(parent Authorizer, policies []*Policy, sentinel sentinel.Evaluator) (*PolicyAuthorizer, error) {
|
|
|
|
p := &PolicyAuthorizer{
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
parent: parent,
|
2016-12-13 07:05:11 +00:00
|
|
|
agentRules: radix.New(),
|
2018-03-04 08:38:04 +00:00
|
|
|
intentionRules: radix.New(),
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
keyRules: radix.New(),
|
2016-12-07 04:05:15 +00:00
|
|
|
nodeRules: radix.New(),
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
serviceRules: radix.New(),
|
2016-12-13 04:20:28 +00:00
|
|
|
sessionRules: radix.New(),
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
eventRules: radix.New(),
|
|
|
|
preparedQueryRules: radix.New(),
|
2017-09-14 19:31:01 +00:00
|
|
|
sentinel: sentinel,
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
policy := MergePolicies(policies)
|
|
|
|
|
|
|
|
// Load the agent policy (exact matches)
|
2016-12-13 07:05:11 +00:00
|
|
|
for _, ap := range policy.Agents {
|
2018-10-19 16:04:07 +00:00
|
|
|
insertPolicyIntoRadix(ap.Node, p.agentRules, ap.Policy, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the agent policy (prefix matches)
|
|
|
|
for _, ap := range policy.AgentPrefixes {
|
|
|
|
insertPolicyIntoRadix(ap.Node, p.agentRules, nil, ap.Policy)
|
2016-12-13 07:05:11 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// Load the key policy (exact matches)
|
2014-08-06 22:08:17 +00:00
|
|
|
for _, kp := range policy.Keys {
|
2018-10-19 16:04:07 +00:00
|
|
|
policyRule := RulePolicy{
|
|
|
|
aclPolicy: kp.Policy,
|
|
|
|
sentinelPolicy: kp.Sentinel,
|
|
|
|
}
|
|
|
|
insertPolicyIntoRadix(kp.Prefix, p.keyRules, policyRule, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the key policy (prefix matches)
|
|
|
|
for _, kp := range policy.KeyPrefixes {
|
|
|
|
policyRule := RulePolicy{
|
2017-09-14 19:31:01 +00:00
|
|
|
aclPolicy: kp.Policy,
|
|
|
|
sentinelPolicy: kp.Sentinel,
|
|
|
|
}
|
2018-10-19 16:04:07 +00:00
|
|
|
insertPolicyIntoRadix(kp.Prefix, p.keyRules, nil, policyRule)
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
2014-12-01 03:33:46 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// Load the node policy (exact matches)
|
2016-12-07 04:05:15 +00:00
|
|
|
for _, np := range policy.Nodes {
|
2018-10-19 16:04:07 +00:00
|
|
|
policyRule := RulePolicy{
|
2017-09-14 19:31:01 +00:00
|
|
|
aclPolicy: np.Policy,
|
|
|
|
sentinelPolicy: np.Sentinel,
|
|
|
|
}
|
2018-10-19 16:04:07 +00:00
|
|
|
insertPolicyIntoRadix(np.Name, p.nodeRules, policyRule, nil)
|
2016-12-07 04:05:15 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// Load the node policy (prefix matches)
|
|
|
|
for _, np := range policy.NodePrefixes {
|
|
|
|
policyRule := RulePolicy{
|
|
|
|
aclPolicy: np.Policy,
|
|
|
|
sentinelPolicy: np.Sentinel,
|
|
|
|
}
|
|
|
|
insertPolicyIntoRadix(np.Name, p.nodeRules, nil, policyRule)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the service policy (exact matches)
|
2014-12-01 03:33:46 +00:00
|
|
|
for _, sp := range policy.Services {
|
2018-10-19 16:04:07 +00:00
|
|
|
policyRule := RulePolicy{
|
2017-09-14 19:31:01 +00:00
|
|
|
aclPolicy: sp.Policy,
|
|
|
|
sentinelPolicy: sp.Sentinel,
|
|
|
|
}
|
2018-10-19 16:04:07 +00:00
|
|
|
insertPolicyIntoRadix(sp.Name, p.serviceRules, policyRule, nil)
|
2018-03-04 08:38:04 +00:00
|
|
|
|
|
|
|
intention := sp.Intentions
|
|
|
|
if intention == "" {
|
|
|
|
switch sp.Policy {
|
|
|
|
case PolicyRead, PolicyWrite:
|
|
|
|
intention = PolicyRead
|
|
|
|
default:
|
|
|
|
intention = PolicyDeny
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
policyRule = RulePolicy{
|
2018-03-04 08:38:04 +00:00
|
|
|
aclPolicy: intention,
|
|
|
|
sentinelPolicy: sp.Sentinel,
|
|
|
|
}
|
2018-10-19 16:04:07 +00:00
|
|
|
insertPolicyIntoRadix(sp.Name, p.intentionRules, policyRule, nil)
|
2014-12-01 03:33:46 +00:00
|
|
|
}
|
2015-06-18 01:56:29 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// Load the service policy (prefix matches)
|
|
|
|
for _, sp := range policy.ServicePrefixes {
|
|
|
|
policyRule := RulePolicy{
|
|
|
|
aclPolicy: sp.Policy,
|
|
|
|
sentinelPolicy: sp.Sentinel,
|
|
|
|
}
|
|
|
|
insertPolicyIntoRadix(sp.Name, p.serviceRules, nil, policyRule)
|
|
|
|
|
|
|
|
intention := sp.Intentions
|
|
|
|
if intention == "" {
|
|
|
|
switch sp.Policy {
|
|
|
|
case PolicyRead, PolicyWrite:
|
|
|
|
intention = PolicyRead
|
|
|
|
default:
|
|
|
|
intention = PolicyDeny
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
policyRule = RulePolicy{
|
|
|
|
aclPolicy: intention,
|
|
|
|
sentinelPolicy: sp.Sentinel,
|
|
|
|
}
|
|
|
|
insertPolicyIntoRadix(sp.Name, p.intentionRules, nil, policyRule)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the session policy (exact matches)
|
2016-12-13 04:20:28 +00:00
|
|
|
for _, sp := range policy.Sessions {
|
2018-10-19 16:04:07 +00:00
|
|
|
insertPolicyIntoRadix(sp.Node, p.sessionRules, sp.Policy, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the session policy (prefix matches)
|
|
|
|
for _, sp := range policy.SessionPrefixes {
|
|
|
|
insertPolicyIntoRadix(sp.Node, p.sessionRules, nil, sp.Policy)
|
2016-12-13 04:20:28 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// Load the event policy (exact matches)
|
2015-06-18 01:56:29 +00:00
|
|
|
for _, ep := range policy.Events {
|
2018-10-19 16:04:07 +00:00
|
|
|
insertPolicyIntoRadix(ep.Event, p.eventRules, ep.Policy, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the event policy (prefix matches)
|
|
|
|
for _, ep := range policy.EventPrefixes {
|
|
|
|
insertPolicyIntoRadix(ep.Event, p.eventRules, nil, ep.Policy)
|
2015-06-18 01:56:29 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// Load the prepared query policy (exact matches)
|
|
|
|
for _, qp := range policy.PreparedQueries {
|
|
|
|
insertPolicyIntoRadix(qp.Prefix, p.preparedQueryRules, qp.Policy, nil)
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// Load the prepared query policy (prefix matches)
|
|
|
|
for _, qp := range policy.PreparedQueryPrefixes {
|
|
|
|
insertPolicyIntoRadix(qp.Prefix, p.preparedQueryRules, nil, qp.Policy)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the acl policy
|
|
|
|
p.aclRule = policy.ACL
|
|
|
|
|
2015-07-07 00:28:09 +00:00
|
|
|
// Load the keyring policy
|
2015-07-07 16:45:38 +00:00
|
|
|
p.keyringRule = policy.Keyring
|
2015-07-07 00:28:09 +00:00
|
|
|
|
2016-08-30 02:09:57 +00:00
|
|
|
// Load the operator policy
|
|
|
|
p.operatorRule = policy.Operator
|
|
|
|
|
2014-08-06 22:08:17 +00:00
|
|
|
return p, nil
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// ACLRead checks if listing of ACLs is allowed
|
|
|
|
func (p *PolicyAuthorizer) ACLRead() bool {
|
|
|
|
if allow, recurse := enforce(p.aclRule, PolicyRead); !recurse {
|
|
|
|
return allow
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.parent.ACLRead()
|
2016-12-02 04:31:50 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// ACLWrite checks if modification of ACLs is allowed
|
|
|
|
func (p *PolicyAuthorizer) ACLWrite() bool {
|
|
|
|
if allow, recurse := enforce(p.aclRule, PolicyWrite); !recurse {
|
|
|
|
return allow
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.parent.ACLWrite()
|
2016-12-02 04:31:50 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 07:05:11 +00:00
|
|
|
// AgentRead checks for permission to read from agent endpoints for a given
|
|
|
|
// node.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) AgentRead(node string) bool {
|
2016-12-13 07:05:11 +00:00
|
|
|
// Check for an exact rule or catch-all
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(node, p.agentRules); ok {
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(rule.(string), PolicyRead); !recurse {
|
|
|
|
return allow
|
2016-12-13 07:05:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.AgentRead(node)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AgentWrite checks for permission to make changes via agent endpoints for a
|
|
|
|
// given node.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) AgentWrite(node string) bool {
|
2016-12-13 07:05:11 +00:00
|
|
|
// Check for an exact rule or catch-all
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(node, p.agentRules); ok {
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(rule.(string), PolicyWrite); !recurse {
|
|
|
|
return allow
|
2016-12-13 07:05:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.AgentWrite(node)
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// Snapshot checks if taking and restoring snapshots is allowed.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) Snapshot() bool {
|
|
|
|
if allow, recurse := enforce(p.aclRule, PolicyWrite); !recurse {
|
|
|
|
return allow
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
return p.parent.Snapshot()
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventRead is used to determine if the policy allows for a
|
|
|
|
// specific user event to be read.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) EventRead(name string) bool {
|
2016-12-02 04:31:50 +00:00
|
|
|
// Longest-prefix match on event names
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(name, p.eventRules); ok {
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(rule.(string), PolicyRead); !recurse {
|
|
|
|
return allow
|
2016-12-02 04:31:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-24 20:21:56 +00:00
|
|
|
// No matching rule, use the parent.
|
2016-12-02 04:31:50 +00:00
|
|
|
return p.parent.EventRead(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventWrite is used to determine if new events can be created
|
|
|
|
// (fired) by the policy.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) EventWrite(name string) bool {
|
2016-12-02 04:31:50 +00:00
|
|
|
// Longest-prefix match event names
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(name, p.eventRules); ok {
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(rule.(string), PolicyWrite); !recurse {
|
|
|
|
return allow
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No match, use parent
|
|
|
|
return p.parent.EventWrite(name)
|
|
|
|
}
|
|
|
|
|
2018-03-27 17:08:20 +00:00
|
|
|
// IntentionDefaultAllow returns whether the default behavior when there are
|
2018-03-26 01:50:05 +00:00
|
|
|
// no matching intentions is to allow or deny.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) IntentionDefaultAllow() bool {
|
2018-03-26 01:50:05 +00:00
|
|
|
// We always go up, this can't be determined by a policy.
|
2018-03-27 17:08:20 +00:00
|
|
|
return p.parent.IntentionDefaultAllow()
|
2018-03-26 01:50:05 +00:00
|
|
|
}
|
|
|
|
|
2018-03-04 08:38:04 +00:00
|
|
|
// IntentionRead checks if writing (creating, updating, or deleting) of an
|
|
|
|
// intention is allowed.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) IntentionRead(prefix string) bool {
|
2018-03-04 08:38:04 +00:00
|
|
|
// Check for an exact rule or catch-all
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(prefix, p.intentionRules); ok {
|
|
|
|
pr := rule.(RulePolicy)
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(pr.aclPolicy, PolicyRead); !recurse {
|
|
|
|
return allow
|
2018-03-04 08:38:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.IntentionRead(prefix)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IntentionWrite checks if writing (creating, updating, or deleting) of an
|
|
|
|
// intention is allowed.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) IntentionWrite(prefix string) bool {
|
2018-03-04 08:38:04 +00:00
|
|
|
// Check for an exact rule or catch-all
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(prefix, p.intentionRules); ok {
|
|
|
|
pr := rule.(RulePolicy)
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(pr.aclPolicy, PolicyWrite); !recurse {
|
2018-10-19 16:04:07 +00:00
|
|
|
// TODO (ACL-V2) - should we do sentinel enforcement here
|
2018-07-24 20:21:56 +00:00
|
|
|
return allow
|
2018-03-04 08:38:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.IntentionWrite(prefix)
|
|
|
|
}
|
|
|
|
|
2014-08-06 22:08:17 +00:00
|
|
|
// KeyRead returns if a key is allowed to be read
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) KeyRead(key string) bool {
|
2014-08-06 22:08:17 +00:00
|
|
|
// Look for a matching rule
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(key, p.keyRules); ok {
|
|
|
|
pr := rule.(RulePolicy)
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(pr.aclPolicy, PolicyRead); !recurse {
|
|
|
|
return allow
|
2014-08-11 05:01:03 +00:00
|
|
|
}
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.KeyRead(key)
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:10:21 +00:00
|
|
|
// KeyList returns if a key is allowed to be listed
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) KeyList(key string) bool {
|
2017-10-02 22:10:21 +00:00
|
|
|
// Look for a matching rule
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(key, p.keyRules); ok {
|
|
|
|
pr := rule.(RulePolicy)
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(pr.aclPolicy, PolicyList); !recurse {
|
|
|
|
return allow
|
2017-10-02 22:10:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.KeyList(key)
|
|
|
|
}
|
|
|
|
|
2014-08-06 22:08:17 +00:00
|
|
|
// KeyWrite returns if a key is allowed to be written
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) KeyWrite(key string, scope sentinel.ScopeFn) bool {
|
2014-08-06 22:08:17 +00:00
|
|
|
// Look for a matching rule
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(key, p.keyRules); ok {
|
|
|
|
pr := rule.(RulePolicy)
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(pr.aclPolicy, PolicyWrite); !recurse {
|
|
|
|
if allow {
|
|
|
|
return p.executeCodePolicy(&pr.sentinelPolicy, scope)
|
|
|
|
}
|
2014-08-11 05:01:03 +00:00
|
|
|
return false
|
|
|
|
}
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
2017-09-14 19:31:01 +00:00
|
|
|
return p.parent.KeyWrite(key, scope)
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
2014-08-12 22:09:01 +00:00
|
|
|
|
2014-08-14 22:53:02 +00:00
|
|
|
// KeyWritePrefix returns if a prefix is allowed to be written
|
2018-10-19 16:04:07 +00:00
|
|
|
//
|
|
|
|
// This is mainly used to detect whether a whole tree within
|
|
|
|
// the KV can be removed. For that reason we must be able to
|
|
|
|
// delete everything under the prefix. First we must have "write"
|
|
|
|
// on the prefix itself
|
|
|
|
func (p *PolicyAuthorizer) KeyWritePrefix(prefix string) bool {
|
2019-05-22 20:13:30 +00:00
|
|
|
parentAllows := p.parent.KeyWritePrefix(prefix)
|
|
|
|
|
2014-08-14 22:53:02 +00:00
|
|
|
// Look for a matching rule that denies
|
2019-05-22 20:13:30 +00:00
|
|
|
prefixAllowed := parentAllows
|
2018-10-19 16:04:07 +00:00
|
|
|
found := false
|
|
|
|
|
|
|
|
// Look for a prefix rule that would apply to the prefix we are checking
|
|
|
|
// WalkPath starts at the root and walks down to the given prefix.
|
|
|
|
// Therefore the last prefix rule we see is the one that matters
|
|
|
|
p.keyRules.WalkPath(prefix, func(path string, leaf interface{}) bool {
|
|
|
|
rule := leaf.(*policyAuthorizerRadixLeaf)
|
|
|
|
|
|
|
|
if rule.prefix != nil {
|
|
|
|
found = true
|
|
|
|
if rule.prefix.(RulePolicy).aclPolicy != PolicyWrite {
|
|
|
|
prefixAllowed = false
|
|
|
|
} else {
|
|
|
|
prefixAllowed = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
2019-05-22 20:13:30 +00:00
|
|
|
// This will be false if we had a prefix that didn't allow write or if
|
|
|
|
// there was no prefix rule and the parent policy would deny access.
|
2018-10-19 16:04:07 +00:00
|
|
|
if !prefixAllowed {
|
2014-08-14 22:53:02 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// Look if any of our children do not allow write access. This loop takes
|
|
|
|
// into account both prefix and exact match rules.
|
2014-08-14 22:53:02 +00:00
|
|
|
deny := false
|
2018-10-19 16:04:07 +00:00
|
|
|
p.keyRules.WalkPrefix(prefix, func(path string, leaf interface{}) bool {
|
|
|
|
rule := leaf.(*policyAuthorizerRadixLeaf)
|
|
|
|
|
|
|
|
if rule.prefix != nil && rule.prefix.(RulePolicy).aclPolicy != PolicyWrite {
|
2014-08-14 22:53:02 +00:00
|
|
|
deny = true
|
|
|
|
return true
|
|
|
|
}
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule.exact != nil && rule.exact.(RulePolicy).aclPolicy != PolicyWrite {
|
|
|
|
deny = true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2014-08-14 22:53:02 +00:00
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
// Deny the write if any sub-rules may be violated
|
|
|
|
if deny {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-05-22 20:13:30 +00:00
|
|
|
// If we had a matching prefix rule and it allowed writes, then we can allow the access
|
2018-10-19 16:04:07 +00:00
|
|
|
if found {
|
2014-08-14 22:53:02 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-05-22 20:13:30 +00:00
|
|
|
// No matching rule, use the parent policy.
|
|
|
|
return parentAllows
|
2014-08-14 22:53:02 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// KeyringRead is used to determine if the keyring can be
|
|
|
|
// read by the current ACL token.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) KeyringRead() bool {
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(p.keyringRule, PolicyRead); !recurse {
|
|
|
|
return allow
|
2014-12-01 03:33:46 +00:00
|
|
|
}
|
2018-07-24 20:21:56 +00:00
|
|
|
|
|
|
|
return p.parent.KeyringRead()
|
2014-12-01 03:33:46 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// KeyringWrite determines if the keyring can be manipulated.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) KeyringWrite() bool {
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(p.keyringRule, PolicyWrite); !recurse {
|
|
|
|
return allow
|
2014-12-01 03:33:46 +00:00
|
|
|
}
|
2018-07-24 20:21:56 +00:00
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
return p.parent.KeyringWrite()
|
2014-12-01 03:33:46 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// OperatorRead determines if the read-only operator functions are allowed.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) OperatorRead() bool {
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(p.operatorRule, PolicyRead); !recurse {
|
|
|
|
return allow
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.parent.OperatorRead()
|
|
|
|
}
|
|
|
|
|
|
|
|
// OperatorWrite determines if the state-changing operator functions are
|
|
|
|
// allowed.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) OperatorWrite() bool {
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(p.operatorRule, PolicyWrite); !recurse {
|
|
|
|
return allow
|
2015-06-18 01:56:29 +00:00
|
|
|
}
|
2018-07-24 20:21:56 +00:00
|
|
|
|
|
|
|
return p.parent.OperatorWrite()
|
2015-06-18 01:56:29 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 04:05:15 +00:00
|
|
|
// NodeRead checks if reading (discovery) of a node is allowed
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) NodeRead(name string) bool {
|
2016-12-07 04:05:15 +00:00
|
|
|
// Check for an exact rule or catch-all
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(name, p.nodeRules); ok {
|
|
|
|
pr := rule.(RulePolicy)
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(pr.aclPolicy, PolicyRead); !recurse {
|
2018-10-19 16:04:07 +00:00
|
|
|
// TODO (ACL-V2) - Should we do sentinel enforcement here
|
2018-07-24 20:21:56 +00:00
|
|
|
return allow
|
2016-12-07 04:05:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.NodeRead(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NodeWrite checks if writing (registering) a node is allowed
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) NodeWrite(name string, scope sentinel.ScopeFn) bool {
|
2016-12-07 04:05:15 +00:00
|
|
|
// Check for an exact rule or catch-all
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(name, p.nodeRules); ok {
|
|
|
|
pr := rule.(RulePolicy)
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(pr.aclPolicy, PolicyWrite); !recurse {
|
|
|
|
return allow
|
2016-12-07 04:05:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
2017-09-14 19:31:01 +00:00
|
|
|
return p.parent.NodeWrite(name, scope)
|
2016-12-07 04:05:15 +00:00
|
|
|
}
|
|
|
|
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
// PreparedQueryRead checks if reading (listing) of a prepared query is
|
|
|
|
// allowed - this isn't execution, just listing its contents.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) PreparedQueryRead(prefix string) bool {
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
// Check for an exact rule or catch-all
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(prefix, p.preparedQueryRules); ok {
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(rule.(string), PolicyRead); !recurse {
|
|
|
|
return allow
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.PreparedQueryRead(prefix)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PreparedQueryWrite checks if writing (creating, updating, or deleting) of a
|
|
|
|
// prepared query is allowed.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) PreparedQueryWrite(prefix string) bool {
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
// Check for an exact rule or catch-all
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(prefix, p.preparedQueryRules); ok {
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(rule.(string), PolicyWrite); !recurse {
|
|
|
|
return allow
|
Creates new "prepared-query" ACL type and new token capture behavior.
Prior to this change, prepared queries had the following behavior for
ACLs, which will need to change to support templates:
1. A management token, or a token with read access to the service being
queried needed to be provided in order to create a prepared query.
2. The token used to create the prepared query was stored with the query
in the state store and used to execute the query.
3. A management token, or the token used to create the query needed to be
supplied to perform and CRUD operations on an existing prepared query.
This was pretty subtle and complicated behavior, and won't work for
templates since the service name is computed at execution time. To solve
this, we introduce a new "prepared-query" ACL type, where the prefix
applies to the query name for static prepared query types and to the
prefix for template prepared query types.
With this change, the new behavior is:
1. A management token, or a token with "prepared-query" write access to
the query name or (soon) the given template prefix is required to do
any CRUD operations on a prepared query, or to list prepared queries
(the list is filtered by this ACL).
2. You will no longer need a management token to list prepared queries,
but you will only be able to see prepared queries that you have access
to (you get an empty list instead of permission denied).
3. When listing or getting a query, because it was easy to capture
management tokens given the past behavior, this will always blank out
the "Token" field (replacing the contents as <hidden>) for all tokens
unless a management token is supplied. Going forward, we should
discourage people from binding tokens for execution unless strictly
necessary.
4. No token will be captured by default when a prepared query is created.
If the user wishes to supply an execution token then can pass it in via
the "Token" field in the prepared query definition. Otherwise, this
field will default to empty.
5. At execution time, we will use the captured token if it exists with the
prepared query definition, otherwise we will use the token that's passed
in with the request, just like we do for other RPCs (or you can use the
agent's configured token for DNS).
6. Prepared queries with no name (accessible only by ID) will not require
ACLs to create or modify (execution time will depend on the service ACL
configuration). Our argument here is that these are designed to be
ephemeral and the IDs are as good as an ACL. Management tokens will be
able to list all of these.
These changes enable templates, but also enable delegation of authority to
manage the prepared query namespace.
2016-02-23 08:12:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.PreparedQueryWrite(prefix)
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// ServiceRead checks if reading (discovery) of a service is allowed
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) ServiceRead(name string) bool {
|
2016-12-02 04:31:50 +00:00
|
|
|
// Check for an exact rule or catch-all
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(name, p.serviceRules); ok {
|
|
|
|
pr := rule.(RulePolicy)
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(pr.aclPolicy, PolicyRead); !recurse {
|
|
|
|
return allow
|
2016-12-02 04:31:50 +00:00
|
|
|
}
|
2016-08-30 02:09:57 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.ServiceRead(name)
|
2016-08-30 02:09:57 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// ServiceWrite checks if writing (registering) a service is allowed
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) ServiceWrite(name string, scope sentinel.ScopeFn) bool {
|
2016-12-02 04:31:50 +00:00
|
|
|
// Check for an exact rule or catch-all
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(name, p.serviceRules); ok {
|
|
|
|
pr := rule.(RulePolicy)
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(pr.aclPolicy, PolicyWrite); !recurse {
|
|
|
|
return allow
|
2016-12-02 04:31:50 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-26 02:20:24 +00:00
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// No matching rule, use the parent.
|
2017-09-14 19:31:01 +00:00
|
|
|
return p.parent.ServiceWrite(name, scope)
|
2016-10-26 02:20:24 +00:00
|
|
|
}
|
2016-12-13 04:20:28 +00:00
|
|
|
|
|
|
|
// SessionRead checks for permission to read sessions for a given node.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) SessionRead(node string) bool {
|
2016-12-13 04:20:28 +00:00
|
|
|
// Check for an exact rule or catch-all
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(node, p.sessionRules); ok {
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(rule.(string), PolicyRead); !recurse {
|
|
|
|
return allow
|
2016-12-13 04:20:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.SessionRead(node)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SessionWrite checks for permission to create sessions for a given node.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) SessionWrite(node string) bool {
|
2016-12-13 04:20:28 +00:00
|
|
|
// Check for an exact rule or catch-all
|
2018-10-19 16:04:07 +00:00
|
|
|
if rule, ok := getPolicy(node, p.sessionRules); ok {
|
2018-07-24 20:21:56 +00:00
|
|
|
if allow, recurse := enforce(rule.(string), PolicyWrite); !recurse {
|
|
|
|
return allow
|
2016-12-13 04:20:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.SessionWrite(node)
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
|
|
|
|
// executeCodePolicy will run the associated code policy if code policies are
|
|
|
|
// enabled.
|
2018-10-19 16:04:07 +00:00
|
|
|
func (p *PolicyAuthorizer) executeCodePolicy(policy *Sentinel, scope sentinel.ScopeFn) bool {
|
2017-09-14 19:31:01 +00:00
|
|
|
if p.sentinel == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if policy.Code == "" || scope == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
enforcement := policy.EnforcementLevel
|
|
|
|
if enforcement == "" {
|
|
|
|
enforcement = DefaultPolicyEnforcementLevel
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.sentinel.Execute(policy.Code, enforcement, scope())
|
|
|
|
}
|