Skip to content

Commit 86f6212

Browse files
author
Frieder Paape
committed
feat: auto detect tee env on issuer side
1 parent 24c49a8 commit 86f6212

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

cmd/proxy-client/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ var flags []cli.Flag = []cli.Flag{
4545
},
4646
&cli.StringFlag{
4747
Name: "client-attestation-type",
48-
Value: string(proxy.AttestationNone),
49-
Usage: "type of attestation to present (" + proxy.AvailableAttestationTypes + ")",
48+
Value: "auto",
49+
Usage: "type of attestation to present (" + proxy.AvailableAttestationTypes + "). If not set, automatically detected.",
5050
},
5151
&cli.BoolFlag{
5252
Name: "log-json",

cmd/proxy-server/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ var flags []cli.Flag = []cli.Flag{
4040
&cli.StringFlag{
4141
Name: "server-attestation-type",
4242
EnvVars: []string{"SERVER_ATTESTATION_TYPE"},
43-
Value: string(proxy.AttestationAzureTDX),
44-
Usage: "type of attestation to present (" + proxy.AvailableAttestationTypes + ")",
43+
Value: "auto",
44+
Usage: "type of attestation to present (" + proxy.AvailableAttestationTypes + "). If not set, automatically detected.",
4545
},
4646
&cli.StringFlag{
4747
Name: "tls-certificate-path",

proxy/atls_config.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ type AttestationType string
2424

2525
const (
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

3334
func 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+
5981
func 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

Comments
 (0)