Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(CAT-1301) Add check unsafe interpolations check #142

Merged
merged 1 commit into from
Aug 25, 2023

Conversation

GSPatton
Copy link

This commit adds the check unsafe interpolations check to core puppet-lint insted of having it as a standalone gem

Summary

Provide a detailed description of all the changes present in this pull request.

Additional Context

Add any additional context about the problem here.

  • Root cause and the steps to reproduce. (If applicable)
  • Thought process behind the implementation.

Related Issues (if any)

Mention any related issues or pull requests.

Checklist

  • 🟢 Spec tests.
  • 🟢 Acceptance tests.
  • Manually verified.

@GSPatton GSPatton added the enhancement New feature or request label Aug 18, 2023
@GSPatton GSPatton requested review from bastelfreak and a team as code owners August 18, 2023 10:32
Copy link

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does depend on PUP-5704, so that raises the minimum compatibility to Puppet 7.10.0 which should be noted in the compatibility section of README.

And RuboCop is not happy with you.

end
end
end

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, Rubocop really isn't happy with me... thanks @ekohl. I'll fix this up

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, what is PUP-5704? Do you mean a specific version of puppet?

@GSPatton GSPatton force-pushed the CAT-1301-add_unsafe_interpolations_check branch from 0b3812c to 8e11a99 Compare August 21, 2023 09:43
@ekohl
Copy link

ekohl commented Aug 21, 2023

This does depend on PUP-5704, so that raises the minimum compatibility to Puppet 7.10.0 which should be noted in the compatibility section of README.

In puppetlabs/puppetlabs-apache#2444 I was corrected and Puppet 7.9.0 introduced the PUP-5704 feature this new style needs. That means if this lint rule is applied and a user runs Puppet < 7.9 (or Puppet < 6.24) the code will be invalid. It needs puppetlabs/puppet@59d045b.

@ekohl
Copy link

ekohl commented Aug 21, 2023

Perhaps submit the RuboCop fixes in a separate PR first to make reviewing a bit easier?

@GSPatton GSPatton force-pushed the CAT-1301-add_unsafe_interpolations_check branch 2 times, most recently from 8e11a99 to 1c645d6 Compare August 22, 2023 14:21
Copy link

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is one check that would work must better on a parsed tree, rather than on tokens. Today puppet-lint doesn't offer such a thing, but it may be worth considering if more of these checks are added.

def parameterised?(token)
current_token = token
while current_token.type != :NEWLINE
return true if current_token.type == :FARROW && current_token.next_token.next_token.type == :LBRACK
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is valid. There may be multiple tokens between, like whitespace.

# This function checks if the current token is a :FARROW and if so, if it is followed by an LBRACK
def parameterised?(token)
current_token = token
while current_token.type != :NEWLINE
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puppet doesn't care about whitespace, so why does this matter? Don't you want to look for a comma or } instead, which signifies that the next attribute comes or the definition is over.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure what you mean. This function is used before checking the contents of the command to check if the command is parameterised. Because if so, the command won't need checked. Parameterising the command is one of the ways of making string interpolation safer

@GSPatton GSPatton force-pushed the CAT-1301-add_unsafe_interpolations_check branch from 1c645d6 to 0f76677 Compare August 24, 2023 14:04
@GSPatton GSPatton changed the title (WIP) (CAT-1301) Add check unsafe interpolations check (CAT-1301) Add check unsafe interpolations check Aug 24, 2023
@GSPatton GSPatton force-pushed the CAT-1301-add_unsafe_interpolations_check branch from 0f76677 to 31b72b8 Compare August 25, 2023 10:09
.rubocop_todo.yml Outdated Show resolved Hide resolved
.rubocop_todo.yml Outdated Show resolved Hide resolved
This commit adds the check unsafe interpolations check to core puppet-lint insted of having it as a standalone gem. It corrects rubocop warnings in the plugin and adds the update .rubocop_todo which will be addressed in a separate PR
@GSPatton GSPatton force-pushed the CAT-1301-add_unsafe_interpolations_check branch from 31b72b8 to d3c9d9f Compare August 25, 2023 10:34
@david22swan david22swan merged commit 8eaddd1 into main Aug 25, 2023
6 checks passed
@david22swan david22swan deleted the CAT-1301-add_unsafe_interpolations_check branch August 25, 2023 10:44
@ekohl
Copy link

ekohl commented Aug 27, 2023

This does give false positives. If command is present the title doesn't need to be validated. An example:
https://github.com/voxpupuli/puppet-trusted_ca/blob/8f9ccc04a12ed3608131d9cb4d80d9d9ecffb380/manifests/ca.pp#L74-L81

Or simplified:

exec { "validate ${filename}":
  command => "openssl x509 -in ${filename} -noout",
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants