2014-08-06 22:08:17 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-08-12 17:35:27 +00:00
|
|
|
func TestRootACL(t *testing.T) {
|
|
|
|
if RootACL("allow") != AllowAll() {
|
|
|
|
t.Fatalf("Bad root")
|
|
|
|
}
|
|
|
|
if RootACL("deny") != DenyAll() {
|
|
|
|
t.Fatalf("Bad root")
|
|
|
|
}
|
2014-08-12 22:09:01 +00:00
|
|
|
if RootACL("manage") != ManageAll() {
|
|
|
|
t.Fatalf("Bad root")
|
|
|
|
}
|
2014-08-12 17:35:27 +00:00
|
|
|
if RootACL("foo") != nil {
|
|
|
|
t.Fatalf("bad root")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-06 22:08:17 +00:00
|
|
|
func TestStaticACL(t *testing.T) {
|
|
|
|
all := AllowAll()
|
|
|
|
if _, ok := all.(*StaticACL); !ok {
|
|
|
|
t.Fatalf("expected static")
|
|
|
|
}
|
|
|
|
|
|
|
|
none := DenyAll()
|
|
|
|
if _, ok := none.(*StaticACL); !ok {
|
|
|
|
t.Fatalf("expected static")
|
|
|
|
}
|
|
|
|
|
2014-08-12 22:09:01 +00:00
|
|
|
manage := ManageAll()
|
2017-08-09 06:21:21 +00:00
|
|
|
if _, ok := manage.(*StaticACL); !ok {
|
2014-08-12 22:09:01 +00:00
|
|
|
t.Fatalf("expected static")
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:31:50 +00:00
|
|
|
if all.ACLList() {
|
|
|
|
t.Fatalf("should not allow")
|
2014-12-01 03:33:46 +00:00
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if all.ACLModify() {
|
|
|
|
t.Fatalf("should not allow")
|
2014-12-01 03:33:46 +00:00
|
|
|
}
|
2016-12-13 07:05:11 +00:00
|
|
|
if !all.AgentRead("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
|
|
|
if !all.AgentWrite("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2015-07-07 17:07:37 +00:00
|
|
|
if !all.EventRead("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
|
|
|
if !all.EventWrite("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2018-03-04 08:38:04 +00:00
|
|
|
if !all.IntentionWrite("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if !all.KeyRead("foobar") {
|
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
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if !all.KeyWrite("foobar", nil) {
|
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
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2015-07-07 17:07:37 +00:00
|
|
|
if !all.KeyringRead() {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
|
|
|
if !all.KeyringWrite() {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-12-07 04:05:15 +00:00
|
|
|
if !all.NodeRead("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if !all.NodeWrite("foobar", nil) {
|
2016-12-07 04:05:15 +00:00
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-08-30 02:09:57 +00:00
|
|
|
if !all.OperatorRead() {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
|
|
|
if !all.OperatorWrite() {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if !all.PreparedQueryRead("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
2014-08-12 22:09:01 +00:00
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if !all.PreparedQueryWrite("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
2014-08-12 22:09:01 +00:00
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if !all.ServiceRead("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
2016-10-26 02:20:24 +00:00
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if !all.ServiceWrite("foobar", nil) {
|
2016-12-02 04:31:50 +00:00
|
|
|
t.Fatalf("should allow")
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
2016-12-13 04:20:28 +00:00
|
|
|
if !all.SessionRead("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
|
|
|
if !all.SessionWrite("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if all.Snapshot() {
|
2014-08-06 22:08:17 +00:00
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
|
|
|
|
if none.ACLList() {
|
2014-12-01 03:33:46 +00:00
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if none.ACLModify() {
|
2014-12-01 03:33:46 +00:00
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2016-12-13 07:05:11 +00:00
|
|
|
if none.AgentRead("foobar") {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
|
|
|
if none.AgentWrite("foobar") {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2015-06-18 01:56:29 +00:00
|
|
|
if none.EventRead("foobar") {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
|
|
|
if none.EventRead("") {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
|
|
|
if none.EventWrite("foobar") {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
|
|
|
if none.EventWrite("") {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2018-03-04 08:38:04 +00:00
|
|
|
if none.IntentionWrite("foo") {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if none.KeyRead("foobar") {
|
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
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if none.KeyWrite("foobar", nil) {
|
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
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2015-07-07 17:07:37 +00:00
|
|
|
if none.KeyringRead() {
|
|
|
|
t.Fatalf("should now allow")
|
|
|
|
}
|
|
|
|
if none.KeyringWrite() {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2016-12-07 04:05:15 +00:00
|
|
|
if none.NodeRead("foobar") {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if none.NodeWrite("foobar", nil) {
|
2016-12-07 04:05:15 +00:00
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2016-08-30 02:09:57 +00:00
|
|
|
if none.OperatorRead() {
|
|
|
|
t.Fatalf("should now allow")
|
|
|
|
}
|
|
|
|
if none.OperatorWrite() {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if none.PreparedQueryRead("foobar") {
|
2015-06-19 17:20:38 +00:00
|
|
|
t.Fatalf("should not allow")
|
2014-08-12 22:09:01 +00:00
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if none.PreparedQueryWrite("foobar") {
|
2015-06-19 17:20:38 +00:00
|
|
|
t.Fatalf("should not allow")
|
2014-08-12 22:09:01 +00:00
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if none.ServiceRead("foobar") {
|
2016-10-26 02:20:24 +00:00
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if none.ServiceWrite("foobar", nil) {
|
2016-12-02 04:31:50 +00:00
|
|
|
t.Fatalf("should not allow")
|
2014-08-12 22:09:01 +00:00
|
|
|
}
|
2016-12-13 04:20:28 +00:00
|
|
|
if none.SessionRead("foobar") {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
|
|
|
if none.SessionWrite("foobar") {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if none.Snapshot() {
|
|
|
|
t.Fatalf("should not allow")
|
2014-08-12 22:09:01 +00:00
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
|
|
|
|
if !manage.ACLList() {
|
2014-12-01 03:33:46 +00:00
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if !manage.ACLModify() {
|
2014-12-01 03:33:46 +00:00
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-12-13 07:05:11 +00:00
|
|
|
if !manage.AgentRead("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
|
|
|
if !manage.AgentWrite("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2015-07-07 17:07:37 +00:00
|
|
|
if !manage.EventRead("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
|
|
|
if !manage.EventWrite("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2018-03-04 08:38:04 +00:00
|
|
|
if !manage.IntentionWrite("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if !manage.KeyRead("foobar") {
|
2015-07-07 17:07:37 +00:00
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if !manage.KeyWrite("foobar", nil) {
|
2015-07-07 17:07:37 +00:00
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
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 !manage.KeyringRead() {
|
2014-08-12 22:09:01 +00:00
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
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 !manage.KeyringWrite() {
|
2014-08-12 22:09:01 +00:00
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-12-07 04:05:15 +00:00
|
|
|
if !manage.NodeRead("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if !manage.NodeWrite("foobar", nil) {
|
2016-12-07 04:05:15 +00:00
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-08-30 02:09:57 +00:00
|
|
|
if !manage.OperatorRead() {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
|
|
|
if !manage.OperatorWrite() {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if !manage.PreparedQueryRead("foobar") {
|
2015-11-04 23:16:21 +00:00
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-12-02 04:31:50 +00:00
|
|
|
if !manage.PreparedQueryWrite("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
|
|
|
if !manage.ServiceRead("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if !manage.ServiceWrite("foobar", nil) {
|
2015-11-04 23:16:21 +00:00
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-12-13 04:20:28 +00:00
|
|
|
if !manage.SessionRead("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
|
|
|
if !manage.SessionWrite("foobar") {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2016-10-26 02:20:24 +00:00
|
|
|
if !manage.Snapshot() {
|
|
|
|
t.Fatalf("should allow")
|
|
|
|
}
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPolicyACL(t *testing.T) {
|
|
|
|
all := AllowAll()
|
|
|
|
policy := &Policy{
|
2016-12-02 04:31:50 +00:00
|
|
|
Events: []*EventPolicy{
|
|
|
|
&EventPolicy{
|
|
|
|
Event: "",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
&EventPolicy{
|
|
|
|
Event: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
&EventPolicy{
|
|
|
|
Event: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2014-08-06 22:08:17 +00:00
|
|
|
Keys: []*KeyPolicy{
|
|
|
|
&KeyPolicy{
|
|
|
|
Prefix: "foo/",
|
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
|
|
|
Policy: PolicyWrite,
|
2014-08-06 22:08:17 +00:00
|
|
|
},
|
|
|
|
&KeyPolicy{
|
|
|
|
Prefix: "foo/priv/",
|
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
|
|
|
Policy: PolicyDeny,
|
2014-08-06 22:08:17 +00:00
|
|
|
},
|
|
|
|
&KeyPolicy{
|
|
|
|
Prefix: "bar/",
|
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
|
|
|
Policy: PolicyDeny,
|
2014-08-06 22:08:17 +00:00
|
|
|
},
|
|
|
|
&KeyPolicy{
|
|
|
|
Prefix: "zip/",
|
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
|
|
|
Policy: PolicyRead,
|
2014-08-06 22:08:17 +00:00
|
|
|
},
|
2017-10-02 22:10:21 +00:00
|
|
|
&KeyPolicy{
|
|
|
|
Prefix: "zap/",
|
|
|
|
Policy: PolicyList,
|
|
|
|
},
|
2014-08-06 22:08:17 +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
|
|
|
PreparedQueries: []*PreparedQueryPolicy{
|
|
|
|
&PreparedQueryPolicy{
|
|
|
|
Prefix: "",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
&PreparedQueryPolicy{
|
|
|
|
Prefix: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
&PreparedQueryPolicy{
|
|
|
|
Prefix: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
&PreparedQueryPolicy{
|
|
|
|
Prefix: "zoo",
|
|
|
|
Policy: PolicyWrite,
|
2015-06-18 01:56:29 +00:00
|
|
|
},
|
|
|
|
},
|
2016-12-02 04:31:50 +00:00
|
|
|
Services: []*ServicePolicy{
|
|
|
|
&ServicePolicy{
|
|
|
|
Name: "",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
&ServicePolicy{
|
|
|
|
Name: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
&ServicePolicy{
|
|
|
|
Name: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
&ServicePolicy{
|
2018-03-04 08:38:04 +00:00
|
|
|
Name: "barfoo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
Intentions: PolicyWrite,
|
|
|
|
},
|
|
|
|
&ServicePolicy{
|
|
|
|
Name: "intbaz",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
Intentions: PolicyDeny,
|
2016-12-02 04:31:50 +00:00
|
|
|
},
|
|
|
|
},
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
acl, err := New(all, policy, nil)
|
2014-08-06 22:08:17 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
2014-12-01 03:33:46 +00:00
|
|
|
type keycase struct {
|
2014-08-14 22:53:02 +00:00
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
writePrefix bool
|
2017-10-02 22:10:21 +00:00
|
|
|
list bool
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
2014-12-01 03:33:46 +00:00
|
|
|
cases := []keycase{
|
2017-10-02 22:10:21 +00:00
|
|
|
{"other", true, true, true, true},
|
|
|
|
{"foo/test", true, true, true, true},
|
|
|
|
{"foo/priv/test", false, false, false, false},
|
|
|
|
{"bar/any", false, false, false, false},
|
|
|
|
{"zip/test", true, false, false, false},
|
|
|
|
{"foo/", true, true, false, true},
|
|
|
|
{"", true, true, false, true},
|
|
|
|
{"zap/test", true, false, false, true},
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
for _, c := range cases {
|
|
|
|
if c.read != acl.KeyRead(c.inp) {
|
|
|
|
t.Fatalf("Read fail: %#v", c)
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if c.write != acl.KeyWrite(c.inp, nil) {
|
2014-08-06 22:08:17 +00:00
|
|
|
t.Fatalf("Write fail: %#v", c)
|
|
|
|
}
|
2014-08-14 22:53:02 +00:00
|
|
|
if c.writePrefix != acl.KeyWritePrefix(c.inp) {
|
|
|
|
t.Fatalf("Write prefix fail: %#v", c)
|
|
|
|
}
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
2014-12-01 03:33:46 +00:00
|
|
|
|
2018-03-04 08:38:04 +00:00
|
|
|
// Test the intentions
|
|
|
|
type intentioncase struct {
|
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
}
|
|
|
|
icases := []intentioncase{
|
|
|
|
{"other", true, false},
|
|
|
|
{"foo", true, false},
|
|
|
|
{"bar", false, false},
|
|
|
|
{"foobar", true, false},
|
|
|
|
{"barfo", false, false},
|
|
|
|
{"barfoo", true, true},
|
|
|
|
{"barfoo2", true, true},
|
|
|
|
{"intbaz", false, false},
|
|
|
|
}
|
|
|
|
for _, c := range icases {
|
|
|
|
if c.read != acl.IntentionRead(c.inp) {
|
|
|
|
t.Fatalf("Read fail: %#v", c)
|
|
|
|
}
|
|
|
|
if c.write != acl.IntentionWrite(c.inp) {
|
|
|
|
t.Fatalf("Write fail: %#v", c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-01 03:33:46 +00:00
|
|
|
// Test the services
|
|
|
|
type servicecase struct {
|
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
}
|
|
|
|
scases := []servicecase{
|
|
|
|
{"other", true, true},
|
|
|
|
{"foo", true, false},
|
|
|
|
{"bar", false, false},
|
2015-05-05 06:25:19 +00:00
|
|
|
{"foobar", true, false},
|
|
|
|
{"barfo", false, false},
|
|
|
|
{"barfoo", true, true},
|
|
|
|
{"barfoo2", true, true},
|
2014-12-01 03:33:46 +00:00
|
|
|
}
|
|
|
|
for _, c := range scases {
|
|
|
|
if c.read != acl.ServiceRead(c.inp) {
|
|
|
|
t.Fatalf("Read fail: %#v", c)
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if c.write != acl.ServiceWrite(c.inp, nil) {
|
2014-12-01 03:33:46 +00:00
|
|
|
t.Fatalf("Write fail: %#v", c)
|
|
|
|
}
|
|
|
|
}
|
2015-06-18 01:56:29 +00:00
|
|
|
|
2015-07-07 17:21:27 +00:00
|
|
|
// Test the events
|
2015-06-18 01:56:29 +00:00
|
|
|
type eventcase struct {
|
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
}
|
|
|
|
eventcases := []eventcase{
|
|
|
|
{"foo", true, true},
|
|
|
|
{"foobar", true, true},
|
|
|
|
{"bar", false, false},
|
|
|
|
{"barbaz", false, false},
|
|
|
|
{"baz", true, false},
|
|
|
|
}
|
|
|
|
for _, c := range eventcases {
|
|
|
|
if c.read != acl.EventRead(c.inp) {
|
|
|
|
t.Fatalf("Event fail: %#v", c)
|
|
|
|
}
|
|
|
|
if c.write != acl.EventWrite(c.inp) {
|
|
|
|
t.Fatalf("Event fail: %#v", c)
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
// Test prepared queries
|
|
|
|
type querycase struct {
|
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
}
|
|
|
|
querycases := []querycase{
|
|
|
|
{"foo", true, true},
|
|
|
|
{"foobar", true, true},
|
|
|
|
{"bar", false, false},
|
|
|
|
{"barbaz", false, false},
|
|
|
|
{"baz", true, false},
|
|
|
|
{"nope", true, false},
|
|
|
|
{"zoo", true, true},
|
|
|
|
{"zookeeper", true, true},
|
|
|
|
}
|
|
|
|
for _, c := range querycases {
|
|
|
|
if c.read != acl.PreparedQueryRead(c.inp) {
|
|
|
|
t.Fatalf("Prepared query fail: %#v", c)
|
|
|
|
}
|
|
|
|
if c.write != acl.PreparedQueryWrite(c.inp) {
|
|
|
|
t.Fatalf("Prepared query fail: %#v", c)
|
|
|
|
}
|
|
|
|
}
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPolicyACL_Parent(t *testing.T) {
|
|
|
|
deny := DenyAll()
|
|
|
|
policyRoot := &Policy{
|
|
|
|
Keys: []*KeyPolicy{
|
|
|
|
&KeyPolicy{
|
|
|
|
Prefix: "foo/",
|
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
|
|
|
Policy: PolicyWrite,
|
2014-08-06 22:08:17 +00:00
|
|
|
},
|
|
|
|
&KeyPolicy{
|
|
|
|
Prefix: "bar/",
|
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
|
|
|
Policy: PolicyRead,
|
2014-08-06 22:08:17 +00:00
|
|
|
},
|
|
|
|
},
|
2016-02-24 09:26:16 +00:00
|
|
|
PreparedQueries: []*PreparedQueryPolicy{
|
|
|
|
&PreparedQueryPolicy{
|
|
|
|
Prefix: "other",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
&PreparedQueryPolicy{
|
|
|
|
Prefix: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
},
|
2016-12-02 04:31:50 +00:00
|
|
|
Services: []*ServicePolicy{
|
|
|
|
&ServicePolicy{
|
|
|
|
Name: "other",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
&ServicePolicy{
|
|
|
|
Name: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
},
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
root, err := New(deny, policyRoot, nil)
|
2014-08-06 22:08:17 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
policy := &Policy{
|
|
|
|
Keys: []*KeyPolicy{
|
|
|
|
&KeyPolicy{
|
|
|
|
Prefix: "foo/priv/",
|
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
|
|
|
Policy: PolicyRead,
|
2014-08-06 22:08:17 +00:00
|
|
|
},
|
|
|
|
&KeyPolicy{
|
|
|
|
Prefix: "bar/",
|
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
|
|
|
Policy: PolicyDeny,
|
2014-08-06 22:08:17 +00:00
|
|
|
},
|
|
|
|
&KeyPolicy{
|
|
|
|
Prefix: "zip/",
|
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
|
|
|
Policy: PolicyRead,
|
2014-08-06 22:08:17 +00:00
|
|
|
},
|
|
|
|
},
|
2016-02-24 09:26:16 +00:00
|
|
|
PreparedQueries: []*PreparedQueryPolicy{
|
|
|
|
&PreparedQueryPolicy{
|
|
|
|
Prefix: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2016-12-02 04:31:50 +00:00
|
|
|
Services: []*ServicePolicy{
|
|
|
|
&ServicePolicy{
|
|
|
|
Name: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
acl, err := New(root, policy, nil)
|
2014-08-06 22:08:17 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
2014-12-01 03:33:46 +00:00
|
|
|
type keycase struct {
|
2014-08-14 22:53:02 +00:00
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
writePrefix bool
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
2014-12-01 03:33:46 +00:00
|
|
|
cases := []keycase{
|
2014-08-14 22:53:02 +00:00
|
|
|
{"other", false, false, false},
|
|
|
|
{"foo/test", true, true, true},
|
|
|
|
{"foo/priv/test", true, false, false},
|
|
|
|
{"bar/any", false, false, false},
|
|
|
|
{"zip/test", true, false, false},
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
|
|
|
for _, c := range cases {
|
|
|
|
if c.read != acl.KeyRead(c.inp) {
|
|
|
|
t.Fatalf("Read fail: %#v", c)
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if c.write != acl.KeyWrite(c.inp, nil) {
|
2014-08-06 22:08:17 +00:00
|
|
|
t.Fatalf("Write fail: %#v", c)
|
|
|
|
}
|
2014-08-14 22:53:02 +00:00
|
|
|
if c.writePrefix != acl.KeyWritePrefix(c.inp) {
|
|
|
|
t.Fatalf("Write prefix fail: %#v", c)
|
|
|
|
}
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
2014-12-01 03:33:46 +00:00
|
|
|
|
|
|
|
// Test the services
|
|
|
|
type servicecase struct {
|
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
}
|
|
|
|
scases := []servicecase{
|
|
|
|
{"fail", false, false},
|
|
|
|
{"other", true, true},
|
|
|
|
{"foo", true, false},
|
|
|
|
{"bar", false, false},
|
|
|
|
}
|
|
|
|
for _, c := range scases {
|
|
|
|
if c.read != acl.ServiceRead(c.inp) {
|
|
|
|
t.Fatalf("Read fail: %#v", c)
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if c.write != acl.ServiceWrite(c.inp, nil) {
|
2014-12-01 03:33:46 +00:00
|
|
|
t.Fatalf("Write fail: %#v", c)
|
|
|
|
}
|
|
|
|
}
|
2015-11-04 23:16:21 +00:00
|
|
|
|
2016-02-24 09:26:16 +00:00
|
|
|
// Test prepared queries
|
|
|
|
type querycase struct {
|
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
}
|
|
|
|
querycases := []querycase{
|
|
|
|
{"foo", true, false},
|
|
|
|
{"foobar", true, false},
|
|
|
|
{"bar", false, false},
|
|
|
|
{"barbaz", false, false},
|
|
|
|
{"baz", false, false},
|
|
|
|
{"nope", false, false},
|
|
|
|
}
|
|
|
|
for _, c := range querycases {
|
|
|
|
if c.read != acl.PreparedQueryRead(c.inp) {
|
|
|
|
t.Fatalf("Prepared query fail: %#v", c)
|
|
|
|
}
|
|
|
|
if c.write != acl.PreparedQueryWrite(c.inp) {
|
|
|
|
t.Fatalf("Prepared query fail: %#v", c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-04 23:16:21 +00:00
|
|
|
// Check some management functions that chain up
|
|
|
|
if acl.ACLList() {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
|
|
|
if acl.ACLModify() {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2016-10-26 02:20:24 +00:00
|
|
|
if acl.Snapshot() {
|
|
|
|
t.Fatalf("should not allow")
|
|
|
|
}
|
2014-08-06 22:08:17 +00:00
|
|
|
}
|
2015-07-07 17:21:27 +00:00
|
|
|
|
2016-12-13 07:05:11 +00:00
|
|
|
func TestPolicyACL_Agent(t *testing.T) {
|
|
|
|
deny := DenyAll()
|
|
|
|
policyRoot := &Policy{
|
|
|
|
Agents: []*AgentPolicy{
|
|
|
|
&AgentPolicy{
|
|
|
|
Node: "root-nope",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
&AgentPolicy{
|
|
|
|
Node: "root-ro",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
&AgentPolicy{
|
|
|
|
Node: "root-rw",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
&AgentPolicy{
|
|
|
|
Node: "override",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
root, err := New(deny, policyRoot, nil)
|
2016-12-13 07:05:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
policy := &Policy{
|
|
|
|
Agents: []*AgentPolicy{
|
|
|
|
&AgentPolicy{
|
|
|
|
Node: "child-nope",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
&AgentPolicy{
|
|
|
|
Node: "child-ro",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
&AgentPolicy{
|
|
|
|
Node: "child-rw",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
&AgentPolicy{
|
|
|
|
Node: "override",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
acl, err := New(root, policy, nil)
|
2016-12-13 07:05:11 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
type agentcase struct {
|
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
}
|
|
|
|
cases := []agentcase{
|
|
|
|
{"nope", false, false},
|
|
|
|
{"root-nope", false, false},
|
|
|
|
{"root-ro", true, false},
|
|
|
|
{"root-rw", true, true},
|
|
|
|
{"root-nope-prefix", false, false},
|
|
|
|
{"root-ro-prefix", true, false},
|
|
|
|
{"root-rw-prefix", true, true},
|
|
|
|
{"child-nope", false, false},
|
|
|
|
{"child-ro", true, false},
|
|
|
|
{"child-rw", true, true},
|
|
|
|
{"child-nope-prefix", false, false},
|
|
|
|
{"child-ro-prefix", true, false},
|
|
|
|
{"child-rw-prefix", true, true},
|
|
|
|
{"override", true, true},
|
|
|
|
}
|
|
|
|
for _, c := range cases {
|
|
|
|
if c.read != acl.AgentRead(c.inp) {
|
|
|
|
t.Fatalf("Read fail: %#v", c)
|
|
|
|
}
|
|
|
|
if c.write != acl.AgentWrite(c.inp) {
|
|
|
|
t.Fatalf("Write fail: %#v", c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 17:21:27 +00:00
|
|
|
func TestPolicyACL_Keyring(t *testing.T) {
|
|
|
|
type keyringcase struct {
|
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
}
|
2016-08-30 02:09:57 +00:00
|
|
|
cases := []keyringcase{
|
2015-07-07 17:21:27 +00:00
|
|
|
{"", false, false},
|
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
|
|
|
{PolicyRead, true, false},
|
|
|
|
{PolicyWrite, true, true},
|
|
|
|
{PolicyDeny, false, false},
|
2015-07-07 17:21:27 +00:00
|
|
|
}
|
2016-08-30 02:09:57 +00:00
|
|
|
for _, c := range cases {
|
2017-09-14 19:31:01 +00:00
|
|
|
acl, err := New(DenyAll(), &Policy{Keyring: c.inp}, nil)
|
2015-07-07 17:21:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
|
|
|
if acl.KeyringRead() != c.read {
|
|
|
|
t.Fatalf("bad: %#v", c)
|
|
|
|
}
|
|
|
|
if acl.KeyringWrite() != c.write {
|
|
|
|
t.Fatalf("bad: %#v", c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 02:09:57 +00:00
|
|
|
|
|
|
|
func TestPolicyACL_Operator(t *testing.T) {
|
|
|
|
type operatorcase struct {
|
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
}
|
|
|
|
cases := []operatorcase{
|
|
|
|
{"", false, false},
|
|
|
|
{PolicyRead, true, false},
|
|
|
|
{PolicyWrite, true, true},
|
|
|
|
{PolicyDeny, false, false},
|
|
|
|
}
|
|
|
|
for _, c := range cases {
|
2017-09-14 19:31:01 +00:00
|
|
|
acl, err := New(DenyAll(), &Policy{Operator: c.inp}, nil)
|
2016-08-30 02:09:57 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad: %s", err)
|
|
|
|
}
|
|
|
|
if acl.OperatorRead() != c.read {
|
|
|
|
t.Fatalf("bad: %#v", c)
|
|
|
|
}
|
|
|
|
if acl.OperatorWrite() != c.write {
|
|
|
|
t.Fatalf("bad: %#v", c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-07 04:05:15 +00:00
|
|
|
|
|
|
|
func TestPolicyACL_Node(t *testing.T) {
|
|
|
|
deny := DenyAll()
|
|
|
|
policyRoot := &Policy{
|
|
|
|
Nodes: []*NodePolicy{
|
|
|
|
&NodePolicy{
|
|
|
|
Name: "root-nope",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
&NodePolicy{
|
|
|
|
Name: "root-ro",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
&NodePolicy{
|
|
|
|
Name: "root-rw",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
&NodePolicy{
|
|
|
|
Name: "override",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
root, err := New(deny, policyRoot, nil)
|
2016-12-07 04:05:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
policy := &Policy{
|
|
|
|
Nodes: []*NodePolicy{
|
|
|
|
&NodePolicy{
|
|
|
|
Name: "child-nope",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
&NodePolicy{
|
|
|
|
Name: "child-ro",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
&NodePolicy{
|
|
|
|
Name: "child-rw",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
&NodePolicy{
|
|
|
|
Name: "override",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
acl, err := New(root, policy, nil)
|
2016-12-07 04:05:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
type nodecase struct {
|
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
}
|
|
|
|
cases := []nodecase{
|
|
|
|
{"nope", false, false},
|
|
|
|
{"root-nope", false, false},
|
|
|
|
{"root-ro", true, false},
|
|
|
|
{"root-rw", true, true},
|
|
|
|
{"root-nope-prefix", false, false},
|
|
|
|
{"root-ro-prefix", true, false},
|
|
|
|
{"root-rw-prefix", true, true},
|
|
|
|
{"child-nope", false, false},
|
|
|
|
{"child-ro", true, false},
|
|
|
|
{"child-rw", true, true},
|
|
|
|
{"child-nope-prefix", false, false},
|
|
|
|
{"child-ro-prefix", true, false},
|
|
|
|
{"child-rw-prefix", true, true},
|
|
|
|
{"override", true, true},
|
|
|
|
}
|
|
|
|
for _, c := range cases {
|
|
|
|
if c.read != acl.NodeRead(c.inp) {
|
|
|
|
t.Fatalf("Read fail: %#v", c)
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
if c.write != acl.NodeWrite(c.inp, nil) {
|
2016-12-07 04:05:15 +00:00
|
|
|
t.Fatalf("Write fail: %#v", c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-13 04:20:28 +00:00
|
|
|
|
|
|
|
func TestPolicyACL_Session(t *testing.T) {
|
|
|
|
deny := DenyAll()
|
|
|
|
policyRoot := &Policy{
|
|
|
|
Sessions: []*SessionPolicy{
|
|
|
|
&SessionPolicy{
|
|
|
|
Node: "root-nope",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
&SessionPolicy{
|
|
|
|
Node: "root-ro",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
&SessionPolicy{
|
|
|
|
Node: "root-rw",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
&SessionPolicy{
|
|
|
|
Node: "override",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
root, err := New(deny, policyRoot, nil)
|
2016-12-13 04:20:28 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
policy := &Policy{
|
|
|
|
Sessions: []*SessionPolicy{
|
|
|
|
&SessionPolicy{
|
|
|
|
Node: "child-nope",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
&SessionPolicy{
|
|
|
|
Node: "child-ro",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
&SessionPolicy{
|
|
|
|
Node: "child-rw",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
&SessionPolicy{
|
|
|
|
Node: "override",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2017-09-14 19:31:01 +00:00
|
|
|
acl, err := New(root, policy, nil)
|
2016-12-13 04:20:28 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
type sessioncase struct {
|
|
|
|
inp string
|
|
|
|
read bool
|
|
|
|
write bool
|
|
|
|
}
|
|
|
|
cases := []sessioncase{
|
|
|
|
{"nope", false, false},
|
|
|
|
{"root-nope", false, false},
|
|
|
|
{"root-ro", true, false},
|
|
|
|
{"root-rw", true, true},
|
|
|
|
{"root-nope-prefix", false, false},
|
|
|
|
{"root-ro-prefix", true, false},
|
|
|
|
{"root-rw-prefix", true, true},
|
|
|
|
{"child-nope", false, false},
|
|
|
|
{"child-ro", true, false},
|
|
|
|
{"child-rw", true, true},
|
|
|
|
{"child-nope-prefix", false, false},
|
|
|
|
{"child-ro-prefix", true, false},
|
|
|
|
{"child-rw-prefix", true, true},
|
|
|
|
{"override", true, true},
|
|
|
|
}
|
|
|
|
for _, c := range cases {
|
|
|
|
if c.read != acl.SessionRead(c.inp) {
|
|
|
|
t.Fatalf("Read fail: %#v", c)
|
|
|
|
}
|
|
|
|
if c.write != acl.SessionWrite(c.inp) {
|
|
|
|
t.Fatalf("Write fail: %#v", c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|