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

Add support for client in Bash installation #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
# path to host private key, usually puppet agent private key
# May be overriden if the rh_certificate_consumer_host_key fact is found
#
# @param package_name
# Package name for Ruby foreman_scap_client package
#
# @param package_provider
# @param package_provider
# provider for the package, defaults to yum but can be set to gem, or any other valid
# puppet package provider
#
Expand Down Expand Up @@ -80,6 +77,9 @@
# @param timeout
# Timeout when sending reports to proxy
#
# @param obsolete
# Whether to use the obsolete client wrapper in Ruby
#
# @example Run a weekly SCAP audit
# class { foreman_scap_client:
# server => 'proxy.example.com',
Expand Down Expand Up @@ -110,7 +110,6 @@
Stdlib::Absolutepath $ca_file = $foreman_scap_client::params::ca_file,
Stdlib::Absolutepath $host_certificate = $foreman_scap_client::params::host_certificate,
Stdlib::Absolutepath $host_private_key = $foreman_scap_client::params::host_private_key,
String $package_name = 'rubygem-foreman_scap_client',
Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about leaving this, but found in git history that we dropped support for Debian based package.

Choose a reason for hiding this comment

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

I'd rather keep it in. We (as theforeman org on github) might have dropped it, but our friends at atix still carry it in their repos https://oss.atix.de/Debian12/pool/ , although the version there is a bit dated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Then I'd need a Puppet master to teach me how one can reassign that variable since Puppet doesn't allow me :/ A different way will be to leave this variable and then add another one as a flag to choose. Or maybe revert c4270a1#diff-e78db79abb0b543310767fb9d2814cc4e2408f613de4985186251c70bdd4edbbL6 and add a similar check, but I have no idea how I can propagate obsolete variable in there...

@ekohl, since you're the master and the maintainer, can I ask you for a hint maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I've found a way, but for Debian installation it'll require to provide obsolete = true with a different package name to mimik current behavior.

By default it'll try to install the new package with the new config.

Optional[String] $package_provider = undef,
Optional[String] $foreman_repo_rel = undef,
String $foreman_repo_key = 'https://yum.theforeman.org/RPM-GPG-KEY-foreman',
Expand All @@ -120,9 +119,21 @@
String $cron_template = 'foreman_scap_client/cron.erb',
Integer[0] $cron_splay = 600,
Integer[0] $timeout = 60,
Boolean $obsolete = true,
) inherits foreman_scap_client::params {
$cron_sleep = fqdn_rand($cron_splay)

if $obsolete {
$package_name = 'rubygem-foreman_scap_client'
$config_path = '/etc/foreman_scap_client/config.yaml'
$template_path = 'foreman_scap_client/config.yaml.erb'
}
else {
$package_name = 'rubygem-foreman_scap_client_bash'
$config_path = '/etc/foreman_scap_client/config'
$template_path = 'foreman_scap_client/config.erb'
}

if $foreman_repo_rel {
if $foreman_repo_key =~ /^http/ {
$gpgkey = $foreman_repo_key
Expand Down Expand Up @@ -176,8 +187,8 @@

file { 'foreman_scap_client':
ensure => file,
path => '/etc/foreman_scap_client/config.yaml',
content => template('foreman_scap_client/config.yaml.erb'),
path => $config_path,
content => template($template_path),
owner => 'root',
}

Expand Down
18 changes: 18 additions & 0 deletions spec/acceptance/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,22 @@
describe package('rubygem-foreman_scap_client') do
it { is_expected.to be_installed }
end

it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<~PUPPET
class { 'foreman_scap_client':
foreman_repo_rel => 'nightly',
server => 'foreman.example.com',
port => 8443,
policies => [ { id: 1, profile_id: 'default', content_path: '/usr/share/xml/scap/ssg/content/ssg-rhel7-ds.xml' } ],
adamruzicka marked this conversation as resolved.
Show resolved Hide resolved
obsolete => false,
}
PUPPET
end
end

describe package('rubygem-foreman_scap_client_bash') do
it { is_expected.to be_installed }

Check failure on line 36 in spec/acceptance/basic_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - CentOS 9

foreman_scap_client Package "rubygem-foreman_scap_client_bash" is expected to be installed Failure/Error: it { is_expected.to be_installed } expected Package "rubygem-foreman_scap_client_bash" to be installed

Check failure on line 36 in spec/acceptance/basic_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - CentOS 9

foreman_scap_client Package "rubygem-foreman_scap_client_bash" is expected to be installed Failure/Error: it { is_expected.to be_installed } expected Package "rubygem-foreman_scap_client_bash" to be installed

Check failure on line 36 in spec/acceptance/basic_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - AlmaLinux 8

foreman_scap_client Package "rubygem-foreman_scap_client_bash" is expected to be installed Failure/Error: it { is_expected.to be_installed } expected Package "rubygem-foreman_scap_client_bash" to be installed

Check failure on line 36 in spec/acceptance/basic_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - AlmaLinux 8

foreman_scap_client Package "rubygem-foreman_scap_client_bash" is expected to be installed Failure/Error: it { is_expected.to be_installed } expected Package "rubygem-foreman_scap_client_bash" to be installed

Check failure on line 36 in spec/acceptance/basic_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - AlmaLinux 9

foreman_scap_client Package "rubygem-foreman_scap_client_bash" is expected to be installed Failure/Error: it { is_expected.to be_installed } expected Package "rubygem-foreman_scap_client_bash" to be installed

Check failure on line 36 in spec/acceptance/basic_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - AlmaLinux 9

foreman_scap_client Package "rubygem-foreman_scap_client_bash" is expected to be installed Failure/Error: it { is_expected.to be_installed } expected Package "rubygem-foreman_scap_client_bash" to be installed
end
end
23 changes: 23 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@
.with_content(%r{^:host_private_key: '/etc/rhsm/host/key\.pem'$})
end
end

context 'with flag to install bash version' do
let(:params) do
super().merge({
obsolete: false,
policies: [
{
id: 1,
profile_id: 'default',
content_path: '/usr/share/xml/scap/ssg/content/ssg-rhel7-ds.xml',
}
]
})
end

it { is_expected.to compile.with_all_deps }
it do
is_expected.to contain_file('foreman_scap_client')
.with_path('/etc/foreman_scap_client/config')
.with_content(%r{^POLICY_1_PROFILE="default"$})
.with_content(%r{^POLICY_1_CONTENT_PATH="/usr/share/xml/scap/ssg/content/ssg-rhel7-ds.xml"$})
end
end
end
end
end
Expand Down
41 changes: 41 additions & 0 deletions templates/config.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# DO NOT EDIT THIS FILE MANUALLY
# IT IS MANAGED BY PUPPET

# Foreman proxy to which reports should be uploaded
SERVER="<%= @server %>"
PORT=<%= @port %>

# Timeout for sending reports to proxy
TIMEOUT=<%= @timeout %>

# Should --fetch-remote-resources be added to `oscap xccdf eval` command
FETCH_REMOTE_RESOURCES="<%= @fetch_remote_resources %>"

# HTTP proxy server for downloading remote resources
HTTP_PROXY_SERVER="<%= @http_proxy_server %>"
HTTP_PROXY_PORT="<%= @http_proxy_port %>"

## SSL specific options ##
# Client CA file.
# It could be Puppet CA certificate (e.g., '/var/lib/puppet/ssl/certs/ca.pem')
# Or (recommended for client reporting to Katello) subscription manager CA file, (e.g., '/etc/rhsm/ca/katello-server-ca.pem')
CA_FILE="<%= @ca_file %>"
# Client host certificate.
# It could be Puppet agent host certificate (e.g., '/var/lib/puppet/ssl/certs/myhost.example.com.pem')
# Or (recommended for client reporting to Katello) consumer certificate (e.g., '/etc/pki/consumer/cert.pem')
HOST_CERTIFICATE="<%= @host_certificate %>"
# Client private key
# It could be Puppet agent private key (e.g., '/var/lib/puppet/ssl/private_keys/myhost.example.com.pem')
# Or (recommended for client reporting to Katello) consumer private key (e.g., '/etc/pki/consumer/key.pem')
HOST_PRIVATE_KEY="<%= @host_private_key %>"

# policy (key is id as in Foreman)
<% @policies.each do |policy| %>
POLICY_<%= policy['id'] -%>_PROFILE="<%= policy['profile_id'] -%>"
POLICY_<%= policy['id'] -%>_CONTENT_PATH="<%= policy['content_path'] -%>"
# Download path
# A path to download SCAP content from proxy
POLICY_<%= policy['id'] -%>_DOWNLOAD_PATH="<%= policy['download_path'] -%>"
POLICY_<%= policy['id'] -%>_TAILORING_PATH="<%= policy['tailoring_path'] -%>"
POLICY_<%= policy['id'] -%>_TAILORING_DOWNLOAD_PATH="<%= policy['tailoring_download_path'] -%>"
<% end %>
Loading