Skip to content

pkiCert does not properly save certificates across multiple templates #24803

@remilapeyre

Description

@remilapeyre

Nomad version

v1.9.3

Issue

The information at

#### As individual files
For templates, all dependencies are mapped into a single list. This means that
multiple templates watching the same path return the same data.
```hcl
template {
data = <<EOH
{{ with pkiCert "pki/issue/foo" "common_name=foo.service.consul" "ip_sans=127.0.0.1" }}
{{- .Cert -}}
{{ end }}
EOH
destination = "${NOMAD_SECRETS_DIR}/certificate.crt"
change_mode = "restart"
}
template {
data = <<EOH
{{ with pkiCert "pki/issue/foo" "common_name=foo.service.consul" "ip_sans=127.0.0.1" }}
{{- .CA -}}
{{ end }}
EOH
destination = "${NOMAD_SECRETS_DIR}/ca.crt"
change_mode = "restart"
}
template {
data = <<EOH
{{ with pkiCert "pki/issue/foo" "common_name=foo.service.consul" "ip_sans=127.0.0.1" }}
{{- .Key -}}
{{ end }}
EOH
destination = "${NOMAD_SECRETS_DIR}/private_key.key"
change_mode = "restart"
}
```
These are three different input templates, but when run under the Nomad job,
they are compressed into a single call, sharing the resulting data.
is wrong, pkiCert does not save the certificates and all three templates make a call to Vault, which means that the certificate and the private key will not match.

This part of the documentation as been changed in 1eb1dbf#diff-2e97a76f1d2de1fec74a5033b6be6625127e85de0c991ce328535bd384659807L654. Previously the example used the secret function which does save its result across invocations so the text was correct.

The change to this part of the documentation should be rollbacked for now and caching support could be added to pkiCert in a second time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Needs Roadmapping

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions