Jira (PUP-11753) decrypted eyaml lookup has last newline removed

5 views
Skip to first unread message

Hannes De Valkeneer (Jira)

unread,
Feb 6, 2023, 3:15:04 PM2/6/23
to puppe...@googlegroups.com
Hannes De Valkeneer created an issue
 
Puppet / Bug PUP-11753
decrypted eyaml lookup has last newline removed
Issue Type: Bug Bug
Assignee: Unassigned
Components: Hiera & Lookup
Created: 2023/02/06 12:14 PM
Priority: Normal Normal
Reporter: Hannes De Valkeneer

Puppet Version:
Puppet Server Version:
OS Name/Version:

When encrypting a file that has a newline at the end (e.g. a openssh private key) the file is missing the newline when decrypted.

in a puppet module we create a file resource with some content, passed in from hiera.

 

file { "path/to/file":
  content => $content
}
 

where the content is encrypted

# private.eyaml
---
enc_file: ENC[PKCS7,Y22exl+O...]
...
# common.yaml
my_module::content: "%{lookup('enc_file')}"

Desired Behavior:

The newline of encrypted content should not be removed.

Actual Behavior:

The newline in the encrypted file gets removed.

Potential Fix:

I think the issue is by either the eyaml parser to emit an extra NonMatchToken or the eyaml_lookup_key function to join the trailing NonMatchToken.

Removing chomp shows tests failing because of an extra newline. When filtering out NonMatchTokens and then join the tokens, tests are still green, and the encrypted file will keep its newline.

diff --git a/lib/puppet/functions/eyaml_lookup_key.rb b/lib/puppet/functions/eyaml_lookup_key.rb
index 5fbae35b3a..321aa191fb 100644
--- a/lib/puppet/functions/eyaml_lookup_key.rb
+++ b/lib/puppet/functions/eyaml_lookup_key.rb
@@ -87,7 +87,7 @@ Puppet::Functions.create_function(:eyaml_lookup_key) do
       Hiera::Backend::Eyaml::Options.set(options)
       begin
         tokens = Hiera::Backend::Eyaml::Parser::ParserFactory.hiera_backend_parser.parse(data)
-        data = tokens.map(&:to_plain_text).join.chomp
+        data = tokens.select{|token| not token.kind_of? Hiera::Backend::Eyaml::Parser::NonMatchToken}.map(&:to_plain_text).join
       rescue StandardError => ex
         raise Puppet::DataBinding::LookupError,
           _("hiera-eyaml backend error decrypting %{data} when looking up %{key} in %{path}. Error was %{message}") % { data: data, key: key, path: options['path'], message: ex.message }

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.20.11#820011-sha1:0629dd8)
Atlassian logo

Michael Hashizume (Jira)

unread,
Feb 7, 2023, 4:09:04 PM2/7/23
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages