Skip to content

lines in file resource content looking like a checksum throws an error #9412

Open
@sprd-tmu

Description

@sprd-tmu

Describe the Bug

Using Puppet 8.7.0, issuing this line:
$ puppet apply -e "file { '/tmp/test': ensure => 'file', content => \"# anything\n{abc}$\n# anything\" }"
results in a deprecation warning and error:

$ puppet apply -e "file { '/tmp/test': ensure => 'file', content => \"# anything\n{abc}$\n# anything\" }"
Notice: Compiled catalog for my_machine in environment production in 0.01 seconds
Warning: Using a checksum in a file's "content" property is deprecated. The ability to use a checksum to retrieve content from the filebucket using the "content" property will be removed in a future release. The literal value of the "content" property will be written to the file. The checksum retrieval functionality is being replaced by the use of static catalogs. See https://puppet.com/docs/puppet/latest/static_catalogs.html for more information.
   (file: unknown, line: 1)
Error: Could not retrieve content for # anything
{abc}$
# anything from filebucket: Could not get filebucket from file
Error: /Stage[main]/Main/File[/tmp/test]/ensure: change from 'absent' to 'file' failed: Could not retrieve content for # anything
{abc}$
# anything from filebucket: Could not get filebucket from file
Notice: Applied catalog in 0.01 seconds

Expected Behavior

File /tmp/test is created without error with content:

# anything
{abc}$
# anything

Steps to Reproduce

Steps to reproduce the behavior:

  1. Run puppet apply -e "file { '/tmp/test': ensure => 'file', content => \"# anything\n{abc}$\n# anything\" }"

Environment

  • Version 8.7.0
  • Platform Linux

Additional Context

  • This block triggers the deprecation warning and maybe the error too:
elsif value.is_a?(String) && checksum?(value)
  # XXX This is potentially dangerous because it means users can't write a file whose
  # entire contents are a plain checksum unless it is a Binary content.
  Puppet.puppet_deprecation_warning([
...

https://github.com/puppetlabs/puppet/blob/main/lib/puppet/type/file/content.rb#L50

  • The checksum() function is this:
# Is the provided string a checksum?
def checksum?(string)
  # 'sha256lite'.length == 10
  string =~ /^\{(\w{3,10})\}\S+/
end

https://github.com/puppetlabs/puppet/blob/main/lib/puppet/util/checksums.rb#L41

  • Any line that matches the RegEx in the checksum() function seems to trigger the error.
  • The whole functionality was scheduled to be removed in Puppet 7, but is still there. Ticket: https://puppet.atlassian.net/browse/PUP-1043

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedValid issue that we intend to work on when we have the bandwidthbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions