Skip to content

Commit 88f14cd

Browse files
davidhadasdavidhIBM
authored andcommitted
SecureComms: Add support daemonConfig
Support configuring the APF Secure Comms from the CAA side including: - WN public Key - PP private key - Activating Secure Comms - inbouns and outbounds of th PP This is useful for activating Secure Comms from the CAA and without Trustee. It can be used for Testing without producing dedicated podvms which activate Secure Comms and set Inbounds/Outbounds by default. It can also be used for non-Coco peerpods. Signed-off-by: David Hadas <[email protected]>
1 parent 04ba307 commit 88f14cd

File tree

18 files changed

+345
-164
lines changed

18 files changed

+345
-164
lines changed

src/cloud-api-adaptor/cmd/agent-protocol-forwarder/main.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ func (cfg *Config) Setup() (cmd.Starter, error) {
9393
return nil, err
9494
}
9595

96-
if secureComms {
96+
if secureComms || cfg.daemonConfig.SecureComms {
97+
var inbounds, outbounds []string
98+
9799
ppssh.Singleton()
98100
host, port, err := net.SplitHostPort(cfg.listenAddr)
99101
if err != nil {
@@ -103,15 +105,32 @@ func (cfg *Config) Setup() (cmd.Starter, error) {
103105
logger.Printf("Address %s is changed to 127.0.0.1:%s since secure-comms is enabled.", cfg.listenAddr, port)
104106
cfg.listenAddr = "127.0.0.1:" + port
105107
}
106-
inbounds := append([]string{"BOTH_PHASES:KBS:8080"}, strings.Split(secureCommsInbounds, ",")...)
107-
outbounds := append([]string{"KUBERNETES_PHASE:KATAAGENT:" + port}, strings.Split(secureCommsOutbounds, ",")...)
108108

109109
// Create a Client that will approach the api-server-rest service at the podns
110110
// To obtain secrets from KBS, we approach the api-server-rest service which then approaches the CDH asking for a secret resource
111111
// the CDH than contact the KBS (possibly after approaching Attestation Agent for a token) and the KBS serves the requested key
112112
// The communication between the CDH (and Attestation Agent) and the KBS is performed via an SSH tunnel named "KBS"
113113
apic := apic.NewApiClient(API_SERVER_REST_PORT, cfg.podNamespace)
114-
services = append(services, ppssh.NewSshServer(inbounds, outbounds, ppssh.GetSecret(apic.GetKey), sshutil.SSHPORT))
114+
115+
ppSecrets := ppssh.NewPpSecrets(ppssh.GetSecret(apic.GetKey))
116+
117+
if secureComms {
118+
// CoCo in production
119+
ppSecrets.AddKey(ppssh.WN_PUBLIC_KEY)
120+
ppSecrets.AddKey(ppssh.PP_PRIVATE_KEY)
121+
inbounds = append([]string{"BOTH_PHASES:KBS:8080"}, strings.Split(secureCommsInbounds, ",")...)
122+
outbounds = append([]string{"KUBERNETES_PHASE:KATAAGENT:" + port}, strings.Split(secureCommsOutbounds, ",")...)
123+
124+
} else {
125+
// Never here under CoCo in production
126+
// Set secureComms using daemonConfig for testing
127+
ppSecrets.SetKey(ppssh.WN_PUBLIC_KEY, cfg.daemonConfig.WnPublicKey)
128+
ppSecrets.SetKey(ppssh.PP_PRIVATE_KEY, cfg.daemonConfig.PpPrivateKey)
129+
inbounds = append([]string{"BOTH_PHASES:KBS:8080"}, strings.Split(cfg.daemonConfig.SecureCommsInbounds, ",")...)
130+
outbounds = append([]string{"KUBERNETES_PHASE:KATAAGENT:" + port}, strings.Split(cfg.daemonConfig.SecureCommsOutbounds, ",")...)
131+
}
132+
133+
services = append(services, ppssh.NewSshServer(inbounds, outbounds, ppSecrets, sshutil.SSHPORT))
115134
} else {
116135
if !disableTLS {
117136
cfg.tlsConfig = &tlsConfig

src/cloud-api-adaptor/cmd/cloud-api-adaptor/main.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99
"fmt"
1010
"io"
1111
"os"
12+
"strings"
1213

1314
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/cmd"
1415
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/adaptor"
16+
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/adaptor/cloud"
1517
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/adaptor/proxy"
1618
daemon "github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/forwarder"
1719
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/podnetwork/tunneler/vxlan"
@@ -28,7 +30,7 @@ const (
2830
)
2931

3032
type daemonConfig struct {
31-
serverConfig adaptor.ServerConfig
33+
serverConfig cloud.ServerConfig
3234
networkConfig
3335
}
3436

@@ -86,12 +88,14 @@ func (cfg *daemonConfig) Setup() (cmd.Starter, error) {
8688
}
8789

8890
var (
89-
disableTLS bool
90-
tlsConfig tlsutil.TLSConfig
91-
secureComms bool
92-
secureCommsInbounds string
93-
secureCommsOutbounds string
94-
secureCommsKbsAddr string
91+
disableTLS bool
92+
tlsConfig tlsutil.TLSConfig
93+
secureComms bool
94+
secureCommsInbounds string
95+
secureCommsOutbounds string
96+
secureCommsPpInbounds string
97+
secureCommsPpOutbounds string
98+
secureCommsKbsAddr string
9599
)
96100

97101
cmd.Parse(programName, os.Args[1:], func(flags *flag.FlagSet) {
@@ -112,9 +116,11 @@ func (cfg *daemonConfig) Setup() (cmd.Starter, error) {
112116
flags.BoolVar(&tlsConfig.SkipVerify, "tls-skip-verify", false, "Skip TLS certificate verification - use it only for testing")
113117
flags.BoolVar(&disableTLS, "disable-tls", false, "Disable TLS encryption - use it only for testing")
114118
flags.BoolVar(&secureComms, "secure-comms", false, "Use SSH to secure communication between cluster and peer pods")
115-
flags.StringVar(&secureCommsInbounds, "secure-comms-inbounds", "", "Inbound tags for secure communication tunnels")
116-
flags.StringVar(&secureCommsOutbounds, "secure-comms-outbounds", "", "Outbound tags for secure communication tunnels")
117-
flags.StringVar(&secureCommsKbsAddr, "secure-comms-kbs", "kbs-service.kbs-operator-system:8080", "Address of a KBS Service for Secure-Comms")
119+
flags.StringVar(&secureCommsInbounds, "secure-comms-inbounds", "", "WN Inbound tags for secure communication tunnels")
120+
flags.StringVar(&secureCommsOutbounds, "secure-comms-outbounds", "", "WN Outbound tags for secure communication tunnels")
121+
flags.StringVar(&secureCommsPpInbounds, "secure-comms-pp-inbounds", "", "PP Inbound tags for secure communication tunnels")
122+
flags.StringVar(&secureCommsPpOutbounds, "secure-comms-pp-outbounds", "", "PP Outbound tags for secure communication tunnels")
123+
flags.StringVar(&secureCommsKbsAddr, "secure-comms-kbs", "kbs-service.trustee-operator-system:8080", "Address of a Trustee Service for Secure-Comms")
118124
flags.DurationVar(&cfg.serverConfig.ProxyTimeout, "proxy-timeout", proxy.DefaultProxyTimeout, "Maximum timeout in minutes for establishing agent proxy connection")
119125

120126
flags.StringVar(&cfg.networkConfig.TunnelType, "tunnel-type", podnetwork.DefaultTunnelType, "Tunnel provider")
@@ -137,10 +143,15 @@ func (cfg *daemonConfig) Setup() (cmd.Starter, error) {
137143
if err != nil {
138144
return nil, fmt.Errorf("secure comms failed to initialize KubeMgr: %w", err)
139145
}
146+
if strings.EqualFold(secureCommsKbsAddr, "false") {
147+
secureCommsKbsAddr = ""
148+
}
140149

141150
cfg.serverConfig.SecureComms = true
142151
cfg.serverConfig.SecureCommsInbounds = secureCommsInbounds
143152
cfg.serverConfig.SecureCommsOutbounds = secureCommsOutbounds
153+
cfg.serverConfig.SecureCommsPpInbounds = secureCommsPpInbounds
154+
cfg.serverConfig.SecureCommsPpOutbounds = secureCommsPpOutbounds
144155
cfg.serverConfig.SecureCommsKbsAddress = secureCommsKbsAddr
145156
} else {
146157
if !disableTLS {

src/cloud-api-adaptor/docs/SecureComms.md

Lines changed: 91 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,35 @@ Once the "Kubernetes Phase" SSH channel is established, Secure Comms connects th
2727

2828
See [Secure Comms Architecture Slides](./SecureComms.pdf) for more details.
2929

30-
## Setup
30+
## Setup for for testing without Trustee (and for non-CoCo peerpods)
31+
32+
### Deploy CAA
33+
Use any of the option for installing CAA depending on the cloud driver used.
34+
35+
36+
### Activate Secure-Comms feature from CAA side
37+
Activate Secure-Comms from CAA side by changing the `SECURE_COMMS` parameter of the `peer-pods-cm` configMap in the `confidential-containers-system` namespace to `"true"`.
38+
39+
```sh
40+
kubectl -n confidential-containers-system get cm peer-pods-cm -o yaml | sed "s/SECURE_COMMS: \"false\"/SECURE_COMMS: \"true\"/"|kubectl apply -f -
41+
```
42+
43+
You may also include additional Inbounds and Outbounds configurations to the Adaptor side using the `SECURE_COMMS_INBOUNDS` and `SECURE_COMMS_OUTBOUNDS` config points.
44+
You may also add Inbounds and Outbounds configurations to the Forwarder side using the `SECURE_COMMS_PP_INBOUNDS` and `SECURE_COMMS_PP_OUTBOUNDS` config points. [See more details regarding Inbounds and Outbounds below.](#adding-named-tunnels-to-the-ssh-channel)
45+
46+
Use `kubectl edit cm peer-pods-cm -n confidential-containers-system` to make such changes in the configMap, for example:
47+
```sh
48+
apiVersion: v1
49+
data:
50+
...
51+
SECURE_COMMS: "true"
52+
SECURE_COMMS_OUTBOUNDS: "KUBERNETES_PHASE:mytunnel:149.81.64.62:7777"
53+
SECURE_COMMS_PP_INBOUNDS: "KUBERNETES_PHASE:mytunnel:6666"
54+
SECURE_COMMS_KBS_ADDR: "false"
55+
...
56+
```
57+
58+
## Setup for CoCo with Trustee
3159

3260
### Deploy CAA
3361
Use any of the option for installing CAA depending on the cloud driver used.
@@ -37,19 +65,25 @@ Deploy Trustee-Operator by following instructions at [trustee Operator Getting S
3765

3866
Make sure to uncomment the secret generation as recommended for both public and private key (`kbs-auth-public-key` and `kbs-client` secrets).
3967

40-
Copy the kbs-client secret from the `kbs-operator-system` namespace to the `confidential-containers-system` ns. This can be done using:
68+
```sh
69+
kubectl get secrets -n trustee-operator-system
70+
NAME TYPE DATA AGE
71+
kbs-auth-public-key Opaque 1 28h
72+
kbs-client Opaque 1 28h
73+
```
74+
75+
Copy the kbs-client secret from the `trustee-operator-system` namespace to the `confidential-containers-system` ns. This can be done using:
4176

4277
```sh
43-
kubectl get secret kbs-client -n kbs-operator-system -o json|jq --arg ns "confidential-containers-system" 'del(.metadata["creationTimestamp","resourceVersion","selfLink","uid","annotations"]) | .metadata.namespace |= $ns' |kubectl apply -f -
78+
kubectl get secret kbs-client -n trustee-operator-system -o json|jq --arg ns "confidential-containers-system" 'del(.metadata["creationTimestamp","resourceVersion","selfLink","uid","annotations"]) | .metadata.namespace |= $ns' |kubectl apply -f -
4479
```
4580

4681
For a testing environment, you may need to change the policy of the KBS and AS using the KBS Client to allow all or fit your own policy. One way to do that is:
4782

4883
```sh
49-
kubectl -n kbs-operator-system exec deployment/trustee-deployment --container as -it -- /bin/bash
50-
sed -i.bak 's/^default allow = false/default allow = true/' /opt/confidential-containers/attestation-service/opa/default.rego
84+
kubectl -n trustee-operator-system exec deployment/trustee-deployment --container as -it -- sed -i.bak 's/^default allow = false/default allow = true/' /opt/confidential-containers/attestation-service/opa/default.rego
5185

52-
kubectl -n kbs-operator-system get cm resource-policy -o yaml | sed "s/default allow = false/default allow = true/"|kubectl apply -f -
86+
kubectl -n trustee-operator-system get cm resource-policy -o yaml | sed "s/default allow = false/default allow = true/"|kubectl apply -f -
5387
```
5488

5589
### Build a podvm that enforces Secure-Comms
@@ -59,27 +93,73 @@ Change the `src/cloud-api-adaptor/podvm/files/etc/systemd/system/agent-protocol-
5993
ExecStart=/usr/local/bin/agent-protocol-forwarder -pod-namespace /run/netns/podns -secure-comms -kata-agent-socket /run/kata-containers/agent.sock $TLS_OPTIONS $OPTIONS
6094
```
6195

62-
You may also include additional Inbounds and Outbounds configurations to the Forwarder using the `-secure-comms-inbounds` and `-secure-comms-outbounds` flags. See more details regarding Inbounds and Outbounds below.
96+
You may also include additional Inbounds and Outbounds configurations to the Forwarder using the `-secure-comms-inbounds` and `-secure-comms-outbounds` flags. [See more details regarding Inbounds and Outbounds below.](#adding-named-tunnels-to-the-ssh-channel)
97+
98+
For example:
99+
```sh
100+
ExecStart=/usr/local/bin/agent-protocol-forwarder -kata-agent-namespace /run/netns/podns -secure-comms -secure-comms-inbounds KUBERNETES_PHASE:mytunnel:6666 -kata-agent-socket /run/kata-containers/agent.sock $TLS_OPTIONS $OPTIONS
101+
```
63102

64103
Once you changed `podvm/files/etc/systemd/system/agent-protocol-forwarder.service`, you will need to [rebuild the podvm](./../podvm/README.md).
65104

66105

67106
### Activate CAA Secure-Comms feature
68-
Use `kubectl edit cm peer-pods-cm -n confidential-containers-system` to add to the `peer-pods-cm` config map at the `confidential-containers-system` namespace:
107+
Activate Secure-Comms of CAA by changing the `SECURE_COMMS` parameter of the `peer-pods-cm` configMap in the `confidential-containers-system` namespace to `"true"`.
108+
109+
```sh
110+
kubectl -n confidential-containers-system get cm peer-pods-cm -o yaml | sed "s/SECURE_COMMS: \"false\"/SECURE_COMMS: \"true\"/"|kubectl apply -f -
111+
```
112+
113+
Set InitData to point KBC services to IP address 127.0.0.1
114+
```sh
115+
cat <<EOF > /tmp/initdata.txt
116+
algorithm = "sha384"
117+
version = "0.1.0"
118+
119+
[data]
120+
"aa.toml" = '''
121+
[token_configs]
122+
[token_configs.coco_as]
123+
url = 'http://127.0.0.1:8080'
124+
125+
[token_configs.kbs]
126+
url = 'http://127.0.0.1:8080'
127+
'''
128+
"apf.json" = '''
129+
{
130+
"sc": true
131+
}
132+
'''
133+
"cdh.toml" = '''
134+
socket = 'unix:///run/confidential-containers/cdh.sock'
135+
credentials = []
136+
137+
[kbc]
138+
name = 'cc_kbc'
139+
url = 'http://127.0.0.1:8080'
140+
'''
141+
EOF
142+
export INITDATA=`base64 -w 0 /tmp/initdata.txt`
143+
kubectl -n confidential-containers-system get cm peer-pods-cm -o yaml | sed 's/^INITDATA: .*/INITDATA: '$INITDATA'/'|kubectl apply -f -
144+
145+
```
146+
147+
You may also include additional Inbounds and Outbounds configurations to the Adaptor using the `SECURE_COMMS_INBOUNDS` and `SECURE_COMMS_OUTBOUNDS` config points. [See more details regarding Inbounds and Outbounds below.](#adding-named-tunnels-to-the-ssh-channel)
148+
149+
Use `kubectl edit cm peer-pods-cm -n confidential-containers-system` to make such changes in the configMap, for example:
69150
```sh
70151
apiVersion: v1
71152
data:
72153
...
73154
SECURE_COMMS: "true"
155+
SECURE_COMMS_OUTBOUNDS: "KUBERNETES_PHASE:mytunnel:149.81.64.62:7777"
74156
...
75157
```
76158

77-
You may also include additional Inbounds and Outbounds configurations to the Adaptor using the `SECURE_COMMS_INBOUNDS` and `SECURE_COMMS_OUTBOUNDS` config points. See more details regarding Inbounds and Outbounds below.
78-
79159
You may also set the KBS address using the `SECURE_COMMS_KBS_ADDR` config point.
80160

81161

82-
### Adding named tunnels to the SSH channel
162+
## Adding named tunnels to the SSH channel
83163
Named tunnels can be added to the SSH channel. Adding a named tunnel requires adding an Inbound at one of the SSH channel peers and an Outbound at the other SSH channel peer. The Inbound and Outbound both carry the name of the tunnel being created.
84164

85165
|---------Tunnel----------|
@@ -117,5 +197,4 @@ Alternatively, the client and server can be separately executed in independent t
117197

118198
- Add DeleteResource() support in KBS, KBC, api-server-rest, than cleanup resources added by Secure Comms to KBS whenever a Peer Pod fail to be created or when a Peer Pod is terminated.
119199
- Add support for running the vxlan tunnel traffic via a Secure Comms SSH tunnel
120-
- Add support for non-confidential Peer Pods which do not go via an Attestation Phase.
121200
- Add support for KBS identities allowing a Peer Pod to register its own identity in KBS and replace the current Secure Comms mechanism which delivers a private key to the Peer Pod via the KBS

src/cloud-api-adaptor/entrypoint.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ optionals+=""
2424
[[ "${SECURE_COMMS}" == "true" ]] && optionals+="-secure-comms "
2525
[[ "${SECURE_COMMS_INBOUNDS}" ]] && optionals+="-secure-comms-inbounds ${SECURE_COMMS_INBOUNDS} "
2626
[[ "${SECURE_COMMS_OUTBOUNDS}" ]] && optionals+="-secure-comms-outbounds ${SECURE_COMMS_OUTBOUNDS} "
27+
[[ "${SECURE_COMMS_PP_INBOUNDS}" ]] && optionals+="-secure-comms-pp-inbounds ${SECURE_COMMS_PP_INBOUNDS} "
28+
[[ "${SECURE_COMMS_PP_OUTBOUNDS}" ]] && optionals+="-secure-comms-pp-outbounds ${SECURE_COMMS_PP_OUTBOUNDS} "
2729
[[ "${SECURE_COMMS_KBS_ADDR}" ]] && optionals+="-secure-comms-kbs ${SECURE_COMMS_KBS_ADDR} "
2830
[[ "${PEERPODS_LIMIT_PER_NODE}" ]] && optionals+="-peerpods-limit-per-node ${PEERPODS_LIMIT_PER_NODE} "
2931

0 commit comments

Comments
 (0)