-
Notifications
You must be signed in to change notification settings - Fork 461
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
Allow GPG key fingerprints. #354
Conversation
This patch allows 40-digit GPG fingerprints as key values in addition to 8 and 16-digit key IDs. |
This patch needs support for checking if the key is already present, which it fails to do now. |
This is a good idea, especially with regard to the recent short-id collisions, one of them involving the Puppet Labs key. Do you have a plan on how to deal with the fingerprints in |
I'm currently looking into that. There's a way to do it from The key collision for the Puppet signing key is scary, noticed that last night. |
Does this have to wait on the check for already present? There are already 2 pull requests to address the 40 bit key problem (and I was about to submit a 3rd). Maybe we can get this in and work on the already present check separately? It does work, even if it's not perfect. |
Would this work: apt-key adv --list-keys --with-colons --fingerprint Not the prettiest output, but gives the 40 character fingerprints. |
This works as expected. |
Also note that the pub lines in --with-colons output contain the 16 character keys. So between "apt-key list" and "apt-key adv --list-keys --with-colons --fingerprint" you can get all 3 versions of the keys for validation. Why there isn't a single command that gives all 3 versions is a mystery.... |
@WolverineFan Thanks for figuring out the commands though, I'll see if I can whip up something during the contrib summit at Puppetconf. Should allow a few people to weigh in too and we can get this fixed once and for all. |
Any chance this patch can get merged while you work on the better validation? Currently 40 character fingerprints just barf completely and this patch fixes that problem at least. |
So me and @mhaskel would like to merge this because we're gearing up for a release but we can't do this without tests. It hasn't broken the current behaviour but we do need tests to prove that it works with the fingerprints too. |
@rfkrocktk can you also update the documentation with the updated support for GPG key fingerprints? |
Life is a bit hectic right now but I'll try to get this in within the next On Wed, Sep 24, 2014 at 3:00 PM, Morgan Haskel [email protected]
|
@rfkrocktk Did you get a chance to look at this? |
I'm back at work next week, it'll have to wait until at least then, sorry
|
No problem, but good to know. Thank you! |
Ping? |
I've resumed work on this and am looking into it. I'm trying now to find a command I can use to list out all keys, their expiry, and their fingerprints so I can update I'm specifically trying to find a command that outputs 8-digit key IDs, 16-digit key IDs, and 40-digit key fingerprints so that all checks will work properly. After I figure this out (see relevant question on unix.stackexchange), I'll update the tests and hopefully we'll see this get merged. The previous command |
Alright, so I've found a way to fix it, but I'm really not sure how some of the Puppet provider internals work. How do I run the tests locally to make sure my changes work properly? |
@rfkrocktk you can run the unit tests with |
I have a design problem that I'd like to get some input on. In the apt-key provider, it currently uses only 8-digit identifiers for key ids and if I were to replace them with the 40-digit fingerprints exclusively, this would introduce backwards-incompatible changes. Here's what I've done so far in the apt-key provider. I've rewritten the following methods:
This provider makes it easy to parse the output of the command mentioned above to get everything from the key ids, expiry and created dates, key size and type, fingerprint, etc. I'm new to writing Ruby Puppet code, so I'm not sure where the actual comparison is ever done to
Where is this done? I've done almost all of the work here, I just need to wrap things up to make sure that comparison is done properly. I'd like to support comparison between all three key types (short 8, long 16, fingerprint 40). |
That's done for you. What this provider does is prefetch all the resources for you and generate one for every key that exists. Then it takes the This is done here: https://github.com/puppetlabs/puppetlabs-apt/blob/master/lib/puppet/type/apt_key.rb#L28 The As you can see the |
Actually, it seems that some of the logic is already done in the provider's
If I emend this to add another if statement to set the provider on Is that right? The problem I'm seeing is the mismatch between what the user supplies and requests that we |
This will not be idempotent yet as the apt_key will always base the match on the short key. The aforementioned shortname was removed at 87f3f10 , we should either munge the name to be the shortname or reimplement the prefetch munging. |
@cyberious I've pushed all of my modifications, please take a look. Feel free to complete the work on your own (if you know more about writing Ruby for Puppet than I do, which is easily possible), or at least tell me what changes I should make in order to complete the work on matching fingerprints properly. |
I think shortening the long key in 87f3f10 is bad. That's going to lead to collisions (maybe that's what you meant). It would be better to save all the variants and use the length to figure out which key to check. I tried a quick hack to do that and it doesn't work the way I expected. Maybe I'm not understanding how the prefetch method works. |
Prefetch has all of the keys ahead of time and can not figure out the ID length. A possible solution is to add a property that we would read in as well for the fingerprint and upon prefetch if the id == 40 than we would match based on fingerprint rather than id/name. |
This is what I was thinking, but my Ruby (and Puppet) are not great, so maybe this can't work? We would store each option in the apt_keys hash and use the name length to figure out which key to match on. def self.prefetch(resources)
apt_keys = instances
resources.keys.each do |name|
if name.length == 40
if provider = apt_keys.find{ |key| key.fingerprint == name }
resources[name].provider = provider
end
elsif name.length == 16
if provider = apt_keys.find{ |key| key.long == name }
resources[name].provider = provider
end
elsif name.length == 8
if provider = apt_keys.find{ |key| key.short == name }
resources[name].provider = provider
end
end
end
end |
that logic looks correct. |
However with that we need to add the properties for long short and fingerprint. |
I did that too: def self.key_line_hash(pub_line, fpr_line)
pub_split = pub_line.split(':')
fpr_split = fpr_line.split(':')
fingerprint = fpr_split.last
return_hash = {
:key_fingerprint => fingerprint,
:key_long => fingerprint[-16..-1], # last 16 characters of fingerprint
:key_short => fingerprint[-8..-1], # last 8 characters of fingerprint And referenced them in the self.instances function. Maybe some other change I made is causing the failure. I'll do some more experimenting today if I can get the tests running locally |
Thanks everyone for helping out on this. You're planning on adding tests to
|
Very true. I'm going to rebase all of this on current master and merge it all into a single commit to keep it pretty. |
Thank you so much, it'll be nice to see this hit production :) On Thu, Jan 8, 2015, 11:22 AM WolverineFan [email protected] wrote:
|
Opened #404 with the new tests and bug fixes |
I'm going to close this in favour of #404. |
Patch to allow GPG key fingerprints as key values.