Skip to content

Commit

Permalink
Add check for sha1 server certificate before upgrading
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Nov 26, 2024
1 parent e31bbdb commit c02995e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
24 changes: 24 additions & 0 deletions definitions/checks/check_sha1_certificate_authority.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Checks::CheckSha1CertificateAuthority < ForemanMaintain::Check
metadata do
label :check_sha1_certificate_authority
description 'Check if server certificate authority is sha1 signed'

confine do
feature(:katello)
end

do_not_whitelist
end

def run
installer_answers = feature(:installer).answers
server_ca = installer_answers[:certs][:server_ca_cert]

certificate = OpenSSL::X509::Certificate.new(File.read(server_ca))

assert(
certificate.signature_algorithm != 'sha1WithRSAEncryption',
"Server CA certificate signed with sha1 which will break on upgrade."
)
end
end
1 change: 1 addition & 0 deletions definitions/scenarios/foreman_upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def compose
Checks::PackageManager::Dnf::ValidateDnfConfig,
Checks::Repositories::CheckNonRhRepository,
Checks::CheckOrganizationContentAccessMode,
Checks::CheckSha1CertificateAuthority,
Checks::Repositories::Validate
)
end
Expand Down
1 change: 1 addition & 0 deletions definitions/scenarios/satellite_upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def compose
Checks::CheckIpv6Disable,
Checks::Disk::AvailableSpacePostgresql13,
Checks::CheckOrganizationContentAccessMode,
Checks::CheckSha1CertificateAuthority,
Checks::Repositories::Validate.new(:version => target_version),
)
end
Expand Down
43 changes: 43 additions & 0 deletions test/definitions/checks/check_sha1_certificate_authority_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'test_helper'

require_relative '../test_helper'
require_relative '../../../definitions/checks/check_sha1_certificate_authority'

describe Checks::CheckSha1CertificateAuthority do
include DefinitionsTestHelper

subject { Checks::CheckSha1CertificateAuthority.new }

let(:ca_cert) do
<<~CERT
-----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coGzvSEge3Pv/lUSZ3uoOobp/
-----END CERTIFICATE-----
CERT
end

it 'throws an error message when server CA certificate is signed with sha1' do
assume_feature_present(:katello)
assume_feature_present(:installer, answers: {:certs => {:server_ca_cert => 'ca-sha1.crt'}})

Check failure on line 37 in test/definitions/checks/check_sha1_certificate_authority_test.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Layout/SpaceInsideHashLiteralBraces: Space inside { missing.

Check failure on line 37 in test/definitions/checks/check_sha1_certificate_authority_test.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Layout/SpaceInsideHashLiteralBraces: Space inside { missing.

Check failure on line 37 in test/definitions/checks/check_sha1_certificate_authority_test.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Layout/SpaceInsideHashLiteralBraces: Space inside } missing.

Check failure on line 37 in test/definitions/checks/check_sha1_certificate_authority_test.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
File.expects(:read).with('ca-sha1.crt').returns(ca_cert)
result = run_step(subject)

assert result.fail?
end
end
2 changes: 2 additions & 0 deletions test/definitions/scenarios/katello_upgrade_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
Checks::Repositories::CheckNonRhRepository,
Checks::Disk::AvailableSpacePostgresql13,
Checks::CheckOrganizationContentAccessMode,
Checks::CheckSha1CertificateAuthority,
Checks::Repositories::Validate,
)
end
Expand Down Expand Up @@ -72,6 +73,7 @@
Checks::Repositories::CheckNonRhRepository,
Checks::Disk::AvailableSpacePostgresql13,
Checks::CheckOrganizationContentAccessMode,
Checks::CheckSha1CertificateAuthority,
Checks::Repositories::Validate,
)
end
Expand Down
2 changes: 2 additions & 0 deletions test/definitions/scenarios/satellite_upgrade_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
Checks::CheckIpv6Disable,
Checks::Disk::AvailableSpacePostgresql13,
Checks::CheckOrganizationContentAccessMode,
Checks::CheckSha1CertificateAuthority,
Checks::Repositories::Validate,
)
end
Expand Down Expand Up @@ -122,6 +123,7 @@
Checks::CheckIpv6Disable,
Checks::Disk::AvailableSpacePostgresql13,
Checks::CheckOrganizationContentAccessMode,
Checks::CheckSha1CertificateAuthority,
Checks::Repositories::Validate,
)
end
Expand Down

0 comments on commit c02995e

Please sign in to comment.