Create Nomad ACL policies
In this tutorial, you will create Nomad ACL policies to provide controlled
access for two different personas to your Nomad Cluster. You will use the sample
job created with the nomad init -short
command as a sample job.
To complete this tutorial, you will need the following:
A Nomad cluster with the ACL system bootstrapped.
A management token. You can use the bootstrap token, however, for production systems you should use an user-specific token.
Meet the personas
In this tutorial, you will create policies to manage cluster access for two different user personas. These are contrived to suit the scenario, and you should design your ACL policies around your organization's specific needs.
As a best practice, access should be limited as much as possible given the needs of the user's roles.
Challenge
Consider extending this scenario to include namespaces.
Application Developer
The application developer needs to be able to deploy an application into the Nomad cluster and control its lifecycle. They should not be able to perform any other node operations.
Application developers are allowed to fetch logs from their running containers, but should not be allowed to run commands inside of them or access the filesystem for running workloads.
Production Operations
The production operations team needs to be able to perform cluster maintenance and view the workload, including attached resources like volumes, in the running cluster. However, because the application developers are the owners of the running workload, the production operators should not be allowed to run or stop jobs in the cluster.
Write the policy rules
Application Developer policy
Considering the requirements listed above, what rules should you add to your
policy? Nomad will deny all requests that are not explicitly permitted, so focus
on the policies and capabilities you would like to permit. However, be mindful
of the coarse-grained permissions in namespace
rules--they might grant more
permissions than you need for your use case.
The application developer needs to be able to deploy an application into the Nomad cluster and control its lifecycle. They should not be able to perform any other node operations.
Application developers are allowed to fetch logs from their running containers, but should not be allowed to run commands inside of them or access the filesystem for running workloads.
Recall that namespace
rules govern the job application deployment behaviors
and introspection capabilities for a Nomad cluster.
First define the policy in terms of required capabilities. What capabilities from the available options will this policy need to provide to Application Developers?
Capability | Desired |
---|---|
deny - When multiple policies are associated with a token, deny will take precedence and prevent any capabilities. | N/A |
list-jobs - Allows listing the jobs and seeing coarse grain status. | ✅ |
read-job - Allows inspecting a job and seeing fine grain status. | ✅ |
submit-job - Allows jobs to be submitted or modified. | ✅ |
dispatch-job - Allows jobs to be dispatched | ✅ |
read-logs - Allows the logs associated with a job to be viewed. | ✅ |
read-fs - Allows the filesystem of allocations associated to be viewed. | 🚫 |
alloc-exec - Allows an operator to connect and run commands in running allocations. | 🚫 |
alloc-node-exec - Allows an operator to connect and run commands in allocations running without filesystem isolation, for example, raw_exec jobs. | 🚫 |
alloc-lifecycle - Allows an operator to stop individual allocations manually. | 🚫 |
csi-register-plugin - Allows jobs to be submitted that register themselves as CSI plugins. | 🚫 |
csi-write-volume - Allows CSI volumes to be registered or deregistered. | 🚫 |
csi-read-volume - Allows inspecting a CSI volume and seeing fine grain status. | 🚫 |
csi-list-volume - Allows listing CSI volumes and seeing coarse grain status. | 🚫 |
csi-mount-volume - Allows jobs to be submitted that claim a CSI volume. | 🚫 |
list-scaling-policies - Allows listing scaling policies. | 🚫 |
read-scaling-policy - Allows inspecting a scaling policy. | 🚫 |
read-job-scaling - Allows inspecting the current scaling of a job. | 🚫 |
scale-job - Allows scaling a job up or down. | 🚫 |
sentinel-override - Allows soft mandatory policies to be overridden. | 🚫 |
Remember that the coarse-grained policy
value of a namespace rule is a list of
capabilities.
policy value | capabilities |
---|---|
deny | deny |
read | list-jobs read-job csi-list-volume csi-read-volume list-scaling-policies read-scaling-policy read-job-scaling |
write | list-jobs read-job submit-job dispatch-job read-logs read-fs alloc-exec alloc-lifecycle csi-write-volume csi-mount-volume list-scaling-policies read-scaling-policy read-job-scaling scale-job |
scale | list-scaling-policies read-scaling-policy read-job-scaling scale-job |
list | (grants listing plugin metadata only) |
Express this in policy form. Create an file named app-dev.policy.hcl
to write
your policy.
Note that the namespace rule has policy = "read"
. The write policy is not
suitable because it is overly permissive, granting "read-fs", "alloc-exec", and
"alloc-lifecycle".
Production Operations policy
Consider the requirements listed above, what rules should you add to your policy? Nomad will deny all requests that are not explicitly supplied, so focus on the policies you would like to permit.
The production operations team needs to be able to perform cluster maintenance and view the workload, including attached resources like volumes, in the running cluster. However, because the application developers are the owners of the running workload, the production operators should not be allowed to run or stop jobs in the cluster.
Recall that namespace
rules govern the job application deployment behaviors
and introspection capabilities for a Nomad cluster.
First define the policy in terms of required capabilities. What capabilities from the available options will this policy need to provide to Production Operators?
Capability | Desired |
---|---|
deny - When multiple policies are associated with a token, deny will take precedence and prevent any capabilities. | N/A |
list-jobs - Allows listing the jobs and seeing coarse grain status. | ✅ |
read-job - Allows inspecting a job and seeing fine grain status. | ✅ |
submit-job - Allows jobs to be submitted or modified. | 🚫 |
dispatch-job - Allows jobs to be dispatched | 🚫 |
read-logs - Allows the logs associated with a job to be viewed. | 🚫 |
read-fs - Allows the filesystem of allocations associated to be viewed. | 🚫 |
alloc-exec - Allows an operator to connect and run commands in running allocations. | 🚫 |
alloc-node-exec - Allows an operator to connect and run commands in allocations running without filesystem isolation, for example, raw_exec jobs. | 🚫 |
alloc-lifecycle - Allows an operator to stop individual allocations manually. | 🚫 |
csi-register-plugin - Allows jobs to be submitted that register themselves as CSI plugins. | 🚫 |
csi-write-volume - Allows CSI volumes to be registered or deregistered. | 🚫 |
csi-read-volume - Allows inspecting a CSI volume and seeing fine grain status. | ✅ |
csi-list-volume - Allows listing CSI volumes and seeing coarse grain status. | ✅ |
csi-mount-volume - Allows jobs to be submitted that claim a CSI volume. | 🚫 |
list-scaling-policies - Allows listing scaling policies. | 🚫 |
read-scaling-policy - Allows inspecting a scaling policy. | 🚫 |
read-job-scaling - Allows inspecting the current scaling of a job. | 🚫 |
scale-job - Allows scaling a job up or down. | 🚫 |
sentinel-override - Allows soft mandatory policies to be overridden. | 🚫 |
Again, the coarse-grained policy
value of a namespace rule is a list of
capabilities.
policy value | capabilities |
---|---|
deny | deny |
read | list-jobs read-job csi-list-volume csi-read-volume list-scaling-policies read-scaling-policy read-job-scaling |
write | list-jobs read-job submit-job dispatch-job read-logs read-fs alloc-exec alloc-lifecycle csi-write-volume csi-mount-volume list-scaling-policies read-scaling-policy read-job-scaling scale-job |
scale | list-scaling-policies read-scaling-policy read-job-scaling scale-job |
list | (grants listing plugin metadata only) |
Express this in policy form. Create an file named prod-ops.policy.hcl
to write
your policy. The capabilities required over the Namespace API is captured with
the read
policy value.
Operators will also need to have access to several other API endpoints: node, agent, operator. Consult the individual API documentation for more details on the endpoints.
Add all of these policy elements to your prod-ops.policy.hcl
file and save it.
Upload the policies
Use the nomad acl policy apply
command to upload your policy specifications.
Don't forget to provide a management token via the NOMAD_TOKEN environment
variable or the -token
flag. As practice, this time use the -token
flag.
Upload the "Application Developer policy."
Upload the "Production Operations policy."
Verify the policy
In order to verify the policy works properly, you will need to create tokens and check the success case and the failure cases.
Create an app-dev token. For this tutorial, pipe your output into the tee command
to save it as app-dev.token
.
Next, create a prod-ops token, piping your output into the tee command to save
it as prod-ops.token
.
Submit a job using each token
First, set the active token to your test app-dev token. You can extract it from the files that you created above.
Create the sample job with nomad init
.
Submit the sample job to your Nomad cluster.
Verify that the job starts completely using the nomad job status
command.
Switch to the prod-ops token.
Try to stop the job; note that you are unable to do so.
Switch back to the app-dev token.
Try again to stop the job; note that this time you are successful.
Stimulate GC on your cluster
With the app-dev token still active, export your cluster address into a variable for convenience.
Try to use the Nodes API to list out the Nomad clients in the cluster.
Set the active token to your test prod-ops token.
Resubmit your Nodes API query. Expect to have a significant amount of JSON returned to your screen which indicates successful API call.
Challenge: Restrict anonymous users
The bootstrapping tutorial provides a very permissive anonymous user policy to minimize user and workload impacts from Nomad's default deny-all policy. This allows cluster users and other submitting agents to continue to work while tokens are being created and deployed.
As a challenge to yourself, consider the minimum viable set of permissions for anonymous users in your organization. Craft a policy that prevents user access to capabilities that are not in your user's critical path.
Clean up
If you would like to remove the objects that you created in this tutorial, switch back to your management token and revoke the tokens that you created above using the accessors in the files.
If you receive a "Permission denied" error when you are running the delete commands, ensure that you have loaded your management token back into the NOMAD_TOKEN environment variable.
Next, remove the prod-ops and app-dev policies that you created.
Next steps
Now that you have deployed your own policy into the cluster, you will learn about Nomad access tokens. Nomad users will need to provide tokens for non-anonymous requests. These tokens map to one or more ACL policies which define the accessible Nomad objects for that request.