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

Don't use a hidden value of certname if use_uuid_for_certificates has been toggled on/off #925

Closed
wants to merge 3 commits into from

Conversation

sodabrew
Copy link
Member

@sodabrew sodabrew commented Oct 2, 2013

Expected:

  • Enable use_uuid_for_certificates
  • Create a host
  • Host has a UUID now
  • Set host to Build, pull the host's template, watch the certname UUID value be added to the Puppet Autosign file.
  • ... realize that uuid certificates aren't right for your organization ...
  • Disable use_uuid_for_certificates
  • Set host to Build, pull the host's template, watch the certname hostname value be added to the autosign file.

Actual:

  • Set host to Build, pull the host's template, watch the certname UUID value be added to the Puppet Autosign file.
  • Watch as your Puppet run fails to get a certificate because the client has submitted a certificate request using its hostname now.

Patch fixes this by checking for state of the use_uuid_for_certificates setting in the certname model method.

@domcleal
Copy link
Contributor

domcleal commented Oct 4, 2013

So the scenario here is that you enable the setting, create the host, disable the setting, you provision the host and it stays in effect. I'm worried about another case where you enable the setting, provision the host, disable it and then Foreman doesn't know the correct certname for the host.

In that case you'd want Foreman to still know the old UUID certname, but not issue UUID certnames to new hosts. Does that make sense? I'm not sure which is correct if so.

@GregSutcliffe, what are your thoughts?

@sodabrew
Copy link
Member Author

sodabrew commented Oct 4, 2013

The UI hides the certname when you disable that option, so you cannot see or edit it. The behavior should be made consistent - the other way around is never to hide the certname if it has been set, that way I can see that I have to delete it.

@domcleal
Copy link
Contributor

domcleal commented Oct 7, 2013

Yes, having the ability to view and edit the certname would be useful generally and probably help here. I think that'd be a viable solution.

Another way, which I think would keep both of our scenarios working, would be to reset the certname according to the current value of the UUID setting while performing the certificate revocation and setting up autosigning.

e.g. in app/models/host/managed.rb, handle_ca:

respond_to?(:initialize_puppetca,true) && initialize_puppetca && delCertificate && setAutosign

Between delCertificate (revocation) and setAutosign (adding autosign entry), we reset certname if it contains a UUID and the UUID setting's now off:

certname = name if certname =~ /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\Z/ && !Setting[:use_uuid_for_certificates]  

I think this would solve the problem you're hitting, while keeping certname working for existing hosts?

@GregSutcliffe
Copy link
Member

@domcleal that makes a lot of sense, apart from being able to edit the certname. Since that's closely tied to certificate generation/revocation, I'm not sure making it editable is a good idea. I definitely agree with displaying it if it's not == to the hostname (or maybe just all the time), and the reset code looks good too.

@sodabrew
Copy link
Member Author

sodabrew commented Oct 7, 2013

Seems complicated?

I like that my proposal has simple logic based on the one setting, because I don't want to keep the UUID cert name after toggling this option off anyhow.

@GregSutcliffe
Copy link
Member

@sodabrew I agree, the issue is that your patch as written will mean that when you rebuild a host, the old cert won't get cleaned out from your puppetmaster.

This is because the clean operation happens as the host is being rebuilt (specifically when it retrieves it's provision template), which will be after you've altered the Setting and thus it tries to clean host.name rather than uuid from the puppetmaster.

What @domcleal is proposing is to fix that problem by resetting the certname after the clean has happened, rather than before - i.e by hooking in at the right time in the orchestration. Otherwise the logic is pretty much the same, the only extra bit is looking explicitly for old UUID certnames, rather than any certname. It's still based on the one setting, as you rightly want.

@sodabrew
Copy link
Member Author

sodabrew commented Oct 7, 2013

Oh, gotcha. Sounds good - will you be able to code this up for 1.3, or shall I jump in on it?

@domcleal
Copy link
Contributor

domcleal commented Oct 7, 2013

If you're able to, that'd be great - though I'd ask for tests too please. test/unit/host_test.rb in the handle_ca area would be a good place to start I think, since there's a test that stubs out most of those calls already. Thanks!

@sodabrew
Copy link
Member Author

sodabrew commented Oct 8, 2013

If this works and looks mergeble then I'll rebase/squash first :) ... caveat that I haven't actually run the unit tests yet.

@domcleal
Copy link
Contributor

domcleal commented Oct 8, 2013

[test]

1 similar comment
@domcleal
Copy link
Contributor

domcleal commented Oct 8, 2013

[test]

h.expects(:delCertificate).returns(true)
h.expects(:setAutosign).returns(true)
assert h.handle_ca
assert h.certname.nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

This is failing in the tests as h.certname will return the name if not defined. Perhaps use .read_attribute(:certname) or assert_equal to the name?

@domcleal
Copy link
Contributor

domcleal commented Oct 8, 2013

Last one? [test]

@sodabrew
Copy link
Member Author

sodabrew commented Oct 8, 2013

I hope so, sorry for the dumb errors! I couldn't get tests running locally at all :/

@domcleal
Copy link
Contributor

domcleal commented Oct 8, 2013

No worries, that's unusual. It's normally OK after copying the settings/database files in place, db:migrate and rake test.

@sodabrew
Copy link
Member Author

sodabrew commented Oct 8, 2013

Did the tests begin?

@domcleal
Copy link
Contributor

domcleal commented Oct 8, 2013

Yep, on their way now. It checks every 15 mins, so there's some latency involved :)

@sodabrew
Copy link
Member Author

sodabrew commented Oct 8, 2013

Huh.

- expected exactly once, not yet invoked: #<Object:0x7f504d4606f0>.set_autosign('dhcp.mydomain.net')
- expected exactly once, not yet invoked: #<Object:0x7f504d4606f0>.del_certificate('b4340f6c-9ce7-4958-9dcf-de02d36461d5')

@domcleal
Copy link
Contributor

domcleal commented Oct 8, 2013

Ah, because the methods on the host itself (which calls the PuppetCA object) are stubbed:

- expected exactly once, invoked once: #<Host::Managed:0x7ff7fe2532f0>.setAutosign(any_parameters)
- expected exactly once, invoked once: #<Host::Managed:0x7ff7fe2532f0>.delCertificate(any_parameters)

Removing these lines and making the puppetca stubs return true makes the test pass locally: domcleal@3a7f4dd

…based certificate and before enabling autosign for a hostname-based certificate
@domcleal
Copy link
Contributor

domcleal commented Oct 8, 2013

[test]

return false unless delCertificate

# If the user has changed use_uuid_for_certificates to false,
# then null out the certname. This means we may revoke the hostname
Copy link
Member

Choose a reason for hiding this comment

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

shouldnt we do this when the setting change instead?
this might be a bit unexpected?

Copy link
Contributor

Choose a reason for hiding this comment

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

That then raises the issue in my first two comments, we lose track of certificates of existing hosts. This is less surprising, as existing certs continue to work and Foreman can delete them (as we continue to track them), but then sign new certificates as per the current value of the setting.

Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we have some way to warn the user? that this change is potentially impacting some of the hosts?

ideally, we should have a way to:

  1. let the user know which systems might be impacted
  2. let the user decide what to do on a per system base?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps ideally, but that's a lot of complexity and work for a single setting.

Copy link
Member

Choose a reason for hiding this comment

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

I see a few options forward then:

  1. document well
  2. open another follow up feature request and merge as is
  3. extend this PR to include a warning to the user?

any other option? what would be your take?

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer (1) and (2). I think the behaviour this PR currently implements is good - it doesn't break existing hosts and automatically picks up the change when required. I can add a note to the setting in the manual and file a related ticket on merge.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@sodabrew
Copy link
Member Author

sodabrew commented Oct 8, 2013

Added logging?

@domcleal
Copy link
Contributor

domcleal commented Oct 8, 2013

Nice, thanks @sodabrew. I'll give this a try and merge tomorrow.

@sodabrew
Copy link
Member Author

sodabrew commented Oct 8, 2013

Thank you too, I appreciated the pointers along the way.

@domcleal
Copy link
Contributor

domcleal commented Oct 9, 2013

No problem. Thanks for the contribution @sodabrew, merged as 89e506f for Foreman 1.3.0 final.

@domcleal domcleal closed this Oct 9, 2013
@sodabrew sodabrew deleted the patch-1 branch October 9, 2013 19:05
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants