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

Hide sensitive parameters #33

Merged
merged 1 commit into from
Aug 7, 2020
Merged

Conversation

alexjfisher
Copy link
Member

This solves an issue for me where even though both 'to' and 'from'
catalogs were being compiled, (not coming from puppetdb), resources with
sensitive data were still being marked as 'changed'.

With this commit, sensitive data won't be leaked, but replaced by a
simple hash so that diffs should still show.

lib/puppet/catalog-diff/compilecatalog.rb Show resolved Hide resolved
if resource.key? 'sensitive_parameters'
resource['sensitive_parameters'].each do |p|
hash = Digest::SHA256.hexdigest Marshal.dump(resource['parameters'][p])
resource['parameters'][p] = 'Sensitive [hash ' + hash + ']'
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use a more Ruby-esque syntax:

"Sensitive [hash #{hash}]"

hash = Digest::SHA256.hexdigest Marshal.dump(resource['parameters'][p])
resource['parameters'][p] = 'Sensitive [hash ' + hash + ']'
end
resource.tap { |hs| hs.delete('sensitive_parameters') }
Copy link
Member

Choose a reason for hiding this comment

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

What is #tap for?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll own up to taking this from stackoverflow! https://stackoverflow.com/a/9027559

Copy link
Member

Choose a reason for hiding this comment

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

But why not modify the original hash?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, ok. Doh! I should have looked more carefully. The original poster was after a one-liner. I had just forgotten whether you set a key to nil to delete it, or if there was a method to use.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, do we really need to remove the sensitive_parameters field, if it's only the list of keys?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I think so. Otherwise our useful hashes get replaced by standard puppet redacted stuff sometime later. IIRC I think during https://github.com/camptocamp/puppet-catalog-diff/blob/b5d0f72d37a58948f45c920caaa39a4a9c90cf44/lib/puppet/catalog-diff/differ.rb#L28? (But would have to double check to be sure if it was after this line or somewhere else)

catalog
end

def redact_sensitive(data)
Copy link
Member

Choose a reason for hiding this comment

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

Could this be used in clean_sensitive_parameters to reduce code duplication?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure...

@alexjfisher alexjfisher force-pushed the sensitive branch 2 times, most recently from fb3b7d2 to fa57725 Compare August 3, 2020 15:42

def redact_sensitive(data)
if data.is_a?(Hash) && data.key?('__ptype')
data[:catalog_diff_hash] = Digest::SHA256.hexdigest Marshal.dump(data['__pvalue'])
Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally, I think I would have liked to replace this hash with a "Sensitive [hash #{hash}]" style string (instead of replacing the __ptype and __pvalue keys. I couldn't figure out how to do this in place though.

@raphink
Copy link
Member

raphink commented Aug 5, 2020

Sorry, I didn't see your changes from 2 days ago. I'll review again tomorrow.

This solves an issue for me where even though both 'to' and 'from'
catalogs were being compiled, (not coming from puppetdb), resources with
sensitive data were still being marked as 'changed'.

With this commit, sensitive data won't be leaked, but replaced by a
simple hash so that diffs should still show.
@alexjfisher
Copy link
Member Author

Rubocop issue should be sorted now.

@raphink raphink merged commit bb09bd2 into voxpupuli:master Aug 7, 2020
@raphink raphink added the enhancement New feature or request label Aug 7, 2020
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.

2 participants