|
|
|
@ -58,6 +58,13 @@ type ACL interface {
|
|
|
|
|
// EventWrite determines if a specific event may be fired.
|
|
|
|
|
EventWrite(string) bool
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
// ACLList checks for permission to list all the ACLs
|
|
|
|
|
ACLList() bool
|
|
|
|
|
|
|
|
|
@ -101,6 +108,14 @@ func (s *StaticACL) EventWrite(string) bool {
|
|
|
|
|
return s.defaultAllow
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *StaticACL) KeyringRead() bool {
|
|
|
|
|
return s.defaultAllow
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *StaticACL) KeyringWrite() bool {
|
|
|
|
|
return s.defaultAllow
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *StaticACL) ACLList() bool {
|
|
|
|
|
return s.allowManage
|
|
|
|
|
}
|
|
|
|
@ -153,6 +168,11 @@ type PolicyACL struct {
|
|
|
|
|
|
|
|
|
|
// eventRules contains the user event policies
|
|
|
|
|
eventRules *radix.Tree
|
|
|
|
|
|
|
|
|
|
// keyringRules contains the keyring policies. The keyring has
|
|
|
|
|
// a very simple yes/no without prefix mathing, so here we
|
|
|
|
|
// don't need to use a radix tree.
|
|
|
|
|
keyringRules map[string]struct{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// New is used to construct a policy based ACL from a set of policies
|
|
|
|
@ -163,6 +183,7 @@ func New(parent ACL, policy *Policy) (*PolicyACL, error) {
|
|
|
|
|
keyRules: radix.New(),
|
|
|
|
|
serviceRules: radix.New(),
|
|
|
|
|
eventRules: radix.New(),
|
|
|
|
|
keyringRules: make(map[string]struct{}),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Load the key policy
|
|
|
|
@ -180,6 +201,11 @@ func New(parent ACL, policy *Policy) (*PolicyACL, error) {
|
|
|
|
|
p.eventRules.Insert(ep.Event, ep.Policy)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Load the keyring policy
|
|
|
|
|
for _, krp := range policy.Keyring {
|
|
|
|
|
p.keyringRules[krp.Policy] = struct{}{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return p, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -321,6 +347,34 @@ func (p *PolicyACL) EventWrite(name string) bool {
|
|
|
|
|
return p.parent.EventWrite(name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// KeyringRead is used to determine if the keyring can be
|
|
|
|
|
// read by the current ACL token.
|
|
|
|
|
func (p *PolicyACL) KeyringRead() bool {
|
|
|
|
|
// First check for an explicit deny
|
|
|
|
|
if _, ok := p.keyringRules[KeyringPolicyDeny]; ok {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now check for read or write. Write implies read.
|
|
|
|
|
_, ok := p.keyringRules[KeyringPolicyRead]
|
|
|
|
|
if !ok {
|
|
|
|
|
_, ok = p.keyringRules[KeyringPolicyWrite]
|
|
|
|
|
}
|
|
|
|
|
return ok
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// KeyringWrite determines if the keyring can be manipulated.
|
|
|
|
|
func (p *PolicyACL) KeyringWrite() bool {
|
|
|
|
|
// First check for an explicit deny
|
|
|
|
|
if _, ok := p.keyringRules[KeyringPolicyDeny]; ok {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for read permission
|
|
|
|
|
_, ok := p.keyringRules[KeyringPolicyWrite]
|
|
|
|
|
return ok
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ACLList checks if listing of ACLs is allowed
|
|
|
|
|
func (p *PolicyACL) ACLList() bool {
|
|
|
|
|
return p.parent.ACLList()
|
|
|
|
|