Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osbuild: add openscap profile and compliance policy id to facts #903

Merged
merged 2 commits into from
Sep 4, 2024
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
2 changes: 1 addition & 1 deletion pkg/distro/rhel/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func osCustomizations(
}

if t.IsRHEL() && options.Facts != nil {
osc.FactAPIType = &options.Facts.APIType
osc.RHSMFacts = options.Facts
}

var err error
Expand Down
22 changes: 17 additions & 5 deletions pkg/manifest/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"path/filepath"
"strings"

"github.com/google/uuid"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/internal/environment"
"github.com/osbuild/images/internal/workload"
Expand Down Expand Up @@ -124,7 +126,6 @@ type OSCustomizations struct {
UdevRules *osbuild.UdevRulesStageOptions
WSLConfig *osbuild.WSLConfStageOptions
LeapSecTZ *string
FactAPIType *facts.APIType
Presets []osbuild.Preset
ContainersStorage *string

Expand All @@ -134,6 +135,7 @@ type OSCustomizations struct {
Subscription *subscription.ImageOptions
// The final RHSM config to be applied to the image
RHSMConfig *subscription.RHSMConfig
RHSMFacts *facts.ImageOptions

// Custom directories and files to create in the image
Directories []*fsnode.Directory
Expand Down Expand Up @@ -747,11 +749,21 @@ func (p *OS) serialize() osbuild.Pipeline {
pipeline.AddStage(bootloader)
}

if p.FactAPIType != nil {
if p.RHSMFacts != nil {
rhsmFacts := osbuild.RHSMFacts{
ApiType: p.RHSMFacts.APIType.String(),
}

if p.RHSMFacts.OpenSCAPProfileID != "" {
rhsmFacts.OpenSCAPProfileID = p.RHSMFacts.OpenSCAPProfileID
}

if p.RHSMFacts.CompliancePolicyID != uuid.Nil {
rhsmFacts.CompliancePolicyID = p.RHSMFacts.CompliancePolicyID.String()
}

pipeline.AddStage(osbuild.NewRHSMFactsStage(&osbuild.RHSMFactsStageOptions{
Facts: osbuild.RHSMFacts{
ApiType: p.FactAPIType.String(),
},
Facts: rhsmFacts,
}))
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/osbuild/rhsm_facts_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ type RHSMFactsStageOptions struct {
}

type RHSMFacts struct {
ApiType string `json:"image-builder.osbuild-composer.api-type"`
ApiType string `json:"image-builder.osbuild-composer.api-type"`
OpenSCAPProfileID string `json:"image-builder.insights.openscap-profile-id,omitempty"`
CompliancePolicyID string `json:"image-builder.insights.compliance-policy-id,omitempty"`
}

func (RHSMFactsStageOptions) isStageOptions() {}
Expand Down
19 changes: 19 additions & 0 deletions pkg/osbuild/rhsm_facts_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ func TestRHSMFactsStageJson(t *testing.T) {
},
JsonString: fmt.Sprintf(`{"facts":{"image-builder.osbuild-composer.api-type":"%s"}}`, "test-api"),
},
{
Options: RHSMFactsStageOptions{
Facts: RHSMFacts{
ApiType: "test-api",
OpenSCAPProfileID: "test-profile-id",
},
},
JsonString: fmt.Sprintf(`{"facts":{"image-builder.osbuild-composer.api-type":"%s","image-builder.insights.openscap-profile-id":"%s"}}`, "test-api", "test-profile-id"),
},
{
Options: RHSMFactsStageOptions{
Facts: RHSMFacts{
ApiType: "test-api",
OpenSCAPProfileID: "test-profile-id",
CompliancePolicyID: "test-compliance-policy-id",
},
},
JsonString: fmt.Sprintf(`{"facts":{"image-builder.osbuild-composer.api-type":"%s","image-builder.insights.openscap-profile-id":"%s","image-builder.insights.compliance-policy-id":"%s"}}`, "test-api", "test-profile-id", "test-compliance-policy-id"),
},
}
for _, test := range tests {
marshaledJson, err := json.Marshal(test.Options)
Expand Down
10 changes: 8 additions & 2 deletions pkg/rhsm/facts/facts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package facts

import "fmt"
import (
"fmt"

"github.com/google/uuid"
)

type APIType uint64

Expand All @@ -25,5 +29,7 @@ const (
// The ImageOptions specify things to be stored into the Insights facts
// storage. This mostly relates to how the build of the image was performed.
type ImageOptions struct {
APIType APIType
APIType APIType
OpenSCAPProfileID string
CompliancePolicyID uuid.UUID
}
Loading