2019-10-15 20:58:50 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
var (
|
|
|
|
// allowAll is a singleton policy which allows all
|
|
|
|
// non-management actions
|
|
|
|
allowAll Authorizer = &StaticAuthorizer{
|
|
|
|
allowManage: false,
|
|
|
|
defaultAllow: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
// denyAll is a singleton policy which denies all actions
|
|
|
|
denyAll Authorizer = &StaticAuthorizer{
|
|
|
|
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.
|
|
|
|
manageAll Authorizer = &StaticAuthorizer{
|
|
|
|
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.
|
|
|
|
type StaticAuthorizer struct {
|
|
|
|
allowManage bool
|
|
|
|
defaultAllow bool
|
|
|
|
}
|
|
|
|
|
2019-12-18 18:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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:43:24 +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
|
|
|
|
}
|
|
|
|
}
|