-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #23799 - Refactor: Make PuppetCa pluggable
- Loading branch information
Julian Todt
committed
Jun 7, 2018
1 parent
14a7505
commit 4ce8ee0
Showing
17 changed files
with
225 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
# | ||
# Configuration of the PuppetCA hostverify provider | ||
# | ||
|
||
#:autosignfile: /etc/puppet/autosign.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Proxy::PuppetCa | ||
module DependencyInjection | ||
include Proxy::DependencyInjection::Accessors | ||
def container_instance | ||
@container_instance ||= ::Proxy::Plugins.instance.find {|p| p[:name] == :puppetca }[:di_container] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module ::Proxy::PuppetCa | ||
class PluginConfiguration | ||
def load_classes | ||
require 'puppetca/puppetca_certmanager' | ||
require 'puppetca/dependency_injection' | ||
require 'puppetca/puppetca_api' | ||
end | ||
|
||
def load_dependency_injection_wirings(container_instance, settings) | ||
container_instance.dependency :cert_manager, lambda { ::Proxy::PuppetCa::Certmanager.new } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
require 'puppetca/plugin_configuration' | ||
require 'puppetca/puppetca_plugin' | ||
|
||
module Proxy::PuppetCa; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module ::Proxy::PuppetCa::Hostverify | ||
class PluginConfiguration | ||
def load_classes | ||
require 'puppetca_hostverify/puppetca_hostverify_autosigner' | ||
end | ||
|
||
def load_dependency_injection_wirings(container_instance, settings) | ||
container_instance.dependency :autosigner, lambda { ::Proxy::PuppetCa::Hostverify::Autosigner.new } | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'puppetca_hostverify/plugin_configuration' | ||
require 'puppetca_hostverify/puppetca_hostverify_plugin' |
57 changes: 57 additions & 0 deletions
57
modules/puppetca_hostverify/puppetca_hostverify_autosigner.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module ::Proxy::PuppetCa::Hostverify | ||
class Autosigner | ||
include ::Proxy::Log | ||
include ::Proxy::Util | ||
|
||
def autosign_file | ||
Proxy::PuppetCa::Hostverify::Plugin.settings.autosignfile | ||
end | ||
|
||
#remove certname from autosign if exists | ||
def disable certname | ||
raise "No such file #{autosign_file}" unless File.exist?(autosign_file) | ||
|
||
found = false | ||
entries = File.readlines(autosign_file).collect do |l| | ||
if l.chomp != certname | ||
l | ||
else | ||
found = true | ||
nil | ||
end | ||
end.uniq.compact | ||
if found | ||
open(autosign_file, File::TRUNC|File::RDWR) do |autosign| | ||
autosign.write entries.join | ||
end | ||
logger.debug "Removed #{certname} from autosign" | ||
else | ||
logger.debug "Attempt to remove nonexistent client autosign for #{certname}" | ||
raise ::Proxy::PuppetCa::NotPresent, "Attempt to remove nonexistent client autosign for #{certname}" | ||
end | ||
end | ||
|
||
# add certname to puppet autosign file | ||
# parameter is certname to use | ||
def autosign certname | ||
FileUtils.touch(autosign_file) unless File.exist?(autosign_file) | ||
|
||
open(autosign_file, File::RDWR) do |autosign| | ||
# Check that we don't have that host already | ||
found = autosign.readlines.find { |line| line.chomp == certname } | ||
autosign.puts certname unless found | ||
end | ||
logger.debug "Added #{certname} to autosign" | ||
end | ||
|
||
# list of hosts which are now allowed to be installed via autosign | ||
def autosign_list | ||
return [] unless File.exist?(autosign_file) | ||
File.read(autosign_file).split("\n").reject do |v| | ||
v =~ /^\s*#.*|^$/ ## Remove comments and empty lines | ||
end.map do |v| | ||
v.chomp ## Strip trailing spaces | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module ::Proxy::PuppetCa::Hostverify | ||
class Plugin < ::Proxy::Provider | ||
plugin :puppetca_hostverify, ::Proxy::VERSION | ||
|
||
requires :puppetca, ::Proxy::VERSION | ||
default_settings :autosignfile => '/etc/puppet/autosign.conf' | ||
|
||
load_classes ::Proxy::PuppetCa::Hostverify::PluginConfiguration | ||
load_dependency_injection_wirings ::Proxy::PuppetCa::Hostverify::PluginConfiguration | ||
end | ||
end |
Oops, something went wrong.