Skip to content

Commit

Permalink
Adds a new management ACL for prepared queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Phillips committed Nov 16, 2015
1 parent ff351b2 commit ce0881a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
24 changes: 24 additions & 0 deletions acl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ type ACL interface {

// ACLModify checks for permission to manipulate ACLs
ACLModify() bool

// QueryList checks for permission to list all the prepared queries.
QueryList() bool

// QueryModify checks for permission to modify any prepared query.
QueryModify() bool
}

// StaticACL is used to implement a base ACL policy. It either
Expand Down Expand Up @@ -124,6 +130,14 @@ func (s *StaticACL) ACLModify() bool {
return s.allowManage
}

func (s *StaticACL) QueryList() bool {
return s.allowManage
}

func (s *StaticACL) QueryModify() bool {
return s.allowManage
}

// AllowAll returns an ACL rule that allows all operations
func AllowAll() ACL {
return allowAll
Expand Down Expand Up @@ -374,3 +388,13 @@ func (p *PolicyACL) ACLList() bool {
func (p *PolicyACL) ACLModify() bool {
return p.parent.ACLModify()
}

// QueryList checks if listing of all prepared queries is allowed.
func (p *PolicyACL) QueryList() bool {
return p.parent.QueryList()
}

// QueryModify checks if modifying of any prepared query is allowed.
func (p *PolicyACL) QueryModify() bool {
return p.parent.QueryModify()
}
32 changes: 32 additions & 0 deletions acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func TestStaticACL(t *testing.T) {
if all.ACLModify() {
t.Fatalf("should not allow")
}
if all.QueryList() {
t.Fatalf("should not allow")
}
if all.QueryModify() {
t.Fatalf("should not allow")
}

if none.KeyRead("foobar") {
t.Fatalf("should not allow")
Expand Down Expand Up @@ -102,6 +108,12 @@ func TestStaticACL(t *testing.T) {
if none.ACLModify() {
t.Fatalf("should not allow")
}
if none.QueryList() {
t.Fatalf("should not allow")
}
if none.QueryModify() {
t.Fatalf("should not allow")
}

if !manage.KeyRead("foobar") {
t.Fatalf("should allow")
Expand Down Expand Up @@ -133,6 +145,12 @@ func TestStaticACL(t *testing.T) {
if !manage.ACLModify() {
t.Fatalf("should allow")
}
if !manage.QueryList() {
t.Fatalf("should allow")
}
if !manage.QueryModify() {
t.Fatalf("should allow")
}
}

func TestPolicyACL(t *testing.T) {
Expand Down Expand Up @@ -369,6 +387,20 @@ func TestPolicyACL_Parent(t *testing.T) {
t.Fatalf("Write fail: %#v", c)
}
}

// Check some management functions that chain up
if acl.ACLList() {
t.Fatalf("should not allow")
}
if acl.ACLModify() {
t.Fatalf("should not allow")
}
if acl.QueryList() {
t.Fatalf("should not allow")
}
if acl.QueryModify() {
t.Fatalf("should not allow")
}
}

func TestPolicyACL_Keyring(t *testing.T) {
Expand Down

0 comments on commit ce0881a

Please sign in to comment.