Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions pkg/hostcrypt/dynamic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build libvirt
// +build libvirt

package hostcrypt

import "fmt"

func allowFIPSCluster() error {
fipsEnabled, err := hostFIPSEnabled()
if err != nil {
return err
}
if fipsEnabled {
return nil
}
return fmt.Errorf("enable FIPS mode on the host")
}
20 changes: 12 additions & 8 deletions pkg/hostcrypt/hostcrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,27 @@ func VerifyHostTargetState(fips bool) error {
if !fips {
return nil
}

if err := allowFIPSCluster(); err != nil {
return fmt.Errorf("target cluster is in FIPS mode, %w", err)
}
return nil
}

func hostFIPSEnabled() (bool, error) {
if runtime.GOOS != "linux" {
return fmt.Errorf("target cluster is in FIPS mode, operation requires a Linux client")
return false, fmt.Errorf("operation requires a Linux client")
}

hostFIPSData, err := os.ReadFile(fipsFile)
if err != nil {
return fmt.Errorf("target cluster is in FIPS mode, but failed to read client FIPS state %s: %w", fipsFile, err)
return false, fmt.Errorf("failed to read client FIPS state %s: %w", fipsFile, err)
}

hostFIPS, err := strconv.ParseBool(strings.TrimSuffix(string(hostFIPSData), "\n"))
if err != nil {
return fmt.Errorf("target cluster is in FIPS mode, but failed to parse client FIPS state %s: %w", fipsFile, err)
}

if !hostFIPS {
return fmt.Errorf("target cluster is in FIPS mode, operation requires a FIPS enabled client")
return false, fmt.Errorf("failed to parse client FIPS state %s: %w", fipsFile, err)
}

return nil
return hostFIPS, nil
}
17 changes: 17 additions & 0 deletions pkg/hostcrypt/static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build !libvirt
// +build !libvirt

package hostcrypt

import "fmt"

const binaryInstructions = "To obtain a suitable binary, download the openshift-install-rhel8 archive from the client mirror, or extract the openshift-install-fips command from the release payload."

func allowFIPSCluster() error {
hostMsg := ""
if fipsEnabled, err := hostFIPSEnabled(); err != nil || !fipsEnabled {
hostMsg = " on a host with FIPS enabled"
}
return fmt.Errorf("use the FIPS-capable installer binary for RHEL 8%s.\n%s",
hostMsg, binaryInstructions)
}