2023-06-14 08:17:52 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/api/attestationconfigapi"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/idkeydigest"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/measurements"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/attestation/variant"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
2024-01-24 09:10:15 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/encoding"
|
2023-06-14 08:17:52 -04:00
|
|
|
)
|
|
|
|
|
2024-01-24 09:10:15 -05:00
|
|
|
var (
|
|
|
|
_ svnResolveMarshaller = &AzureSEVSNP{}
|
|
|
|
_ svnResolveMarshaller = &AzureTDX{}
|
|
|
|
)
|
2024-01-10 07:32:13 -05:00
|
|
|
|
2023-06-14 08:17:52 -04:00
|
|
|
// DefaultForAzureSEVSNP returns the default configuration for Azure SEV-SNP attestation.
|
|
|
|
// Version numbers have placeholder values and the latest available values can be fetched using [AzureSEVSNP.FetchAndSetLatestVersionNumbers].
|
|
|
|
func DefaultForAzureSEVSNP() *AzureSEVSNP {
|
|
|
|
return &AzureSEVSNP{
|
|
|
|
Measurements: measurements.DefaultsFor(cloudprovider.Azure, variant.AzureSEVSNP{}),
|
2024-06-12 04:24:16 -04:00
|
|
|
BootloaderVersion: NewLatestPlaceholderVersion[uint8](),
|
|
|
|
TEEVersion: NewLatestPlaceholderVersion[uint8](),
|
|
|
|
SNPVersion: NewLatestPlaceholderVersion[uint8](),
|
|
|
|
MicrocodeVersion: NewLatestPlaceholderVersion[uint8](),
|
2023-06-14 08:17:52 -04:00
|
|
|
FirmwareSignerConfig: SNPFirmwareSignerConfig{
|
|
|
|
AcceptedKeyDigests: idkeydigest.DefaultList(),
|
|
|
|
EnforcementPolicy: idkeydigest.MAAFallback,
|
|
|
|
},
|
2023-11-06 08:22:44 -05:00
|
|
|
AMDRootKey: mustParsePEM(arkPEM),
|
2023-06-14 08:17:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetVariant returns azure-sev-snp as the variant.
|
|
|
|
func (AzureSEVSNP) GetVariant() variant.Variant {
|
|
|
|
return variant.AzureSEVSNP{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMeasurements returns the measurements used for attestation.
|
|
|
|
func (c AzureSEVSNP) GetMeasurements() measurements.M {
|
|
|
|
return c.Measurements
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMeasurements updates a config's measurements using the given measurements.
|
|
|
|
func (c *AzureSEVSNP) SetMeasurements(m measurements.M) {
|
|
|
|
c.Measurements = m
|
|
|
|
}
|
|
|
|
|
|
|
|
// EqualTo returns true if the config is equal to the given config.
|
|
|
|
func (c AzureSEVSNP) EqualTo(old AttestationCfg) (bool, error) {
|
|
|
|
otherCfg, ok := old.(*AzureSEVSNP)
|
|
|
|
if !ok {
|
|
|
|
return false, fmt.Errorf("cannot compare %T with %T", c, old)
|
|
|
|
}
|
|
|
|
|
|
|
|
firmwareSignerCfgEqual := c.FirmwareSignerConfig.EqualTo(otherCfg.FirmwareSignerConfig)
|
|
|
|
measurementsEqual := c.Measurements.EqualTo(otherCfg.Measurements)
|
|
|
|
bootloaderEqual := c.BootloaderVersion == otherCfg.BootloaderVersion
|
|
|
|
teeEqual := c.TEEVersion == otherCfg.TEEVersion
|
|
|
|
snpEqual := c.SNPVersion == otherCfg.SNPVersion
|
|
|
|
microcodeEqual := c.MicrocodeVersion == otherCfg.MicrocodeVersion
|
|
|
|
rootKeyEqual := bytes.Equal(c.AMDRootKey.Raw, otherCfg.AMDRootKey.Raw)
|
|
|
|
|
|
|
|
return firmwareSignerCfgEqual && measurementsEqual && bootloaderEqual && teeEqual && snpEqual && microcodeEqual && rootKeyEqual, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FetchAndSetLatestVersionNumbers fetches the latest version numbers from the configapi and sets them.
|
2023-09-25 05:53:02 -04:00
|
|
|
func (c *AzureSEVSNP) FetchAndSetLatestVersionNumbers(ctx context.Context, fetcher attestationconfigapi.Fetcher) error {
|
2023-11-14 07:25:03 -05:00
|
|
|
// Only talk to the API if at least one version number is set to latest.
|
|
|
|
if !(c.BootloaderVersion.WantLatest || c.TEEVersion.WantLatest || c.SNPVersion.WantLatest || c.MicrocodeVersion.WantLatest) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-06-11 09:12:05 -04:00
|
|
|
versions, err := fetcher.FetchLatestVersion(ctx, variant.AzureSEVSNP{})
|
2023-06-14 08:17:52 -04:00
|
|
|
if err != nil {
|
2023-11-14 07:25:03 -05:00
|
|
|
return fmt.Errorf("fetching latest TCB versions from configapi: %w", err)
|
2023-06-14 08:17:52 -04:00
|
|
|
}
|
|
|
|
// set number and keep isLatest flag
|
2023-11-14 04:03:01 -05:00
|
|
|
c.mergeWithLatestVersion(versions.SEVSNPVersion)
|
2023-06-14 08:17:52 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-11-14 04:03:01 -05:00
|
|
|
func (c *AzureSEVSNP) mergeWithLatestVersion(latest attestationconfigapi.SEVSNPVersion) {
|
2023-06-14 08:17:52 -04:00
|
|
|
if c.BootloaderVersion.WantLatest {
|
|
|
|
c.BootloaderVersion.Value = latest.Bootloader
|
|
|
|
}
|
|
|
|
if c.TEEVersion.WantLatest {
|
|
|
|
c.TEEVersion.Value = latest.TEE
|
|
|
|
}
|
|
|
|
if c.SNPVersion.WantLatest {
|
|
|
|
c.SNPVersion.Value = latest.SNP
|
|
|
|
}
|
|
|
|
if c.MicrocodeVersion.WantLatest {
|
|
|
|
c.MicrocodeVersion.Value = latest.Microcode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-10 07:32:13 -05:00
|
|
|
func (c *AzureSEVSNP) getToMarshallLatestWithResolvedVersions() AttestationCfg {
|
|
|
|
cp := *c
|
|
|
|
cp.BootloaderVersion.WantLatest = false
|
|
|
|
cp.TEEVersion.WantLatest = false
|
|
|
|
cp.SNPVersion.WantLatest = false
|
|
|
|
cp.MicrocodeVersion.WantLatest = false
|
|
|
|
return &cp
|
|
|
|
}
|
|
|
|
|
2023-06-14 08:17:52 -04:00
|
|
|
// GetVariant returns azure-trusted-launch as the variant.
|
|
|
|
func (AzureTrustedLaunch) GetVariant() variant.Variant {
|
|
|
|
return variant.AzureTrustedLaunch{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMeasurements returns the measurements used for attestation.
|
|
|
|
func (c AzureTrustedLaunch) GetMeasurements() measurements.M {
|
|
|
|
return c.Measurements
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMeasurements updates a config's measurements using the given measurements.
|
|
|
|
func (c *AzureTrustedLaunch) SetMeasurements(m measurements.M) {
|
|
|
|
c.Measurements = m
|
|
|
|
}
|
|
|
|
|
|
|
|
// EqualTo returns true if the config is equal to the given config.
|
|
|
|
func (c AzureTrustedLaunch) EqualTo(other AttestationCfg) (bool, error) {
|
|
|
|
otherCfg, ok := other.(*AzureTrustedLaunch)
|
|
|
|
if !ok {
|
|
|
|
return false, fmt.Errorf("cannot compare %T with %T", c, other)
|
|
|
|
}
|
|
|
|
return c.Measurements.EqualTo(otherCfg.Measurements), nil
|
|
|
|
}
|
2024-01-24 09:10:15 -05:00
|
|
|
|
|
|
|
// DefaultForAzureTDX returns the default configuration for Azure TDX attestation.
|
|
|
|
func DefaultForAzureTDX() *AzureTDX {
|
|
|
|
return &AzureTDX{
|
|
|
|
Measurements: measurements.DefaultsFor(cloudprovider.Azure, variant.AzureTDX{}),
|
2024-01-26 09:46:21 -05:00
|
|
|
// TODO(AB#3798): Enable latest versioning for Azure TDX
|
2024-06-12 04:24:16 -04:00
|
|
|
QESVN: NewLatestPlaceholderVersion[uint16](),
|
|
|
|
PCESVN: NewLatestPlaceholderVersion[uint16](),
|
|
|
|
TEETCBSVN: NewLatestPlaceholderVersion[encoding.HexBytes](),
|
|
|
|
QEVendorID: NewLatestPlaceholderVersion[encoding.HexBytes](),
|
2024-04-22 08:07:24 -04:00
|
|
|
// Don't set a default for MRSEAM as it effectively prevents upgrading the SEAM module
|
|
|
|
// Quote verification still makes sure the module comes from Intel (through MRSIGNERSEAM), and is not of a lower version than expected
|
|
|
|
// MRSeam: nil,
|
2024-06-12 04:24:16 -04:00
|
|
|
XFAM: NewLatestPlaceholderVersion[encoding.HexBytes](),
|
2024-01-24 09:10:15 -05:00
|
|
|
|
|
|
|
IntelRootKey: mustParsePEM(tdxRootPEM),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetVariant returns azure-tdx as the variant.
|
|
|
|
func (AzureTDX) GetVariant() variant.Variant {
|
|
|
|
return variant.AzureTDX{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMeasurements returns the measurements used for attestation.
|
|
|
|
func (c AzureTDX) GetMeasurements() measurements.M {
|
|
|
|
return c.Measurements
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMeasurements updates a config's measurements using the given measurements.
|
|
|
|
func (c *AzureTDX) SetMeasurements(m measurements.M) {
|
|
|
|
c.Measurements = m
|
|
|
|
}
|
|
|
|
|
|
|
|
// EqualTo returns true if the config is equal to the given config.
|
|
|
|
func (c AzureTDX) EqualTo(other AttestationCfg) (bool, error) {
|
|
|
|
otherCfg, ok := other.(*AzureTDX)
|
|
|
|
if !ok {
|
|
|
|
return false, fmt.Errorf("cannot compare %T with %T", c, other)
|
|
|
|
}
|
|
|
|
return c.Measurements.EqualTo(otherCfg.Measurements), nil
|
|
|
|
}
|
|
|
|
|
2024-06-12 04:24:16 -04:00
|
|
|
// FetchAndSetLatestVersionNumbers fetches the latest version numbers from the configapi and sets them.
|
|
|
|
func (c *AzureTDX) FetchAndSetLatestVersionNumbers(ctx context.Context, fetcher attestationconfigapi.Fetcher) error {
|
|
|
|
// Only talk to the API if at least one version number is set to latest.
|
|
|
|
if !(c.PCESVN.WantLatest || c.QESVN.WantLatest || c.TEETCBSVN.WantLatest || c.QEVendorID.WantLatest || c.XFAM.WantLatest) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
versions, err := fetcher.FetchLatestVersion(ctx, variant.AzureTDX{})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("fetching latest TCB versions from configapi: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// set values and keep WantLatest flag
|
|
|
|
if c.PCESVN.WantLatest {
|
|
|
|
c.PCESVN.Value = versions.PCESVN
|
|
|
|
}
|
|
|
|
if c.QESVN.WantLatest {
|
|
|
|
c.QESVN.Value = versions.QESVN
|
|
|
|
}
|
|
|
|
if c.TEETCBSVN.WantLatest {
|
|
|
|
c.TEETCBSVN.Value = versions.TEETCBSVN[:]
|
|
|
|
}
|
|
|
|
if c.QEVendorID.WantLatest {
|
|
|
|
c.QEVendorID.Value = versions.QEVendorID[:]
|
|
|
|
}
|
|
|
|
if c.XFAM.WantLatest {
|
|
|
|
c.XFAM.Value = versions.XFAM[:]
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-24 09:10:15 -05:00
|
|
|
func (c *AzureTDX) getToMarshallLatestWithResolvedVersions() AttestationCfg {
|
|
|
|
cp := *c
|
2024-06-12 04:24:16 -04:00
|
|
|
cp.PCESVN.WantLatest = false
|
|
|
|
cp.QESVN.WantLatest = false
|
|
|
|
cp.TEETCBSVN.WantLatest = false
|
|
|
|
cp.QEVendorID.WantLatest = false
|
|
|
|
cp.XFAM.WantLatest = false
|
2024-01-24 09:10:15 -05:00
|
|
|
return &cp
|
|
|
|
}
|