Update policy to template the Nomad node name in.

pull/21872/head
Tristan Morgan 2024-11-04 11:59:54 +11:00
parent e495978eeb
commit b00c1a8b59
No known key found for this signature in database
9 changed files with 20 additions and 16 deletions

View File

@ -1,7 +1,7 @@
agent_prefix "" { agent_prefix "" {
policy = "read" policy = "read"
} }
node_prefix "" { node "{{.Name}}" {
policy = "write" policy = "write"
} }
service_prefix "" { service_prefix "" {

View File

@ -5,7 +5,7 @@ mesh = "write"
agent_prefix "" { agent_prefix "" {
policy = "read" policy = "read"
} }
node_prefix "" { node "{{.Name}}" {
policy = "write" policy = "write"
} }
service_prefix "" { service_prefix "" {

View File

@ -71,11 +71,11 @@ func (f *prettyFormatter) FormatTemplatedPolicy(templatedPolicy api.ACLTemplated
switch templatedPolicy.TemplateName { switch templatedPolicy.TemplateName {
case api.ACLTemplatedPolicyServiceName: case api.ACLTemplatedPolicyServiceName:
nameRequiredVariableOutput(&buffer, templatedPolicy.TemplateName, "The name of the service", "api") nameRequiredVariableOutput(&buffer, templatedPolicy.TemplateName, "The name of the service", "api")
case api.ACLTemplatedPolicyNodeName: case api.ACLTemplatedPolicyNodeName, api.ACLTemplatedPolicyNomadServerName, api.ACLTemplatedPolicyNomadClientName:
nameRequiredVariableOutput(&buffer, templatedPolicy.TemplateName, "The node name", "node-1") nameRequiredVariableOutput(&buffer, templatedPolicy.TemplateName, "The node name", "node-1")
case api.ACLTemplatedPolicyAPIGatewayName: case api.ACLTemplatedPolicyAPIGatewayName:
nameRequiredVariableOutput(&buffer, templatedPolicy.TemplateName, "The api gateway service name", "api-gateway") nameRequiredVariableOutput(&buffer, templatedPolicy.TemplateName, "The api gateway service name", "api-gateway")
case api.ACLTemplatedPolicyDNSName, api.ACLTemplatedPolicyNomadServerName, api.ACLTemplatedPolicyNomadClientName: case api.ACLTemplatedPolicyDNSName:
noRequiredVariablesOutput(&buffer, templatedPolicy.TemplateName) noRequiredVariablesOutput(&buffer, templatedPolicy.TemplateName)
default: default:
buffer.WriteString(" None\n") buffer.WriteString(" None\n")

View File

@ -1,6 +1,6 @@
{ {
"TemplateName": "builtin/nomad-client", "TemplateName": "builtin/nomad-client",
"Schema": "", "Schema": "",
"Template": "agent_prefix \"\" {\n policy = \"read\"\n}\nnode_prefix \"\" {\n policy = \"write\"\n}\nservice_prefix \"\" {\n policy = \"write\"\n}\nkey_prefix \"\" {\n policy = \"read\"\n}", "Template": "agent_prefix \"\" {\n policy = \"read\"\n}\nnode \"{{.Name}}\" {\n policy = \"write\"\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." "Description": "Gives the token or role permissions required for integration with a nomad client."
} }

View File

@ -1,13 +1,14 @@
Name: builtin/nomad-client Name: builtin/nomad-client
Description: Gives the token or role permissions required for integration with a nomad client. Description: Gives the token or role permissions required for integration with a nomad client.
Input variables: None Input variables:
Name: String - Required - The node name.
Example usage: Example usage:
consul acl token create -templated-policy builtin/nomad-client consul acl token create -templated-policy builtin/nomad-client -var name:node-1
Raw Template: Raw Template:
agent_prefix "" { agent_prefix "" {
policy = "read" policy = "read"
} }
node_prefix "" { node "{{.Name}}" {
policy = "write" policy = "write"
} }
service_prefix "" { service_prefix "" {

View File

@ -1,5 +1,6 @@
Name: builtin/nomad-client Name: builtin/nomad-client
Description: Gives the token or role permissions required for integration with a nomad client. Description: Gives the token or role permissions required for integration with a nomad client.
Input variables: None Input variables:
Name: String - Required - The node name.
Example usage: Example usage:
consul acl token create -templated-policy builtin/nomad-client consul acl token create -templated-policy builtin/nomad-client -var name:node-1

View File

@ -1,6 +1,6 @@
{ {
"TemplateName": "builtin/nomad-server", "TemplateName": "builtin/nomad-server",
"Schema": "", "Schema": "",
"Template": "\nacl = \"write\"\nmesh = \"write\"\n\nagent_prefix \"\" {\n policy = \"read\"\n}\nnode_prefix \"\" {\n policy = \"write\"\n}\nservice_prefix \"\" {\n policy = \"write\"\n}", "Template": "\nacl = \"write\"\nmesh = \"write\"\n\nagent_prefix \"\" {\n policy = \"read\"\n}\nnode \"{{.Name}}\" {\n policy = \"write\"\n}\nservice_prefix \"\" {\n policy = \"write\"\n}",
"Description": "Gives the token or role permissions required for integration with a nomad server." "Description": "Gives the token or role permissions required for integration with a nomad server."
} }

View File

@ -1,8 +1,9 @@
Name: builtin/nomad-server Name: builtin/nomad-server
Description: Gives the token or role permissions required for integration with a nomad server. Description: Gives the token or role permissions required for integration with a nomad server.
Input variables: None Input variables:
Name: String - Required - The node name.
Example usage: Example usage:
consul acl token create -templated-policy builtin/nomad-server consul acl token create -templated-policy builtin/nomad-server -var name:node-1
Raw Template: Raw Template:
acl = "write" acl = "write"
@ -11,7 +12,7 @@ mesh = "write"
agent_prefix "" { agent_prefix "" {
policy = "read" policy = "read"
} }
node_prefix "" { node "{{.Name}}" {
policy = "write" policy = "write"
} }
service_prefix "" { service_prefix "" {

View File

@ -1,5 +1,6 @@
Name: builtin/nomad-server Name: builtin/nomad-server
Description: Gives the token or role permissions required for integration with a nomad server. Description: Gives the token or role permissions required for integration with a nomad server.
Input variables: None Input variables:
Name: String - Required - The node name.
Example usage: Example usage:
consul acl token create -templated-policy builtin/nomad-server consul acl token create -templated-policy builtin/nomad-server -var name:node-1