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

joinservice: cache certificates for Azure SEV-SNP attestation #2336

Merged
merged 35 commits into from
Sep 29, 2023

Conversation

msanft
Copy link
Contributor

@msanft msanft commented Sep 14, 2023

Context

Caching ASK intermediate certificates is a prerequisite for VLEK-based signer attestation as performed on AWS SEV-SNP, but can also be used on Azure.

Proposed change(s)

  • On cluster initialization, request the Milan certificate chain from the AMD KDS in the join service, and save it in a configmap.
  • When creating the validator for a joinservice pod, pass the cached certificate to the validator if it exists.
  • In the validator, use the cached certificate. On Azure, this is a special case as there is a 3-step precedence in which certificates should be taken:
    • If the ARK and ASK from the THIM response are intact, use them.
    • If the THIM response does not contain the cert chain, use the ARK from the Constellation config and the cached ASK.
    • If neither of these cases applies, retrieve ARK and ASK from AMD KDS.
      // attestationWithCerts returns a formatted version of the attestation report and its certificates from the instanceInfo.
      // Certificates are retrieved in the following precedence:
      // 1. ASK or ARK from THIM
      // 2. ASK or ARK from fallbackCerts
      // 3. ASK or ARK from AMD KDS

Additional info

Checklist

  • Add labels (e.g., for changelog category)
  • Is PR title adequate for changelog?
  • Link to Milestone

@msanft msanft added the feature This introduces new functionality label Sep 14, 2023
@msanft msanft added this to the v2.12.0 milestone Sep 14, 2023
@thomasten
Copy link
Member

This introduces attestation-variant-specific code in otherwise attestation-variant-agnostic code. This can get messy if we add more variants in the future. We should try to reduce this where possible.
Thing that come into my mind:

  • Adding a parameter for attestation-variant-specific data (like cfg, but for non-user-defined data) to the Validator func instead of adding a very specific ValidatorWithASKCertCache func.
  • Do we need a separate config map for the cached cert? If yes, should it be named more generically for all kinds of (future) attestation-variant-specific data?
  • Better separate the attestation-variant-specific code in joinservice's main.go. (At least move it to an own func.)

Not sure if all of this makes sense or if there are better ways. Please think about it.

@msanft
Copy link
Contributor Author

msanft commented Sep 15, 2023

This introduces attestation-variant-specific code in otherwise attestation-variant-agnostic code. This can get messy if we add more variants in the future. We should try to reduce this where possible.

I definitely see the point here and agree.

Regarding having a ValidatorWithASKCertCache, I discussed this with Leo and we agreed that changing current validator function signatures would come at the cost of a lot of refactoring to do. However, I also think that this might be worth it, in case other attestation-variant-specific features are introduced in the future. Potentially we should consider a builder pattern or something similar here. I also think that wrapping the csp/attestation-specific things behind a returned interface is not a great abstraction necessarily. Regarding the other 2 points, i will think about it.

@thomasten
Copy link
Member

changing current validator function signatures would come at the cost of a lot of refactoring to do. However, I also think that this might be worth it, in case other attestation-variant-specific features are introduced in the future.

True. We should discuss that with @daniel-weisse. I think he has designed most of the current architecture.

Base automatically changed from feat/attestation/go-sev-attestation to main September 21, 2023 12:08
@msanft msanft requested a review from malt3 as a code owner September 21, 2023 12:08
Copy link
Member

@daniel-weisse daniel-weisse left a comment

Choose a reason for hiding this comment

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

What about adding the ASK as an optional value to the Azure attestation config?
While this would still require attestation variant specific code in the join-service, it would keep the function signature intact, and also allows us to easily disable the caching behavior for the CLI (by not setting the optional ASK field).
We already do something similar for the MAA URL on Azure.

joinservice/cmd/main.go Outdated Show resolved Hide resolved
joinservice/internal/certcache/certcache.go Show resolved Hide resolved
joinservice/internal/kubernetes/kubernetes.go Outdated Show resolved Hide resolved
@netlify
Copy link

netlify bot commented Sep 21, 2023

Deploy Preview for constellation-docs canceled.

Name Link
🔨 Latest commit 87f29b2
🔍 Latest deploy log https://app.netlify.com/sites/constellation-docs/deploys/651695b8d62add0008e28861

internal/config/config.go Outdated Show resolved Hide resolved
joinservice/internal/watcher/validator.go Outdated Show resolved Hide resolved
joinservice/internal/watcher/validator.go Outdated Show resolved Hide resolved
joinservice/internal/certcache/certcache.go Outdated Show resolved Hide resolved
joinservice/internal/kubernetes/kubernetes.go Outdated Show resolved Hide resolved
joinservice/internal/certcache/certcache.go Outdated Show resolved Hide resolved
joinservice/internal/certcache/certcache.go Outdated Show resolved Hide resolved
@msanft msanft force-pushed the feat/joinservice/manage-ask branch 2 times, most recently from 32e0d25 to 19cfd86 Compare September 22, 2023 11:51
@msanft msanft marked this pull request as draft September 22, 2023 14:18
@msanft msanft marked this pull request as ready for review September 25, 2023 13:27
Copy link
Member

@daniel-weisse daniel-weisse left a comment

Choose a reason for hiding this comment

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

Implementation looks good to me now

joinservice/internal/kubernetes/kubernetes.go Outdated Show resolved Hide resolved
internal/attestation/azure/snp/validator.go Outdated Show resolved Hide resolved
internal/attestation/azure/snp/validator.go Outdated Show resolved Hide resolved
Copy link
Member

@daniel-weisse daniel-weisse left a comment

Choose a reason for hiding this comment

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

Please run e2e tests before merging.
Otherwise looks good to me

@malt3 malt3 removed their request for review September 26, 2023 09:38
@malt3
Copy link
Contributor

malt3 commented Sep 26, 2023

Looks good from a high level. I think Daniel and Thomas are the best reviewers when it comes to the attestation details.

joinservice/internal/kubernetes/kubernetes.go Show resolved Hide resolved
joinservice/cmd/main.go Outdated Show resolved Hide resolved
Copy link
Member

@3u13r 3u13r left a comment

Choose a reason for hiding this comment

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

LGTM

@msanft msanft temporarily deployed to e2e September 27, 2023 08:23 — with GitHub Actions Inactive
msanft and others added 23 commits September 29, 2023 07:28
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Co-authored-by: Thomas Tendyck <51411342+thomasten@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Co-authored-by: Thomas Tendyck <51411342+thomasten@users.noreply.github.com>
Co-authored-by: Thomas Tendyck <51411342+thomasten@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
@github-actions
Copy link
Contributor

Coverage report

Package Old New Trend
internal/attestation/azure/snp 46.90% 49.00% ↗️
internal/attestation/choose 85.00% 85.00% ↔️
internal/attestation/variant [no test files] [no test files] 🚧
internal/config 80.10% 80.20% ↗️
internal/constants [no test files] [no test files] 🚧
internal/crypto 50.00% 69.60% ↗️
joinservice/cmd [no test files] [no test files] 🚧
joinservice/internal/certcache 0.00% 73.60% 🆕
joinservice/internal/certcache/amdkds 0.00% 100.00% 🆕
joinservice/internal/kubernetes 8.50% 6.90% ↘️
joinservice/internal/server 76.20% 79.20% ↗️
joinservice/internal/watcher 80.40% 78.90% ↘️

Comment on lines 79 to 80
// X509CertToPem takes an x.509 certificate and returns it as a PEM-encoded certificate.
func X509CertToPem(cert *x509.Certificate) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// X509CertToPem takes an x.509 certificate and returns it as a PEM-encoded certificate.
func X509CertToPem(cert *x509.Certificate) ([]byte, error) {
// X509CertToPEM takes an x.509 certificate and returns it as a PEM-encoded certificate.
func X509CertToPEM(cert *x509.Certificate) ([]byte, error) {

PEM should be the correct form here

@msanft msanft merged commit a5021c5 into main Sep 29, 2023
8 checks passed
@msanft msanft deleted the feat/joinservice/manage-ask branch September 29, 2023 12:29
@malt3 malt3 removed the feature This introduces new functionality label Oct 10, 2023
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

6 participants