I am working on setting up a Nomad Job that will be able to run a service which needs to access a database.
I have a Vault cluster already setup and active. I have built a Nomad cluster with Terraform. The Nomad cluster is also integrated with a Consul cluster.
I was able to spin up a database cluster using a Terraform provider. I was also able to connect that database cluster to the Vault cluster with the vault_database_secret_backend_* Terraform resources.
Now I just need to figure out what to put in my Nomad Job specification file that will allow the Nomad/Job/Task to access the database.
I could certainly manually write a secret to Vault, at some arbitrary location:
However, it seems like the Nomad Job should be able to lease some credentials automatically from Vault that would allow it to connect to that database so that I would not need to add credentials to the Nomad Job specification.
However, it seems like the Nomad Job should be able to lease some credentials automatically from Vault that would allow it to connect to that database so that I would not need to add credentials to the Nomad Job specification.
Yes! This is one of the key reasons to make use of Vault with Nomad. If you haven’t already, check out the Nomad+Vault tutorial [1] , which has you setup Nomad with Vault to generate dynamic secrets for Postgres using Vault’s database secrets engine.
@seth.hoenig, I think I have looked at that document. I have looked at so many, they are all blurring together in my mind.
Looking at it again though is helpful. I am seeing some parts of it that I probably missed the first time.
One thing that would make the article even more helpful is if it also included doing the whole project with Terraform. That seems to be where I am getting hung up. The Terraform resources take care of many aspects under the hood, or are defined in slightly different ways. So I am trying to understand the process from that perspective.
Oh, I read about that change. I did not try it because I did not think that the vault_database_secret_backend_[connection|role] were using kv v2. I tried that change just now at your suggestion. I was hopeful, but the result did not change.
The fact that Nomad is receiving an error about permission makes me wonder what credentials Nomad is using to make the request to Vault in order for it to be denied. When I make the request on the command line, I am using an administrative token that has all access. Perhaps the policy that I specify in the template is not granting enough permission.
Ah hah! It turned out to be something even simpler. I did lookup the policies on the server token. The token did not have that policy listed, but that did not seem to be a problem. The problem turned out to be that the Nomad job was specifying a policy name that was different than the actual policy.
Such a small thing. That is why they call them bugs.