Skip to content

Commit b80f72c

Browse files
Merge pull request openshift#8760 from andfasano/day2-fips
AGENT-900: enable fips for add-nodes workflow
2 parents 6dfd868 + 606b4d1 commit b80f72c

File tree

5 files changed

+139
-11
lines changed

5 files changed

+139
-11
lines changed

hack/build-node-joiner.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ then
4444
GOOS='' GOARCH='' go generate ./data
4545
fi
4646

47+
if (echo "${TAGS}" | grep -q '\bfipscapable\b')
48+
then
49+
export CGO_ENABLED=1
50+
fi
51+
4752
echo "building node-joiner"
4853

4954
# shellcheck disable=SC2086

pkg/asset/agent/image/kargs.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package image
22

33
import (
44
"context"
5+
"fmt"
56

67
"github.com/sirupsen/logrus"
78

89
hiveext "github.com/openshift/assisted-service/api/hiveextension/v1beta1"
910
"github.com/openshift/assisted-service/models"
1011
"github.com/openshift/installer/pkg/asset"
12+
"github.com/openshift/installer/pkg/asset/agent/joiner"
1113
"github.com/openshift/installer/pkg/asset/agent/manifests"
1214
"github.com/openshift/installer/pkg/asset/agent/workflow"
1315
)
@@ -22,28 +24,33 @@ type Kargs struct {
2224
func (a *Kargs) Dependencies() []asset.Asset {
2325
return []asset.Asset{
2426
&workflow.AgentWorkflow{},
27+
&joiner.ClusterInfo{},
2528
&manifests.AgentClusterInstall{},
2629
}
2730
}
2831

2932
// Generate generates the kernel args configurations for the agent ISO image and PXE assets.
3033
func (a *Kargs) Generate(_ context.Context, dependencies asset.Parents) error {
3134
agentWorkflow := &workflow.AgentWorkflow{}
35+
clusterInfo := &joiner.ClusterInfo{}
3236
agentClusterInstall := &manifests.AgentClusterInstall{}
33-
dependencies.Get(agentClusterInstall, agentWorkflow)
37+
dependencies.Get(agentClusterInstall, agentWorkflow, clusterInfo)
3438

35-
// Not required for AddNodes workflow
36-
if agentWorkflow.Workflow == workflow.AgentWorkflowTypeAddNodes {
37-
return nil
38-
}
39+
switch agentWorkflow.Workflow {
40+
case workflow.AgentWorkflowTypeInstall:
41+
a.fips = agentClusterInstall.FIPSEnabled()
42+
// Add kernel args for external oci platform
43+
if agentClusterInstall.GetExternalPlatformName() == string(models.PlatformTypeOci) {
44+
logrus.Debugf("Added kernel args to enable serial console for %s %s platform", hiveext.ExternalPlatformType, string(models.PlatformTypeOci))
45+
a.consoleArgs = " console=ttyS0"
46+
}
3947

40-
// Add kernel args for external oci platform
41-
if agentClusterInstall.GetExternalPlatformName() == string(models.PlatformTypeOci) {
42-
logrus.Debugf("Added kernel args to enable serial console for %s %s platform", hiveext.ExternalPlatformType, string(models.PlatformTypeOci))
43-
a.consoleArgs = " console=ttyS0"
44-
}
48+
case workflow.AgentWorkflowTypeAddNodes:
49+
a.fips = clusterInfo.FIPS
4550

46-
a.fips = agentClusterInstall.FIPSEnabled()
51+
default:
52+
return fmt.Errorf("AgentWorkflowType value not supported: %s", agentWorkflow.Workflow)
53+
}
4754

4855
return nil
4956
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package image
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
10+
"github.com/openshift/assisted-service/api/hiveextension/v1beta1"
11+
"github.com/openshift/installer/pkg/asset"
12+
"github.com/openshift/installer/pkg/asset/agent/joiner"
13+
"github.com/openshift/installer/pkg/asset/agent/manifests"
14+
"github.com/openshift/installer/pkg/asset/agent/workflow"
15+
)
16+
17+
func TestKargs_Generate(t *testing.T) {
18+
cases := []struct {
19+
name string
20+
workflow workflow.AgentWorkflowType
21+
agentClusterInstall *manifests.AgentClusterInstall
22+
clusterInfo *joiner.ClusterInfo
23+
expectedArgs string
24+
expectedErr string
25+
}{
26+
{
27+
name: "install workflow - default",
28+
workflow: workflow.AgentWorkflowTypeInstall,
29+
expectedArgs: "",
30+
},
31+
{
32+
name: "install workflow - fips enabled",
33+
workflow: workflow.AgentWorkflowTypeInstall,
34+
agentClusterInstall: &manifests.AgentClusterInstall{
35+
Config: &v1beta1.AgentClusterInstall{
36+
ObjectMeta: v1.ObjectMeta{
37+
Annotations: map[string]string{
38+
"agent-install.openshift.io/install-config-overrides": `{"fips": true}`,
39+
},
40+
},
41+
},
42+
},
43+
expectedArgs: " fips=1",
44+
},
45+
{
46+
name: "install workflow - oci with fips enabled",
47+
workflow: workflow.AgentWorkflowTypeInstall,
48+
agentClusterInstall: &manifests.AgentClusterInstall{
49+
Config: &v1beta1.AgentClusterInstall{
50+
ObjectMeta: v1.ObjectMeta{
51+
Annotations: map[string]string{
52+
"agent-install.openshift.io/install-config-overrides": `{"fips": true}`,
53+
},
54+
},
55+
Spec: v1beta1.AgentClusterInstallSpec{
56+
ExternalPlatformSpec: &v1beta1.ExternalPlatformSpec{
57+
PlatformName: "oci",
58+
},
59+
},
60+
},
61+
},
62+
expectedArgs: " console=ttyS0 fips=1",
63+
},
64+
{
65+
name: "add-nodes workflow - default",
66+
workflow: workflow.AgentWorkflowTypeAddNodes,
67+
expectedArgs: "",
68+
},
69+
{
70+
name: "add-nodes workflow - fips enabled",
71+
workflow: workflow.AgentWorkflowTypeAddNodes,
72+
clusterInfo: &joiner.ClusterInfo{
73+
FIPS: true,
74+
},
75+
expectedArgs: " fips=1",
76+
},
77+
}
78+
for _, tc := range cases {
79+
t.Run(tc.name, func(t *testing.T) {
80+
dependencies := []asset.Asset{
81+
&workflow.AgentWorkflow{Workflow: tc.workflow},
82+
}
83+
aci := &manifests.AgentClusterInstall{
84+
Config: &v1beta1.AgentClusterInstall{},
85+
}
86+
if tc.agentClusterInstall != nil {
87+
aci = tc.agentClusterInstall
88+
}
89+
ci := &joiner.ClusterInfo{}
90+
if tc.clusterInfo != nil {
91+
ci = tc.clusterInfo
92+
}
93+
94+
dependencies = append(dependencies, ci)
95+
dependencies = append(dependencies, aci)
96+
parents := asset.Parents{}
97+
parents.Add(dependencies...)
98+
99+
kargs := &Kargs{}
100+
err := kargs.Generate(context.Background(), parents)
101+
102+
if tc.expectedErr == "" {
103+
assert.NoError(t, err)
104+
assert.Equal(t, tc.expectedArgs, string(kargs.KernelCmdLine()))
105+
} else {
106+
assert.Regexp(t, tc.expectedErr, err.Error())
107+
}
108+
})
109+
}
110+
}

pkg/asset/agent/joiner/clusterinfo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type ClusterInfo struct {
5050
OSImage *stream.Stream
5151
OSImageLocation string
5252
IgnitionEndpointWorker *models.IgnitionEndpoint
53+
FIPS bool
5354
}
5455

5556
var _ asset.WritableAsset = (*ClusterInfo)(nil)
@@ -244,6 +245,7 @@ func (ci *ClusterInfo) retrieveInstallConfigData() error {
244245
ci.SSHKey = installConfig.SSHKey
245246
ci.ClusterName = installConfig.ObjectMeta.Name
246247
ci.APIDNSName = fmt.Sprintf("api.%s.%s", ci.ClusterName, installConfig.BaseDomain)
248+
ci.FIPS = installConfig.FIPS
247249

248250
return nil
249251
}

pkg/asset/agent/joiner/clusterinfo_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func TestClusterInfo_Generate(t *testing.T) {
161161
URL: ptr.To("https://192.168.111.5:22623/config/worker"),
162162
CaCertificate: ptr.To("LS0tL_FakeCertificate_LS0tCg=="),
163163
},
164+
FIPS: true,
164165
},
165166
},
166167
{
@@ -276,6 +277,7 @@ func TestClusterInfo_Generate(t *testing.T) {
276277
SSHKey: "my-ssh-key",
277278
OSImage: buildStreamData(),
278279
OSImageLocation: "http://my-coreosimage-url/416.94.202402130130-1",
280+
FIPS: true,
279281
},
280282
},
281283
}
@@ -314,6 +316,7 @@ func TestClusterInfo_Generate(t *testing.T) {
314316
assert.Equal(t, tc.expectedClusterInfo.OSImageLocation, clusterInfo.OSImageLocation)
315317
assert.Equal(t, tc.expectedClusterInfo.OSImage, clusterInfo.OSImage)
316318
assert.Equal(t, tc.expectedClusterInfo.IgnitionEndpointWorker, clusterInfo.IgnitionEndpointWorker)
319+
assert.Equal(t, tc.expectedClusterInfo.FIPS, clusterInfo.FIPS)
317320
})
318321
}
319322
}
@@ -382,6 +385,7 @@ func makeInstallConfig(t *testing.T) string {
382385
BareMetal: &baremetal.Platform{},
383386
},
384387
SSHKey: "my-ssh-key",
388+
FIPS: true,
385389
}
386390
data, err := yaml.Marshal(ic)
387391
if err != nil {

0 commit comments

Comments
 (0)