@@ -24,16 +24,19 @@ type AttestationType string
2424
2525const (
2626 AttestationNone AttestationType = "none"
27+ AttestationAuto AttestationType = "auto"
2728 AttestationAzureTDX AttestationType = "azure-tdx"
2829 AttestationDCAPTDX AttestationType = "dcap-tdx"
2930)
3031
31- const AvailableAttestationTypes string = "none, azure-tdx, dcap-tdx"
32+ const AvailableAttestationTypes string = "none, auto, azure-tdx, dcap-tdx"
3233
3334func ParseAttestationType (attestationType string ) (AttestationType , error ) {
3435 switch attestationType {
3536 case string (AttestationNone ):
3637 return AttestationNone , nil
38+ case string (AttestationAuto ):
39+ return AttestationAuto , nil
3740 case string (AttestationAzureTDX ):
3841 return AttestationAzureTDX , nil
3942 case string (AttestationDCAPTDX ):
@@ -56,7 +59,31 @@ func CreateAttestationIssuer(log *slog.Logger, attestationType AttestationType)
5659 }
5760}
5861
62+ // DetectAttestationType determines the attestation type based on environment
63+ func DetectAttestationType () AttestationType {
64+ // Check for TDX device files - these indicate DCAP TDX
65+ _ , tdxErr1 := os .Stat ("/dev/tdx-guest" )
66+ _ , tdxErr2 := os .Stat ("/dev/tdx_guest" )
67+ if tdxErr1 == nil || tdxErr2 == nil {
68+ return AttestationDCAPTDX
69+ }
70+
71+ // Try Azure TDX attestation - if it works, we're in Azure TDX
72+ issuer := azure_tdx .NewIssuer (nil ) // nil logger for detection
73+ _ , err := issuer .Issue (context .Background (), []byte ("test" ), []byte ("test" ))
74+ if err == nil {
75+ return AttestationAzureTDX
76+ }
77+
78+ return AttestationNone
79+ }
80+
5981func CreateAttestationValidators (log * slog.Logger , attestationType AttestationType , jsonMeasurementsPath string ) ([]atls.Validator , error ) {
82+ if attestationType == AttestationAuto {
83+ attestationType = DetectAttestationType ()
84+ log .With ("detected_attestation" , attestationType ).Info ("Auto-detected attestation type" )
85+ }
86+
6087 if attestationType == AttestationNone {
6188 return nil , nil
6289 }
0 commit comments