Skip to content

Commit a475695

Browse files
committed
sdk: require opt-in for insecure deployments.
For verifying an insecure deployment, an SDK user must now instantiate the client `.WithInsecure`, aligning it to the CLI behavior.
1 parent e3ad77b commit a475695

2 files changed

Lines changed: 65 additions & 4 deletions

File tree

sdk/verify.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ type Client struct {
3737

3838
log *slog.Logger
3939

40+
// allowInsecure must be set to true to allow verification of manifests
41+
// that contain insecure (non-CC) reference values. Without this, ValidateAttestation
42+
// will return an error if the manifest allows insecure platforms.
43+
allowInsecure bool
44+
4045
// validatorsFromManifestOverride is used by tests to replace the validators.
4146
validatorsFromManifestOverride func(*certcache.CachedHTTPSGetter, *manifest.Manifest, *slog.Logger) ([]atls.Validator, error)
4247
}
@@ -80,6 +85,15 @@ func (c *Client) WithHTTPClient(httpClient *http.Client) *Client {
8085
return c
8186
}
8287

88+
// WithInsecure allows the Client to verify manifests containing insecure (non-CC) reference values.
89+
//
90+
// By default, [Client.ValidateAttestation] will return an error if the manifest allows insecure
91+
// platforms. This method opts in to accepting such manifests.
92+
func (c *Client) WithInsecure() *Client {
93+
c.allowInsecure = true
94+
return c
95+
}
96+
8397
// GetAttestation requests attestation evidence from the Coordinator's HTTP API.
8498
//
8599
// The URL needs to map to the http://coordinator:1314/attest endpoint, but can be reverse-proxied
@@ -159,6 +173,10 @@ func (c Client) ValidateAttestation(ctx context.Context, nonce []byte, attestati
159173
return nil, fmt.Errorf("validating latest manifest: %w", err)
160174
}
161175

176+
if latestManifest.AllowInsecure() && !c.allowInsecure {
177+
return nil, fmt.Errorf("manifest contains insecure platforms: use WithInsecure() to allow verification of insecure deployments")
178+
}
179+
162180
kdsGetter := certcache.NewCachedHTTPSGetter(c.fsstore, certcache.NeverGCTicker, c.log.WithGroup("kds-getter"))
163181
validatorsFromManifest := ValidatorsFromManifest
164182
if c.validatorsFromManifestOverride != nil {

sdk/verify_test.go

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ func TestGetAttestation(t *testing.T) {
107107
func TestValidateAttestation(t *testing.T) {
108108
testNonce := make([]byte, 32)
109109
for name, tc := range map[string]struct {
110-
nonce []byte
111-
resp *httpapi.AttestationResponse
112-
validateErr error
113-
wantErr string
110+
nonce []byte
111+
resp *httpapi.AttestationResponse
112+
validateErr error
113+
allowInsecure bool
114+
wantErr string
114115
}{
115116
"success": {
116117
nonce: testNonce,
@@ -143,6 +144,26 @@ func TestValidateAttestation(t *testing.T) {
143144
validateErr: assert.AnError,
144145
wantErr: assert.AnError.Error(),
145146
},
147+
"insecure manifest without opt-in": {
148+
nonce: testNonce,
149+
resp: &httpapi.AttestationResponse{
150+
RawAttestationDoc: testNonce,
151+
CoordinatorState: httpapi.CoordinatorState{
152+
Manifests: [][]byte{testInsecureManifest},
153+
},
154+
},
155+
wantErr: "WithInsecure",
156+
},
157+
"insecure manifest with opt-in": {
158+
nonce: testNonce,
159+
allowInsecure: true,
160+
resp: &httpapi.AttestationResponse{
161+
RawAttestationDoc: testNonce,
162+
CoordinatorState: httpapi.CoordinatorState{
163+
Manifests: [][]byte{testInsecureManifest},
164+
},
165+
},
166+
},
146167
} {
147168
t.Run(name, func(t *testing.T) {
148169
assert := assert.New(t)
@@ -152,6 +173,9 @@ func TestValidateAttestation(t *testing.T) {
152173
require.NoError(err)
153174

154175
c := New()
176+
if tc.allowInsecure {
177+
c = c.WithInsecure()
178+
}
155179

156180
c.validatorsFromManifestOverride = func(*certcache.CachedHTTPSGetter, *manifest.Manifest, *slog.Logger) ([]atls.Validator, error) {
157181
return []atls.Validator{&stubValidator{err: tc.validateErr}}, nil
@@ -224,6 +248,25 @@ var testManifest = []byte(`
224248
}
225249
`)
226250

251+
var testInsecureManifest = []byte(`
252+
{
253+
"Policies": {
254+
"ef27c1c91a0ce044c67f0ec10d7c66ea9f178453dc96a233e97f0675578042f2": {
255+
"SANs": ["coordinator"],
256+
"WorkloadSecretID": "apps/v1/StatefulSet/default/coordinator",
257+
"Role": "coordinator"
258+
}
259+
},
260+
"ReferenceValues": {
261+
"snp": [
262+
{
263+
"Platform": "metal-qemu-snp-insecure"
264+
}
265+
]
266+
}
267+
}
268+
`)
269+
227270
type stubValidator struct {
228271
atls.Validator
229272

0 commit comments

Comments
 (0)