I am trying to understand in the Pull model of AppRole based authentication, which actor is best placed to generate a wrapped secret-id.
My use case is I am using AWS, Packer, Ansible, Terraform and Vault. I wish to create an AMI of a simple server which when spun up will fetch a secret from vault in order to run some software. The server will be part of an autoscaling group so everything needs automating. The required secret is already in vault.
As I understand it, in order for the server EC2 instance when booted up to be able to pull secrets out of vault it needs access to a role-id and a secret-id, so that it can perform the vault approle login function. Best practice suggests including both, using the pull model and using Response wrapping.
So as a human operator, I first of all generate a role-id:
vault write auth/approle/role/myappserver bind_secret_id=true \
secret_id_ttl=10m \
secret_id_num_uses=99999 \
token_ttl=10m \
tokenmax_ttl=10m \
policies=myappserver
I can then read the role-id with:
role_id_myappserver=$( vault read -format=json auth/approle/role/myappserver/role-id | jq -r '.data | .role_id' )
Now I write the role-id into configuration management (e.g. ansible), and packer build an AMI with the role-id baked in. When an EC2 instance based on this AMI spins up as part of the auto-scaling-group, it will know one side of the tuple. Great!
Now I need to generate a secret-id - the other side of the tuple. However reading the documentation, they advise using pull model, with response wrapping, so as not to expose the secret-id anywhere. So here is an example command that needs to be run by something:
vault write -wrap-ttl=60s -f auth/approle/role/myappserver/secret-id
However, my question is, who should do this, and how should the wrapped secret-id be distributed? I can eliminate some possibilities from the list:
User-data is the obvious choice, so I assumed (being a user of Terraform) that terraform would be able to supply user-data containing a wrapped secret-id generated by terraform. - but terraform has no integration with vault's approle function, because approle is a POST operation and terraform only supports write with PUT/DELETE operations > https://www.terraform.io/docs/providers/vault/r/generic_secret.html
However, and here is the crux of the matter!!!-- even supposing there WAS a terraform way of injecting the wrapped secret-id into the ec2 instance, the ec2 instance when spun up could not itself unwrap the response-wrapped secret-id in order to login to vault, because:
ec2-instance:
$ vault unwrap 3b7a4930-4ce5-c8ba-7522-228e0ac4ebc2
Error making API request.
...
* permission denied
In other words, the instance needs to be authenticated in order to unwrap the secret-id.
Could anyone pour some light on how this should work? Who should be creating the secret-id (the operator? an automated script at terraform time? an automated script at ec2 spinup time? a separate daemon?) and how to distribute it to the newly spun-up instance so that it is able to log in (according to best practice).
Any help gratefully received!