Skip to content

Commit 62ff36a

Browse files
authored
Update launcher flags and launcher_spec (#220)
Remove useLocalImage and serverAddr flags Add defaultAttestationServiceEndpoint in launcher_spec, and allow the endpoint to be configured from MDS. Update launcher service file to support hardened and debug images Signed-off-by: Jiankun Lu <[email protected]>
1 parent 6b74ec9 commit 62ff36a

9 files changed

+39
-21
lines changed

cloudbuild.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ substitutions:
22
'_BASE_IMAGE': 'cos-dev-101-16963-0-0'
33
'_BASE_IMAGE_PROJECT': 'cos-cloud'
44
'_OUTPUT_IMAGE': ''
5-
'_ATTEST_ENDPOINT': ''
5+
'_IMAGE_ENV': 'debug'
66

77
steps:
88
- name: golang:1.18
@@ -21,7 +21,7 @@ steps:
2121
- name: 'gcr.io/cos-cloud/cos-customizer'
2222
args: ['run-script',
2323
'-script=launcher/preload.sh',
24-
'-env=ATTEST_ENDPOINT=${_ATTEST_ENDPOINT}']
24+
'-env=IMAGE_ENV=${_IMAGE_ENV}']
2525
- name: 'gcr.io/cos-cloud/cos-customizer'
2626
args: ['seal-oem']
2727
- name: 'gcr.io/cos-cloud/cos-customizer'

launcher/container-runner.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Wants=network-online.target gcr-online.target containerd.service
44
After=network-online.target gcr-online.target containerd.service
55

66
[Service]
7-
ExecStart=/var/lib/google/cc_container_launcher --addr=${ATTEST_ENDPOINT}
7+
ExecStart=/var/lib/google/cc_container_launcher
88
# Shutdown the host after the launcher exits
99
ExecStopPost=/bin/sleep 60
1010
ExecStopPost=/usr/bin/systemctl poweroff

launcher/container_runner.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,6 @@ func (r *ContainerRunner) Run(ctx context.Context) error {
393393
}
394394

395395
func initImage(ctx context.Context, cdClient *containerd.Client, launchSpec spec.LauncherSpec, token oauth2.Token, logger *log.Logger) (containerd.Image, error) {
396-
if launchSpec.UseLocalImage {
397-
image, err := cdClient.GetImage(ctx, launchSpec.ImageRef)
398-
if err != nil {
399-
return nil, fmt.Errorf("cannot get local image: [%w]", err)
400-
}
401-
return image, nil
402-
}
403-
404396
var remoteOpt containerd.RemoteOpt
405397
if token.Valid() {
406398
remoteOpt = containerd.WithResolver(Resolver(token.AccessToken))

launcher/debug.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[Service]
2+
# debug image machine won't shutdown
3+
ExecStopPost=

launcher/entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ main() {
55
cp /usr/share/oem/cc_container_launcher /var/lib/google/cc_container_launcher
66
chmod +x /var/lib/google/cc_container_launcher
77

8+
# copy systemd files
89
cp /usr/share/oem/container-runner.service /etc/systemd/system/container-runner.service
10+
mkdir -p /etc/systemd/system/container-runner.service.d/
11+
cp /usr/share/oem/launcher.conf /etc/systemd/system/container-runner.service.d/launcher.conf
12+
913
systemctl daemon-reload
1014
systemctl enable container-runner.service
1115
systemctl start container-runner.service

launcher/hardened.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Service]
2+
# hardened image should exit after workflow finished
3+
ExecStopPost=
4+
ExecStopPost=/bin/sleep 60
5+
ExecStopPost=/usr/bin/systemctl poweroff

launcher/main.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ import (
1717
"github.com/google/go-tpm/tpm2"
1818
)
1919

20-
var (
21-
useLocalImage = flag.Bool("use_local_image", false, "use local image instead of pulling image from the repo, only for testing purpose")
22-
serverAddr = flag.String("addr", "", "The server address in the format of host:port")
23-
)
24-
2520
const (
2621
logName = "confidential-space-launcher"
2722
)
@@ -59,8 +54,6 @@ func run() int {
5954
return 1
6055
}
6156

62-
spec.UseLocalImage = *useLocalImage
63-
spec.AttestationServiceAddr = *serverAddr
6457
logger.Println("Launcher Spec: ", spec)
6558

6659
client, err := containerd.New(defaults.DefaultAddress)

launcher/preload.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ copy_launcher() {
77
setup_launcher_systemd_unit() {
88
cp launcher/container-runner.service /usr/share/oem/container-runner.service
99
# set attest service endpoint
10-
sed -i 's/\${ATTEST_ENDPOINT}/'${ATTEST_ENDPOINT}'/g' /usr/share/oem/container-runner.service
10+
11+
if [ "$IMAGE_ENV" == "hardened" ]; then
12+
cp launcher/hardened.conf /usr/share/oem/launcher.conf
13+
elif [ "$IMAGE_ENV" == "debug" ]; then
14+
cp launcher/debug.conf /usr/share/oem/launcher.conf
15+
else
16+
echo "Unknown IMAGE_ENV, use hardened or debug"
17+
exit 1
18+
fi
1119
}
1220

1321
append_cmdline() {

launcher/spec/launcher_spec.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,21 @@ const (
2828
Never RestartPolicy = "Never"
2929
)
3030

31+
const (
32+
defaultAttestationServiceEndpoint = "attestation-verifier.confidential-computing-test-org.joonix.net:9090"
33+
)
34+
3135
const (
3236
imageRefKey = "tee-image-reference"
3337
restartPolicyKey = "tee-restart-policy"
3438
cmdKey = "tee-cmd"
3539
envKeyPrefix = "tee-env-"
3640
impersonateServiceAccounts = "tee-impersonate-service-accounts"
37-
instanceAttributesQuery = "instance/attributes/?recursive=true"
41+
attestationServiceAddrKey = "tee-attestation-service-endpoint"
42+
)
43+
44+
const (
45+
instanceAttributesQuery = "instance/attributes/?recursive=true"
3846
)
3947

4048
var errImageRefNotSpecified = fmt.Errorf("%s is not specified in the custom metadata", imageRefKey)
@@ -52,7 +60,6 @@ type LauncherSpec struct {
5260
RestartPolicy RestartPolicy
5361
Cmd []string
5462
Envs []EnvVar
55-
UseLocalImage bool
5663
AttestationServiceAddr string
5764
ImpersonateServiceAccounts []string
5865
}
@@ -98,6 +105,8 @@ func (s *LauncherSpec) UnmarshalJSON(b []byte) error {
98105
}
99106
}
100107

108+
s.AttestationServiceAddr = unmarshaledMap[attestationServiceAddrKey]
109+
101110
return nil
102111
}
103112

@@ -116,5 +125,9 @@ func GetLauncherSpec(client *metadata.Client) (LauncherSpec, error) {
116125
return LauncherSpec{}, err
117126
}
118127

128+
if spec.AttestationServiceAddr == "" {
129+
spec.AttestationServiceAddr = defaultAttestationServiceEndpoint
130+
}
131+
119132
return *spec, nil
120133
}

0 commit comments

Comments
 (0)