Skip to content

Commit cde56f6

Browse files
(SIMP-7822) Add EPEL installer (#138)
* Added: * A `enable_epel_on` function that follows the instructions on the EPEL website to properly enable EPEL on hosts. May be disabled using `BEAKER_enable_epel=no`. * An `enable_epel_on` function that follows the instructions on the EPEL website to properly enable EPEL on hosts. May be disabled using `BEAKER_enable_epel=no`. * An Ubuntu nodeset to make sure our default settings don't destroy other Linux systems. * Ensure that crypto policies get updated across the board so that the order of FIPS enforcement is irrelevant. * Fixed: * Workaround URI.open change in Ruby 3 SIMP-7822 #comment added EPEL installer for consistency.
1 parent 0855d22 commit cde56f6

6 files changed

Lines changed: 132 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
### 1.20.0 / 2021-01-05
2+
* Added:
3+
* A `enable_epel_on` function that follows the instructions on the EPEL
4+
website to properly enable EPEL on hosts. May be disabled using
5+
`BEAKER_enable_epel=no`.
6+
* An Ubuntu nodeset to make sure our default settings don't destroy other
7+
Linux systems.
8+
* Added has_crypto_policies method for determining if crypto policies are
9+
present on the SUT
10+
* Added munge_ssh_crypto_policies to allow vagrant to SSH back into systems
11+
with restrictive crypto policies (usually FIPS)
12+
* Fixed:
13+
* Modify all crypto-policy backend files to support ssh-rsa keys
14+
* Try harder when doing yum installations
15+
116
### 1.19.4 / 2021-01-05
217
* Fixed:
318
* Only return a default empty string when `pfact_on` finds a `nil` value

lib/simp/beaker_helpers.rb

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,19 @@ def copy_fixture_modules_to( suts = hosts, opts = {})
321321
pluginsync_on(suts) if opts[:pluginsync]
322322
end
323323

324+
def has_crypto_policies(sut)
325+
file_exists_on(sut, '/etc/crypto-policies/config')
326+
end
327+
328+
def munge_ssh_crypto_policies(sut, key_types=['ssh-rsa'])
329+
if has_crypto_policies(sut)
330+
on(sut, "yum update -y crypto-policies", :accept_all_exit_codes => true)
331+
332+
# Since we may be doing this prior to having a box flip into FIPS mode, we
333+
# need to find and modify *all* of the affected policies
334+
on( sut, %{sed --follow-symlinks -i 's/PubkeyAcceptedKeyTypes\\(.\\)/PubkeyAcceptedKeyTypes\\1#{key_types.join(',')},/' $( grep -L ssh-rsa $( find /etc/crypto-policies /usr/share/crypto-policies -type f -a \\( -name '*.txt' -o -name '*.config' \\) -exec grep -l PubkeyAcceptedKeyTypes {} \\; ) ) })
335+
end
336+
end
324337

325338
# Configure and reboot SUTs into FIPS mode
326339
def enable_fips_mode_on( suts = hosts )
@@ -374,17 +387,14 @@ def enable_fips_mode_on( suts = hosts )
374387
on(sut, module_install_cmd)
375388
end
376389

377-
# Enable FIPS and then reboot to finish.
378-
on(sut, %(puppet apply --verbose #{fips_enable_modulepath} -e "class { 'fips': enabled => true }"))
379-
380390
# Work around Vagrant and cipher restrictions in EL8+
381391
#
382392
# Hopefully, Vagrant will update the used ciphers at some point but who
383393
# knows when that will be
384-
opensshserver_config = '/etc/crypto-policies/back-ends/opensshserver.config'
385-
if file_exists_on(sut, opensshserver_config)
386-
on(sut, "sed --follow-symlinks -i 's/PubkeyAcceptedKeyTypes=/PubkeyAcceptedKeyTypes=ssh-rsa,/' #{opensshserver_config}")
387-
end
394+
munge_ssh_crypto_policies(sut)
395+
396+
# Enable FIPS and then reboot to finish.
397+
on(sut, %(puppet apply --verbose #{fips_enable_modulepath} -e "class { 'fips': enabled => true }"))
388398

389399
sut.reboot
390400
end
@@ -477,6 +487,45 @@ def create_yum_resource( repo, metadata )
477487
repo_manifest = repo_manifest + %(\n#{repo_manifest_opts.join(",\n")}) + "\n}\n"
478488
end
479489

490+
# Enable EPEL if appropriate to do so and the system is online
491+
#
492+
# Can be disabled by setting BEAKER_enable_epel=no
493+
def enable_epel_on(sut)
494+
if ONLINE && (ENV['BEAKER_stringify_facts'] != 'no')
495+
os_info = fact_on(sut, 'os')
496+
os_maj_rel = os_info['release']['major']
497+
498+
# This is based on the official EPEL docs https://fedoraproject.org/wiki/EPEL
499+
if ['RedHat', 'CentOS'].include?(os_info['name'])
500+
on(
501+
sut,
502+
%{yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-#{os_maj_rel}.noarch.rpm},
503+
:max_retries => 3,
504+
:retry_interval => 10
505+
)
506+
507+
if os_info['name'] == 'RedHat'
508+
if os_maj_rel == '7'
509+
on sut, %{subscription-manager repos --enable "rhel-*-optional-rpms"}
510+
on sut, %{subscription-manager repos --enable "rhel-*-extras-rpms"}
511+
on sut, %{subscription-manager repos --enable "rhel-ha-for-rhel-*-server-rpms"}
512+
end
513+
514+
if os_maj_rel == '8'
515+
on sut, %{subscription-manager repos --enable "codeready-builder-for-rhel-8-#{os_info['architecture']}-rpms"}
516+
end
517+
end
518+
519+
if os_info['name'] == 'CentOS'
520+
if os_maj_rel == '8'
521+
# 8.0 fallback
522+
on sut, %{dnf config-manager --set-enabled powertools || dnf config-manager --set-enabled PowerTools}
523+
end
524+
end
525+
end
526+
end
527+
end
528+
480529
def linux_errata( sut )
481530
# We need to be able to flip between server and client without issue
482531
on sut, 'puppet resource group puppet gid=52'
@@ -562,6 +611,7 @@ def linux_errata( sut )
562611
end
563612

564613
enable_yum_repos_on(sut)
614+
enable_epel_on(sut)
565615

566616
# net-tools required for netstat utility being used by be_listening
567617
if fact_on(sut, 'operatingsystemmajrelease') == '7'
@@ -1246,11 +1296,21 @@ def install_simp_repos(sut, disable = [])
12461296
# NOTE: Do *NOT* use puppet in this method since it may not be available yet
12471297

12481298
if on(sut, 'rpm -q yum-utils', :accept_all_exit_codes => true).exit_code != 0
1249-
on(sut, 'yum -y install yum-utils')
1299+
on(
1300+
sut,
1301+
'yum -y install yum-utils',
1302+
:max_retries => 3,
1303+
:retry_interval => 10
1304+
)
12501305
end
12511306

12521307
if on(sut, 'rpm -q simp-release-community', :accept_all_exit_codes => true).exit_code != 0
1253-
on(sut, 'yum -y install "https://download.simp-project.com/simp-release-community.rpm"')
1308+
on(
1309+
sut,
1310+
'yum -y install "https://download.simp-project.com/simp-release-community.rpm"',
1311+
:max_retries => 3,
1312+
:retry_interval => 10
1313+
)
12541314
end
12551315

12561316
to_disable = disable.dup

lib/simp/beaker_helpers/constants.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ module Simp::BeakerHelpers
1717
require 'open-uri'
1818

1919
begin
20-
ONLINE = true if open('http://google.com')
20+
if URI.respond_to?(:open)
21+
ONLINE = true if URI.open('http://google.com')
22+
else
23+
ONLINE = true if open('http://google.com')
24+
end
2125
rescue
2226
ONLINE = false
2327
end

lib/simp/beaker_helpers/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Simp; end
22

33
module Simp::BeakerHelpers
4-
VERSION = '1.19.4'
4+
VERSION = '1.20.0'
55
end

spec/acceptance/nodesets/default.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@
66
end
77
-%>
88
HOSTS:
9-
server-el7:
9+
el7:
1010
roles:
11-
- server
12-
- master
13-
- default
1411
- el7
12+
- master
1513
platform: el-7-x86_64
1614
box: centos/7
1715
hypervisor: <%= hypervisor %>
1816

19-
server-el8:
17+
el8:
18+
roles:
19+
- el8
20+
platform: el-8-x86_64
21+
box: centos/8
22+
hypervisor: <%= hypervisor %>
23+
24+
el8-0:
2025
roles:
2126
- el8
2227
platform: el-8-x86_64
2328
box: centos/8
29+
box_version: "1905.1"
2430
hypervisor: <%= hypervisor %>
2531

2632
CONFIG:
@@ -30,3 +36,14 @@ CONFIG:
3036
<% if ENV['BEAKER_PUPPET_COLLECTION'] -%>
3137
puppet_collection: <%= ENV['BEAKER_PUPPET_COLLECTION'] %>
3238
<% end -%>
39+
ssh:
40+
keepalive: true
41+
keepalive_interval: 10
42+
host_key:
43+
- <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:host_key].join("\n#{' '*6}- ") %>
44+
kex:
45+
- <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:kex].join("\n#{' '*6}- ") %>
46+
encryption:
47+
- <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:encryption].join("\n#{' '*6}- ") %>
48+
hmac:
49+
- <%= Net::SSH::Transport::Algorithms::ALGORITHMS[:hmac].join("\n#{' '*6}- ") %>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<%
2+
if ENV['BEAKER_HYPERVISOR']
3+
hypervisor = ENV['BEAKER_HYPERVISOR']
4+
else
5+
hypervisor = 'vagrant'
6+
end
7+
-%>
8+
HOSTS:
9+
focal:
10+
platform: ubuntu-20.04-x86_64
11+
box: ubuntu/focal64
12+
hypervisor: <%= hypervisor %>
13+
14+
CONFIG:
15+
log_level: verbose
16+
type: aio
17+
vagrant_memsize: 256
18+
<% if ENV['BEAKER_PUPPET_COLLECTION'] -%>
19+
puppet_collection: <%= ENV['BEAKER_PUPPET_COLLECTION'] %>
20+
<% end -%>

0 commit comments

Comments
 (0)