-
Notifications
You must be signed in to change notification settings - Fork 222
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 #23799 - Refactor: Make PuppetCa pluggable #586
Conversation
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 like solid work. I just left some small comments regarding naming. If they are resolved this looks ready to 🚢.
@@ -2,7 +2,9 @@ | |||
# Can be true, false, or http/https to enable just one of the protocols | |||
:enabled: false | |||
|
|||
# valid providers: | |||
# - puppetca_hostverify (verify CSRs based on hostnames) |
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.
Puppet calls this basic autosigning. I think we should stick with the term or use something like autosignfile
.
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.
I don't like basic autosigning
because it says nothing about how it works, autosignfile
is better, but because the token based approach will also use a file it is not clear which is which. The thing that will distinguish the providers is the attribute which is compared during autosigning which is certname
vs. token
.
So imho the best name would be puppetca_hostnamebasedautosigning
(or certnamebased
) but this is a pain to read.
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.
How about HostnameWhitelisting
?
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.
I like that, but wouldn't we want to use snake_case?
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.
Yep, 🐍.
|
||
class NotPresent < RuntimeError; end | ||
|
||
class << self | ||
class Certmanager |
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.
Can we find a better name for this? It's not clear what this is doing. Maybe something like CaInterface
or CertificateAuthority
?
@@ -0,0 +1,57 @@ | |||
module ::Proxy::PuppetCa::Hostverify | |||
class Autosigner |
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.
Sorry to be so picky about the names, but what about FileBasedAutosign
.
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.
The token-based-autosigning-approach will also use a file, so that would not work. See above.
modules/puppetca/puppetca_api.rb
Outdated
@@ -2,14 +2,18 @@ | |||
|
|||
module Proxy::PuppetCa | |||
class Api < ::Sinatra::Base | |||
extend Proxy::PuppetCa::DependencyInjection | |||
inject_attr :cert_manager, :cert_manager |
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.
I'd call this ca
or ca_interface
or something similar.
E.g. inject_attr :ca_provider, :ca
reads a lot cleaner in my opinion.
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.
Well ca
is the whole thing, which consists of managing certificates and autosign-entries. Since the cert_manager
basically uses the puppet cert
command for everything it does, I thought this would be matching name.
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.
I don't see autosigning as part of the CA. Basically you have two separate strings:
- Interface to the CA (ask the ca to issue/remove/... a certificate, ...)
- Interface to an autosigning provider (list whitelisted hosts, whitelist a host, ...). This is typically not part of the CA, but of the RA.
Certmanager is definitely misleading. Please use something else.
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.
Well, its part of the puppetCA module and under the puppet/ca/
api endpoint...
But I can understand that that may be confusing, how about just puppet_cert
so its obvious it uses the puppet cert
command?
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.
Ok, works for me.
modules/puppetca/puppetca_api.rb
Outdated
@@ -2,14 +2,18 @@ | |||
|
|||
module Proxy::PuppetCa | |||
class Api < ::Sinatra::Base | |||
extend Proxy::PuppetCa::DependencyInjection | |||
inject_attr :cert_manager, :cert_manager | |||
inject_attr :autosigner, :autosigner |
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.
How about just autosign
?
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.
I like to refer to objects with nouns, makes it better to read imho ^^
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.
Ok, works for me.
require 'puppetca_hostverify/puppetca_hostverify' | ||
require 'puppetca_hostverify/puppetca_hostverify_plugin' | ||
|
||
class PuppetCAHostverifyConfigTest < Test::Unit::TestCase |
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.
Nit: Please stick either to Ca
or CA
. I'd prefer the former.
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.
Thanks! Left some thoughts about the naming inline @timogoebel
@@ -2,7 +2,9 @@ | |||
# Can be true, false, or http/https to enable just one of the protocols | |||
:enabled: false | |||
|
|||
# valid providers: | |||
# - puppetca_hostverify (verify CSRs based on hostnames) |
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.
I don't like basic autosigning
because it says nothing about how it works, autosignfile
is better, but because the token based approach will also use a file it is not clear which is which. The thing that will distinguish the providers is the attribute which is compared during autosigning which is certname
vs. token
.
So imho the best name would be puppetca_hostnamebasedautosigning
(or certnamebased
) but this is a pain to read.
modules/puppetca/puppetca_api.rb
Outdated
@@ -2,14 +2,18 @@ | |||
|
|||
module Proxy::PuppetCa | |||
class Api < ::Sinatra::Base | |||
extend Proxy::PuppetCa::DependencyInjection | |||
inject_attr :cert_manager, :cert_manager |
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.
Well ca
is the whole thing, which consists of managing certificates and autosign-entries. Since the cert_manager
basically uses the puppet cert
command for everything it does, I thought this would be matching name.
modules/puppetca/puppetca_api.rb
Outdated
@@ -2,14 +2,18 @@ | |||
|
|||
module Proxy::PuppetCa | |||
class Api < ::Sinatra::Base | |||
extend Proxy::PuppetCa::DependencyInjection | |||
inject_attr :cert_manager, :cert_manager | |||
inject_attr :autosigner, :autosigner |
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.
I like to refer to objects with nouns, makes it better to read imho ^^
@@ -0,0 +1,57 @@ | |||
module ::Proxy::PuppetCa::Hostverify | |||
class Autosigner |
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.
The token-based-autosigning-approach will also use a file, so that would not work. See above.
4ce8ee0
to
e490faf
Compare
Updated the PR with the requested naming changes. |
@@ -2,14 +2,18 @@ | |||
|
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.
The line above has to be changed to require 'puppetca/puppetca_puppet_cert'
as modules/puppetca/puppetca_main.rb is renamed to modules/puppetca/puppetca_puppet_cert.rb so it can load the feature.
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.
puppetca/puppetca_puppet_cert
is loaded via plugin_configuration::load_classes
, so we don't need it here. This require can therefore be deleted.
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.
You are right, deleting it works also.
e490faf
to
0dcd549
Compare
Fixed @dgoetz. Added a migration for the settings, so that users who had set the |
0dcd549
to
58e983b
Compare
58e983b
to
641f2e4
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.
Tested the latest commit including the migration and it works.
Thanks, @juliantodt. |
Looks like nightly bats tests are now failing with an error regarding PuppetCA, could it be related to this change? http://ci.theforeman.org/blue/rest/organizations/jenkins/pipelines/foreman-nightly-release/runs/248/nodes/34/steps/41/log/?start=0 |
@tbrisker: Yes, it is probably related. The proxy logs could be helpful. |
We already have a PR open to fix the puppet modules, see theforeman/puppet-foreman_proxy#433. |
Thanks @juliantodt and @timogoebel! in the future, when something requires changes in multiple repos, please make sure all PRs are ready to merge first and are merged in coordination to avoid breakages such as this. |
@juliantodt @timogoebel Care to update the manuals for 1.19 forward with this change? Looks like some users are stumbling on it - https://community.theforeman.org/t/puppetca-foreman-proxy-disabled-beacuse-of-autosign-issue/12290 |
Since we are planning to offer alternative options for autosinging in the future (token based instead of hostname based) (see redmine issue) and want to allow users to choose their autosigning variant (primarily to allow compatibility with old versions, old foreman versions etc) we need to make the PuppetCA module pluggable, which means moving the autosinging functionality to a provider, which can then be swapped using the SmartProxy settings. We also want to clean up the module a bit and use dependency injections etc. The common logic for listing/signing/cleaning certificates (not autosign-entries) that uses the
puppet cert
command will remain in the puppetca-module.This is btw an alternative approach to #576 which should allow for backwards compatibility and a compatible API between the autosigning variants.