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

first pass at simple encryption #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,26 @@ datacat_fragment { 'open ssh':
}
```

Optional: in-catalog encryption
---------------------
If you have the [`binford2k/node_encrypt`](https://forge.puppetlabs.com/binford2k/node_encrypt)
module installed, then you can transparently encrypt any data element using the
`node_encrypt()` function. **Remember to set `show_diff => false` to keep the
secrets from appearing in your reports!**

```Puppet
datacat { '/tmp/test':
template_body => "Decrypted value: <%= @data["value"] %>",
show_diff => false,
}
datacat_fragment { 'encryption test':
target => '/tmp/test',
data => {
value => node_encrypt('This string will not be included in the catalog.'),
},
}
```

Caveats
-------

Expand Down
10 changes: 10 additions & 0 deletions lib/puppet/provider/datacat_collector/datacat_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ def exists?
r.is_a?(Puppet::Type.type(:datacat_fragment)) && ((our_names & [ r[:target] ].flatten).size > 0)
end

# decrypt any encrypted fragments
if defined?(Puppet_X::Binford2k::NodeEncrypt)
fragments.each do |fragment|
fragment[:data].each do |key,value|
next unless Puppet_X::Binford2k::NodeEncrypt.encrypted?(value)
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not keen on this particular check as it smells like it's checking for a magic number, and it also seems too soft. I think I'd sooner have an additional explicit flag on the fragment, something more like:

fragments.each do |fragment|
  if fragment[:encrypted]
    fragment[:data].each do |key,value|
      fragment[:data][key] = Puppet_X::Binford2k::NodeEncrypt.decrypt(value)
    end
  end
end

Then it's less automagic and more explicit.

Copy link
Author

Choose a reason for hiding this comment

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

It's checking for the guard string -----BEGIN PKCS7-----. I can't figure a more robust way to do this transparently to the end-user. I'd totally be happy if you found a good way to do this.

I suppose you could require an additional encrypted => true parameter to be set, but that might make it awkward because all values or no values would be marked as encrypted.

Copy link
Author

Choose a reason for hiding this comment

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

maybe we could do both approaches, flag the fragment with a parameter, then iterate each value like I'm currently doing. Thoughts?

Copy link
Owner

Choose a reason for hiding this comment

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

That's what my code fragment was meant to be showing, unless you mean it could optimistically check if the value looks encrypted so a warning can be issued if it wasn't flagged as being encrypted? More like:

fragments.each do |fragment|
  fragment[:data].each do |key,value|
    if Puppet_X::Binford2k::NodeEncrypt.encrypted?(value)
      if fragment[:encrypted]
        fragment[:data][key] = Puppet_X::Binford2k::NodeEncrypt.decrypt(value)
      else
        warn "Fragment looked encrypted but wasn't flagged as being encrypted"
      end
    end
  end
end

fragment[:data][key] = Puppet_X::Binford2k::NodeEncrypt.decrypt(value)
end
end
end

# order fragments on their :order property
fragments = fragments.sort { |a,b| a[:order] <=> b[:order] }

Expand Down
5 changes: 5 additions & 0 deletions lib/puppet_x/richardc/datacat.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
begin
require 'puppet_x/binford2k/node_encrypt'
rescue LoadError
end

module Puppet_X
module Richardc
class Datacat
Expand Down