diff --git a/.changelog/2029.txt b/.changelog/2029.txt new file mode 100644 index 0000000000..c864419eba --- /dev/null +++ b/.changelog/2029.txt @@ -0,0 +1,3 @@ +```release-note:bug +api-gateway: fix ACL issue where when adminPartitions and ACLs are enabled, API Gateway Controller is unable to create a new namespace in Consul +``` \ No newline at end of file diff --git a/control-plane/subcommand/server-acl-init/rules.go b/control-plane/subcommand/server-acl-init/rules.go index ee6ae41e40..02831dc4de 100644 --- a/control-plane/subcommand/server-acl-init/rules.go +++ b/control-plane/subcommand/server-acl-init/rules.go @@ -151,8 +151,10 @@ partition "{{ .PartitionName }}" { operator = "write" acl = "write" {{- end }} + {{- if .EnableNamespaces }} namespace_prefix "" { + policy = "write" {{- end }} service_prefix "" { policy = "write" @@ -167,7 +169,7 @@ namespace_prefix "" { {{- if .EnablePartitions }} } {{- end }} - ` +` return c.renderRules(apiGatewayRulesTpl) } diff --git a/control-plane/subcommand/server-acl-init/rules_test.go b/control-plane/subcommand/server-acl-init/rules_test.go index 22e63ed0ce..622ed341a8 100644 --- a/control-plane/subcommand/server-acl-init/rules_test.go +++ b/control-plane/subcommand/server-acl-init/rules_test.go @@ -143,6 +143,7 @@ func TestAPIGatewayControllerRules(t *testing.T) { cases := []struct { Name string EnableNamespaces bool + Partition string Expected string }{ { @@ -165,6 +166,7 @@ acl = "write" operator = "write" acl = "write" namespace_prefix "" { + policy = "write" service_prefix "" { policy = "write" intentions = "write" @@ -172,6 +174,26 @@ namespace_prefix "" { node_prefix "" { policy = "read" } +}`, + }, + { + Name: "Namespaces are enabled, partitions enabled", + EnableNamespaces: true, + Partition: "Default", + Expected: ` +partition "Default" { + mesh = "write" + acl = "write" +namespace_prefix "" { + policy = "write" + service_prefix "" { + policy = "write" + intentions = "write" + } + node_prefix "" { + policy = "read" + } +} }`, }, } @@ -180,7 +202,9 @@ namespace_prefix "" { t.Run(tt.Name, func(t *testing.T) { cmd := Command{ flagEnableNamespaces: tt.EnableNamespaces, - consulFlags: &flags.ConsulFlags{}, + consulFlags: &flags.ConsulFlags{ + Partition: tt.Partition, + }, } meshGatewayRules, err := cmd.apiGatewayControllerRules()