-
Notifications
You must be signed in to change notification settings - Fork 994
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
Fixes #23210 - Handle PuppetCA tokens #5730
Conversation
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}" |
There was a problem hiding this comment.
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.
37d8ece
to
b4c8ffe
Compare
b4c8ffe
to
1b31cd1
Compare
test/models/token/build_test.rb
Outdated
assert_equal 1, Token.count | ||
end | ||
end | ||
|
There was a problem hiding this comment.
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.
1b31cd1
to
28fb52a
Compare
There was a problem hiding this 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? |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
28fb52a
to
8ad5c2d
Compare
Updated, thanks @timogoebel. Tests are now green as well. |
There was a problem hiding this 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.
8ad5c2d
to
7075e12
Compare
@timogoebel Thanks for the review, is done. |
7075e12
to
a18186d
Compare
a18186d
to
2ddb60b
Compare
There was a problem hiding this 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
app/models/token.rb
Outdated
@@ -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? |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
2ddb60b
to
29916f1
Compare
Thanks, @juliantodt. |
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.