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

initdata: migrate key release test cases to initdata #2006

Merged
merged 5 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 2 additions & 5 deletions src/cloud-api-adaptor/cmd/cloud-api-adaptor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import (
)

const (
programName = "cloud-api-adaptor"
AA_KBC_PARAMS_DEFAULT = "cc_kbc::http://127.0.0.1:8080"
programName = "cloud-api-adaptor"
)

type daemonConfig struct {
Expand Down Expand Up @@ -122,7 +121,7 @@ func (cfg *daemonConfig) Setup() (cmd.Starter, error) {
flags.StringVar(&cfg.networkConfig.HostInterface, "host-interface", "", "Host Interface")
flags.IntVar(&cfg.networkConfig.VXLANPort, "vxlan-port", vxlan.DefaultVXLANPort, "VXLAN UDP port number (VXLAN tunnel mode only")
flags.IntVar(&cfg.networkConfig.VXLANMinID, "vxlan-min-id", vxlan.DefaultVXLANMinID, "Minimum VXLAN ID (VXLAN tunnel mode only")
flags.StringVar(&cfg.serverConfig.AAKBCParams, "aa-kbc-params", "", "attestation-agent KBC parameters")
flags.StringVar(&cfg.serverConfig.GlobalInitdata, "global-initdata", "", "Default initdata for all Pods")
flags.BoolVar(&cfg.serverConfig.EnableCloudConfigVerify, "cloud-config-verify", false, "Enable cloud config verify - should use it for production")

cloud.ParseCmd(flags)
Expand All @@ -142,8 +141,6 @@ func (cfg *daemonConfig) Setup() (cmd.Starter, error) {
cfg.serverConfig.SecureCommsInbounds = secureCommsInbounds
cfg.serverConfig.SecureCommsOutbounds = secureCommsOutbounds
cfg.serverConfig.SecureCommsKbsAddress = secureCommsKbsAddr

cfg.serverConfig.AAKBCParams = AA_KBC_PARAMS_DEFAULT
} else {
if !disableTLS {
cfg.serverConfig.TLSConfig = &tlsConfig
Expand Down
4 changes: 2 additions & 2 deletions src/cloud-api-adaptor/docs/addnewprovider.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ optionals+=""
[[ "${CERT_FILE}" ]] && [[ "${CERT_KEY}" ]] && optionals+="-cert-file ${CERT_FILE} -cert-key ${CERT_KEY} "
[[ "${TLS_SKIP_VERIFY}" ]] && optionals+="-tls-skip-verify "
[[ "${PROXY_TIMEOUT}" ]] && optionals+="-proxy-timeout ${PROXY_TIMEOUT} "
[[ "${AA_KBC_PARAMS}" ]] && optionals+="-aa-kbc-params ${AA_KBC_PARAMS} "
[[ "${GLOBAL_INITDATA}" ]] && optionals+="-global-initdata ${GLOBAL_INITDATA} "
[[ "${FORWARDER_PORT}" ]] && optionals+="-forwarder-port ${FORWARDER_PORT} "
[[ "${CLOUD_CONFIG_VERIFY}" == "true" ]] && optionals+="-cloud-config-verify "

Expand Down Expand Up @@ -396,7 +396,7 @@ cloud-api-adaptor version v0.8.2-dev
cloud-api-adaptor: starting Cloud API Adaptor daemon for "libvirt"
2024/04/17 04:34:56 [adaptor/cloud/libvirt] libvirt config: &libvirt.Config{URI:"qemu+ssh://[email protected]/system?no_verify=1", PoolName:"default", NetworkName:"default", DataDir:"/opt/data-dir", DisableCVM:true, VolName:"podvm-base.qcow2", LaunchSecurity:"", Firmware:"/usr/share/edk2/ovmf/OVMF_CODE.fd"}
2024/04/17 04:34:56 [adaptor/cloud/libvirt] Created libvirt connection
2024/04/17 04:34:56 [adaptor] server config: &adaptor.ServerConfig{TLSConfig:(*tlsutil.TLSConfig)(0xc0000d4080), SocketPath:"/run/peerpod/hypervisor.sock", CriSocketPath:"", PauseImage:"", PodsDir:"/run/peerpod/pods", ForwarderPort:"15150", ProxyTimeout:300000000000, AAKBCParams:"", EnableCloudConfigVerify:false}
2024/04/17 04:34:56 [adaptor] server config: &adaptor.ServerConfig{TLSConfig:(*tlsutil.TLSConfig)(0xc0000d4080), SocketPath:"/run/peerpod/hypervisor.sock", CriSocketPath:"", PauseImage:"", PodsDir:"/run/peerpod/pods", ForwarderPort:"15150", ProxyTimeout:300000000000, EnableCloudConfigVerify:false}
2024/04/17 04:34:56 [util/k8sops] initialized PeerPodService
2024/04/17 04:34:56 [probe/probe] Using port: 8000
2024/04/17 04:34:56 [adaptor] server started
Expand Down
20 changes: 19 additions & 1 deletion src/cloud-api-adaptor/docs/initdata.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

The document describes the implementation of the [initdata](https://github.com/confidential-containers/trustee/blob/main/kbs/docs/initdata.md) spec in PeerPods.

Initdata is used when `AA_KBC_PARAMS` is not set at the moment, the plan is to remove `AA_KBC_PARAMS` support after `initdata` function works completely.

## Initdata example

Expand Down Expand Up @@ -175,5 +174,24 @@ allow if {
}
```

## Global initdata
huoqifeng marked this conversation as resolved.
Show resolved Hide resolved
If all of your applications(Pods) are using same initdata, it's convenient you set the `GLOBAL_INITDATA` in configmap `peer-pods-cm`, so that you don't need add initdata annotation in each Pod yaml. For example, for libvirt provider, it looks like:
```
kubectl -n confidential-containers-system get cm peer-pods-cm -o yaml
apiVersion: v1
data:
CLOUD_CONFIG_VERIFY: "false"
CLOUD_PROVIDER: libvirt
DISABLECVM: "true"
ENABLE_CLOUD_PROVIDER_EXTERNAL_PLUGIN: "false"
GLOBAL_INITDATA: YWxnb3JpdGhtID0gInNoYTM4NCIKdmVyc2lvbiA9ICIwLjEuMCIKCltkYXRhXQoiYWEudG9tbCIgPSAnJycKW3Rva2VuX2NvbmZpZ3NdClt0b2tlbl9jb25maWdzLmNvY29fYXNdCnVybCA9ICdodHRwOi8vMTI3LjAuMC4xOjgwODAnCgpbdG9rZW5fY29uZmlncy5rYnNdCnVybCA9ICdodHRwOi8vMTI3LjAuMC4xOjgwODAnCmNlcnQgPSAiIiIKLS0tLS1CRUdJTiBDRV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VxdWVzdCA6PSB0cnVlCmRlZmF1bHQgUmVtb3ZlU3RhbGVWaXJ0aW9mc1NoYXJlTW91bnRzUmVxdWVzdCA6PSB0cnVlCmRlZmF1bHQgU2lnbmFsUHJvY2Vzc1JlcXVlc3QgOj0gdHJ1ZQpkZWZhdWx0IFN0YXJ0Q29udGFpbmVyUmVxdWVzdCA6PSB0cnVlCmRlZmF1bHQgU3RhdHNDb250YWluZXJSZXF1ZXN0IDo9IHRydWUKZGVmYXVsdCBUdHlXaW5SZXNpemVSZXF1ZXN0IDo9IHRydWUKZGVmYXVsdCBVcGRhdGVFcGhlbWVyYWxNb3VudHNSZXF1ZXN0IDo9IHRydWUKZGVmYXVsdCBVcGRhdGVJbnRlcmZhY2VSZXF1ZXN0IDo9IHRydWUKZGVmYXVsdCBVcGRhdGVSb3V0ZXNSZXF1ZXN0IDo9IHRydWUKZGVmYXVsdCBXYWl0UHJvY2Vzc1JlcXVlc3QgOj0gdHJ1ZQpkZWZhdWx0IFdyaXRlU3RyZWFtUmVxdWVzdCA6PSBmYWxzZQonJyc=
LIBVIRT_NET: default
LIBVIRT_POOL: default
LIBVIRT_URI: qemu+ssh://[email protected]/system?no_verify=1
LIBVIRT_VOL_NAME: podvm-base.qcow2
SECURE_COMMS: "false"
kind: ConfigMap
```

## TODO
A large policy bodies that cannot be provisioned via IMDS user-data, the limitation depends on providers IMDS limitation. We need add checking and limitations according to test result future.
2 changes: 1 addition & 1 deletion src/cloud-api-adaptor/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ optionals+=""
[[ "${CERT_FILE}" ]] && [[ "${CERT_KEY}" ]] && optionals+="-cert-file ${CERT_FILE} -cert-key ${CERT_KEY} "
[[ "${TLS_SKIP_VERIFY}" ]] && optionals+="-tls-skip-verify "
[[ "${PROXY_TIMEOUT}" ]] && optionals+="-proxy-timeout ${PROXY_TIMEOUT} "
[[ "${AA_KBC_PARAMS}" ]] && optionals+="-aa-kbc-params ${AA_KBC_PARAMS} "
[[ "${GLOBAL_INITDATA}" ]] && optionals+="-global-initdata ${GLOBAL_INITDATA} "
[[ "${FORWARDER_PORT}" ]] && optionals+="-forwarder-port ${FORWARDER_PORT} "
[[ "${CLOUD_CONFIG_VERIFY}" == "true" ]] && optionals+="-cloud-config-verify "
[[ "${SECURE_COMMS}" == "true" ]] && optionals+="-secure-comms "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ configMapGenerator:
# /subscriptions/<AZURE_SUBSCRIPTION_ID>/resourceGroups/<AZURE_RESOURCE_GROUP>/providers/Microsoft.Compute/images/<AZURE_IMAGE>
- AZURE_IMAGE_ID="" #set
- SSH_USERNAME="" #set peer pod vm admin user name
- AA_KBC_PARAMS="" #set KBC params for podvm
- GLOBAL_INITDATA="" # set default initdata for podvm
#- DISABLECVM="" # Uncomment it if you want a generic VM
#- PAUSE_IMAGE="" # Uncomment and set if you want to use a specific pause image
#- VXLAN_PORT="" # Uncomment and set if you want to use a specific vxlan port. Defaults to 4789
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ configMapGenerator:
- LIBVIRT_POOL="default" # set
- DISABLECVM="true" # set as false to enable confidential VM
- SECURE_COMMS="false" # set as true to enable Secure Comms
- AA_KBC_PARAMS="" #set KBC params for podvm
- GLOBAL_INITDATA="" # set default initdata for podvm
#- LIBVIRT_LAUNCH_SECURITY="" #sev or s390-pv
#- LIBVIRT_FIRMWARE="" # Uncomment and set if you want to change the firmware path. Defaults to /usr/share/edk2/ovmf/OVMF_CODE.fd
#- LIBVIRT_VOL_NAME="" # Uncomment and set if you want to use a specific volume name. Defaults to podvm-base.qcow2
Expand Down
51 changes: 0 additions & 51 deletions src/cloud-api-adaptor/pkg/aa/config.go

This file was deleted.

36 changes: 0 additions & 36 deletions src/cloud-api-adaptor/pkg/aa/config_test.go

This file was deleted.

61 changes: 20 additions & 41 deletions src/cloud-api-adaptor/pkg/adaptor/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import (
"github.com/containerd/containerd/pkg/cri/annotations"
pb "github.com/kata-containers/kata-containers/src/runtime/protocols/hypervisor"

"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/aa"
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/adaptor/k8sops"
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/adaptor/proxy"
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/agent"
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/cdh"
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/forwarder"
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/podnetwork"
"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/securecomms/wnssh"
Expand All @@ -35,7 +33,9 @@ import (

const (
SrcAuthfilePath = "/root/containers/auth.json"
AaFilePath = "/run/peerpod/aa.toml"
huoqifeng marked this conversation as resolved.
Show resolved Hide resolved
AuthFilePath = "/run/peerpod/auth.json"
CdhFilePath = "/run/peerpod/cdh.toml"
huoqifeng marked this conversation as resolved.
Show resolved Hide resolved
InitdataPath = "/run/peerpod/initdata"
Version = "0.0.0"
)
Expand Down Expand Up @@ -79,8 +79,7 @@ func (s *cloudService) removeSandbox(id sandboxID) error {
}

func NewService(provider provider.Provider, proxyFactory proxy.Factory, workerNode podnetwork.WorkerNode,
secureComms bool, secureCommsInbounds, secureCommsOutbounds, kbsAddress, podsDir, daemonPort, aaKBCParams, sshport string,
) Service {
secureComms bool, secureCommsInbounds, secureCommsOutbounds, kbsAddress, podsDir, daemonPort, globalInitdata, sshport string) Service {
var err error
var sshClient *wnssh.SshClient

Expand All @@ -94,14 +93,14 @@ func NewService(provider provider.Provider, proxyFactory proxy.Factory, workerNo
}

s := &cloudService{
provider: provider,
proxyFactory: proxyFactory,
sandboxes: map[sandboxID]*sandbox{},
podsDir: podsDir,
daemonPort: daemonPort,
workerNode: workerNode,
aaKBCParams: aaKBCParams,
sshClient: sshClient,
provider: provider,
proxyFactory: proxyFactory,
sandboxes: map[sandboxID]*sandbox{},
podsDir: podsDir,
daemonPort: daemonPort,
globalInitdata: globalInitdata,
workerNode: workerNode,
sshClient: sshClient,
}
s.cond = sync.NewCond(&s.mutex)
s.ppService, err = k8sops.NewPeerPodService()
Expand Down Expand Up @@ -292,39 +291,19 @@ func (s *cloudService) CreateVM(ctx context.Context, req *pb.CreateVMRequest) (r
}
}

if s.aaKBCParams != "" { // Keep AA_KBC_PARAMS support as it is used by e2e test, KBS is dynamic k8s service in e2e test
bpradipt marked this conversation as resolved.
Show resolved Hide resolved
logger.Printf("aaKBCParams: %s, support cc_kbc::*", s.aaKBCParams)
toml, err := cdh.CreateConfigFile(s.aaKBCParams)
if err != nil {
return nil, fmt.Errorf("creating CDH config: %w", err)
}
cloudConfig.WriteFiles = append(cloudConfig.WriteFiles, cloudinit.WriteFile{
Path: cdh.ConfigFilePath,
Content: toml,
})
initdataStr := util.GetInitdataFromAnnotation(req.Annotations)
logger.Printf("initdata in Pod annotation: %s", initdataStr)

toml, err = aa.CreateConfigFile(s.aaKBCParams)
if err != nil {
return nil, fmt.Errorf("creating attestation agent config: %w", err)
}
cloudConfig.WriteFiles = append(cloudConfig.WriteFiles, cloudinit.WriteFile{
Path: aa.ConfigFilePath,
Content: toml,
})
if initdataStr == "" {
huoqifeng marked this conversation as resolved.
Show resolved Hide resolved
logger.Printf("initdata in pod annotation is empty, use global initdata: %s", s.globalInitdata)
initdataStr = s.globalInitdata
}

initdataStr := util.GetInitdataFromAnnotation(req.Annotations)
logger.Printf("initdata: %s", initdataStr)
if initdataStr != "" {
if s.aaKBCParams != "" {
logger.Printf("Initdata ignored because AA_KBC_PARAMS set")
} else {
logger.Printf("Set and use initdata when no AA_KBC_PARAMS")
cloudConfig.WriteFiles = append(cloudConfig.WriteFiles, cloudinit.WriteFile{
Path: InitdataPath,
Content: initdataStr,
})
}
cloudConfig.WriteFiles = append(cloudConfig.WriteFiles, cloudinit.WriteFile{
Path: InitdataPath,
Content: initdataStr,
})
}

sandbox := &sandbox{
Expand Down
22 changes: 11 additions & 11 deletions src/cloud-api-adaptor/pkg/adaptor/cloud/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ type Service interface {
}

type cloudService struct {
provider provider.Provider
proxyFactory proxy.Factory
workerNode podnetwork.WorkerNode
sandboxes map[sandboxID]*sandbox
cond *sync.Cond
podsDir string
daemonPort string
mutex sync.Mutex
ppService *k8sops.PeerPodService
aaKBCParams string
sshClient *wnssh.SshClient
provider provider.Provider
proxyFactory proxy.Factory
workerNode podnetwork.WorkerNode
sandboxes map[sandboxID]*sandbox
cond *sync.Cond
podsDir string
daemonPort string
mutex sync.Mutex
ppService *k8sops.PeerPodService
globalInitdata string
sshClient *wnssh.SshClient
}

type sandboxID string
Expand Down
4 changes: 2 additions & 2 deletions src/cloud-api-adaptor/pkg/adaptor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ServerConfig struct {
PodsDir string
ForwarderPort string
ProxyTimeout time.Duration
AAKBCParams string
GlobalInitdata string
EnableCloudConfigVerify bool
SecureComms bool
SecureCommsInbounds string
Expand Down Expand Up @@ -71,7 +71,7 @@ func NewServer(provider provider.Provider, cfg *ServerConfig, workerNode podnetw

agentFactory := proxy.NewFactory(cfg.PauseImage, cfg.TLSConfig, cfg.ProxyTimeout)
cloudService := cloud.NewService(provider, agentFactory, workerNode,
cfg.SecureComms, cfg.SecureCommsInbounds, cfg.SecureCommsOutbounds, cfg.SecureCommsKbsAddress, cfg.PodsDir, cfg.ForwarderPort, cfg.AAKBCParams, sshutil.SSHPORT)
cfg.SecureComms, cfg.SecureCommsInbounds, cfg.SecureCommsOutbounds, cfg.SecureCommsKbsAddress, cfg.PodsDir, cfg.ForwarderPort, cfg.GlobalInitdata, sshutil.SSHPORT)
mkulke marked this conversation as resolved.
Show resolved Hide resolved
vmInfoService := vminfo.NewService(cloudService)

return &server{
Expand Down
Loading
Loading