|
|
|
@ -69,6 +69,30 @@ func RunWorkloadSelectingTypeACLsTests[T WorkloadSelecting](t *testing.T, typ *p
|
|
|
|
|
WriteOK: resourcetest.ALLOW,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
"service test write with multiple named selectors": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service "workload1" { policy = "read" } service "workload2" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{Names: []string{"workload1", "workload2"}}),
|
|
|
|
|
Typ: typ,
|
|
|
|
|
ReadOK: resourcetest.ALLOW,
|
|
|
|
|
WriteOK: resourcetest.ALLOW,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
"service test write with multiple named selectors and insufficient policy": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service "workload1" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{Names: []string{"workload1", "workload2"}}),
|
|
|
|
|
Typ: typ,
|
|
|
|
|
ReadOK: resourcetest.ALLOW,
|
|
|
|
|
WriteOK: resourcetest.DENY,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
"service test write with multiple named selectors and prefixed policy": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service_prefix "workload" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{Names: []string{"workload1", "workload2"}}),
|
|
|
|
|
Typ: typ,
|
|
|
|
|
ReadOK: resourcetest.ALLOW,
|
|
|
|
|
WriteOK: resourcetest.ALLOW,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
"service test write with prefixed selectors": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service_prefix "workload-" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{Prefixes: []string{"workload-"}}),
|
|
|
|
@ -77,7 +101,7 @@ func RunWorkloadSelectingTypeACLsTests[T WorkloadSelecting](t *testing.T, typ *p
|
|
|
|
|
WriteOK: resourcetest.ALLOW,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
"service test write with prefixed selectors and a policy with more specific than the selector": {
|
|
|
|
|
"service test write with prefixed selectors and a policy with more specific prefix than the selector": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service_prefix "workload-" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{Prefixes: []string{"wor"}}),
|
|
|
|
|
Typ: typ,
|
|
|
|
@ -85,7 +109,8 @@ func RunWorkloadSelectingTypeACLsTests[T WorkloadSelecting](t *testing.T, typ *p
|
|
|
|
|
WriteOK: resourcetest.DENY,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
"service test write with prefixed selectors and a policy with less specific than the selector": {
|
|
|
|
|
|
|
|
|
|
"service test write with prefixed selectors and a policy with less specific prefix than the selector": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service_prefix "wor" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{Prefixes: []string{"workload-"}}),
|
|
|
|
|
Typ: typ,
|
|
|
|
@ -93,13 +118,73 @@ func RunWorkloadSelectingTypeACLsTests[T WorkloadSelecting](t *testing.T, typ *p
|
|
|
|
|
WriteOK: resourcetest.ALLOW,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
// Prefix-based selectors should not allow writes when a policy only allows
|
|
|
|
|
// to read a specific service from that selector.
|
|
|
|
|
"service test write with prefixed selectors and a policy with a specific service": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service "workload" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{Prefixes: []string{"workload"}}),
|
|
|
|
|
Typ: typ,
|
|
|
|
|
ReadOK: resourcetest.ALLOW,
|
|
|
|
|
// TODO (ishustava): this is wrong and should be fixed in a follow up PR. We should not allow
|
|
|
|
|
// a policy for a specific service when only prefixes are specified in the selector.
|
|
|
|
|
Rules: `service "test" { policy = "write" } service "workload" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{Prefixes: []string{"workload"}}),
|
|
|
|
|
Typ: typ,
|
|
|
|
|
ReadOK: resourcetest.ALLOW,
|
|
|
|
|
WriteOK: resourcetest.DENY,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
"service test write with multiple prefixed selectors": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service_prefix "workload" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{Prefixes: []string{"workload-1", "workload-2"}}),
|
|
|
|
|
Typ: typ,
|
|
|
|
|
ReadOK: resourcetest.ALLOW,
|
|
|
|
|
WriteOK: resourcetest.ALLOW,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
"service test write with multiple prefixed selectors and insufficient policy": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service_prefix "workload-1" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{Prefixes: []string{"workload-1", "workload-2"}}),
|
|
|
|
|
Typ: typ,
|
|
|
|
|
ReadOK: resourcetest.ALLOW,
|
|
|
|
|
WriteOK: resourcetest.DENY,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
"service test write with a mix of named and prefixed selectors and insufficient policy": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service_prefix "workload" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{
|
|
|
|
|
Prefixes: []string{"workload-1", "workload-2"},
|
|
|
|
|
Names: []string{"other-1", "other-2"},
|
|
|
|
|
}),
|
|
|
|
|
Typ: typ,
|
|
|
|
|
ReadOK: resourcetest.ALLOW,
|
|
|
|
|
WriteOK: resourcetest.DENY,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
"service test write with a mix of named and prefixed selectors and prefixed policy": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service_prefix "workload" { policy = "read" } service_prefix "other" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{
|
|
|
|
|
Prefixes: []string{"workload-1", "workload-2"},
|
|
|
|
|
Names: []string{"other-1", "other-2"},
|
|
|
|
|
}),
|
|
|
|
|
Typ: typ,
|
|
|
|
|
ReadOK: resourcetest.ALLOW,
|
|
|
|
|
WriteOK: resourcetest.ALLOW,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
"service test write with a mix of named and prefixed selectors and both prefixed and specific policy": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service_prefix "workload" { policy = "read" } service "other-1" { policy = "read" } service "other-2" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{
|
|
|
|
|
Prefixes: []string{"workload-1", "workload-2"},
|
|
|
|
|
Names: []string{"other-1", "other-2"},
|
|
|
|
|
}),
|
|
|
|
|
Typ: typ,
|
|
|
|
|
ReadOK: resourcetest.ALLOW,
|
|
|
|
|
WriteOK: resourcetest.ALLOW,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|
"service test write with a mix of named and prefixed selectors and wildcard service read policy": {
|
|
|
|
|
Rules: `service "test" { policy = "write" } service_prefix "" { policy = "read" }`,
|
|
|
|
|
Data: getData(&pbcatalog.WorkloadSelector{
|
|
|
|
|
Prefixes: []string{"workload-1", "workload-2"},
|
|
|
|
|
Names: []string{"other-1", "other-2"},
|
|
|
|
|
}),
|
|
|
|
|
Typ: typ,
|
|
|
|
|
ReadOK: resourcetest.ALLOW,
|
|
|
|
|
WriteOK: resourcetest.ALLOW,
|
|
|
|
|
ListOK: resourcetest.DEFAULT,
|
|
|
|
|
},
|
|
|
|
|