2014-08-06 22:08:17 +00:00
|
|
|
package acl
|
|
|
|
|
|
|
|
import (
|
2015-07-07 20:46:41 +00:00
|
|
|
"strings"
|
2014-08-06 22:08:17 +00:00
|
|
|
"testing"
|
2018-03-06 18:51:26 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2014-08-06 22:08:17 +00:00
|
|
|
)
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func errStartsWith(t *testing.T, actual error, expected string) {
|
|
|
|
t.Helper()
|
|
|
|
require.Error(t, actual)
|
|
|
|
require.Truef(t, strings.HasPrefix(actual.Error(), expected), "Received unexpected error: %#v\nExpecting an error with the prefix: %q", actual, expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPolicySourceParse(t *testing.T) {
|
2018-03-04 00:14:33 +00:00
|
|
|
cases := []struct {
|
2021-08-20 22:11:01 +00:00
|
|
|
Name string
|
|
|
|
Syntax SyntaxVersion
|
|
|
|
Rules string
|
|
|
|
RulesJSON string
|
|
|
|
Expected *Policy
|
|
|
|
Err string
|
2018-03-04 00:14:33 +00:00
|
|
|
}{
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Basic",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `
|
|
|
|
agent_prefix "bar" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
agent "foo" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
event_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
event "foo" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
event "bar" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
key_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
key_prefix "foo/" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
key_prefix "foo/bar/" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
key "foo/bar/baz" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
keyring = "deny"
|
|
|
|
node_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
node "foo" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
node "bar" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
operator = "deny"
|
|
|
|
mesh = "deny"
|
|
|
|
service_prefix "" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
service "foo" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
session "foo" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
session "bar" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
session_prefix "baz" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
query_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
query "foo" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
query "bar" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
RulesJSON: `
|
|
|
|
{
|
|
|
|
"agent_prefix": {
|
|
|
|
"bar": {
|
|
|
|
"policy": "write"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"agent": {
|
|
|
|
"foo": {
|
|
|
|
"policy": "read"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"event_prefix": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"event": {
|
|
|
|
"foo": {
|
|
|
|
"policy": "write"
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
"policy": "deny"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"key_prefix": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
},
|
|
|
|
"foo/": {
|
|
|
|
"policy": "write"
|
|
|
|
},
|
|
|
|
"foo/bar/": {
|
|
|
|
"policy": "read"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"key": {
|
|
|
|
"foo/bar/baz": {
|
|
|
|
"policy": "deny"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"keyring": "deny",
|
|
|
|
"node_prefix": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"node": {
|
|
|
|
"foo": {
|
|
|
|
"policy": "write"
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
"policy": "deny"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"operator": "deny",
|
|
|
|
"mesh": "deny",
|
|
|
|
"service_prefix": {
|
|
|
|
"": {
|
|
|
|
"policy": "write"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"service": {
|
|
|
|
"foo": {
|
|
|
|
"policy": "read"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"session_prefix": {
|
|
|
|
"baz": {
|
|
|
|
"policy": "deny"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"session": {
|
|
|
|
"foo": {
|
|
|
|
"policy": "write"
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
"policy": "deny"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"query_prefix": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"query": {
|
|
|
|
"foo": {
|
|
|
|
"policy": "write"
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
"policy": "deny"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
Expected: &Policy{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
AgentPrefixes: []*AgentRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "bar",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2021-08-20 22:11:01 +00:00
|
|
|
Agents: []*AgentRule{
|
|
|
|
{
|
|
|
|
Node: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
EventPrefixes: []*EventRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2021-08-20 22:11:01 +00:00
|
|
|
},
|
|
|
|
Events: []*EventRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Keyring: PolicyDeny,
|
2019-10-15 20:58:50 +00:00
|
|
|
KeyPrefixes: []*KeyRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo/",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo/bar/",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2021-08-20 22:11:01 +00:00
|
|
|
},
|
|
|
|
Keys: []*KeyRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo/bar/baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
NodePrefixes: []*NodeRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2021-08-20 22:11:01 +00:00
|
|
|
},
|
|
|
|
Nodes: []*NodeRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Operator: PolicyDeny,
|
2021-08-20 22:11:01 +00:00
|
|
|
Mesh: PolicyDeny,
|
2019-10-15 20:58:50 +00:00
|
|
|
PreparedQueryPrefixes: []*PreparedQueryRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2021-08-20 22:11:01 +00:00
|
|
|
},
|
|
|
|
PreparedQueries: []*PreparedQueryRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
ServicePrefixes: []*ServiceRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2021-08-20 22:11:01 +00:00
|
|
|
},
|
|
|
|
Services: []*ServiceRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
SessionPrefixes: []*SessionRule{
|
2021-08-20 22:11:01 +00:00
|
|
|
{
|
|
|
|
Node: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Sessions: []*SessionRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Legacy Basic",
|
|
|
|
Syntax: SyntaxLegacy,
|
|
|
|
Rules: `
|
|
|
|
agent "foo" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
agent "bar" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
event "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
event "foo" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
event "bar" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
key "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
key "foo/" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
key "foo/bar/" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
key "foo/bar/baz" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
keyring = "deny"
|
|
|
|
node "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
node "foo" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
node "bar" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
operator = "deny"
|
|
|
|
service "" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
service "foo" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
session "foo" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
session "bar" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
session "baz" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
query "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
query "foo" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
query "bar" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
RulesJSON: `
|
|
|
|
{
|
|
|
|
"agent": {
|
|
|
|
"foo": {
|
|
|
|
"policy": "read"
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
"policy": "write"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"event": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
"policy": "write"
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
"policy": "deny"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"key": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
},
|
|
|
|
"foo/": {
|
|
|
|
"policy": "write"
|
|
|
|
},
|
|
|
|
"foo/bar/": {
|
|
|
|
"policy": "read"
|
|
|
|
},
|
|
|
|
"foo/bar/baz": {
|
|
|
|
"policy": "deny"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"keyring": "deny",
|
|
|
|
"node": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
"policy": "write"
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
"policy": "deny"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"operator": "deny",
|
|
|
|
"service": {
|
|
|
|
"": {
|
|
|
|
"policy": "write"
|
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
"policy": "read"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"session": {
|
|
|
|
"foo": {
|
|
|
|
"policy": "write"
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
"policy": "deny"
|
|
|
|
},
|
|
|
|
"baz": {
|
|
|
|
"policy": "deny"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"query": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
},
|
|
|
|
"foo": {
|
|
|
|
"policy": "write"
|
|
|
|
},
|
|
|
|
"bar": {
|
|
|
|
"policy": "deny"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
Expected: &Policy{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
AgentPrefixes: []*AgentRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "foo",
|
2021-08-20 22:11:01 +00:00
|
|
|
Policy: PolicyRead,
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "bar",
|
2021-08-20 22:11:01 +00:00
|
|
|
Policy: PolicyWrite,
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
EventPrefixes: []*EventRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Keyring: PolicyDeny,
|
2019-10-15 20:58:50 +00:00
|
|
|
KeyPrefixes: []*KeyRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo/",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo/bar/",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo/bar/baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
NodePrefixes: []*NodeRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Operator: PolicyDeny,
|
2019-10-15 20:58:50 +00:00
|
|
|
PreparedQueryPrefixes: []*PreparedQueryRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
ServicePrefixes: []*ServiceRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
SessionPrefixes: []*SessionRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "bar",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
2021-08-20 22:11:01 +00:00
|
|
|
{
|
|
|
|
Node: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Service No Intentions (Legacy)",
|
|
|
|
Syntax: SyntaxLegacy,
|
|
|
|
Rules: `service "foo" { policy = "write" }`,
|
|
|
|
RulesJSON: `{ "service": { "foo": { "policy": "write" }}}`,
|
|
|
|
Expected: &Policy{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
ServicePrefixes: []*ServiceRule{
|
2018-03-04 00:14:33 +00:00
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Policy: "write",
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2018-03-04 00:14:33 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Service Intentions (Legacy)",
|
|
|
|
Syntax: SyntaxLegacy,
|
|
|
|
Rules: `service "foo" { policy = "write" intentions = "read" }`,
|
|
|
|
RulesJSON: `{ "service": { "foo": { "policy": "write", "intentions": "read" }}}`,
|
|
|
|
Expected: &Policy{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
ServicePrefixes: []*ServiceRule{
|
2018-03-04 00:14:33 +00:00
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Policy: "write",
|
|
|
|
Intentions: "read",
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2018-03-04 00:14:33 +00:00
|
|
|
},
|
2018-10-19 16:04:07 +00:00
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Service Intention: invalid value (Legacy)",
|
|
|
|
Syntax: SyntaxLegacy,
|
|
|
|
Rules: `service "foo" { policy = "write" intentions = "foo" }`,
|
|
|
|
RulesJSON: `{ "service": { "foo": { "policy": "write", "intentions": "foo" }}}`,
|
|
|
|
Err: "Invalid service intentions policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Service No Intentions",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `service "foo" { policy = "write" }`,
|
|
|
|
RulesJSON: `{ "service": { "foo": { "policy": "write" }}}`,
|
|
|
|
Expected: &Policy{PolicyRules: PolicyRules{
|
|
|
|
Services: []*ServiceRule{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Policy: "write",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
2018-03-04 00:14:33 +00:00
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Service Intentions",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `service "foo" { policy = "write" intentions = "read" }`,
|
|
|
|
RulesJSON: `{ "service": { "foo": { "policy": "write", "intentions": "read" }}}`,
|
|
|
|
Expected: &Policy{PolicyRules: PolicyRules{
|
|
|
|
Services: []*ServiceRule{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Policy: "write",
|
|
|
|
Intentions: "read",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Service Intention: invalid value",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `service "foo" { policy = "write" intentions = "foo" }`,
|
|
|
|
RulesJSON: `{ "service": { "foo": { "policy": "write", "intentions": "foo" }}}`,
|
|
|
|
Err: "Invalid service intentions policy",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Bad Policy - ACL",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `acl = "list"`, // there is no list policy but this helps to exercise another check in isPolicyValid
|
|
|
|
RulesJSON: `{ "acl": "list" }`, // there is no list policy but this helps to exercise another check in isPolicyValid
|
|
|
|
Err: "Invalid acl policy",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Bad Policy - Agent",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `agent "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "agent": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid agent policy",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Bad Policy - Agent Prefix",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `agent_prefix "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "agent_prefix": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid agent_prefix policy",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Bad Policy - Key",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `key "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "key": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid key policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Key Prefix",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `key_prefix "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "key_prefix": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid key_prefix policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Node",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `node "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "node": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid node policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Node Prefix",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `node_prefix "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "node_prefix": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid node_prefix policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Service",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `service "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "service": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid service policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Service Prefix",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `service_prefix "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "service_prefix": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid service_prefix policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Session",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `session "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "session": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid session policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Session Prefix",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `session_prefix "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "session_prefix": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid session_prefix policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Event",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `event "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "event": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid event policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Event Prefix",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `event_prefix "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "event_prefix": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid event_prefix policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Prepared Query",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `query "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "query": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid query policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Prepared Query Prefix",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `query_prefix "foo" { policy = "nope" }`,
|
|
|
|
RulesJSON: `{ "query_prefix": { "foo": { "policy": "nope" }}}`,
|
|
|
|
Err: "Invalid query_prefix policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Keyring",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `keyring = "nope"`,
|
|
|
|
RulesJSON: `{ "keyring": "nope" }`,
|
|
|
|
Err: "Invalid keyring policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Operator",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `operator = "nope"`,
|
|
|
|
RulesJSON: `{ "operator": "nope" }`,
|
|
|
|
Err: "Invalid operator policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Bad Policy - Mesh",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `mesh = "nope"`,
|
|
|
|
RulesJSON: `{ "mesh": "nope" }`,
|
|
|
|
Err: "Invalid mesh policy",
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Keyring Empty",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `keyring = ""`,
|
|
|
|
RulesJSON: `{ "keyring": "" }`,
|
|
|
|
Expected: &Policy{PolicyRules: PolicyRules{Keyring: ""}},
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Operator Empty",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `operator = ""`,
|
|
|
|
RulesJSON: `{ "operator": "" }`,
|
|
|
|
Expected: &Policy{PolicyRules: PolicyRules{Operator: ""}},
|
2018-10-19 16:04:07 +00:00
|
|
|
},
|
|
|
|
{
|
2021-08-20 22:11:01 +00:00
|
|
|
Name: "Mesh Empty",
|
|
|
|
Syntax: SyntaxCurrent,
|
|
|
|
Rules: `mesh = ""`,
|
|
|
|
RulesJSON: `{ "mesh": "" }`,
|
|
|
|
Expected: &Policy{PolicyRules: PolicyRules{Mesh: ""}},
|
2018-03-04 00:14:33 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
2021-08-20 22:11:01 +00:00
|
|
|
require.True(t, tc.Rules != "" || tc.RulesJSON != "")
|
|
|
|
if tc.Rules != "" {
|
|
|
|
t.Run("hcl", func(t *testing.T) {
|
2021-10-15 17:33:31 +00:00
|
|
|
actual, err := NewPolicyFromSource(tc.Rules, tc.Syntax, nil, nil)
|
2021-08-20 22:11:01 +00:00
|
|
|
if tc.Err != "" {
|
|
|
|
errStartsWith(t, err, tc.Err)
|
|
|
|
} else {
|
|
|
|
require.Equal(t, tc.Expected, actual)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if tc.RulesJSON != "" {
|
|
|
|
t.Run("json", func(t *testing.T) {
|
2021-10-15 17:33:31 +00:00
|
|
|
actual, err := NewPolicyFromSource(tc.RulesJSON, tc.Syntax, nil, nil)
|
2021-08-20 22:11:01 +00:00
|
|
|
if tc.Err != "" {
|
|
|
|
errStartsWith(t, err, tc.Err)
|
|
|
|
} else {
|
|
|
|
require.Equal(t, tc.Expected, actual)
|
|
|
|
}
|
|
|
|
})
|
2018-03-04 00:14:33 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func TestMergePolicies(t *testing.T) {
|
|
|
|
type mergeTest struct {
|
|
|
|
name string
|
|
|
|
input []*Policy
|
|
|
|
expected *Policy
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []mergeTest{
|
|
|
|
{
|
|
|
|
name: "Agents",
|
|
|
|
input: []*Policy{
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
Agents: []*AgentRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "baz",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
AgentPrefixes: []*AgentRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "222",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
Agents: []*AgentRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
AgentPrefixes: []*AgentRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "000",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
|
|
|
expected: &Policy{PolicyRules: PolicyRules{
|
|
|
|
Agents: []*AgentRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
AgentPrefixes: []*AgentRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2015-06-18 01:56:29 +00:00
|
|
|
},
|
2018-10-19 16:04:07 +00:00
|
|
|
{
|
|
|
|
name: "Events",
|
|
|
|
input: []*Policy{
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
Events: []*EventRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "baz",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
EventPrefixes: []*EventRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "222",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
Events: []*EventRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
EventPrefixes: []*EventRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "000",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2016-12-02 04:31:50 +00:00
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
expected: &Policy{PolicyRules: PolicyRules{
|
|
|
|
Events: []*EventRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
EventPrefixes: []*EventRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Event: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2016-12-02 04:31:50 +00:00
|
|
|
},
|
2018-10-19 16:04:07 +00:00
|
|
|
{
|
|
|
|
name: "Node",
|
|
|
|
input: []*Policy{
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
Nodes: []*NodeRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "baz",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
NodePrefixes: []*NodeRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "222",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
Nodes: []*NodeRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
NodePrefixes: []*NodeRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "000",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
|
|
|
expected: &Policy{PolicyRules: PolicyRules{
|
|
|
|
Nodes: []*NodeRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
NodePrefixes: []*NodeRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2016-12-13 04:20:28 +00:00
|
|
|
},
|
2018-10-19 16:04:07 +00:00
|
|
|
{
|
|
|
|
name: "Keys",
|
|
|
|
input: []*Policy{
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
Keys: []*KeyRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "baz",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "zoo",
|
|
|
|
Policy: PolicyList,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
KeyPrefixes: []*KeyRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "222",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "333",
|
|
|
|
Policy: PolicyList,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
Keys: []*KeyRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "zoo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
KeyPrefixes: []*KeyRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "000",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "333",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2016-12-13 07:05:11 +00:00
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
expected: &Policy{PolicyRules: PolicyRules{
|
|
|
|
Keys: []*KeyRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "zoo",
|
|
|
|
Policy: PolicyList,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
KeyPrefixes: []*KeyRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "333",
|
|
|
|
Policy: PolicyList,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2016-12-13 07:05:11 +00:00
|
|
|
},
|
2018-10-19 16:04:07 +00:00
|
|
|
{
|
|
|
|
name: "Services",
|
|
|
|
input: []*Policy{
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
Services: []*ServiceRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
Intentions: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
Intentions: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "baz",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
Intentions: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
ServicePrefixes: []*ServiceRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
Intentions: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
Intentions: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "222",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
Intentions: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
Services: []*ServiceRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
Intentions: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
Intentions: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
ServicePrefixes: []*ServiceRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "000",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
Intentions: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
Intentions: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2016-12-02 04:31:50 +00:00
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
expected: &Policy{PolicyRules: PolicyRules{
|
|
|
|
Services: []*ServiceRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
Intentions: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
Intentions: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
Intentions: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
ServicePrefixes: []*ServiceRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
Intentions: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
Intentions: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Name: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
Intentions: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2016-12-02 04:31:50 +00:00
|
|
|
},
|
2018-10-19 16:04:07 +00:00
|
|
|
{
|
|
|
|
name: "Sessions",
|
|
|
|
input: []*Policy{
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
Sessions: []*SessionRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "baz",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
SessionPrefixes: []*SessionRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "222",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
Sessions: []*SessionRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
SessionPrefixes: []*SessionRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "000",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2014-08-18 21:54:52 +00:00
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
expected: &Policy{PolicyRules: PolicyRules{
|
|
|
|
Sessions: []*SessionRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
SessionPrefixes: []*SessionRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Node: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2014-08-18 21:54:52 +00:00
|
|
|
},
|
2018-10-19 16:04:07 +00:00
|
|
|
{
|
|
|
|
name: "Prepared Queries",
|
|
|
|
input: []*Policy{
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
PreparedQueries: []*PreparedQueryRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "baz",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
PreparedQueryPrefixes: []*PreparedQueryRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "222",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2019-10-15 20:58:50 +00:00
|
|
|
PreparedQueries: []*PreparedQueryRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
PreparedQueryPrefixes: []*PreparedQueryRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "000",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2016-12-07 04:05:15 +00:00
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
expected: &Policy{PolicyRules: PolicyRules{
|
|
|
|
PreparedQueries: []*PreparedQueryRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "foo",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "bar",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "baz",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
PreparedQueryPrefixes: []*PreparedQueryRule{
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "000",
|
|
|
|
Policy: PolicyWrite,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "111",
|
|
|
|
Policy: PolicyRead,
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
{
|
2018-10-19 16:04:07 +00:00
|
|
|
Prefix: "222",
|
|
|
|
Policy: PolicyDeny,
|
|
|
|
},
|
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2016-12-07 04:05:15 +00:00
|
|
|
},
|
2018-10-19 16:04:07 +00:00
|
|
|
{
|
|
|
|
name: "Write Precedence",
|
|
|
|
input: []*Policy{
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2018-10-19 16:04:07 +00:00
|
|
|
ACL: PolicyRead,
|
|
|
|
Keyring: PolicyRead,
|
|
|
|
Operator: PolicyRead,
|
2021-08-20 22:11:01 +00:00
|
|
|
Mesh: PolicyRead,
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2018-10-19 16:04:07 +00:00
|
|
|
ACL: PolicyWrite,
|
|
|
|
Keyring: PolicyWrite,
|
|
|
|
Operator: PolicyWrite,
|
2021-08-20 22:11:01 +00:00
|
|
|
Mesh: PolicyWrite,
|
2019-10-15 20:58:50 +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
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
expected: &Policy{PolicyRules: PolicyRules{
|
2018-10-19 16:04:07 +00:00
|
|
|
ACL: PolicyWrite,
|
|
|
|
Keyring: PolicyWrite,
|
|
|
|
Operator: PolicyWrite,
|
2021-08-20 22:11:01 +00:00
|
|
|
Mesh: PolicyWrite,
|
2019-10-15 20:58:50 +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
|
|
|
},
|
2018-10-19 16:04:07 +00:00
|
|
|
{
|
|
|
|
name: "Deny Precedence",
|
|
|
|
input: []*Policy{
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2018-10-19 16:04:07 +00:00
|
|
|
ACL: PolicyWrite,
|
|
|
|
Keyring: PolicyWrite,
|
|
|
|
Operator: PolicyWrite,
|
2021-08-20 22:11:01 +00:00
|
|
|
Mesh: PolicyWrite,
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2018-10-19 16:04:07 +00:00
|
|
|
ACL: PolicyDeny,
|
|
|
|
Keyring: PolicyDeny,
|
|
|
|
Operator: PolicyDeny,
|
2021-08-20 22:11:01 +00:00
|
|
|
Mesh: PolicyDeny,
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2016-12-02 04:31:50 +00:00
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
expected: &Policy{PolicyRules: PolicyRules{
|
2018-10-19 16:04:07 +00:00
|
|
|
ACL: PolicyDeny,
|
|
|
|
Keyring: PolicyDeny,
|
|
|
|
Operator: PolicyDeny,
|
2021-08-20 22:11:01 +00:00
|
|
|
Mesh: PolicyDeny,
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2016-12-02 04:31:50 +00:00
|
|
|
},
|
2018-10-19 16:04:07 +00:00
|
|
|
{
|
|
|
|
name: "Read Precedence",
|
|
|
|
input: []*Policy{
|
2020-06-16 17:19:31 +00:00
|
|
|
{PolicyRules: PolicyRules{
|
2018-10-19 16:04:07 +00:00
|
|
|
ACL: PolicyRead,
|
|
|
|
Keyring: PolicyRead,
|
|
|
|
Operator: PolicyRead,
|
2021-08-20 22:11:01 +00:00
|
|
|
Mesh: PolicyRead,
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2020-06-16 17:19:31 +00:00
|
|
|
{},
|
2016-12-13 04:20:28 +00:00
|
|
|
},
|
2019-10-15 20:58:50 +00:00
|
|
|
expected: &Policy{PolicyRules: PolicyRules{
|
2018-10-19 16:04:07 +00:00
|
|
|
ACL: PolicyRead,
|
|
|
|
Keyring: PolicyRead,
|
|
|
|
Operator: PolicyRead,
|
2021-08-20 22:11:01 +00:00
|
|
|
Mesh: PolicyRead,
|
2019-10-15 20:58:50 +00:00
|
|
|
}},
|
2016-12-13 04:20:28 +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
|
|
|
}
|
|
|
|
|
2022-01-20 16:45:56 +00:00
|
|
|
require := require.New(t)
|
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
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
for _, tcase := range tests {
|
|
|
|
t.Run(tcase.name, func(t *testing.T) {
|
|
|
|
act := MergePolicies(tcase.input)
|
|
|
|
exp := tcase.expected
|
2022-01-20 16:45:56 +00:00
|
|
|
require.Equal(exp.ACL, act.ACL)
|
|
|
|
require.Equal(exp.Keyring, act.Keyring)
|
|
|
|
require.Equal(exp.Operator, act.Operator)
|
|
|
|
require.Equal(exp.Mesh, act.Mesh)
|
|
|
|
require.ElementsMatch(exp.Agents, act.Agents)
|
|
|
|
require.ElementsMatch(exp.AgentPrefixes, act.AgentPrefixes)
|
|
|
|
require.ElementsMatch(exp.Events, act.Events)
|
|
|
|
require.ElementsMatch(exp.EventPrefixes, act.EventPrefixes)
|
|
|
|
require.ElementsMatch(exp.Keys, act.Keys)
|
|
|
|
require.ElementsMatch(exp.KeyPrefixes, act.KeyPrefixes)
|
|
|
|
require.ElementsMatch(exp.Nodes, act.Nodes)
|
|
|
|
require.ElementsMatch(exp.NodePrefixes, act.NodePrefixes)
|
|
|
|
require.ElementsMatch(exp.PreparedQueries, act.PreparedQueries)
|
|
|
|
require.ElementsMatch(exp.PreparedQueryPrefixes, act.PreparedQueryPrefixes)
|
|
|
|
require.ElementsMatch(exp.Services, act.Services)
|
|
|
|
require.ElementsMatch(exp.ServicePrefixes, act.ServicePrefixes)
|
|
|
|
require.ElementsMatch(exp.Sessions, act.Sessions)
|
|
|
|
require.ElementsMatch(exp.SessionPrefixes, act.SessionPrefixes)
|
2018-10-19 16:04:07 +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
|
|
|
}
|
2018-10-19 16:04:07 +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
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func TestRulesTranslate(t *testing.T) {
|
|
|
|
input := `
|
|
|
|
# top level comment
|
2014-08-18 21:54:52 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
# block comment
|
|
|
|
agent "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
|
|
|
}
|
2014-08-18 21:54:52 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
# block comment
|
|
|
|
key "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
2014-08-18 21:54:52 +00:00
|
|
|
}
|
2015-07-07 20:46:41 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
# block comment
|
|
|
|
node "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
|
|
|
}
|
2016-08-30 02:09:57 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
# block comment
|
|
|
|
event "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
|
|
|
}
|
2016-08-30 02:09:57 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
# block comment
|
|
|
|
service "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
|
|
|
|
# block comment
|
|
|
|
session "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
|
|
|
|
# block comment
|
|
|
|
query "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
|
|
|
|
# comment
|
|
|
|
keyring = "write"
|
|
|
|
|
|
|
|
# comment
|
|
|
|
operator = "write"
|
2021-08-20 22:11:01 +00:00
|
|
|
|
|
|
|
# comment
|
|
|
|
mesh = "write"
|
2018-10-19 16:04:07 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
expected := `
|
|
|
|
# top level comment
|
|
|
|
|
|
|
|
# block comment
|
|
|
|
agent_prefix "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
|
|
|
|
# block comment
|
|
|
|
key_prefix "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
|
|
|
|
# block comment
|
|
|
|
node_prefix "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
|
|
|
|
# block comment
|
|
|
|
event_prefix "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
|
|
|
|
# block comment
|
|
|
|
service_prefix "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
|
|
|
|
# block comment
|
|
|
|
session_prefix "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
|
|
|
|
# block comment
|
|
|
|
query_prefix "" {
|
|
|
|
# policy comment
|
|
|
|
policy = "write"
|
2016-08-30 02:09:57 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
# comment
|
|
|
|
keyring = "write"
|
|
|
|
|
|
|
|
# comment
|
|
|
|
operator = "write"
|
2021-08-20 22:11:01 +00:00
|
|
|
|
|
|
|
# comment
|
|
|
|
mesh = "write"
|
2018-10-19 16:04:07 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
output, err := TranslateLegacyRules([]byte(input))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, strings.Trim(expected, "\n"), string(output))
|
|
|
|
}
|
|
|
|
|
2019-04-15 18:34:36 +00:00
|
|
|
func TestRulesTranslate_GH5493(t *testing.T) {
|
|
|
|
input := `
|
|
|
|
{
|
|
|
|
"key": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
},
|
|
|
|
"key": {
|
|
|
|
"policy": "read"
|
|
|
|
},
|
|
|
|
"policy": {
|
|
|
|
"policy": "read"
|
|
|
|
},
|
|
|
|
"privatething1/": {
|
|
|
|
"policy": "deny"
|
|
|
|
},
|
|
|
|
"anapplication/private/": {
|
|
|
|
"policy": "deny"
|
|
|
|
},
|
|
|
|
"privatething2/": {
|
|
|
|
"policy": "deny"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"session": {
|
|
|
|
"": {
|
|
|
|
"policy": "write"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"node": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"agent": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"service": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"event": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"query": {
|
|
|
|
"": {
|
|
|
|
"policy": "read"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
expected := `
|
|
|
|
key_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
|
|
|
|
key_prefix "key" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
|
|
|
|
key_prefix "policy" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
|
|
|
|
key_prefix "privatething1/" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
|
|
|
|
key_prefix "anapplication/private/" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
|
|
|
|
key_prefix "privatething2/" {
|
|
|
|
policy = "deny"
|
|
|
|
}
|
|
|
|
|
|
|
|
session_prefix "" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
|
|
|
|
node_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
|
|
|
|
agent_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
|
|
|
|
service_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
|
|
|
|
event_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
|
|
|
|
query_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
output, err := TranslateLegacyRules([]byte(input))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, strings.Trim(expected, "\n"), string(output))
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
func TestPrecedence(t *testing.T) {
|
|
|
|
type testCase struct {
|
|
|
|
name string
|
|
|
|
a string
|
|
|
|
b string
|
|
|
|
expected bool
|
2015-07-07 20:46:41 +00:00
|
|
|
}
|
2018-10-19 16:04:07 +00:00
|
|
|
|
|
|
|
cases := []testCase{
|
|
|
|
{
|
|
|
|
name: "Deny Over Write",
|
|
|
|
a: PolicyDeny,
|
|
|
|
b: PolicyWrite,
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Deny Over List",
|
|
|
|
a: PolicyDeny,
|
|
|
|
b: PolicyList,
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Deny Over Read",
|
|
|
|
a: PolicyDeny,
|
|
|
|
b: PolicyRead,
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Deny Over Unknown",
|
|
|
|
a: PolicyDeny,
|
|
|
|
b: "not a policy",
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Write Over List",
|
|
|
|
a: PolicyWrite,
|
|
|
|
b: PolicyList,
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Write Over Read",
|
|
|
|
a: PolicyWrite,
|
|
|
|
b: PolicyRead,
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Write Over Unknown",
|
|
|
|
a: PolicyWrite,
|
|
|
|
b: "not a policy",
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "List Over Read",
|
|
|
|
a: PolicyList,
|
|
|
|
b: PolicyRead,
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "List Over Unknown",
|
|
|
|
a: PolicyList,
|
|
|
|
b: "not a policy",
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Read Over Unknown",
|
|
|
|
a: PolicyRead,
|
|
|
|
b: "not a policy",
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Write Over Deny",
|
|
|
|
a: PolicyWrite,
|
|
|
|
b: PolicyDeny,
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "List Over Deny",
|
|
|
|
a: PolicyList,
|
|
|
|
b: PolicyDeny,
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Read Over Deny",
|
|
|
|
a: PolicyRead,
|
|
|
|
b: PolicyDeny,
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Deny Over Unknown",
|
|
|
|
a: PolicyDeny,
|
|
|
|
b: "not a policy",
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "List Over Write",
|
|
|
|
a: PolicyList,
|
|
|
|
b: PolicyWrite,
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Read Over Write",
|
|
|
|
a: PolicyRead,
|
|
|
|
b: PolicyWrite,
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Unknown Over Write",
|
|
|
|
a: "not a policy",
|
|
|
|
b: PolicyWrite,
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Read Over List",
|
|
|
|
a: PolicyRead,
|
|
|
|
b: PolicyList,
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Unknown Over List",
|
|
|
|
a: "not a policy",
|
|
|
|
b: PolicyList,
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Unknown Over Read",
|
|
|
|
a: "not a policy",
|
|
|
|
b: PolicyRead,
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tcase := range cases {
|
|
|
|
t.Run(tcase.name, func(t *testing.T) {
|
|
|
|
require.Equal(t, tcase.expected, takesPrecedenceOver(tcase.a, tcase.b))
|
|
|
|
})
|
2015-07-07 20:46:41 +00:00
|
|
|
}
|
|
|
|
}
|