@dmitryroshchin @amosc so here is what I have found. I think this was mentioned in the other thread but think maybe context was missing.
Boundary supports templating IN Boundary. Vault is not aware of Boundary’s templating patterns (hence the error when trying to pass something like {{ .User.Name }}
to Vault.
The templating support in Vault is specific to constructs that Vault is aware of (such as the Vault role name).
Part of the Boundary doc that you referenced that may not have been clear was this section:
“For example, this can allow picking the correct role when asking for database credentials (if roles are separated per-user)”
I read this line as “if VAULT roles are separated per-user”, but a coworker took it as Boundary roles.
The setup to get what you are looking for today - to have the Boundary username as part of the target DB dynamic credentials would be to have the Boundary credential library set up with the username template:
boundary credential-libraries create vault-generic \
-credential-store-id $CRED_STORE_ID \
-vault-path "database/creds/{{ .User.Name }}" \
-name "northwind dba"
You would then need a corresponding Vault role for each Boundary login:
vault list database/roles
Keys
----
bill
jonf
thea
With the credential library configured with the username template, the command would be the same:
boundary targets authorize-session -id $DBA_TARGET_ID
But the call to Vault, Boundary would replace the username template with the authenticated Boundary user (looks like this):
GET https://vault-cluster:8200/v1/database/creds/jonf
Boundary substituted the username as part of Boundaries support for templates, and is making an API call to Vault with the substitution in place. The Vault API would need to support receiving additional data/metadata. Currently that API (Database - Secrets Engines - HTTP API | Vault | HashiCorp Developer) does not support POST.
The Vault role then produces the username, which is based on the Vault role for jonf.
Credentials:
Credential Store ID: csvlt_uvSWjCiR4E
Credential Source ID: clvlt_ZhhZREKiCb
Credential Source Type: vault-generic
Credential Source Name: northwind dba
Secret:
{
"password": "1XaeNPuy-1qKn51nyqld",
"username": "v-token-**jonf**-WAdhXxNh1RzIGGmoOnLQ-1700663217"
}
There are some other internal discussions going on around how to provide an auditable experience for this as well since correlating the logs of Vault, Boundary, and the RDBMS would likely not be possible today.
If you have an account manager, I would suggest asking them to submit a feature request or making a feature request in - probably the Vault GitHub repository since Vault needs to be able to accept some sort of additional data/metadata about the Boundary user but may require additional work from both Vault and Boundary.