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

Fixes #23210 - Handle PuppetCA tokens #5730

Merged
merged 1 commit into from
Sep 19, 2018

Conversation

juliantodt
Copy link
Member

In a new SmartProxy PuppetCA autosigning variant tokens get returned that need to be provisioned on the host.
This adds a Token::PuppetCa model; moves the PuppetCa-orchestration form queue to post-queue (we need the host's id to save the token); and handles the response from the SmartProxy correctly (save the token if we get one, don't do anything if we don't).
This is completely backwards-compatible - old SmartProxy versions and the basic autosigning variant will also work with this.

@theforeman-bot
Copy link
Member

Issues: #23210

# return if puppetca is using basic autosigning
return response if response.in? [true, false]
unless response.is_a?(Hash) && response['generated_token'].present?
logger.warn "Received an unexpected smart proxy response: #{response.to_s}"

Choose a reason for hiding this comment

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

Lint/StringConversionInInterpolation: Redundant use of Object#to_s in interpolation.

assert_equal 1, Token.count
end
end

Choose a reason for hiding this comment

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

Layout/TrailingBlankLines: 1 trailing blank lines detected.

@juliantodt juliantodt force-pushed the 23210_handlesptokens branch from 1b31cd1 to 28fb52a Compare June 27, 2018 08:50
Copy link
Member

@timogoebel timogoebel left a comment

Choose a reason for hiding this comment

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

@juliantodt: Thanks, some comments inline.

end

# Removes the host's name from the autosign.conf file
def delAutosign
logger.info "Delete the autosign entry for #{name}"
self.puppetca_token.delete if self.puppetca_token.present?
Copy link
Member

Choose a reason for hiding this comment

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

Please use .destroy so that callbacks run.

@@ -57,15 +65,15 @@ def queue_puppetca
end

def queue_puppetca_certname_reset
queue.create(:name => _("Reset PuppetCA certname for %s") % self, :priority => 49,
:action => [self, :resetCertname])
post_queue.create(:name => _("Reset PuppetCA certname for %s") % self, :priority => 49,
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to take a look at the post_queue?

Copy link
Member Author

Choose a reason for hiding this comment

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

To save tokens, we need the host's id which is only available after the host is saved, therefore we need these actions to happen in the post_queue

@juliantodt juliantodt force-pushed the 23210_handlesptokens branch from 28fb52a to 8ad5c2d Compare June 28, 2018 10:41
@juliantodt
Copy link
Member Author

Updated, thanks @timogoebel. Tests are now green as well.

Copy link
Member

@timogoebel timogoebel left a comment

Choose a reason for hiding this comment

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

@juliantodt: Thanks. Looks good in general.
Could you please add puppetca_token to Host::Managed::Jail so it's allowed in safe mode template rendering? Thanks.

@juliantodt
Copy link
Member Author

@timogoebel Thanks for the review, is done.

@juliantodt juliantodt force-pushed the 23210_handlesptokens branch from 7075e12 to a18186d Compare July 27, 2018 06:58
@juliantodt juliantodt force-pushed the 23210_handlesptokens branch from a18186d to 2ddb60b Compare August 24, 2018 08:03
Copy link
Member

@timogoebel timogoebel left a comment

Choose a reason for hiding this comment

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

Looks good to me. Ready to merge pending these PRs:

SmartProxy:
theforeman/smart-proxy#592

Puppet Foreman Proxy:
theforeman/puppet-foreman_proxy#433
theforeman/puppet-foreman_proxy#425

@@ -2,7 +2,7 @@ class Token < ApplicationRecord
validates_lengths_from_database
belongs_to_host :foreign_key => :host_id

validates :value, :host_id, :expires, :presence => true
validates :value, :host_id, :presence => true

class Jail < ::Safemode::Jail
allow :host, :value, :expires, :nil?
Copy link
Member

Choose a reason for hiding this comment

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

This also needs present? for the community templates PR to work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

In a new SmartProxy PuppetCA autosigning variant
tokens get returned that need to be provisioned on
the host.
@timogoebel timogoebel merged commit 30face9 into theforeman:develop Sep 19, 2018
@timogoebel
Copy link
Member

Thanks, @juliantodt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants