Skip to content

Commit d1e5319

Browse files
committed
Add ITA support to CS
1 parent a0cd32e commit d1e5319

File tree

10 files changed

+321
-221
lines changed

10 files changed

+321
-221
lines changed

launcher/container_runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func NewRunner(ctx context.Context, cdClient *containerd.Client, token oauth2.To
240240
asAddr := launchSpec.AttestationServiceAddr
241241

242242
var verifierClient verifier.Client
243-
if launchSpec.ITARegion == "" {
243+
if launchSpec.ITAConfig.ITARegion == "" {
244244
gcaClient, err := util.NewRESTClient(ctx, asAddr, launchSpec.ProjectID, launchSpec.Region)
245245
if err != nil {
246246
return nil, fmt.Errorf("failed to create REST verifier client: %v", err)

launcher/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ github.com/caarlos0/ctrlc v1.0.0/go.mod h1:CdXpj4rmq0q/1Eb44M9zi2nKB0QraNKuRGYGr
155155
github.com/campoy/unique v0.0.0-20180121183637-88950e537e7e/go.mod h1:9IOqJGCPMSc6E5ydlp5NIonxObaeu/Iub/X03EKPVYo=
156156
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
157157
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e/go.mod h1:oDpT4efm8tSYHXV5tHSdRvBet/b/QzxZ+XyyPehvm3A=
158+
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
158159
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
159160
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
160161
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=

launcher/spec/launch_spec.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/google/go-tpm-tools/launcher/internal/launchermount"
2222
"github.com/google/go-tpm-tools/launcher/internal/logging"
2323
"github.com/google/go-tpm-tools/launcher/launcherfile"
24+
"github.com/google/go-tpm-tools/verifier"
2425
"github.com/google/go-tpm-tools/verifier/util"
2526
)
2627

@@ -124,8 +125,7 @@ type LaunchSpec struct {
124125
MonitoringEnabled MonitoringType
125126
LogRedirect LogRedirectLocation
126127
Mounts []launchermount.Mount
127-
ITARegion string
128-
ITAKey string
128+
ITAConfig verifier.ITAConfig
129129
// DevShmSize is specified in kiB.
130130
DevShmSize int64
131131
AddedCapabilities []string
@@ -252,16 +252,14 @@ func (s *LaunchSpec) UnmarshalJSON(b []byte) error {
252252
itaRegionVal, itaRegionOK := unmarshaledMap[itaRegion]
253253
itaKeyVal, itaKeyOK := unmarshaledMap[itaKey]
254254

255+
// If key and region are both not in the map, do not set up ITA config.
255256
if itaRegionOK != itaKeyOK {
256-
return fmt.Errorf("ITA fields %s and %s must both be provided", itaRegion, itaKey)
257+
return fmt.Errorf("ITA fields %s and %s must both be provided and non-empty", itaRegion, itaKey)
257258
}
258259

259-
if itaRegionOK {
260-
s.ITARegion = itaRegionVal
261-
}
262-
263-
if itaKeyOK {
264-
s.ITAKey = itaKeyVal
260+
s.ITAConfig = verifier.ITAConfig{
261+
ITARegion: itaRegionVal,
262+
ITAKey: itaKeyVal,
265263
}
266264
}
267265

@@ -290,7 +288,7 @@ func (s *LaunchSpec) UnmarshalJSON(b []byte) error {
290288
// LogFriendly creates a copy of the spec that is safe to log by censoring
291289
func (s *LaunchSpec) LogFriendly() LaunchSpec {
292290
safeSpec := *s
293-
safeSpec.ITAKey = strings.Repeat("*", len(s.ITAKey))
291+
safeSpec.ITAConfig.ITAKey = strings.Repeat("*", len(s.ITAConfig.ITAKey))
294292

295293
return safeSpec
296294
}

launcher/spec/launch_spec_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/google/go-cmp/cmp"
88
"github.com/google/go-tpm-tools/launcher/internal/experiments"
99
"github.com/google/go-tpm-tools/launcher/internal/launchermount"
10+
"github.com/google/go-tpm-tools/verifier"
1011
)
1112

1213
func TestLaunchSpecUnmarshalJSONHappyCases(t *testing.T) {
@@ -64,8 +65,10 @@ func TestLaunchSpecUnmarshalJSONHappyCases(t *testing.T) {
6465
DevShmSize: 234234,
6566
Mounts: []launchermount.Mount{launchermount.TmpfsMount{Destination: "/tmpmount", Size: 0},
6667
launchermount.TmpfsMount{Destination: "/sized", Size: 222}},
67-
ITARegion: "US",
68-
ITAKey: "test-api-key",
68+
ITAConfig: verifier.ITAConfig{
69+
ITARegion: "US",
70+
ITAKey: "test-api-key",
71+
},
6972
Experiments: experiments.Experiments{
7073
EnableItaVerifier: true,
7174
},

launcher/teeserver/tee_server.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ import (
1414
"github.com/google/go-tpm-tools/launcher/spec"
1515
"github.com/google/go-tpm-tools/verifier"
1616
"github.com/google/go-tpm-tools/verifier/models"
17-
"github.com/google/go-tpm-tools/verifier/util"
1817
"google.golang.org/grpc/codes"
1918
"google.golang.org/grpc/status"
2019
)
2120

21+
const (
22+
gcaEndpoint = "/v1/token"
23+
itaEndpoint = "/v1/intel/token"
24+
)
25+
2226
var clientErrorCodes = map[codes.Code]struct{}{
2327
codes.InvalidArgument: {},
2428
codes.FailedPrecondition: {},
@@ -43,7 +47,7 @@ type attestHandler struct {
4347
// defaultTokenFile string
4448
logger logging.Logger
4549
launchSpec spec.LaunchSpec
46-
clients *AttestClients
50+
clients AttestClients
4751
}
4852

4953
// TeeServer is a server that can be called from a container through a unix
@@ -54,7 +58,7 @@ type TeeServer struct {
5458
}
5559

5660
// New takes in a socket and start to listen to it, and create a server
57-
func New(ctx context.Context, unixSock string, a agent.AttestationAgent, logger logging.Logger, launchSpec spec.LaunchSpec, clients *AttestClients) (*TeeServer, error) {
61+
func New(ctx context.Context, unixSock string, a agent.AttestationAgent, logger logging.Logger, launchSpec spec.LaunchSpec, clients AttestClients) (*TeeServer, error) {
5862
var err error
5963
nl, err := net.Listen("unix", unixSock)
6064
if err != nil {
@@ -84,8 +88,8 @@ func (a *attestHandler) Handler() http.Handler {
8488
// curl -d '{"audience":"<aud>", "nonces":["<nonce1>"]}' -H "Content-Type: application/json" -X POST
8589
// --unix-socket /tmp/container_launcher/teeserver.sock http://localhost/v1/token
8690

87-
mux.HandleFunc("/v1/token", a.getToken)
88-
mux.HandleFunc("/v1/intel/token", a.getITAToken)
91+
mux.HandleFunc(gcaEndpoint, a.getToken)
92+
mux.HandleFunc(itaEndpoint, a.getITAToken)
8993
return mux
9094
}
9195

@@ -101,16 +105,13 @@ func (a *attestHandler) logAndWriteError(errStr string, status int, w http.Respo
101105
func (a *attestHandler) getToken(w http.ResponseWriter, r *http.Request) {
102106
w.Header().Set("Content-Type", "text/html")
103107

104-
// If the handler does not have a GCA client, create one.
105-
if a.clients.GCA == nil {
106-
gcaClient, err := util.NewRESTClient(a.ctx, a.launchSpec.AttestationServiceAddr, a.launchSpec.ProjectID, a.launchSpec.Region)
107-
if err != nil {
108-
errStr := fmt.Sprintf("failed to create REST verifier client: %v", err)
109-
a.logAndWriteError(errStr, http.StatusInternalServerError, w)
110-
return
111-
}
108+
a.logger.Info(fmt.Sprintf("%s called", gcaEndpoint))
112109

113-
a.clients.GCA = gcaClient
110+
// If the handler does not have an GCA client, return error.
111+
if a.clients.GCA == nil {
112+
errStr := "no GCA verifier client present, please try rebooting your VM"
113+
a.logAndWriteError(errStr, http.StatusInternalServerError, w)
114+
return
114115
}
115116

116117
a.attest(w, r, a.clients.GCA)
@@ -120,10 +121,12 @@ func (a *attestHandler) getToken(w http.ResponseWriter, r *http.Request) {
120121
func (a *attestHandler) getITAToken(w http.ResponseWriter, r *http.Request) {
121122
w.Header().Set("Content-Type", "text/html")
122123

124+
a.logger.Info(fmt.Sprintf("%s called", itaEndpoint))
125+
123126
// If the handler does not have an ITA client, return error.
124127
if a.clients.ITA == nil {
125128
errStr := "no ITA verifier client present - ensure ITA Region and Key are defined in metadata"
126-
a.logAndWriteError(errStr, http.StatusPreconditionFailed, w)
129+
a.logAndWriteError(errStr, http.StatusInternalServerError, w)
127130
return
128131
}
129132

@@ -173,11 +176,10 @@ func (a *attestHandler) attest(w http.ResponseWriter, r *http.Request, client ve
173176
}
174177

175178
// Do not check that TokenTypeOptions matches TokenType in the launcher.
176-
177-
tok, err := a.attestAgent.AttestWithClient(a.ctx, agent.AttestAgentOpts{
179+
opts := agent.AttestAgentOpts{
178180
TokenOptions: &tokenOptions,
179-
}, client)
180-
181+
}
182+
tok, err := a.attestAgent.AttestWithClient(a.ctx, opts, client)
181183
if err != nil {
182184
a.handleAttestError(w, err, "failed to retrieve custom attestation service token")
183185
return

0 commit comments

Comments
 (0)