mirror of https://github.com/hashicorp/consul
Move ACL templated policies to hcl files (#18853)
parent
087539fc7b
commit
49cb84297f
|
@ -27,6 +27,9 @@ project {
|
||||||
"agent/grpc-middleware/rate_limit_mappings.gen.go",
|
"agent/grpc-middleware/rate_limit_mappings.gen.go",
|
||||||
"agent/uiserver/dist/**",
|
"agent/uiserver/dist/**",
|
||||||
|
|
||||||
|
# ignoring policy embedded files
|
||||||
|
"agent/structs/acltemplatedpolicy/policies/ce/**",
|
||||||
|
|
||||||
# licensed under MPL - ignoring for now until the copywrite tool can support
|
# licensed under MPL - ignoring for now until the copywrite tool can support
|
||||||
# multiple licenses per repo.
|
# multiple licenses per repo.
|
||||||
"sdk/**",
|
"sdk/**",
|
||||||
|
|
|
@ -1401,7 +1401,7 @@ func TestACL_HTTP(t *testing.T) {
|
||||||
|
|
||||||
var templatedPolicy api.ACLTemplatedPolicyResponse
|
var templatedPolicy api.ACLTemplatedPolicyResponse
|
||||||
require.NoError(t, json.NewDecoder(resp.Body).Decode(&templatedPolicy))
|
require.NoError(t, json.NewDecoder(resp.Body).Decode(&templatedPolicy))
|
||||||
require.Equal(t, structs.ACLTemplatedPolicyDNSSchema, templatedPolicy.Schema)
|
require.Equal(t, structs.ACLTemplatedPolicyNoRequiredVariablesSchema, templatedPolicy.Schema)
|
||||||
require.Equal(t, api.ACLTemplatedPolicyDNSName, templatedPolicy.TemplateName)
|
require.Equal(t, api.ACLTemplatedPolicyDNSName, templatedPolicy.TemplateName)
|
||||||
require.Equal(t, structs.ACLTemplatedPolicyDNS, templatedPolicy.Template)
|
require.Equal(t, structs.ACLTemplatedPolicyDNS, templatedPolicy.Template)
|
||||||
})
|
})
|
||||||
|
|
|
@ -31,7 +31,8 @@ const (
|
||||||
ACLTemplatedPolicyServiceID = "00000000-0000-0000-0000-000000000003"
|
ACLTemplatedPolicyServiceID = "00000000-0000-0000-0000-000000000003"
|
||||||
ACLTemplatedPolicyNodeID = "00000000-0000-0000-0000-000000000004"
|
ACLTemplatedPolicyNodeID = "00000000-0000-0000-0000-000000000004"
|
||||||
ACLTemplatedPolicyDNSID = "00000000-0000-0000-0000-000000000005"
|
ACLTemplatedPolicyDNSID = "00000000-0000-0000-0000-000000000005"
|
||||||
ACLTemplatedPolicyDNSSchema = "" // empty schema as it does not require variables
|
|
||||||
|
ACLTemplatedPolicyNoRequiredVariablesSchema = "" // catch-all schema for all templated policy that don't require a schema
|
||||||
)
|
)
|
||||||
|
|
||||||
// ACLTemplatedPolicyBase contains basic information about builtin templated policies
|
// ACLTemplatedPolicyBase contains basic information about builtin templated policies
|
||||||
|
@ -63,7 +64,7 @@ var (
|
||||||
api.ACLTemplatedPolicyDNSName: {
|
api.ACLTemplatedPolicyDNSName: {
|
||||||
TemplateID: ACLTemplatedPolicyDNSID,
|
TemplateID: ACLTemplatedPolicyDNSID,
|
||||||
TemplateName: api.ACLTemplatedPolicyDNSName,
|
TemplateName: api.ACLTemplatedPolicyDNSName,
|
||||||
Schema: ACLTemplatedPolicyDNSSchema,
|
Schema: ACLTemplatedPolicyNoRequiredVariablesSchema,
|
||||||
Template: ACLTemplatedPolicyDNS,
|
Template: ACLTemplatedPolicyDNS,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,40 +5,16 @@
|
||||||
|
|
||||||
package structs
|
package structs
|
||||||
|
|
||||||
const (
|
import _ "embed"
|
||||||
ACLTemplatedPolicyService = `
|
|
||||||
service "{{.Name}}" {
|
|
||||||
policy = "write"
|
|
||||||
}
|
|
||||||
service "{{.Name}}-sidecar-proxy" {
|
|
||||||
policy = "write"
|
|
||||||
}
|
|
||||||
service_prefix "" {
|
|
||||||
policy = "read"
|
|
||||||
}
|
|
||||||
node_prefix "" {
|
|
||||||
policy = "read"
|
|
||||||
}`
|
|
||||||
|
|
||||||
ACLTemplatedPolicyNode = `
|
//go:embed acltemplatedpolicy/policies/ce/service.hcl
|
||||||
node "{{.Name}}" {
|
var ACLTemplatedPolicyService string
|
||||||
policy = "write"
|
|
||||||
}
|
|
||||||
service_prefix "" {
|
|
||||||
policy = "read"
|
|
||||||
}`
|
|
||||||
|
|
||||||
ACLTemplatedPolicyDNS = `
|
//go:embed acltemplatedpolicy/policies/ce/node.hcl
|
||||||
node_prefix "" {
|
var ACLTemplatedPolicyNode string
|
||||||
policy = "read"
|
|
||||||
}
|
//go:embed acltemplatedpolicy/policies/ce/dns.hcl
|
||||||
service_prefix "" {
|
var ACLTemplatedPolicyDNS string
|
||||||
policy = "read"
|
|
||||||
}
|
|
||||||
query_prefix "" {
|
|
||||||
policy = "read"
|
|
||||||
}`
|
|
||||||
)
|
|
||||||
|
|
||||||
func (t *ACLToken) TemplatedPolicyList() []*ACLTemplatedPolicy {
|
func (t *ACLToken) TemplatedPolicyList() []*ACLTemplatedPolicy {
|
||||||
if len(t.TemplatedPolicies) == 0 {
|
if len(t.TemplatedPolicies) == 0 {
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
node_prefix "" {
|
||||||
|
policy = "read"
|
||||||
|
}
|
||||||
|
service_prefix "" {
|
||||||
|
policy = "read"
|
||||||
|
}
|
||||||
|
query_prefix "" {
|
||||||
|
policy = "read"
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
node "{{.Name}}" {
|
||||||
|
policy = "write"
|
||||||
|
}
|
||||||
|
service_prefix "" {
|
||||||
|
policy = "read"
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
service "{{.Name}}" {
|
||||||
|
policy = "write"
|
||||||
|
}
|
||||||
|
service "{{.Name}}-sidecar-proxy" {
|
||||||
|
policy = "write"
|
||||||
|
}
|
||||||
|
service_prefix "" {
|
||||||
|
policy = "read"
|
||||||
|
}
|
||||||
|
node_prefix "" {
|
||||||
|
policy = "read"
|
||||||
|
}
|
|
@ -42,7 +42,7 @@ func testFormatTemplatedPolicy(t *testing.T, dirPath string) {
|
||||||
"dns-templated-policy": {
|
"dns-templated-policy": {
|
||||||
templatedPolicy: api.ACLTemplatedPolicyResponse{
|
templatedPolicy: api.ACLTemplatedPolicyResponse{
|
||||||
TemplateName: api.ACLTemplatedPolicyDNSName,
|
TemplateName: api.ACLTemplatedPolicyDNSName,
|
||||||
Schema: structs.ACLTemplatedPolicyDNSSchema,
|
Schema: structs.ACLTemplatedPolicyNoRequiredVariablesSchema,
|
||||||
Template: structs.ACLTemplatedPolicyDNS,
|
Template: structs.ACLTemplatedPolicyDNS,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -94,7 +94,7 @@ func testFormatTemplatedPolicyList(t *testing.T, dirPath string) {
|
||||||
},
|
},
|
||||||
"builtin/dns": {
|
"builtin/dns": {
|
||||||
TemplateName: api.ACLTemplatedPolicyDNSName,
|
TemplateName: api.ACLTemplatedPolicyDNSName,
|
||||||
Schema: structs.ACLTemplatedPolicyDNSSchema,
|
Schema: structs.ACLTemplatedPolicyNoRequiredVariablesSchema,
|
||||||
Template: structs.ACLTemplatedPolicyDNS,
|
Template: structs.ACLTemplatedPolicyDNS,
|
||||||
},
|
},
|
||||||
"builtin/service": {
|
"builtin/service": {
|
||||||
|
|
|
@ -98,5 +98,5 @@ func TestTemplatedPolicyListCommand_JSON(t *testing.T) {
|
||||||
err := json.Unmarshal([]byte(output), &jsonOutput)
|
err := json.Unmarshal([]byte(output), &jsonOutput)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
outputTemplate := jsonOutput[api.ACLTemplatedPolicyDNSName]
|
outputTemplate := jsonOutput[api.ACLTemplatedPolicyDNSName]
|
||||||
assert.Equal(t, structs.ACLTemplatedPolicyDNSSchema, outputTemplate.Schema)
|
assert.Equal(t, structs.ACLTemplatedPolicyNoRequiredVariablesSchema, outputTemplate.Schema)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue