2019-10-15 20:58:50 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
var (
|
|
|
|
// allowAll is a singleton policy which allows all
|
|
|
|
// non-management actions
|
2019-12-18 18:44:32 +00:00
|
|
|
allowAll Authorizer = &staticAuthorizer{
|
2019-10-15 20:58:50 +00:00
|
|
|
allowManage: false,
|
|
|
|
defaultAllow: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
// denyAll is a singleton policy which denies all actions
|
2019-12-18 18:44:32 +00:00
|
|
|
denyAll Authorizer = &staticAuthorizer{
|
2019-10-15 20:58:50 +00:00
|
|
|
allowManage: false,
|
|
|
|
defaultAllow: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
// manageAll is a singleton policy which allows all
|
|
|
|
// actions, including management
|
|
|
|
// TODO (acls) - Do we need to keep this around? Our config parsing doesn't allow
|
|
|
|
// specifying a default "manage" policy so I believe nothing will every use this.
|
2019-12-18 18:44:32 +00:00
|
|
|
manageAll Authorizer = &staticAuthorizer{
|
2019-10-15 20:58:50 +00:00
|
|
|
allowManage: true,
|
|
|
|
defaultAllow: true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// StaticAuthorizer 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.
|
2019-12-18 18:44:32 +00:00
|
|
|
type staticAuthorizer struct {
|
2019-10-15 20:58:50 +00:00
|
|
|
allowManage bool
|
|
|
|
defaultAllow bool
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) ACLRead(*AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.allowManage {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) ACLWrite(*AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.allowManage {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) AgentRead(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) AgentWrite(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) EventRead(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) EventWrite(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) IntentionDefaultAllow(*AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) IntentionRead(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) IntentionWrite(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) KeyRead(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) KeyList(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) KeyWrite(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) KeyWritePrefix(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) KeyringRead(*AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) KeyringWrite(*AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) NodeRead(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) NodeWrite(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) OperatorRead(*AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) OperatorWrite(*AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) PreparedQueryRead(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) PreparedQueryWrite(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) ServiceRead(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) ServiceWrite(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) SessionRead(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) SessionWrite(string, *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.defaultAllow {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:44:32 +00:00
|
|
|
func (s *staticAuthorizer) Snapshot(_ *AuthorizerContext) EnforcementDecision {
|
2019-10-15 20:58:50 +00:00
|
|
|
if s.allowManage {
|
|
|
|
return Allow
|
|
|
|
}
|
|
|
|
return Deny
|
|
|
|
}
|
|
|
|
|
|
|
|
// AllowAll returns an Authorizer that allows all operations
|
|
|
|
func AllowAll() Authorizer {
|
|
|
|
return allowAll
|
|
|
|
}
|
|
|
|
|
|
|
|
// DenyAll returns an Authorizer that denies all operations
|
|
|
|
func DenyAll() Authorizer {
|
|
|
|
return denyAll
|
|
|
|
}
|
|
|
|
|
|
|
|
// ManageAll returns an Authorizer that can manage all resources
|
|
|
|
func ManageAll() Authorizer {
|
|
|
|
return manageAll
|
|
|
|
}
|
|
|
|
|
|
|
|
// RootAuthorizer returns a possible Authorizer if the ID matches a root policy
|
|
|
|
func RootAuthorizer(id string) Authorizer {
|
|
|
|
switch id {
|
|
|
|
case "allow":
|
|
|
|
return allowAll
|
|
|
|
case "deny":
|
|
|
|
return denyAll
|
|
|
|
case "manage":
|
|
|
|
return manageAll
|
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|