Skip to content

Commit

Permalink
blueprint: fix cacerts name for TOML
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap authored and thozza committed Dec 6, 2024
1 parent 4c9b590 commit e82349a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
8 changes: 7 additions & 1 deletion cmd/otk/osbuild-resolve-ostree-commit/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ func TestMockResolve(t *testing.T) {
{
"tree": {
"ref": "otk/ostree/test",
"url": "https://ostree.example.org/repo"
"url": "https://ostree.example.org/repo",
"mtls": {
"ca": "ca.crt",
"client_cert": "client.crt",
"client_key": "client.key"
},
"proxy": "proxy.example.com:8080"
}
}
`
Expand Down
5 changes: 0 additions & 5 deletions pkg/blueprint/ca_customizations.go

This file was deleted.

18 changes: 10 additions & 8 deletions pkg/blueprint/customizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Customizations struct {
Installer *InstallerCustomization `json:"installer,omitempty" toml:"installer,omitempty"`
RPM *RPMCustomization `json:"rpm,omitempty" toml:"rpm,omitempty"`
RHSM *RHSMCustomization `json:"rhsm,omitempty" toml:"rhsm,omitempty"`
CACerts *CACustomization `json:"cacerts,omitempty" toml:"ca,omitempty"`
CACerts *CACustomization `json:"cacerts,omitempty" toml:"cacerts,omitempty"`
}

type IgnitionCustomization struct {
Expand Down Expand Up @@ -144,6 +144,10 @@ type ContainerStorageCustomization struct {
StoragePath *string `json:"destination-path,omitempty" toml:"destination-path,omitempty"`
}

type CACustomization struct {
PEMCerts []string `json:"pem_certs,omitempty" toml:"pem_certs,omitempty"`
}

type CustomizationError struct {
Message string
}
Expand Down Expand Up @@ -441,16 +445,14 @@ func (c *Customizations) GetRHSM() *RHSMCustomization {
}

func (c *Customizations) checkCACerts() error {
if c == nil {
if c == nil || c.CACerts == nil {
return nil
}

if c.CACerts != nil {
for _, bundle := range c.CACerts.PEMCerts {
_, err := cert.ParseCerts(bundle)
if err != nil {
return err
}
for _, bundle := range c.CACerts.PEMCerts {
_, err := cert.ParseCerts(bundle)
if err != nil {
return err
}
}

Expand Down
21 changes: 21 additions & 0 deletions test/scripts/base-host-check.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# vim: sw=4:et
set -euo pipefail

running_wait() {
Expand Down Expand Up @@ -78,6 +79,22 @@ get_oscap_score() {
fi
}

check_ca_cert() {
serial=$(jq -r '.blueprint.customizations.cacerts.pem_certs[0]' "${config}" | openssl x509 -noout -serial | cut -d= -f 2-)

echo "📗 Checking CA cert anchor file"
if ! [ -e "/etc/pki/ca-trust/source/anchors/${serial}.pem" ]; then
echo "Anchor CA file does not exist"
exit 1
fi

echo "📗 Checking extracted CA cert file"
if ! [ -e "/etc/pki/ca-trust/source/extracted/pem/directory-hash/Test_CA_for_osbuild.pem.pem" ]; then
echo "Extracted CA file does not exist"
exit 1
fi
}

echo "❓ Checking system status"
if ! running_wait; then

Expand Down Expand Up @@ -114,4 +131,8 @@ if (( $# > 0 )); then
if jq -e .blueprint.customizations.openscap "${config}"; then
get_oscap_score "${config}"
fi

if jq -e '.blueprint.customizations.cacerts.pem_certs[0]' "${config}"; then
check_ca_cert "${config}"
fi
fi

0 comments on commit e82349a

Please sign in to comment.