@@ -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
0 commit comments