diff --git a/control-plane/subcommand/server-acl-init/rules.go b/control-plane/subcommand/server-acl-init/rules.go index 1d205c950d..ee6ae41e40 100644 --- a/control-plane/subcommand/server-acl-init/rules.go +++ b/control-plane/subcommand/server-acl-init/rules.go @@ -183,10 +183,12 @@ func (c *Command) meshGatewayRules() (string, error) { meshGatewayRulesTpl := `mesh = "write" {{- if .EnablePeering }} peering = "read" +{{- if eq .PartitionName "default" }} partition_prefix "" { peering = "read" } {{- end }} +{{- end }} {{- if .EnableNamespaces }} namespace "default" { {{- end }} diff --git a/control-plane/subcommand/server-acl-init/rules_test.go b/control-plane/subcommand/server-acl-init/rules_test.go index 2218202c16..22e63ed0ce 100644 --- a/control-plane/subcommand/server-acl-init/rules_test.go +++ b/control-plane/subcommand/server-acl-init/rules_test.go @@ -196,6 +196,7 @@ func TestMeshGatewayRules(t *testing.T) { Name string EnableNamespaces bool EnablePeering bool + PartitionName string Expected string }{ { @@ -230,13 +231,45 @@ namespace_prefix "" { }`, }, { - Name: "Peering is enabled", + Name: "Peering is enabled with unspecified partition name (oss case)", EnablePeering: true, Expected: `mesh = "write" +peering = "read" + service "mesh-gateway" { + policy = "write" + } + node_prefix "" { + policy = "read" + } + service_prefix "" { + policy = "read" + }`, + }, + { + Name: "Peering is enabled with partition explicitly specified as default (ent default case)", + EnablePeering: true, + PartitionName: "default", + Expected: `mesh = "write" peering = "read" partition_prefix "" { peering = "read" } + service "mesh-gateway" { + policy = "write" + } + node_prefix "" { + policy = "read" + } + service_prefix "" { + policy = "read" + }`, + }, + { + Name: "Peering is enabled with partition explicitly specified as non-default (ent non-default case)", + EnablePeering: true, + PartitionName: "non-default", + Expected: `mesh = "write" +peering = "read" service "mesh-gateway" { policy = "write" } @@ -253,9 +286,6 @@ partition_prefix "" { EnableNamespaces: true, Expected: `mesh = "write" peering = "read" -partition_prefix "" { - peering = "read" -} namespace "default" { service "mesh-gateway" { policy = "write" @@ -277,7 +307,9 @@ namespace_prefix "" { cmd := Command{ flagEnableNamespaces: tt.EnableNamespaces, flagEnablePeering: tt.EnablePeering, - consulFlags: &flags.ConsulFlags{}, + consulFlags: &flags.ConsulFlags{ + Partition: tt.PartitionName, + }, } meshGatewayRules, err := cmd.meshGatewayRules()