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

Export function to extract and validate AK from server #492

Merged
merged 4 commits into from
Sep 19, 2024

Conversation

yawangwang
Copy link
Collaborator

We need to export a function from server to extract/validate AK, and populate GCE instance info into machine state so that GAV can consume.

server/verify.go Outdated
@@ -183,6 +152,45 @@ func VerifyAttestation(attestation *pb.Attestation, opts VerifyOpts) (*pb.Machin
return nil, fmt.Errorf("attestation does not contain a supported quote")
}

// ParseAndValidateAK parses and validate AK cert in the attestation, and populate GCE instance info.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we have composable funcs where we can verify the attestation key against the Attestation proto and VerifyOpts and then extract info from it. So I suggest a bit more refactoring:

  1. call this ValidateAK
  2. Have ValidateAK just call validateAKPub and validateAKCert
  3. refactor validateAKPub and validateAKCert to only return error
  4. refactor validateAKCert to not call getInstanceInfoFromExtensions
  5. in VerifyAttestation call ValidateAK and then getInstanceInfoFromExtensions (or GetGCEInstanceInfo if cert != nil)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
name: "failed with missing intermediates",
opts: VerifyOpts{TrustedRootCerts: GceEKRoots},
wantPass: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test case setting TrustedAKs in VerifyOpts but not Trusted/Intermediate certs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@yawangwang yawangwang force-pushed the export_validate_AK branch 4 times, most recently from 02dce70 to 65204d1 Compare September 19, 2024 01:18

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@yawangwang
Copy link
Collaborator Author

/gcbrun

@yawangwang yawangwang requested a review from alexmwu September 19, 2024 01:34

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Add CAS-based EK/AK root CAs.
Add warning about using GetGCEInstanceInfo.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@alexmwu
Copy link
Contributor

alexmwu commented Sep 19, 2024

/gcbrun

@@ -77,11 +77,12 @@ jobs:
run: |
GO_EXECUTABLE_PATH=$(which go)
sudo $GO_EXECUTABLE_PATH test -v -run "TestFetchImageSignaturesDockerPublic" ./launcher
sudo $GO_EXECUTABLE_PATH test -v -run "TestHwAttestationPass" ./cmd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this failing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See b/368161073, it returns couldn't create report entry in configfs, no such device error

server/verify.go Outdated
Comment on lines 112 to 118
if akCert != nil {
instanceInfo, err := GetGCEInstanceInfo(akCert)
if err != nil {
return nil, fmt.Errorf("failed to validate AK certificate: %w", err)
return nil, fmt.Errorf("failed to extract GCE instance info from AK cert: %w", err)
}
akPubKey = akCert.PublicKey.(crypto.PublicKey)
// Populate GCE instance info.
machineState.Platform = &pb.PlatformState{InstanceInfo: instanceInfo}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops I realize a security issue: we can't blindly just parse GCE instance info, since we might have validated with the TrustedAKs instead

Which is why we had the extract in validateAK in the first place :).

I'll add something to your PR.

Copy link
Contributor

@alexmwu alexmwu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give my changes a look @yawangwang and merge it in if you feel it looks okay.

@yawangwang
Copy link
Collaborator Author

Please give my changes a look @yawangwang and merge it in if you feel it looks okay.

LGTM, now merging this PR

@yawangwang yawangwang merged commit e71285a into google:main Sep 19, 2024
11 checks passed
jessieqliu pushed a commit that referenced this pull request Sep 25, 2024
* Export ValidateAKCert and add CAS EK root CA + skip TestHwAttestationPass


---------

Co-authored-by: Alex Wu <wuale@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants