Skip to content

Commit 2ef3f5b

Browse files
fnerdmanFrieder Paape
andauthored
feat: auto detect tee env on issuer side (#32)
* feat: auto detect tee env on issuer side * chore: sets client attestation to none, updates readme * Update README.md --------- Co-authored-by: Frieder Paape <frieder@konvera.io>
1 parent aebd334 commit 2ef3f5b

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ Client
3939

4040
- `--listen-addr`: address to listen on (default: "127.0.0.1:8080")
4141
- `--target-addr`: address to proxy requests to (default: "https://localhost:80")
42-
- `--server-attestation-type`: type of attestation to present (none, azure-tdx) (default: "azure-tdx")
42+
- `--server-attestation-type`: type of attestation to present (none, auto, dcap-tdx, azure-tdx) (default: "auto")
4343
- `--tls-certificate-path`: Path to certificate (PEM file) to present. Only valid for --server-attestation-type=none and with `--tls-private-key-path`.
4444
- `--tls-private-key-path`: Path to private key file for the certificate (PEM). Only valid with --tls-certificate-path.
45-
- `--client-attestation-type`: type of attestation to expect and verify (none, azure-tdx) (default: "none")
45+
- `--client-attestation-type`: type of attestation to expect and verify (none, dcap-tdx, azure-tdx) (default: "none")
4646
- `--client-measurements`: optional path to JSON measurements enforced on the client
4747
- `--log-json`: log in JSON format (default: false)
4848
- `--log-debug`: log debug messages (default: false)
@@ -70,7 +70,7 @@ sudo ./build/proxy-server --listen-addr=<listen-addr> --target-addr=<target-addr
7070
docker run -p 8080:8080 -e LOG_JSON=1 cvm-proxy-server
7171
```
7272

73-
By default the server will present Azure TDX attestation, and you can modify that via the `--server-attestation-type` flag.
73+
By default the server will determine the attestation issuer automatically, and you can modify that via the `--server-attestation-type` flag.
7474
The server can be made to present a regular TLS certificate through `--tls-certificate-path` and `--tls-private-key-path` flags instead of aTLS one.
7575

7676
By default the server will not verify client attestations, you can change that via `--client-attestation-type` and `--client-measurements` flags. Valid for both aTLS and regular TLS.
@@ -89,7 +89,7 @@ This repository contains a [dummy http server](./cmd/dummy-server/main.go) that
8989
- `--server-measurements`: optional path to JSON measurements enforced on the server
9090
- `--verify-tls`: verify server's TLS certificate instead of server's attestation. Only valid for server-attestation-type=none.
9191
- `--tls-ca-certificate`: additional CA certificate to verify against (PEM) [default=no additional TLS certs]. Only valid with --verify-tls.
92-
- `--client-attestation-type`: type of attestation to present (none, azure-tdx) (default: "none")
92+
- `--client-attestation-type`: type of attestation to present (none, auto, dcap-tdx, azure-tdx) (default: "none")
9393
- `--log-json`: log in JSON format (default: false)
9494
- `--log-debug`: log debug messages (default: false)
9595
- `--log-dcap-quote`: log dcap quotes to folder quotes/ (default: false)
@@ -111,7 +111,7 @@ make build-proxy-client
111111
By default the client will expect the server to present an Azure TDX attestation, and you can modify that via the `--server-attestation-type` and `--server-measurements` flags.
112112
The server can also be a regular TLS server, which you can configure with the `--verify-tls` flag, which is only valid in combination with `--server-attestation-type=none`. Non-standard CA for the server can also be configured with `--tls-ca-certificate`.
113113

114-
By default the client will not present client attestations, you can change that via `--client-attestation-type` flag. Valid for both aTLS and TLS server proxies.
114+
By default the client will not present client attestations, you can change that via `--client-attestation-type` flag. If this is set to "auto", it will try to determine the attestation issuer automatically. Valid for both aTLS and TLS server proxies.
115115

116116
This repository contains a sample [measurements.json](./measurements.json) file that you can use. The client will (correctly) complain about unexpected measurements that you can then correct.
117117

cmd/proxy-client/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var flags []cli.Flag = []cli.Flag{
4646
&cli.StringFlag{
4747
Name: "client-attestation-type",
4848
Value: string(proxy.AttestationNone),
49-
Usage: "type of attestation to present (" + proxy.AvailableAttestationTypes + ")",
49+
Usage: "type of attestation to present (" + proxy.AvailableAttestationTypes + ").",
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: string(proxy.AttestationAuto),
44+
Usage: "type of attestation to present (" + proxy.AvailableAttestationTypes + "). Defaults to automatic detection.",
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)