Hiera Secrets: eyaml, Sensitive Values, Vault and Safe Credential Handling

Puppet Training Course 22 min min read Updated: Nov 17, 2026 Advanced
Hiera Secrets: eyaml, Sensitive Values, Vault and Safe Credential Handling
Advanced Topic 3 of 3

The Problem

Manifests and Hiera data go into Git. If a database password is written there in plain text, everyone with repository access can read it, and it stays in the Git history for ever. Secrets can also leak through logs, reports, PuppetDB and the catalog. Puppet gives you several tools to reduce this.

Where Secrets Can Leak

PlaceRiskProtection
Git repositoryAnyone who clones sees plain textEncrypt values with eyaml, or store only references
Catalog on the serverContains resource valuesUse Sensitive so values are hidden in logs and reports
Agent reports and logsDiffs of changed files show contentSensitive and show_diff => false
PuppetDBStores catalogs and reportsSensitive data is redacted in reports, check your version and settings
Files on the nodeReadable by other usersStrict mode and owner
Command lines (exec)Visible in psPass secrets by files or environment, not arguments

hiera-eyaml: Encrypted Values in YAML

hiera-eyaml lets you encrypt individual values in a YAML file. The file stays readable and diff-friendly. Only the server's private key can decrypt.

bash # On the Puppet server sudo /opt/puppetlabs/puppet/bin/gem install hiera-eyaml sudo /opt/puppetlabs/puppetserver/bin/puppetserver gem install hiera-eyaml # Create keys (once) sudo mkdir -p /etc/puppetlabs/puppet/eyaml cd /etc/puppetlabs/puppet/eyaml sudo /opt/puppetlabs/puppet/bin/eyaml createkeys sudo chown -R puppet:puppet /etc/puppetlabs/puppet/eyaml sudo chmod 0500 /etc/puppetlabs/puppet/eyaml sudo chmod 0400 /etc/puppetlabs/puppet/eyaml/*.pem # keys: keys/private_key.pkcs7.pem and keys/public_key.pkcs7.pem
bash # On the admin laptop: only the PUBLIC key is needed to encrypt eyaml encrypt -l 'profile::postgresql::admin_password' -s 'S3cr3t!Pass' \ --pkcs7-public-key=./public_key.pkcs7.pem # prints: # profile::postgresql::admin_password: ENC[PKCS7,MIIBiQYJKoZIhvcNAQcDoIIBejCC...] eyaml edit data/secrets.eyaml # open the file, decrypt in an editor, re-encrypt on save (needs the private key) eyaml decrypt -f data/secrets.eyaml
yaml # data/secrets.eyaml --- profile::postgresql::admin_password: > ENC[PKCS7,MIIBiQYJKoZIhvcNAQcDoIIBejCCAXYCAQAxggEhMIIBHQIBADAFMAACAQEw DQYJKoZIhvcNAQEBBQAEggEAhQ2...] profile::app::api_token: ENC[PKCS7,MIIBeQYJKoZIhvc...]

Configure hiera.yaml

yaml --- version: 5 defaults: datadir: data hierarchy: - name: 'Secrets (encrypted)' lookup_key: eyaml_lookup_key paths: - 'secrets/nodes/%{trusted.certname}.eyaml' - 'secrets/common.eyaml' options: pkcs7_private_key: /etc/puppetlabs/puppet/eyaml/keys/private_key.pkcs7.pem pkcs7_public_key: /etc/puppetlabs/puppet/eyaml/keys/public_key.pkcs7.pem - name: 'Normal data' data_hash: yaml_data path: 'common.yaml'
Use it with a typed parameter: Declare Sensitive[String] $admin_password in the class. When Hiera returns a string, Puppet wraps it, so it is redacted in logs.

The Sensitive Type

puppet class profile::app ( Sensitive[String] $db_password, # eyaml or Hiera data is wrapped automatically ) { file { '/etc/app/db.conf': ensure => file, owner => 'app', mode => '0600', content => epp('profile/db.conf.epp', { 'password' => $db_password }), # pass Sensitive into EPP show_diff => false, } }
text <%# templates/db.conf.epp %> <%- | Sensitive[String] $password | -%> password=<%= $password.unwrap %>

Sensitive values print as [redacted] in notices, reports and diffs. Call unwrap only where you must write the real value. A template that outputs a Sensitive value makes the resulting file content sensitive too.

Fetch Secrets on the Agent: Deferred Functions

With eyaml, the secret is decrypted on the server and placed in the catalog. A Deferred function is different: the catalog contains only the *call*, and the agent runs it at apply time, for example to read from a vault. The secret does not sit in the catalog or PuppetDB.

puppet $password = Deferred('vault_lookup::lookup', ['secret/data/myapp/db', 'https://vault.example.com:8200']) file { '/etc/app/db.conf': ensure => file, mode => '0600', content => Deferred('inline_epp', ["password=<%= \$pw.unwrap %>\n", { 'pw' => $password }]), }
Requirements: Deferred functions run on the agent, so the agent needs network access and credentials for the secret store. Check the module documentation (for example puppetlabs-vault_lookup) for your Puppet version.

HashiCorp Vault Example

puppet class profile::app_secrets { $db_pass = Deferred('vault_lookup::lookup', [ 'secret/data/myapp/db', { 'vault_url' => 'https://vault.example.com:8200', 'auth_method' => 'cert', # certificate based, using the agent's Puppet certificate 'field' => 'password', }, ]) file { '/etc/myapp/db.env': ensure => file, owner => 'myapp', mode => '0600', content => Deferred('inline_epp', ["DB_PASSWORD=<%= \$p.unwrap %>\n", { 'p' => $db_pass }]), } }

Vault, cloud secret managers (AWS Secrets Manager, Azure Key Vault) and tools such as 1Password or CyberArk each have Puppet modules or custom Hiera backends. The pattern is the same: store secrets centrally, fetch them at the last moment, limit who can read them.

Other Safe Habits

  • Never commit private keys, private_key.pkcs7.pem, or Vault tokens to Git
  • Restrict the Puppet server, because it can decrypt everything (use full disk encryption and limited admin access)
  • Set mode '0600' and the correct owner for every secret file
  • Use show_diff => false where Sensitive cannot be used
  • Do not print secrets with notice() or exec command arguments
  • Rotate secrets: change the encrypted value, commit, deploy, and Puppet updates nodes on the next run
  • Use different keys or data per environment so staging cannot decrypt production secrets

Checking for Leaks

bash # Search the repo for obvious secrets before committing git grep -nEi 'password *[:=] *[^E ]' -- data/ manifests/ site-modules/ # Check reports and the catalog puppet catalog compile web01.example.com --render-as json | grep -i password

Practice Tasks

  1. Create an eyaml key pair on a lab server and encrypt a password
  2. Configure hiera.yaml with eyaml_lookup_key and read the value in a class with a Sensitive[String] parameter
  3. Write the secret into a file with mode 0600 and check that Puppet output hides it
  4. Try eyaml decrypt with and without the private key
  5. Describe how you would rotate the database password across 50 servers

Conclusion

Never put plain secrets in Git. Encrypt values with hiera-eyaml, type them as Sensitive, protect the files that hold them, and move to agent-side Deferred fetching from a vault when you need a stronger model.

Quick Summary: eyaml encrypt public key / decrypt on server; Sensitive redacts; Deferred = fetch on agent; vault; mode 0600; rotate.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators