Przeglądaj źródła

Read the EAB key at finalize only when the provisioner requires EAB

Finalize read the order account's EAB key for every remote-attest-01
order. A database that reports an account without a key as an error,
as Step CA Pro's does, then failed every remote-attest-01 order under a
provisioner without EAB at finalize. New orders already read the key
only when the provisioner requires EAB; finalize now does the same,
through the provisioner's new IsEABRequired.

Claude-Session: https://claude.ai/code/session_01CjfEMLGpnHQaWsmxe1zmLF
Josh Drake 1 miesiąc temu
rodzic
commit
67e1856f6f

+ 1 - 0
acme/api/account_test.go

@@ -61,6 +61,7 @@ func (*fakeProvisioner) GetOptions() *provisioner.Options              { return
 func (*fakeProvisioner) GetRemoteAttestation() *provisioner.ACMERemoteAttestation {
 	return nil
 }
+func (*fakeProvisioner) IsEABRequired() bool { return false }
 func (*fakeProvisioner) VerifyRemoteAttestation(context.Context, *cmw.Record, string) (*attestation.Result, []byte, error) {
 	return nil, nil, nil
 }

+ 14 - 8
acme/challenge_remote_attestation_test.go

@@ -317,12 +317,16 @@ func TestOrder_Finalize_remoteAttestation(t *testing.T) {
 			MockUpdateOrder: func(context.Context, *Order) error { return nil },
 		}
 	}
-	prov := &MockProvisioner{
-		MauthorizeSign: func(context.Context, string) ([]provisioner.SignOption, error) {
-			return []provisioner.SignOption{&provisioner.WebhookController{}}, nil
-		},
-		MgetOptions: func() *provisioner.Options { return nil },
+	newProv := func(requireEAB bool) *MockProvisioner {
+		return &MockProvisioner{
+			MauthorizeSign: func(context.Context, string) ([]provisioner.SignOption, error) {
+				return []provisioner.SignOption{&provisioner.WebhookController{}}, nil
+			},
+			MgetOptions:    func() *provisioner.Options { return nil },
+			MisEABRequired: func() bool { return requireEAB },
+		}
 	}
+	prov, eabProv := newProv(false), newProv(true)
 	signAndCheck := func(t *testing.T, wantAccount *webhook.AttestationAccount) *mockSignAuth {
 		leaf, intermediate := &x509.Certificate{Raw: []byte("leaf")}, &x509.Certificate{Raw: []byte("intermediate")}
 		return &mockSignAuth{
@@ -350,8 +354,10 @@ func TestOrder_Finalize_remoteAttestation(t *testing.T) {
 	}
 
 	t.Run("ok without eab", func(t *testing.T) {
+		// A provisioner without EAB never reads the key, which some databases
+		// report as missing with an error.
 		o := newOrder()
-		require.NoError(t, o.Finalize(context.Background(), newDB(nil, nil), csr, signAndCheck(t, &webhook.AttestationAccount{ID: "accID"}), prov))
+		require.NoError(t, o.Finalize(context.Background(), newDB(nil, errors.New("not found")), csr, signAndCheck(t, &webhook.AttestationAccount{ID: "accID"}), prov))
 		assert.Equal(t, StatusValid, o.Status)
 		assert.Equal(t, "certID", o.CertificateID)
 	})
@@ -361,12 +367,12 @@ func TestOrder_Finalize_remoteAttestation(t *testing.T) {
 		o := newOrder()
 		require.NoError(t, o.Finalize(context.Background(), newDB(eak, nil), csr, signAndCheck(t, &webhook.AttestationAccount{
 			ID: "accID", ExternalAccountKeyID: "eakID", Reference: "machine-1",
-		}), prov))
+		}), eabProv))
 		assert.Equal(t, StatusValid, o.Status)
 	})
 
 	t.Run("fail eab lookup", func(t *testing.T) {
-		err := newOrder().Finalize(context.Background(), newDB(nil, errors.New("force")), csr, &mockSignAuth{}, prov)
+		err := newOrder().Finalize(context.Background(), newDB(nil, errors.New("force")), csr, &mockSignAuth{}, eabProv)
 		assert.ErrorContains(t, err, "error getting the external account key")
 	})
 

+ 10 - 0
acme/common.go

@@ -82,6 +82,7 @@ type Provisioner interface {
 	DefaultTLSCertDuration() time.Duration
 	GetOptions() *provisioner.Options
 	GetRemoteAttestation() *provisioner.ACMERemoteAttestation
+	IsEABRequired() bool
 	VerifyRemoteAttestation(ctx context.Context, record *cmw.Record, defaultAudience string) (*attestation.Result, []byte, error)
 }
 
@@ -126,6 +127,7 @@ type MockProvisioner struct {
 	MdefaultTLSCertDuration   func() time.Duration
 	MgetOptions               func() *provisioner.Options
 	MgetRemoteAttestation     func() *provisioner.ACMERemoteAttestation
+	MisEABRequired            func() bool
 	MverifyRemoteAttestation  func(ctx context.Context, record *cmw.Record, defaultAudience string) (*attestation.Result, []byte, error)
 }
 
@@ -208,6 +210,14 @@ func (m *MockProvisioner) GetRemoteAttestation() *provisioner.ACMERemoteAttestat
 	return nil
 }
 
+// IsEABRequired mock
+func (m *MockProvisioner) IsEABRequired() bool {
+	if m.MisEABRequired != nil {
+		return m.MisEABRequired()
+	}
+	return false
+}
+
 // VerifyRemoteAttestation mock
 func (m *MockProvisioner) VerifyRemoteAttestation(ctx context.Context, record *cmw.Record, defaultAudience string) (*attestation.Result, []byte, error) {
 	if m.MverifyRemoteAttestation != nil {

+ 8 - 3
acme/order.go

@@ -187,9 +187,14 @@ func (o *Order) checkAttestedKeys(ctx context.Context, db DB, csr *x509.Certific
 
 // attestationAccount returns the order's ACME account for the webhooks of a
 // remote-attest-01 order, with the external account binding key the account
-// was created with, if any.
-func (o *Order) attestationAccount(ctx context.Context, db DB) (*webhook.AttestationAccount, error) {
+// was created with, if any. As for new orders, the key is read only if the
+// provisioner requires one: some databases report an account without a key as
+// an error.
+func (o *Order) attestationAccount(ctx context.Context, db DB, p Provisioner) (*webhook.AttestationAccount, error) {
 	account := &webhook.AttestationAccount{ID: o.AccountID}
+	if !p.IsEABRequired() {
+		return account, nil
+	}
 	eak, err := db.GetExternalAccountKeyByAccountID(ctx, o.ProvisionerID, o.AccountID)
 	if err != nil {
 		return nil, WrapErrorISE(err, "error getting the external account key of account %q", o.AccountID)
@@ -233,7 +238,7 @@ func (o *Order) Finalize(ctx context.Context, db DB, csr *x509.CertificateReques
 		return err
 	}
 	if att != nil {
-		if att.Account, err = o.attestationAccount(ctx, db); err != nil {
+		if att.Account, err = o.attestationAccount(ctx, db, p); err != nil {
 			return err
 		}
 	}

+ 6 - 0
authority/provisioner/acme_remote_attestation.go

@@ -194,6 +194,12 @@ func (p *ACME) GetRemoteAttestation() *ACMERemoteAttestation {
 	return p.RemoteAttestation
 }
 
+// IsEABRequired returns whether new accounts need an external account binding,
+// so whether every account of the provisioner has an EAB key.
+func (p *ACME) IsEABRequired() bool {
+	return p.RequireEAB
+}
+
 // VerifyRemoteAttestation verifies the evidence of a remote-attest-01
 // challenge, a CMW record, and returns it with the data it binds: first the
 // RemoteAttestationBindingSize bytes of the binding, then, for a TDX quote or an