Skip to content

Commit 6ecd034

Browse files
author
Jérémie Pierson
committed
Allow file content that looks like a checksum.
Currently, if a file has a content attribute set to something that looks like a checksum, it will display a deprecation warning and then probably throw an error, as the checksum-link string won't match anything in filebuckets. This code is apparently intended to allow a checksum to be passed instead of actual content, with the effect of replacing file content if it doesn't match the checksum. It appears that this mecanism is replaced by "static catalogs" and was scheduled for removal in Puppet 7. As it is no longer documented (because deprecated), it is surprising to stumble upon the behavior by just having file content that looks like a checksum. I had to work around this in a real usecase involving some proprietary software that uses the same syntax for value to be encrypted at startup. This commit introduces a new setting "use_checksum_in_file_content" that default to true, preserving current behavior. If set to false, it will never look for checksums in file contents. This setting should probably be set to false by default in the next major release.
1 parent a23449f commit 6ecd034

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

lib/puppet/defaults.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,13 @@ def self.initialize_default_settings!(settings)
11141114
# Sure would be nice to set the Puppet::Util::Log destination here in an :on_initialize_and_write hook,
11151115
# unfortunately we have a large number of tests that rely on the logging not resetting itself when the
11161116
# settings are initialized as they test what gets logged during settings initialization.
1117+
},
1118+
:use_checksum_in_file_content => {
1119+
:default => true,
1120+
:type => :boolean,
1121+
:desc => "Whether to allow specifying checksums in file content attributes; this is
1122+
deprecated, the checksum retrieval functionality is being replaced by the use of
1123+
static catalogs."
11171124
}
11181125
)
11191126

lib/puppet/type/file/content.rb

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,43 @@ module Puppet
4848
if value == :absent
4949
value
5050
elsif value.is_a?(String) && checksum?(value)
51-
# XXX This is potentially dangerous because it means users can't write a file whose
52-
# entire contents are a plain checksum unless it is a Binary content.
53-
Puppet.puppet_deprecation_warning([
54-
# TRANSLATORS "content" is an attribute and should not be translated
55-
_('Using a checksum in a file\'s "content" property is deprecated.'),
56-
# TRANSLATORS "filebucket" is a resource type and should not be translated. The quoted occurrence of "content" is an attribute and should not be translated.
57-
_('The ability to use a checksum to retrieve content from the filebucket using the "content" property will be removed in a future release.'),
58-
# TRANSLATORS "content" is an attribute and should not be translated.
59-
_('The literal value of the "content" property will be written to the file.'),
60-
# TRANSLATORS "static catalogs" should not be translated.
61-
_('The checksum retrieval functionality is being replaced by the use of static catalogs.'),
62-
_('See https://puppet.com/docs/puppet/latest/static_catalogs.html for more information.')
63-
].join(" "),
64-
:file => @resource.file,
65-
:line => @resource.line) if !@actual_content && !resource.parameter(:source)
66-
value
51+
# Our argument looks like a checksum. Is it the value of the content
52+
# attribute in Puppet code, that happens to look like a checksum, or is
53+
# it an actual checksum computed on the actual content?
54+
if @actual_content || resource.parameter(:source)
55+
# Actual content is already set, value contains it's checksum
56+
value
57+
else
58+
# The value passed in the "content" attribute of this file looks like a checksum.
59+
if Puppet[:use_checksum_in_file_content]
60+
# Assume user wants the deprecated behavior; display a warning though.
61+
# XXX This is potentially dangerous because it means users can't write a file whose
62+
# entire contents are a plain checksum unless it is a Binary content.
63+
Puppet.puppet_deprecation_warning([
64+
# TRANSLATORS "content" is an attribute and should not be translated
65+
_('Using a checksum in a file\'s "content" property is deprecated.'),
66+
# TRANSLATORS "filebucket" is a resource type and should not be translated. The quoted occurrence of "content" is an attribute and should not be translated.
67+
_('The ability to use a checksum to retrieve content from the filebucket using the "content" property will be removed in a future release.'),
68+
# TRANSLATORS "content" is an attribute and should not be translated.
69+
_('The literal value of the "content" property will be written to the file.'),
70+
# TRANSLATORS "static catalogs" should not be translated.
71+
_('The checksum retrieval functionality is being replaced by the use of static catalogs.'),
72+
_('See https://puppet.com/docs/puppet/latest/static_catalogs.html for more information.')
73+
].join(" "),
74+
:file => @resource.file,
75+
:line => @resource.line) if !@actual_content && !resource.parameter(:source)
76+
# We return the value assuming it really is the checksum of the
77+
# actual content we want. It should be fetched from filebucket
78+
# later on.
79+
value
80+
else
81+
# The content only happens to look like a checksum by chance.
82+
@actual_content = value.is_a?(Puppet::Pops::Types::PBinaryType::Binary) ? value.binary_buffer : value
83+
resource.parameter(:checksum).sum(@actual_content)
84+
end
85+
end
6786
else
87+
# Our argument is definitely not a checksum: set actual_value and return calculated checksum.
6888
@actual_content = value.is_a?(Puppet::Pops::Types::PBinaryType::Binary) ? value.binary_buffer : value
6989
resource.parameter(:checksum).sum(@actual_content)
7090
end
@@ -163,6 +183,8 @@ def each_chunk_from
163183
end
164184

165185
def content_is_really_a_checksum?
186+
return false unless Puppet[:use_checksum_in_file_content]
187+
166188
checksum?(should)
167189
end
168190

0 commit comments

Comments
 (0)