Skip to content

Commit

Permalink
[NET-6251] Nomad client templated policy (#19827)
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodingenthusiast authored Dec 6, 2023
1 parent 334de14 commit dc02fa6
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/19827.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:feature
acl: Adds nomad client templated policy
```
2 changes: 1 addition & 1 deletion agent/acl_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ func TestACL_HTTP(t *testing.T) {

var list map[string]api.ACLTemplatedPolicyResponse
require.NoError(t, json.NewDecoder(resp.Body).Decode(&list))
require.Len(t, list, 6)
require.Len(t, list, 7)

require.Equal(t, api.ACLTemplatedPolicyResponse{
TemplateName: api.ACLTemplatedPolicyServiceName,
Expand Down
9 changes: 9 additions & 0 deletions agent/structs/acl_templated_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ const (
ACLTemplatedPolicyNomadServerID = "00000000-0000-0000-0000-000000000006"
ACLTemplatedPolicyWorkloadIdentityID = "00000000-0000-0000-0000-000000000007"
ACLTemplatedPolicyAPIGatewayID = "00000000-0000-0000-0000-000000000008"
ACLTemplatedPolicyNomadClientID = "00000000-0000-0000-0000-000000000009"

ACLTemplatedPolicyServiceDescription = "Gives the token or role permissions to register a service and discover services in the Consul catalog. It also gives the specified service's sidecar proxy the permission to discover and route traffic to other services."
ACLTemplatedPolicyNodeDescription = "Gives the token or role permissions for a register an agent/node into the catalog. A node is typically a consul agent but can also be a physical server, cloud instance or a container."
ACLTemplatedPolicyDNSDescription = "Gives the token or role permissions for the Consul DNS to query services in the network."
ACLTemplatedPolicyNomadServerDescription = "Gives the token or role permissions required for integration with a nomad server."
ACLTemplatedPolicyWorkloadIdentityDescription = "Gives the token or role permissions for a specific workload identity."
ACLTemplatedPolicyAPIGatewayDescription = "Gives the token or role permissions for a Consul api gateway"
ACLTemplatedPolicyNomadClientDescription = "Gives the token or role permissions required for integration with a nomad client."

ACLTemplatedPolicyNoRequiredVariablesSchema = "" // catch-all schema for all templated policy that don't require a schema
)
Expand Down Expand Up @@ -108,6 +110,13 @@ var (
Template: ACLTemplatedPolicyAPIGateway,
Description: ACLTemplatedPolicyAPIGatewayDescription,
},
api.ACLTemplatedPolicyNomadClientName: {
TemplateID: ACLTemplatedPolicyNomadClientID,
TemplateName: api.ACLTemplatedPolicyNomadClientName,
Schema: ACLTemplatedPolicyNoRequiredVariablesSchema,
Template: ACLTemplatedPolicyNomadClient,
Description: ACLTemplatedPolicyNomadClientDescription,
},
}
)

Expand Down
3 changes: 3 additions & 0 deletions agent/structs/acl_templated_policy_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ var ACLTemplatedPolicyWorkloadIdentity string
//go:embed acltemplatedpolicy/policies/ce/api-gateway.hcl
var ACLTemplatedPolicyAPIGateway string

//go:embed acltemplatedpolicy/policies/ce/nomad-client.hcl
var ACLTemplatedPolicyNomadClient string

func (t *ACLToken) TemplatedPolicyList() []*ACLTemplatedPolicy {
if len(t.TemplatedPolicies) == 0 {
return nil
Expand Down
12 changes: 12 additions & 0 deletions agent/structs/acltemplatedpolicy/policies/ce/nomad-client.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
agent_prefix "" {
policy = "read"
}
node_prefix "" {
policy = "read"
}
service_prefix "" {
policy = "write"
}
key_prefix "" {
policy = "read"
}
1 change: 1 addition & 0 deletions api/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
ACLTemplatedPolicyNomadServerName = "builtin/nomad-server"
ACLTemplatedPolicyWorkloadIdentityName = "builtin/workload-identity"
ACLTemplatedPolicyAPIGatewayName = "builtin/api-gateway"
ACLTemplatedPolicyNomadClientName = "builtin/nomad-client"
)

type ACLLink struct {
Expand Down
2 changes: 1 addition & 1 deletion command/acl/templatedpolicy/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (f *prettyFormatter) FormatTemplatedPolicy(templatedPolicy api.ACLTemplated
nameRequiredVariableOutput(&buffer, templatedPolicy.TemplateName, "The workload name", "api")
case api.ACLTemplatedPolicyAPIGatewayName:
nameRequiredVariableOutput(&buffer, templatedPolicy.TemplateName, "The api gateway service name", "api-gateway")
case api.ACLTemplatedPolicyDNSName, api.ACLTemplatedPolicyNomadServerName:
case api.ACLTemplatedPolicyDNSName, api.ACLTemplatedPolicyNomadServerName, api.ACLTemplatedPolicyNomadClientName:
noRequiredVariablesOutput(&buffer, templatedPolicy.TemplateName)
default:
buffer.WriteString(" None\n")
Expand Down
8 changes: 8 additions & 0 deletions command/acl/templatedpolicy/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ func testFormatTemplatedPolicy(t *testing.T, dirPath string) {
Description: structs.ACLTemplatedPolicyNomadServerDescription,
},
},
"nomad-client-templated-policy": {
templatedPolicy: api.ACLTemplatedPolicyResponse{
TemplateName: api.ACLTemplatedPolicyNomadClientName,
Schema: structs.ACLTemplatedPolicyNoRequiredVariablesSchema,
Template: structs.ACLTemplatedPolicyNomadClient,
Description: structs.ACLTemplatedPolicyNomadClientDescription,
},
},
}

formatters := map[string]Formatter{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"TemplateName": "builtin/nomad-client",
"Schema": "",
"Template": "agent_prefix \"\" {\n policy = \"read\"\n}\nnode_prefix \"\" {\n policy = \"read\"\n}\nservice_prefix \"\" {\n policy = \"write\"\n}\nkey_prefix \"\" {\n policy = \"read\"\n}",
"Description": "Gives the token or role permissions required for integration with a nomad client."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Name: builtin/nomad-client
Description: Gives the token or role permissions required for integration with a nomad client.
Input variables: None
Example usage:
consul acl token create -templated-policy builtin/nomad-client
Raw Template:
agent_prefix "" {
policy = "read"
}
node_prefix "" {
policy = "read"
}
service_prefix "" {
policy = "write"
}
key_prefix "" {
policy = "read"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Name: builtin/nomad-client
Description: Gives the token or role permissions required for integration with a nomad client.
Input variables: None
Example usage:
consul acl token create -templated-policy builtin/nomad-client

0 comments on commit dc02fa6

Please sign in to comment.