I am trying to decode a base64 encoded string that Vault gives me in a Nomad jobspec template. I have seen the base64Decode
function used in several different ways in different examples. What I have here seems to be the proper way to use it.
template {
change_mode = "noop"
env = true
destination = "${NOMAD_SECRETS_DIR}/gcp.env"
data = <<-EOT
{{- $gcp_credentials := secret "gcp/static-account/storage-role/key" -}}
GCP_JSON_DATA={{ $gcp_credentials.Data.private_key_data | base64Decode }}
EOT
}
However, when I run the job, Nomad complains with the following message:
Template failed: (dynamic): execute: template: :24:64:
executing "" at <base64Decode>: invalid value; expected string
If I try the function with this syntax:
GCS_SERVICE_ACCOUNT={{ base64Decode($gcp_credentials.Data.private_key_data) }}
It also does not like it:
Template failed: (dynamic): parse: template: :24:
unexpected "(" in operand
And this:
GCS_SERVICE_ACCOUNT={{ base64Decode $gcp_credentials.Data.private_key_data }}
Returns this:
Template failed: (dynamic): execute: template: :24:52:
executing "" at <$gcp_credentials.Data.private_key_data>: invalid value; expected string
And:
GCS_SERVICE_ACCOUNT={{ base64Decode "$gcp_credentials.Data.private_key_data" }}
Returns:
Template failed: (dynamic): execute: template: :24:23:
executing "" at <base64Decode "$gcp_credentials.Data.private_key_data">:
error calling base64Decode: base64Decode:
illegal base64 data at input byte 0
And:
GCS_SERVICE_ACCOUNT="{{ "$gcp_credentials.Data.private_key_data" | base64Decode }}"
Returns:
Template failed: (dynamic): execute: template: :24:67:
executing "" at <base64Decode>:
error calling base64Decode: base64Decode:
illegal base64 data at input byte 0
Obviously I am holding it wrong.
Can anyone tell me the correct way to use the base64Decode
function in the context of a Nomad jobspec template?