2014-08-06 22:08:17 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/armon/go-radix"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2014-08-12 22:09:01 +00:00
|
|
|
// allowAll is a singleton policy which allows all
|
|
|
|
// non-management actions
|
2014-08-06 22:08:17 +00:00
|
|
|
allowAll ACL
|
|
|
|
|
|
|
|
// denyAll is a singleton policy which denies all actions
|
|
|
|
denyAll ACL
|
2014-08-12 22:09:01 +00:00
|
|
|
|
|
|
|
// manageAll is a singleton policy which allows all
|
|
|
|
// actions, including management
|
|
|
|
manageAll ACL
|
2014-08-06 22:08:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// Setup the singletons
|
2014-08-12 22:09:01 +00:00
|
|
|
allowAll = &StaticACL{
|
|
|
|
allowManage: false,
|
|
|
|
defaultAllow: true,
|
|
|
|
}
|
|
|
|
denyAll = &StaticACL{
|
|
|
|
allowManage: false,
|
|
|
|
defaultAllow: false,
|
|
|
|
}
|
|
|
|
manageAll = &StaticACL{
|
|
|
|
allowManage: true,
|
|
|
|
defaultAllow: true,
|
|
|
|
}
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ACL is the interface for policy enforcement.
|
|
|
|
type ACL interface {
|
2016-12-02 04:31:50 +00:00
|
|
|
// ACLList checks for permission to list all the ACLs
|
|
|
|
ACLList() bool
|
|
|
|
|
|
|
|
// ACLModify checks for permission to manipulate ACLs
|
|
|
|
ACLModify() bool
|
|
|
|
|
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
|
|
|
|
|
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
|
2014-08-06 22:08:17 +00:00
|
|
|
KeyWrite(string) 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.
|
|
|
|
NodeWrite(string) bool
|
|
|
|
|
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
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// PrepardQueryRead determines if a specific prepared query can be read
|
|
|
|
// 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
|
2016-12-02 04:31:50 +00:00
|
|
|
ServiceWrite(string) 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
|
|
|
}
|
|
|
|
|
|
|
|
// StaticACL is used to implement a base ACL policy. It either
|
|
|
|
// allows or denies all requests. This can be used as a parent
|
|
|
|
// ACL to act in a blacklist or whitelist mode.
|
|
|
|
type StaticACL struct {
|
2014-08-12 22:09:01 +00:00
|
|
|
allowManage bool
|
2014-08-06 22:08:17 +00:00
|
|
|
defaultAllow bool
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) ACLList() bool {
|
|
|
|
return s.allowManage
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) ACLModify() bool {
|
|
|
|
return s.allowManage
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 07:05:11 +00:00
|
|
|
func (s *StaticACL) AgentRead(string) bool {
|
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StaticACL) AgentWrite(string) bool {
|
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) EventRead(string) bool {
|
2014-08-14 22:53:02 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) EventWrite(string) bool {
|
2014-12-01 03:33:46 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) KeyRead(string) bool {
|
2014-12-01 03:33:46 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) KeyWrite(string) bool {
|
2015-06-18 01:56:29 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) KeyWritePrefix(string) bool {
|
2015-06-18 01:56:29 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) KeyringRead() bool {
|
2015-07-07 00:28:09 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) KeyringWrite() bool {
|
2015-07-07 00:28:09 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2016-12-07 04:05:15 +00:00
|
|
|
func (s *StaticACL) NodeRead(string) bool {
|
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StaticACL) NodeWrite(string) bool {
|
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) 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
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) 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
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) PreparedQueryRead(string) bool {
|
2016-08-30 02:09:57 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) PreparedQueryWrite(string) bool {
|
2016-08-30 02:09:57 +00:00
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) ServiceRead(string) bool {
|
|
|
|
return s.defaultAllow
|
2015-11-04 23:16:21 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
func (s *StaticACL) ServiceWrite(string) bool {
|
|
|
|
return s.defaultAllow
|
2015-11-04 23:16:21 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 04:20:28 +00:00
|
|
|
func (s *StaticACL) SessionRead(string) bool {
|
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StaticACL) SessionWrite(string) bool {
|
|
|
|
return s.defaultAllow
|
|
|
|
}
|
|
|
|
|
2016-10-26 02:20:24 +00:00
|
|
|
func (s *StaticACL) Snapshot() bool {
|
|
|
|
return s.allowManage
|
|
|
|
}
|
|
|
|
|
2014-08-06 22:08:17 +00:00
|
|
|
// AllowAll returns an ACL rule that allows all operations
|
|
|
|
func AllowAll() ACL {
|
|
|
|
return allowAll
|
|
|
|
}
|
|
|
|
|
|
|
|
// DenyAll returns an ACL rule that denies all operations
|
|
|
|
func DenyAll() ACL {
|
|
|
|
return denyAll
|
|
|
|
}
|
|
|
|
|
2014-08-12 22:09:01 +00:00
|
|
|
// ManageAll returns an ACL rule that can manage all resources
|
|
|
|
func ManageAll() ACL {
|
|
|
|
return manageAll
|
|
|
|
}
|
|
|
|
|
2014-08-12 17:35:27 +00:00
|
|
|
// RootACL returns a possible ACL if the ID matches a root policy
|
|
|
|
func RootACL(id string) ACL {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-06 22:08:17 +00:00
|
|
|
// PolicyACL is used to wrap a set of ACL policies to provide
|
|
|
|
// the ACL interface.
|
|
|
|
type PolicyACL struct {
|
|
|
|
// parent is used to resolve policy if we have
|
|
|
|
// no matching rule.
|
|
|
|
parent ACL
|
|
|
|
|
2016-12-13 07:05:11 +00:00
|
|
|
// agentRules contains the agent policies
|
|
|
|
agentRules *radix.Tree
|
|
|
|
|
2014-08-11 05:01:03 +00:00
|
|
|
// keyRules contains the key policies
|
|
|
|
keyRules *radix.Tree
|
2014-12-01 03:33:46 +00:00
|
|
|
|
2016-12-07 04:05:15 +00:00
|
|
|
// nodeRules contains the node policies
|
|
|
|
nodeRules *radix.Tree
|
|
|
|
|
2014-12-01 03:33:46 +00:00
|
|
|
// serviceRules contains the service policies
|
2015-05-05 06:25:19 +00:00
|
|
|
serviceRules *radix.Tree
|
2015-06-18 01:56:29 +00:00
|
|
|
|
2016-12-13 04:20:28 +00:00
|
|
|
// sessionRules contains the session policies
|
|
|
|
sessionRules *radix.Tree
|
|
|
|
|
2015-06-18 01:56:29 +00:00
|
|
|
// eventRules contains the user event policies
|
|
|
|
eventRules *radix.Tree
|
2015-07-07 00:28:09 +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
|
|
|
// preparedQueryRules contains the prepared query policies
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// New is used to construct a policy based ACL from a set of policies
|
|
|
|
// and a parent policy to resolve missing cases.
|
|
|
|
func New(parent ACL, policy *Policy) (*PolicyACL, error) {
|
|
|
|
p := &PolicyACL{
|
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(),
|
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(),
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 07:05:11 +00:00
|
|
|
// Load the agent policy
|
|
|
|
for _, ap := range policy.Agents {
|
|
|
|
p.agentRules.Insert(ap.Node, ap.Policy)
|
|
|
|
}
|
|
|
|
|
2014-08-06 22:08:17 +00:00
|
|
|
// Load the key policy
|
|
|
|
for _, kp := range policy.Keys {
|
2014-08-11 05:01:03 +00:00
|
|
|
p.keyRules.Insert(kp.Prefix, kp.Policy)
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
2014-12-01 03:33:46 +00:00
|
|
|
|
2016-12-07 04:05:15 +00:00
|
|
|
// Load the node policy
|
|
|
|
for _, np := range policy.Nodes {
|
|
|
|
p.nodeRules.Insert(np.Name, np.Policy)
|
|
|
|
}
|
|
|
|
|
2014-12-01 03:33:46 +00:00
|
|
|
// Load the service policy
|
|
|
|
for _, sp := range policy.Services {
|
2015-05-05 06:25:19 +00:00
|
|
|
p.serviceRules.Insert(sp.Name, sp.Policy)
|
2014-12-01 03:33:46 +00:00
|
|
|
}
|
2015-06-18 01:56:29 +00:00
|
|
|
|
2016-12-13 04:20:28 +00:00
|
|
|
// Load the session policy
|
|
|
|
for _, sp := range policy.Sessions {
|
|
|
|
p.sessionRules.Insert(sp.Node, sp.Policy)
|
|
|
|
}
|
|
|
|
|
2015-06-18 01:56:29 +00:00
|
|
|
// Load the event policy
|
|
|
|
for _, ep := range policy.Events {
|
|
|
|
p.eventRules.Insert(ep.Event, ep.Policy)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Load the prepared query policy
|
|
|
|
for _, pq := range policy.PreparedQueries {
|
|
|
|
p.preparedQueryRules.Insert(pq.Prefix, pq.Policy)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// ACLList checks if listing of ACLs is allowed
|
|
|
|
func (p *PolicyACL) ACLList() bool {
|
|
|
|
return p.parent.ACLList()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ACLModify checks if modification of ACLs is allowed
|
|
|
|
func (p *PolicyACL) ACLModify() bool {
|
|
|
|
return p.parent.ACLModify()
|
|
|
|
}
|
|
|
|
|
2016-12-13 07:05:11 +00:00
|
|
|
// AgentRead checks for permission to read from agent endpoints for a given
|
|
|
|
// node.
|
|
|
|
func (p *PolicyACL) AgentRead(node string) bool {
|
|
|
|
// Check for an exact rule or catch-all
|
|
|
|
_, rule, ok := p.agentRules.LongestPrefix(node)
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
switch rule {
|
|
|
|
case PolicyRead, PolicyWrite:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
func (p *PolicyACL) AgentWrite(node string) bool {
|
|
|
|
// Check for an exact rule or catch-all
|
|
|
|
_, rule, ok := p.agentRules.LongestPrefix(node)
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
switch rule {
|
|
|
|
case PolicyWrite:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
func (p *PolicyACL) Snapshot() bool {
|
|
|
|
return p.parent.Snapshot()
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventRead is used to determine if the policy allows for a
|
|
|
|
// specific user event to be read.
|
|
|
|
func (p *PolicyACL) EventRead(name string) bool {
|
|
|
|
// Longest-prefix match on event names
|
|
|
|
if _, rule, ok := p.eventRules.LongestPrefix(name); ok {
|
|
|
|
switch rule {
|
|
|
|
case PolicyRead, PolicyWrite:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing matched, use parent
|
|
|
|
return p.parent.EventRead(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventWrite is used to determine if new events can be created
|
|
|
|
// (fired) by the policy.
|
|
|
|
func (p *PolicyACL) EventWrite(name string) bool {
|
|
|
|
// Longest-prefix match event names
|
|
|
|
if _, rule, ok := p.eventRules.LongestPrefix(name); ok {
|
|
|
|
return rule == PolicyWrite
|
|
|
|
}
|
|
|
|
|
|
|
|
// No match, use parent
|
|
|
|
return p.parent.EventWrite(name)
|
|
|
|
}
|
|
|
|
|
2014-08-06 22:08:17 +00:00
|
|
|
// KeyRead returns if a key is allowed to be read
|
|
|
|
func (p *PolicyACL) KeyRead(key string) bool {
|
|
|
|
// Look for a matching rule
|
2014-08-11 05:01:03 +00:00
|
|
|
_, rule, ok := p.keyRules.LongestPrefix(key)
|
2014-08-06 22:08:17 +00:00
|
|
|
if ok {
|
2014-08-11 05:01:03 +00:00
|
|
|
switch rule.(string) {
|
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
|
|
|
case PolicyRead, PolicyWrite:
|
2014-08-11 05:01:03 +00:00
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.KeyRead(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
// KeyWrite returns if a key is allowed to be written
|
|
|
|
func (p *PolicyACL) KeyWrite(key string) bool {
|
|
|
|
// Look for a matching rule
|
2014-08-11 05:01:03 +00:00
|
|
|
_, rule, ok := p.keyRules.LongestPrefix(key)
|
2014-08-06 22:08:17 +00:00
|
|
|
if ok {
|
2014-08-11 05:01:03 +00:00
|
|
|
switch rule.(string) {
|
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
|
|
|
case PolicyWrite:
|
2014-08-11 05:01:03 +00:00
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.KeyWrite(key)
|
|
|
|
}
|
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
|
|
|
|
func (p *PolicyACL) KeyWritePrefix(prefix string) bool {
|
|
|
|
// Look for a matching rule that denies
|
|
|
|
_, rule, ok := p.keyRules.LongestPrefix(prefix)
|
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
|
|
|
if ok && rule.(string) != PolicyWrite {
|
2014-08-14 22:53:02 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Look if any of our children have a deny policy
|
|
|
|
deny := false
|
|
|
|
p.keyRules.WalkPrefix(prefix, func(path string, rule interface{}) bool {
|
|
|
|
// We have a rule to prevent a write in a sub-directory!
|
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
|
|
|
if rule.(string) != PolicyWrite {
|
2014-08-14 22:53:02 +00:00
|
|
|
deny = true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
// Deny the write if any sub-rules may be violated
|
|
|
|
if deny {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we had a matching rule, done
|
|
|
|
if ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.KeyWritePrefix(prefix)
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// KeyringRead is used to determine if the keyring can be
|
|
|
|
// read by the current ACL token.
|
|
|
|
func (p *PolicyACL) KeyringRead() bool {
|
|
|
|
switch p.keyringRule {
|
|
|
|
case PolicyRead, PolicyWrite:
|
|
|
|
return true
|
|
|
|
case PolicyDeny:
|
|
|
|
return false
|
|
|
|
default:
|
|
|
|
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.
|
|
|
|
func (p *PolicyACL) KeyringWrite() bool {
|
|
|
|
if p.keyringRule == PolicyWrite {
|
|
|
|
return true
|
2014-12-01 03:33:46 +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.
|
|
|
|
func (p *PolicyACL) OperatorRead() bool {
|
|
|
|
switch p.operatorRule {
|
|
|
|
case PolicyRead, PolicyWrite:
|
|
|
|
return true
|
|
|
|
case PolicyDeny:
|
|
|
|
return false
|
|
|
|
default:
|
|
|
|
return p.parent.OperatorRead()
|
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
|
|
|
|
func (p *PolicyACL) NodeRead(name string) bool {
|
|
|
|
// Check for an exact rule or catch-all
|
|
|
|
_, rule, ok := p.nodeRules.LongestPrefix(name)
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
switch rule {
|
|
|
|
case PolicyRead, PolicyWrite:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.NodeRead(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NodeWrite checks if writing (registering) a node is allowed
|
|
|
|
func (p *PolicyACL) NodeWrite(name string) bool {
|
|
|
|
// Check for an exact rule or catch-all
|
|
|
|
_, rule, ok := p.nodeRules.LongestPrefix(name)
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
switch rule {
|
|
|
|
case PolicyWrite:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.NodeWrite(name)
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// OperatorWrite determines if the state-changing operator functions are
|
|
|
|
// allowed.
|
|
|
|
func (p *PolicyACL) OperatorWrite() bool {
|
|
|
|
if p.operatorRule == PolicyWrite {
|
|
|
|
return true
|
2015-06-18 01:56:29 +00:00
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
return p.parent.OperatorWrite()
|
2015-06-18 01:56:29 +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.
|
|
|
|
func (p *PolicyACL) PreparedQueryRead(prefix string) bool {
|
|
|
|
// Check for an exact rule or catch-all
|
|
|
|
_, rule, ok := p.preparedQueryRules.LongestPrefix(prefix)
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
switch rule {
|
|
|
|
case PolicyRead, PolicyWrite:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
func (p *PolicyACL) PreparedQueryWrite(prefix string) bool {
|
|
|
|
// Check for an exact rule or catch-all
|
|
|
|
_, rule, ok := p.preparedQueryRules.LongestPrefix(prefix)
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
switch rule {
|
|
|
|
case PolicyWrite:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
func (p *PolicyACL) ServiceRead(name string) bool {
|
|
|
|
// Check for an exact rule or catch-all
|
|
|
|
_, rule, ok := p.serviceRules.LongestPrefix(name)
|
2015-07-07 00:28:09 +00:00
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
if ok {
|
|
|
|
switch rule {
|
|
|
|
case PolicyRead, PolicyWrite:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
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
|
|
|
|
func (p *PolicyACL) ServiceWrite(name string) bool {
|
|
|
|
// Check for an exact rule or catch-all
|
|
|
|
_, rule, ok := p.serviceRules.LongestPrefix(name)
|
2014-08-12 22:09:01 +00:00
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
if ok {
|
|
|
|
switch rule {
|
|
|
|
case PolicyWrite:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2016-10-26 02:20:24 +00:00
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.ServiceWrite(name)
|
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.
|
|
|
|
func (p *PolicyACL) SessionRead(node string) bool {
|
|
|
|
// Check for an exact rule or catch-all
|
|
|
|
_, rule, ok := p.sessionRules.LongestPrefix(node)
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
switch rule {
|
|
|
|
case PolicyRead, PolicyWrite:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.SessionRead(node)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SessionWrite checks for permission to create sessions for a given node.
|
|
|
|
func (p *PolicyACL) SessionWrite(node string) bool {
|
|
|
|
// Check for an exact rule or catch-all
|
|
|
|
_, rule, ok := p.sessionRules.LongestPrefix(node)
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
switch rule {
|
|
|
|
case PolicyWrite:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching rule, use the parent.
|
|
|
|
return p.parent.SessionWrite(node)
|
|
|
|
}
|