Skip to content

Commit c89bfc7

Browse files
davidhadasdavidhIBM
authored andcommitted
SecureComms: E2e test SecureComms without KBS
Add support for e2e testing SecureComms without KBS Signed-off-by: David Hadas <[email protected]>
1 parent b9679f0 commit c89bfc7

File tree

7 files changed

+130
-43
lines changed

7 files changed

+130
-43
lines changed

src/cloud-api-adaptor/libvirt/config_libvirt.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ installK8sclis() {
9292
fi
9393
}
9494

95-
TEST_E2E_SECURE_COMMS=${TEST_E2E_SECURE_COMMS:-none}.
95+
TEST_E2E_SECURE_COMMS=${TEST_E2E_SECURE_COMMS:-none}
9696
echo "SECURE_COMMS is ${TEST_E2E_SECURE_COMMS}"
9797

9898
echo "Installing Go..."
@@ -123,10 +123,20 @@ echo "libvirt_ssh_key_file=\"id_rsa\"" >> libvirt.properties
123123
echo "CLUSTER_NAME=\"peer-pods\"" >> libvirt.properties
124124

125125
# switch to the appropriate e2e test and add configs to libvirt.properties as needed
126-
case $TEST_E2E_SECURE_COMMS in
126+
case ${TEST_E2E_SECURE_COMMS} in
127+
128+
withoutKbs)
129+
echo "processing withoutKbs"
130+
echo "SECURE_COMMS=\"true\"" >> libvirt.properties
131+
echo "SECURE_COMMS_NO_TRUSTEE=\"true\"" >> libvirt.properties
132+
echo "INITDATA=\"\"" >> libvirt.properties
133+
;;
127134

128135
*)
129136
echo "processing none"
130137
echo "SECURE_COMMS=\"false\"" >> libvirt.properties
131138
;;
132139
esac
140+
141+
echo "Content of libvirt.properties"
142+
cat libvirt.properties

src/cloud-api-adaptor/libvirt/e2e_matrix_libvirt.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"container_runtime": ["containerd", "crio"],
3-
"secure_comms": ["none"],
3+
"secure_comms": ["none", "withoutKbs"],
44
"os": ["ubuntu"],
55
"provider": ["generic"],
66
"arch": ["amd64"]

src/cloud-api-adaptor/test/e2e/assessment_helpers.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,21 @@ func VerifyAlternateImage(ctx context.Context, t *testing.T, client klient.Clien
292292
return nil
293293
}
294294

295+
func VerifySecureCommsActivated(ctx context.Context, t *testing.T, client klient.Client, pod *v1.Pod) error {
296+
nodeName, err := GetNodeNameFromPod(ctx, client, pod)
297+
if err != nil {
298+
return fmt.Errorf("VerifySecureCommsConnected: GetNodeNameFromPod failed with %v", err)
299+
}
300+
301+
expectedSuccessMessage := "Using PP SecureComms"
302+
err = VerifyCaaPodLogContains(ctx, t, client, nodeName, expectedSuccessMessage)
303+
if err != nil {
304+
return fmt.Errorf("VerifySecureCommsConnected: failed: %v", err)
305+
}
306+
t.Logf("PodVM was brought up using SecureComms")
307+
return nil
308+
}
309+
295310
func VerifyCaaPodLogContains(ctx context.Context, t *testing.T, client klient.Client, nodeName, expected string) error {
296311
caaPod, err := getCaaPod(ctx, client, t, nodeName)
297312
if err != nil {

src/cloud-api-adaptor/test/e2e/assessment_runner.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type ExtraPod struct {
4848
testCommands []TestCommand
4949
}
5050

51+
var testCase_secureComms_isActive bool
52+
5153
type TestCase struct {
5254
testing *testing.T
5355
testEnv env.Environment
@@ -420,6 +422,13 @@ func (tc *TestCase) Run() {
420422
t.Errorf("VerifyAlternateImage failed: %v", err)
421423
}
422424
}
425+
426+
if testCase_secureComms_isActive {
427+
err := VerifySecureCommsActivated(ctx, t, client, tc.pod)
428+
if err != nil {
429+
t.Errorf("VerifySecureCommsActivated failed: %v", err)
430+
}
431+
}
423432
}
424433

425434
if tc.extraPods != nil {

src/cloud-api-adaptor/test/e2e/main_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ func TestMain(m *testing.M) {
123123

124124
// Get properties
125125
props := provisioner.GetProperties(ctx, cfg)
126+
if props["SECURE_COMMS"] == "true" {
127+
testCase_secureComms_isActive = true
128+
log.Info("Do setup secureComms is active")
129+
}
126130

127131
// Set CONTAINER_RUNTIME env variable if present in the properties
128132
// Default value is containerd.

src/cloud-api-adaptor/test/provisioner/libvirt/provision_common.go

Lines changed: 77 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,21 @@ const AlternateVolumeName = "another-podvm-base.qcow2"
2323

2424
// LibvirtProvisioner implements the CloudProvisioner interface for Libvirt.
2525
type LibvirtProvisioner struct {
26-
conn *libvirt.Connect // Libvirt connection
27-
containerRuntime string // Name of the container runtime
28-
network string // Network name
29-
ssh_key_file string // SSH key file used to connect to Libvirt
30-
storage string // Storage pool name
31-
uri string // Libvirt URI
32-
wd string // libvirt's directory path on this repository
33-
volumeName string // Podvm volume name
34-
clusterName string // Cluster name
35-
tunnelType string // Tunnel Type
36-
vxlanPort string // VXLAN port number
26+
conn *libvirt.Connect // Libvirt connection
27+
containerRuntime string // Name of the container runtime
28+
network string // Network name
29+
ssh_key_file string // SSH key file used to connect to Libvirt
30+
storage string // Storage pool name
31+
uri string // Libvirt URI
32+
wd string // libvirt's directory path on this repository
33+
volumeName string // Podvm volume name
34+
clusterName string // Cluster name
35+
tunnelType string // Tunnel Type
36+
vxlanPort string // VXLAN port number
37+
secure_comms string // Activate CAA SECURE_COMMS
38+
secure_comms_no_trustee string // Deactivate Trustee mode in SECURE_COMMS
39+
secure_comms_kbs_addr string // KBS URL
40+
initdata string // InitData
3741
}
3842

3943
// LibvirtInstallOverlay implements the InstallOverlay interface
@@ -95,19 +99,47 @@ func NewLibvirtProvisioner(properties map[string]string) (pv.CloudProvisioner, e
9599
vxlanPort = properties["vxlan_port"]
96100
}
97101

102+
secure_comms := "false"
103+
if properties["SECURE_COMMS"] != "" {
104+
secure_comms = properties["SECURE_COMMS"]
105+
}
106+
107+
log.Tracef("NewLibvirtProvisioner properties %v", properties)
108+
109+
log.Tracef("NewLibvirtProvisioner secure_comms %s", secure_comms)
110+
111+
secure_comms_kbs_addr := ""
112+
if properties["SECURE_COMMS_KBS_ADDR"] != "" {
113+
secure_comms_kbs_addr = properties["SECURE_COMMS_KBS_ADDR"]
114+
}
115+
116+
secure_comms_no_trustee := "false"
117+
if properties["SECURE_COMMS_NO_TRUSTEE"] != "" {
118+
secure_comms_no_trustee = properties["SECURE_COMMS_NO_TRUSTEE"]
119+
}
120+
121+
initdata := ""
122+
if properties["INITDATA"] != "" {
123+
initdata = properties["INITDATA"]
124+
}
125+
98126
// TODO: Check network and storage are not nil?
99127
return &LibvirtProvisioner{
100-
conn: conn,
101-
containerRuntime: properties["container_runtime"],
102-
network: network,
103-
ssh_key_file: ssh_key_file,
104-
storage: storage,
105-
uri: uri,
106-
wd: wd,
107-
volumeName: vol_name,
108-
clusterName: clusterName,
109-
tunnelType: tunnelType,
110-
vxlanPort: vxlanPort,
128+
conn: conn,
129+
containerRuntime: properties["container_runtime"],
130+
network: network,
131+
ssh_key_file: ssh_key_file,
132+
storage: storage,
133+
uri: uri,
134+
wd: wd,
135+
volumeName: vol_name,
136+
clusterName: clusterName,
137+
tunnelType: tunnelType,
138+
vxlanPort: vxlanPort,
139+
secure_comms: secure_comms,
140+
secure_comms_kbs_addr: secure_comms_kbs_addr,
141+
secure_comms_no_trustee: secure_comms_no_trustee,
142+
initdata: initdata,
111143
}, nil
112144
}
113145

@@ -212,14 +244,18 @@ func (l *LibvirtProvisioner) DeleteVPC(ctx context.Context, cfg *envconf.Config)
212244

213245
func (l *LibvirtProvisioner) GetProperties(ctx context.Context, cfg *envconf.Config) map[string]string {
214246
return map[string]string{
215-
"CONTAINER_RUNTIME": l.containerRuntime,
216-
"network": l.network,
217-
"podvm_volume": l.volumeName,
218-
"ssh_key_file": l.ssh_key_file,
219-
"storage": l.storage,
220-
"uri": l.uri,
221-
"tunnel_type": l.tunnelType,
222-
"vxlan_port": l.vxlanPort,
247+
"CONTAINER_RUNTIME": l.containerRuntime,
248+
"network": l.network,
249+
"podvm_volume": l.volumeName,
250+
"ssh_key_file": l.ssh_key_file,
251+
"storage": l.storage,
252+
"uri": l.uri,
253+
"tunnel_type": l.tunnelType,
254+
"vxlan_port": l.vxlanPort,
255+
"SECURE_COMMS": l.secure_comms,
256+
"SECURE_COMMS_KBS_ADDR": l.secure_comms_kbs_addr,
257+
"SECURE_COMMS_NO_TRUSTEE": l.secure_comms_no_trustee,
258+
"INITDATA": l.initdata,
223259
}
224260
}
225261

@@ -326,14 +362,17 @@ func (lio *LibvirtInstallOverlay) Edit(ctx context.Context, cfg *envconf.Config,
326362

327363
// Mapping the internal properties to ConfigMapGenerator properties and their default values.
328364
mapProps := map[string][2]string{
329-
"network": {"default", "LIBVIRT_NET"},
330-
"storage": {"default", "LIBVIRT_POOL"},
331-
"pause_image": {"", "PAUSE_IMAGE"},
332-
"podvm_volume": {"", "LIBVIRT_VOL_NAME"},
333-
"uri": {"qemu+ssh://[email protected]/system?no_verify=1", "LIBVIRT_URI"},
334-
"tunnel_type": {"", "TUNNEL_TYPE"},
335-
"vxlan_port": {"", "VXLAN_PORT"},
336-
"INITDATA": {"", "INITDATA"},
365+
"network": {"default", "LIBVIRT_NET"},
366+
"storage": {"default", "LIBVIRT_POOL"},
367+
"pause_image": {"", "PAUSE_IMAGE"},
368+
"podvm_volume": {"", "LIBVIRT_VOL_NAME"},
369+
"uri": {"qemu+ssh://[email protected]/system?no_verify=1", "LIBVIRT_URI"},
370+
"tunnel_type": {"", "TUNNEL_TYPE"},
371+
"vxlan_port": {"", "VXLAN_PORT"},
372+
"INITDATA": {"", "INITDATA"},
373+
"SECURE_COMMS": {"", "SECURE_COMMS"},
374+
"SECURE_COMMS_NO_TRUSTEE": {"", "SECURE_COMMS_NO_TRUSTEE"},
375+
"SECURE_COMMS_KBS_ADDR": {"", "SECURE_COMMS_KBS_ADDR"},
337376
}
338377

339378
for k, v := range mapProps {

src/cloud-api-adaptor/test/provisioner/provision.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"os/exec"
1111
"path/filepath"
12+
"strings"
1213
"time"
1314

1415
"github.com/BurntSushi/toml"
@@ -220,7 +221,6 @@ func (p *CloudAPIAdaptor) Delete(ctx context.Context, cfg *envconf.Config) error
220221
wait.WithTimeout(time.Minute*1)); err != nil {
221222
return err
222223
}
223-
224224
return nil
225225
}
226226

@@ -295,7 +295,17 @@ func (p *CloudAPIAdaptor) Deploy(ctx context.Context, cfg *envconf.Config, props
295295
}
296296
}
297297

298-
fmt.Printf("Wait for the %s runtimeclass be created\n", p.runtimeClass.GetName())
298+
log.Trace("CAA ConfigMap:\n")
299+
caaConfigMap := exec.Command("kubectl", "get", "cm", "peer-pods-cm", "-n", "confidential-containers-system", "-o", "yaml")
300+
caaConfigMap.Env = append(os.Environ(), fmt.Sprintf("KUBECONFIG="+cfg.KubeconfigFile()))
301+
caaConfigMapOut := new(strings.Builder)
302+
caaConfigMap.Stdout = caaConfigMapOut
303+
if err = caaConfigMap.Run(); err != nil {
304+
return err
305+
}
306+
log.Tracef("%v, CAA ConfigMap: \n%s", caaConfigMap, caaConfigMapOut.String())
307+
308+
log.Infof("Wait for the %s runtimeclass be created\n", p.runtimeClass.GetName())
299309
if err = wait.For(conditions.New(resources).ResourcesFound(&nodev1.RuntimeClassList{Items: []nodev1.RuntimeClass{*p.runtimeClass}}),
300310
wait.WithTimeout(time.Second*60)); err != nil {
301311
return err

0 commit comments

Comments
 (0)