Skip to content

Commit 193ec18

Browse files
committed
[launcher] add flag to disable GCA refresh
The new flag allow user to disable the default initial and hourly GCA attestation token refresh. Delete an obsolete flag (tee-gpu-driver-version) in a test.
1 parent 1d28c42 commit 193ec18

File tree

3 files changed

+54
-15
lines changed

3 files changed

+54
-15
lines changed

launcher/container_runner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,9 @@ func (r *ContainerRunner) Run(ctx context.Context) error {
621621
return fmt.Errorf("failed to measure CEL events: %v", err)
622622
}
623623

624-
// Only refresh token if agent has a default GCA client (not ITA use case).
625-
if r.launchSpec.ITAConfig.ITARegion == "" {
624+
// Only refresh token if agent has a default GCA client (not ITA use case)
625+
// AND GcaRefresh is not disabled
626+
if r.launchSpec.ITAConfig.ITARegion == "" && !r.launchSpec.DisableGcaRefresh {
626627
if err := r.fetchAndWriteToken(ctx); err != nil {
627628
return fmt.Errorf("failed to fetch and write OIDC token: %v", err)
628629
}

launcher/spec/launch_spec.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const (
9494
cgroupNS = "tee-cgroup-ns"
9595
gcaServiceEnv = "gca-service-env"
9696
installGpuDriver = "tee-install-gpu-driver"
97+
disableGcaRefreshKey = "tee-disable-gca-refresh"
9798
)
9899

99100
const (
@@ -135,11 +136,11 @@ type LaunchSpec struct {
135136
LogRedirect LogRedirectLocation
136137
Mounts []launchermount.Mount
137138
ITAConfig verifier.ITAConfig
138-
// DevShmSize is specified in kiB.
139-
DevShmSize int64
140-
AddedCapabilities []string
141-
CgroupNamespace bool
142-
InstallGpuDriver bool
139+
DevShmSize int64 // DevShmSize is specified in kiB.
140+
AddedCapabilities []string
141+
CgroupNamespace bool
142+
InstallGpuDriver bool
143+
DisableGcaRefresh bool
143144
}
144145

145146
// UnmarshalJSON unmarshals an instance attributes list in JSON format from the metadata
@@ -306,6 +307,13 @@ func (s *LaunchSpec) UnmarshalJSON(b []byte) error {
306307
}
307308
}
308309

310+
if val, ok := unmarshaledMap[disableGcaRefreshKey]; ok && val != "" {
311+
var err error
312+
if s.DisableGcaRefresh, err = strconv.ParseBool(val); err != nil {
313+
return fmt.Errorf("invalid value for %v (not a boolean): %w", disableGcaRefreshKey, err)
314+
}
315+
}
316+
309317
return nil
310318
}
311319

launcher/spec/launch_spec_test.go

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ func TestLaunchSpecUnmarshalJSONHappyCases(t *testing.T) {
3030
Experiments: experiments.Experiments{
3131
EnableItaVerifier: true,
3232
},
33-
GcaAddress: "https://confidentialcomputing.googleapis.com",
34-
InstallGpuDriver: true,
33+
GcaAddress: "https://confidentialcomputing.googleapis.com",
34+
InstallGpuDriver: true,
35+
DisableGcaRefresh: false,
3536
}
3637

3738
var testCases = []struct {
@@ -79,8 +80,7 @@ func TestLaunchSpecUnmarshalJSONHappyCases(t *testing.T) {
7980
"tee-mount":"type=tmpfs,source=tmpfs,destination=/tmpmount;type=tmpfs,source=tmpfs,destination=/sized,size=222",
8081
"ita-region":"US",
8182
"ita-api-key":"test-api-key",
82-
"tee-install-gpu-driver":"true",
83-
"tee-gpu-driver-version":"590.48.01"
83+
"tee-install-gpu-driver":"true"
8484
}`,
8585
modifyWant: func(ls LaunchSpec) LaunchSpec {
8686
ls.GcaAddress = ""
@@ -105,8 +105,7 @@ func TestLaunchSpecUnmarshalJSONHappyCases(t *testing.T) {
105105
"ita-region":"US",
106106
"ita-api-key":"test-api-key",
107107
"gca-service-env":"prod",
108-
"tee-install-gpu-driver":"true",
109-
"tee-gpu-driver-version":"590.48.01"
108+
"tee-install-gpu-driver":"true"
110109
}`,
111110
modifyWant: func(ls LaunchSpec) LaunchSpec {
112111
return ls
@@ -130,14 +129,37 @@ func TestLaunchSpecUnmarshalJSONHappyCases(t *testing.T) {
130129
"ita-region":"US",
131130
"ita-api-key":"test-api-key",
132131
"gca-service-env":"staging",
133-
"tee-install-gpu-driver":"true",
134-
"tee-gpu-driver-version":"590.48.01"
132+
"tee-install-gpu-driver":"true"
135133
}`,
136134
modifyWant: func(ls LaunchSpec) LaunchSpec {
137135
ls.GcaAddress = "https://staging-confidentialcomputing.sandbox.googleapis.com"
138136
return ls
139137
},
140138
},
139+
{
140+
testName: "DisableGcaRefreshSetToTrue",
141+
mdsJSON: `{
142+
"tee-cmd":"[\"--foo\",\"--bar\",\"--baz\"]",
143+
"tee-env-foo":"bar",
144+
"tee-image-reference":"docker.io/library/hello-world:latest",
145+
"tee-signed-image-repos":"docker.io/library/hello-world,gcr.io/cloudrun/hello",
146+
"tee-restart-policy":"Always",
147+
"tee-impersonate-service-accounts":"sv1@developer.gserviceaccount.com,sv2@developer.gserviceaccount.com",
148+
"tee-container-log-redirect":"true",
149+
"tee-monitoring-memory-enable":"true",
150+
"tee-dev-shm-size-kb":"234234",
151+
"tee-mount":"type=tmpfs,source=tmpfs,destination=/tmpmount;type=tmpfs,source=tmpfs,destination=/sized,size=222",
152+
"ita-region":"US",
153+
"ita-api-key":"test-api-key",
154+
"tee-install-gpu-driver":"true",
155+
"tee-disable-gca-refresh":"true"
156+
}`,
157+
modifyWant: func(ls LaunchSpec) LaunchSpec {
158+
ls.GcaAddress = ""
159+
ls.DisableGcaRefresh = true
160+
return ls
161+
},
162+
},
141163
}
142164

143165
for _, testcase := range testCases {
@@ -239,6 +261,13 @@ func TestLaunchSpecUnmarshalJSONBadInput(t *testing.T) {
239261
"gca-service-env":""
240262
}`,
241263
},
264+
{
265+
"EmptyStringAsDisableGcaRefresh",
266+
`{
267+
"tee-image-reference":"docker.io/library/hello-world:latest",
268+
"tee-disable-gca-refresh":"badvalue"
269+
}`,
270+
},
242271
}
243272

244273
for _, testcase := range testCases {
@@ -274,6 +303,7 @@ func TestLaunchSpecUnmarshalJSONWithDefaultValue(t *testing.T) {
274303
MonitoringEnabled: None,
275304
GcaAddress: "",
276305
InstallGpuDriver: false,
306+
DisableGcaRefresh: false,
277307
}
278308

279309
if !cmp.Equal(spec, want) {

0 commit comments

Comments
 (0)