-
Notifications
You must be signed in to change notification settings - Fork 329
Conversation
Working as expected, I used the consul {
address = "127.0.0.1:8500"
allow_unauthenticated = false
token = "my-token"
}
vault {
enabled = true
address = "http://127.0.0.1:8200"
allow_unauthenticated = false
token = "my-token"
} ConsulBelow shows before/after running deploy with
VaultBelow shows before/after running deploy with
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, a fairly straightforward change! 🎉
I'm curious, how can we let users of the Nomad plugin know how to use this in both a local and remote runner context? 🤔 I imagine we should document that Waypoint will respect these env vars, but it might not be obvious that they'd need to configure runners with the env var for remote runs.
} | ||
|
||
func VaultAuth() (string, error) { | ||
return os.Getenv("VAULT_TOKEN"), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to confirm this works with remote runners if you haven't already given that a shot with this PR. I think you'd have to do a waypoint config set -runner CONSUL_HTTP_TOKEN=abcd VAULT_TOKEN=1234
and then try an Up operation with ODR/Remote runners and see that the deployment succeeded with these values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@briancain Looking good! I first unset the tokens to verify that it would fail without them w/remote-operations:
% waypoint config set -scope=global -runner VAULT_TOKEN=
% waypoint config set -scope=global -runner CONSUL_HTTP_TOKEN=
% waypoint deploy -p=example-nodejs -local=false -release=false
» Deploying example-nodejs...
Performing this operation on a remote runner with id "JOB_ID"
» Cloning data from Git
URL: https://github.com/hashicorp/waypoint-examples
Ref: feat/nomad-consul-vault-integration
✓ Running deploy v14
✓ Deleting job:
! 2 errors occurred:
* Unexpected response code: 500 (Vault policies requested but missing Vault
Token)
* Error during rollback: Unexpected response code: 500 (missing job ID for
deregistering)
After setting them again, the job deployed:
% waypoint config set -scope=global -runner CONSUL_HTTP_TOKEN=my-token
% waypoint config set -scope=global -runner VAULT_TOKEN=my-token
% waypoint deploy -p=example-nodejs -local=false -release=false
» Deploying example-nodejs...
Performing this operation on a remote runner with id "JOB_ID"
» Cloning data from Git
URL: https://github.com/hashicorp/waypoint-examples
Ref: feat/nomad-consul-vault-integration
✓ Job registration successful
✓ Allocation "ALLOC_ID" created: node "NODE_ID", group "app"
✓ Evaluation status changed: "pending" -> "complete"
✓ Evaluation "EVAL_ID" finished with status "complete"
✓ Deployment successfully rolled out!
✓ Running deploy v15
Performing this operation on a remote runner with id "JOB_ID"
» Cloning data from Git
URL: https://github.com/hashicorp/waypoint-examples
Ref: feat/nomad-consul-vault-integration
✓ Finished building report for Nomad platform
✓ Getting job info...
✓ Job "web" is reporting ready!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! 🎉 Looks great
Actually, in the topic of where to document this, I think each plugin has a top level Doc that can be defined. It might also have an Env var field? waypoint/builtin/nomad/jobspec/platform.go Line 513 in 4e84fdf
|
@@ -211,6 +211,18 @@ func (p *Platform) resourceJobCreate( | |||
job.TaskGroups[0].Tasks[0].Config = config | |||
job.TaskGroups[0].Tasks[0].Env = env | |||
|
|||
// Get Consul ACL token from environment | |||
*job.ConsulToken, err = ConsulAuth() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Soooo I spent a while trying to wrap my head around this, for other reviewers: this is assigned to pointer job because ConsulToken is a pointer string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me @paladin-devops ! You might need to generate the website docs, but otherwise looking gooood 👍🏻
} | ||
|
||
func VaultAuth() (string, error) { | ||
return os.Getenv("VAULT_TOKEN"), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! 🎉 Looks great
"vault_token", | ||
"The Vault token used to deploy the Nomad job with a token having specific Vault policies attached.", | ||
docs.Summary("Uses the runner config environment variable VAULT_TOKEN."), | ||
docs.EnvVar("VAULT_TOKEN"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Awesome, thank you. These env var fields are exactly what I was thinking. Looks gooood 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might need to run a `make gen/website-mdx. I think this will generate the website docs based on these fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@briancain done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Add support for authenticating to Consul & Vault when registering Nomad job for both Nomad deployers. Consul token should be supplied via the
CONSUL_HTTP_TOKEN
env var, and Vault token via theVAULT_TOKEN
env var of the runner.Relevant Nomad API code:
https://github.com/hashicorp/nomad/blob/8f7abae89fb6aef25161a90457e42a1a3cc07fa5/api/jobs.go#L843-L844
Addresses #3206