forked from suse-edge/edge-image-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for enabling FIPS mode via an operating system boolean (…
- Loading branch information
Showing
14 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package combustion | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/suse-edge/edge-image-builder/pkg/fileio" | ||
"github.com/suse-edge/edge-image-builder/pkg/image" | ||
"github.com/suse-edge/edge-image-builder/pkg/log" | ||
) | ||
|
||
const ( | ||
fipsComponentName = "fips" | ||
fipsScriptName = "15-fips-setup.sh" | ||
) | ||
|
||
var ( | ||
//go:embed templates/15-fips-setup.sh | ||
fipsScript string | ||
FipsPackages = []string{"patterns-base-fips"} | ||
FipsKernelArgs = []string{"fips=1"} | ||
) | ||
|
||
func configureFips(ctx *image.Context) ([]string, error) { | ||
fips := ctx.ImageDefinition.OperatingSystem.EnableFips | ||
if !fips { | ||
log.AuditComponentSkipped(fipsComponentName) | ||
return nil, nil | ||
} | ||
|
||
if err := writeFipsCombustionScript(ctx); err != nil { | ||
log.AuditComponentFailed(fipsComponentName) | ||
return nil, err | ||
} | ||
|
||
log.AuditComponentSuccessful(fipsComponentName) | ||
return []string{fipsScriptName}, nil | ||
} | ||
|
||
func writeFipsCombustionScript(ctx *image.Context) error { | ||
fipsScriptFilename := filepath.Join(ctx.CombustionDir, fipsScriptName) | ||
|
||
if err := os.WriteFile(fipsScriptFilename, []byte(fipsScript), fileio.ExecutablePerms); err != nil { | ||
return fmt.Errorf("writing file %s: %w", fipsScriptFilename, err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package combustion | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/suse-edge/edge-image-builder/pkg/fileio" | ||
"github.com/suse-edge/edge-image-builder/pkg/image" | ||
) | ||
|
||
func TestConfigureFips_NoConf(t *testing.T) { | ||
// Setup | ||
var ctx image.Context | ||
|
||
ctx.ImageDefinition = &image.Definition{ | ||
OperatingSystem: image.OperatingSystem{}, | ||
} | ||
|
||
// Test | ||
scripts, err := configureFips(&ctx) | ||
|
||
// Verify | ||
require.NoError(t, err) | ||
assert.Nil(t, scripts) | ||
} | ||
|
||
func TestConfigureFips_Enabled(t *testing.T) { | ||
// Setup | ||
ctx, teardown := setupContext(t) | ||
defer teardown() | ||
|
||
ctx.ImageDefinition = &image.Definition{ | ||
OperatingSystem: image.OperatingSystem{ | ||
EnableFips: true, | ||
}, | ||
} | ||
|
||
// Test | ||
scripts, err := configureFips(ctx) | ||
|
||
// Verify | ||
require.NoError(t, err) | ||
|
||
require.Len(t, scripts, 1) | ||
assert.Equal(t, fipsScriptName, scripts[0]) | ||
|
||
expectedFilename := filepath.Join(ctx.CombustionDir, fipsScriptName) | ||
foundBytes, err := os.ReadFile(expectedFilename) | ||
require.NoError(t, err) | ||
|
||
stats, err := os.Stat(expectedFilename) | ||
require.NoError(t, err) | ||
assert.Equal(t, fileio.ExecutablePerms, stats.Mode()) | ||
|
||
foundContents := string(foundBytes) | ||
|
||
// - Ensure that we have the fips setup script defined | ||
assert.Contains(t, foundContents, "fips-mode-setup --enable", "fips setup script missing") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
fips-mode-setup --enable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ operatingSystem: | |
- alpha=foo | ||
- beta=bar | ||
- baz | ||
enableFIPS: true | ||
systemd: | ||
enable: | ||
- enable0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters