-
Notifications
You must be signed in to change notification settings - Fork 89
Add TDX CCEL support to token command and refactor flags #620
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,17 +2,21 @@ package cmd | |
|
|
||
| import ( | ||
| "context" | ||
| _ "crypto/sha512" // Ensure SHA384 is available | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "log" | ||
| "net/http" | ||
| "os" | ||
| "time" | ||
|
|
||
| "cloud.google.com/go/compute/metadata" | ||
| "cloud.google.com/go/logging" | ||
| "github.com/golang-jwt/jwt/v4" | ||
| tabi "github.com/google/go-tdx-guest/abi" | ||
| "github.com/google/go-tpm-tools/client" | ||
| "github.com/google/go-tpm-tools/internal" | ||
| "github.com/google/go-tpm-tools/verifier" | ||
| "github.com/google/go-tpm-tools/verifier/models" | ||
| "github.com/google/go-tpm-tools/verifier/util" | ||
|
|
@@ -128,7 +132,33 @@ The OIDC token includes claims regarding the GCE VM, which is verified by Attest | |
| if err != nil { | ||
| return fmt.Errorf("failed to get an AK: %w", err) | ||
| } | ||
| attestation, err := ak.Attest(client.AttestOpts{Nonce: challenge.Nonce, CertChainFetcher: http.DefaultClient}) | ||
|
|
||
| attestOpts := client.AttestOpts{Nonce: challenge.Nonce, CertChainFetcher: http.DefaultClient} | ||
|
|
||
| // Add logic to open other hardware devices when required. | ||
| switch teeTechnology { | ||
| case SevSnp: | ||
| attestOpts.TEEDevice, err = client.CreateSevSnpQuoteProvider() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to open %s device: %v", SevSnp, err) | ||
| } | ||
| attestOpts.TEENonce = teeNonce | ||
| case Tdx: | ||
| attestOpts.TEEDevice, err = client.CreateTdxQuoteProvider() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create %s quote provider: %v", Tdx, err) | ||
| } | ||
| attestOpts.TEENonce = teeNonce | ||
| case "": | ||
| if len(teeNonce) != 0 { | ||
| return fmt.Errorf("use of --tee-nonce requires specifying TEE hardware type with --tee-technology") | ||
| } | ||
| default: | ||
| // Change the return statement when more devices are added | ||
| return fmt.Errorf("tee-technology should be either empty or should have values %s or %s", SevSnp, Tdx) | ||
| } | ||
|
|
||
| attestation, err := ak.Attest(attestOpts) | ||
|
Comment on lines
+138
to
+161
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicated with https://github.com/google/go-tpm-tools/blob/main/cmd/attest.go#L84-L105. Please refactor into a helper like |
||
| if err != nil { | ||
| return fmt.Errorf("failed to attest: %v", err) | ||
| } | ||
|
|
@@ -141,6 +171,32 @@ The OIDC token includes claims regarding the GCE VM, which is verified by Attest | |
| TokenOptions: &models.TokenOptions{Audience: audience, Nonces: customNonce, TokenType: "OIDC"}, | ||
| } | ||
|
|
||
| if teeTechnology == Tdx { | ||
| // If TDX, check if we should populate TDCCELAttestation | ||
| if attestation.GetTdxAttestation() != nil { | ||
| fmt.Fprintln(debugOutput(), "Using Explicit TDCCELAttestation Path (ACPI tables)") | ||
|
|
||
| rawQuote, err := tabi.QuoteToAbiBytes(attestation.GetTdxAttestation()) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to convert TDX quote to bytes: %v", err) | ||
| } | ||
|
|
||
| // Try to read CCEL Table and Data | ||
| ccelTable, _ := os.ReadFile(internal.AcpiTableFile) | ||
| ccelData, _ := os.ReadFile(internal.CcelEventLogFile) | ||
|
|
||
| req.TDCCELAttestation = &verifier.TDCCELAttestation{ | ||
| TdQuote: rawQuote, | ||
| CcelAcpiTable: ccelTable, | ||
| CcelData: ccelData, | ||
| AkCert: attestation.AkCert, | ||
| IntermediateCerts: attestation.IntermediateCerts, | ||
| } | ||
|
Comment on lines
+188
to
+194
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This enables sending TDX CVM attestation to GCA for verification. However, since TDX CVM support is not yet GA, users will likely encounter errors when using the CLI. This PR should be held until TDX CVM and hardware binding reach GA. |
||
| // Force using TDCCELAttestation path in verifier client | ||
| req.Attestation = nil | ||
| } | ||
| } | ||
|
|
||
| resp, err := verifierClient.VerifyAttestation(ctx, req) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -210,6 +266,6 @@ func init() { | |
| addEventLogFlag(tokenCmd) | ||
| addCustomNonceFlag(tokenCmd) | ||
| // TODO: Add TEE hardware OIDC token generation | ||
| // addTeeNonceflag(tokenCmd) | ||
| // addTeeTechnology(tokenCmd) | ||
| addTeeNonceflag(tokenCmd) | ||
| addTeeTechnology(tokenCmd) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package internal | ||
|
|
||
| const ( | ||
| // AcpiTableFile is the path to the CCEL ACPI table. | ||
| AcpiTableFile = "/sys/firmware/acpi/tables/CCEL" | ||
| // CcelEventLogFile is the path to the CCEL event log data. | ||
| CcelEventLogFile = "/sys/firmware/acpi/tables/data/CCEL" | ||
| ) |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently there's no binding b/w TPM and TDX attestation, so it's premature to enable tee-nonce and tee-technology flags for the token command.