From 92309c1a6cd049e27b220b059ccbf7d9b634f808 Mon Sep 17 00:00:00 2001 From: Konrad Bucheli Date: Tue, 15 Jul 2025 13:45:34 +0200 Subject: [PATCH] improve documentation adding encrypted files to hiera --- .../configuration/basic/users_and_groups.md | 2 +- .../configuration/files/distribute_files.md | 18 ++++- .../monitoring/central_logging_elastic.md | 2 +- admin-guide/puppet/hiera.md | 67 ++++--------------- 4 files changed, 29 insertions(+), 60 deletions(-) diff --git a/admin-guide/configuration/basic/users_and_groups.md b/admin-guide/configuration/basic/users_and_groups.md index 5c9d061a..563e7ff3 100644 --- a/admin-guide/configuration/basic/users_and_groups.md +++ b/admin-guide/configuration/basic/users_and_groups.md @@ -41,7 +41,7 @@ local_accounts::user_defs: 'managehome': true 'comment': 'TWLHA Operator' ``` -The password is the password has as in `/etc/shadow`. It can be generated with `openssl passwd -6`. Ideally the password hash is stored encrypted with [`eyaml`](../../puppet/hiera) in Hiera. +The password is the password has as in `/etc/shadow`. It can be generated with `openssl passwd -6`. Ideally the password hash is stored encrypted with [`eyaml`](../../puppet/eyaml) in Hiera. To have the user actually configured on a given node, it needs to be added to the `local_accounts::users` Hiera key: diff --git a/admin-guide/configuration/files/distribute_files.md b/admin-guide/configuration/files/distribute_files.md index 74b481e1..f7e84aa3 100644 --- a/admin-guide/configuration/files/distribute_files.md +++ b/admin-guide/configuration/files/distribute_files.md @@ -49,7 +49,8 @@ files::symlinks::force: true ``` but this is then applies for all symlink definitions. -## Create Text Files with Specific Content + +## Create Files with Specific Content Textfiles with specific content can be created as follows: @@ -71,7 +72,18 @@ files::files: /test/zero: base64_content: AAAAAAAAAAAAAA== ``` -If the binary file has been encrypted with eyaml, then this detour is not needed, you can set the encrypted String directly with the `content` key. +If the binary file has been encrypted with [eyaml](../../puppet/eyaml), then this detour is not needed, you can set the encrypted String directly with the `content` key. +It might then look like this: + +``` +files::files: + /var/lib/gssproxy/clients/8547.keytab: + mode: '0400' + content: > + ENC[PKCS7,MIIBuQYJKoZIhvcNAQcDoIIBqjCCAaYCAQAxggEhMIIBHQIBAD + ... + 2KJw==] +``` It is also possible to provide files directly from your Hiera data repository if you configure the path of the desired file within that repo with the `hiera_file` key: @@ -248,7 +260,7 @@ base::enable_filecopy: false ## Encrypt Part of File Content/Download URL in Hiera -If you want to provide a secret like a password or a token inside the file content or as part of an URL, store the [eyaml encrypted encrypt secret](../../puppet/hiera) in an else unused Hiera key and include it into the actual place using string interpolation and the `lookup` function: +If you want to provide a secret like a password or a token inside the file content or as part of an URL, store the [eyaml encrypted encrypt secret](../../puppet/eyaml) in an else unused Hiera key and include it into the actual place using string interpolation and the `lookup` function: ```yaml my-project::my-user::my-password: 'ENC[PKCS7,MIIBmQYJKoZI...dvkM=]' diff --git a/admin-guide/configuration/monitoring/central_logging_elastic.md b/admin-guide/configuration/monitoring/central_logging_elastic.md index 108b2d1d..75bba35e 100644 --- a/admin-guide/configuration/monitoring/central_logging_elastic.md +++ b/admin-guide/configuration/monitoring/central_logging_elastic.md @@ -31,7 +31,7 @@ Replace the space name as well as the space_api_key according to your setup. Notice that `space` contains the `name` without the `input_` prefix, while `space_api_key` contains a `:`-separated value: * the first part corresponds to the `id` of the space, * the second part corresponds to the `api_key`. -* The resulting string `"${space_id}:${space_api_key}"` **should be encrypted** with [eyaml](https://linux.psi.ch/admin-guide/puppet/hiera.html?highlight=eyaml#encrypting-data-with-the-public-key) +* The resulting string `"${space_id}:${space_api_key}"` **should be encrypted** with [eyaml](../../puppet/eyaml) By default __all__ journald logs are shipped to the central Elastic instance. If you want to __limit__ the logs to specific units, the units can be specified as follows: diff --git a/admin-guide/puppet/hiera.md b/admin-guide/puppet/hiera.md index bfe84e12..b90ee2f9 100644 --- a/admin-guide/puppet/hiera.md +++ b/admin-guide/puppet/hiera.md @@ -20,25 +20,24 @@ The values can be stored as classical YAML values or with [encrypted yaml](https The filesystem structure is as follows (the last 3 cannot be controlled by a common admin): -1. ``%{::sysdb_env}/%{::group}/%{::fqdn}.yaml`` or ``%{::sysdb_env}/%{::group}/%{::subgroup}/%{::fqdn}.yaml`` -2. ``%{::sysdb_env}/%{::group}/%{::subgroup}.yaml`` -3. ``%{::sysdb_env}/%{::group}.yaml`` -4. ``%{::sysdb_env}/%{::sysdb_env}.yaml`` - -5. ``%{::environment}/data/server_%{server_facts.servername}.yaml`` -6. ``/srv/puppet/data/global/global.yaml`` -7. ``%{::environment}/data/common.yaml`` +1. `%{::sysdb_env}/%{::group}/%{::fqdn}.yaml` or `%{::sysdb_env}/%{::group}/%{::subgroup}/%{::fqdn}.yaml` +2. `%{::sysdb_env}/%{::group}/%{::subgroup}.yaml` +3. `%{::sysdb_env}/%{::group}.yaml` +4. `%{::sysdb_env}/%{::sysdb_env}.yaml` +5. `%{::environment}/data/server_%{server_facts.servername}.yaml` +6. `/srv/puppet/data/global/global.yaml` +7. `%{::environment}/data/common.yaml` Depending if a subgroup is defined, the node specific YAML is at a different level in the filesysystem hierarchy. -The ``%{variable}`` notation is hiera specific. +The `%{variable}` notation is hiera specific. ## Repositories Hiera data are organized in different repositories. These repositories are located at: https://gitea.psi.ch/puppet -Each __sysdb environment__ has a dedicated hiera repository, called ``data-``, eg. [data-hpc]( https://gitea.psi.ch/puppet/data-hpc). +Each __sysdb environment__ has a dedicated hiera repository, called `data-`, eg. [data-hpc](https://gitea.psi.ch/puppet/data-hpc). The first 4 levels of the filesystem structure shown before are actually the files inside this kind of repositories. Any change to the repo will automatically trigger a redeployment of the new version of its content on the puppet master within a few seconds from the push. @@ -46,7 +45,7 @@ Any change to the repo will automatically trigger a redeployment of the new vers ## Configuration ### Secrets -Secrets and clear-text values can be mixed inside the same yaml file, eg.:: +Secrets and clear-text values can be mixed inside the same yaml file, eg.: ```yaml ntp_client::servers: - pstime1.psi.ch @@ -62,51 +61,9 @@ The encrypted values can be decrypted transparently from Hiera (on a host having this is a secret value ``` -You can edit secure data inside any yaml file with the command `/opt/puppetlabs/puppet/bin/eyaml edit common.yaml`. In this case secure data will appear in clear-text inside the editor. +For encrypting data see [EYAML Secrets in Hiera](eyaml) - -### Encrypt Data -To encrypting data you have to use the public key from your Hiera (`data-*`) git repository named `eyaml_public_key.pem` - -For the lower layers (global, server or data) it is on the Puppet server at [`/etc/puppetlabs/keys/eyaml/public_key.pkcs7.pem`](https://gitea.psi.ch/lx/bootstrap/src/branch/prod/instcode/puppet/puppet_server/files/crypto/public_key.pkcs7.pem). - -Beside this key you also need to have `hiera-eyaml` tool installed on your system. - -```bash -eyaml encrypt --pkcs7-public-key=eyaml_public_key.pem -s secret_string -``` - -While a complete file can be encrypted with: -```bash -eyaml encrypt --pkcs7-public-key=eyaml_public_key.pem -f secret_file -``` - -#### Example - -To encrypting password for a system you can go about like this: - -```bash -# openssl passwd -6 | eyaml encrypt --pkcs7-public-key=eyaml_public_key.pem --stdin -Password: -Verifying - Password: -string: ENC[PKCS7,MIIBxxxxxxxx...xxxxxxxx] - -OR - -block: > - ENC[PKCS7,MIIBxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - ... - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx] -# -``` - - - -and place either the string or the block at the required place in your Hiera YAML. - -# Hiera Variable Interpolation +### Hiera Variable Interpolation Within Hiera also variable interpolation might be use to include other Hiera keys or facts, etc. into the values. For details check out the [Puppet documentation](https://www.puppet.com/docs/puppet/7/hiera_merging.html#interpolation_functions)