Просмотр исходного кода

Carry remote-attest-01 through linkedca

Remote management converts every provisioner through linkedca, and
challengesToLinkedca dropped any challenge it did not know. So an ACME
provisioner that enabled remote-attest-01, and its remoteAttestation
block, could not be configured on a CA under remote management, which
Step CA Pro forces.

This maps linkedca's new REMOTE_ATTEST_01 challenge type both ways and
converts the remoteAttestation block to and from linkedca's
ACMERemoteAttestation. That covers the formats, claims hint, root
overrides, and the Confidential Space roots, audience, maximum token
age and expectations. An unparsable maximum token age is refused.

This branch is stacked on josh/acme-remote-attest. It builds against
linkedca's josh/acme-remote-attest branch through an uncommitted go.work
until linkedca releases the type.

Claude-Session: https://claude.ai/code/session_01CjfEMLGpnHQaWsmxe1zmLF
Josh Drake 1 месяц назад
Родитель
Сommit
834bcfc09f
3 измененных файлов с 172 добавлено и 2 удалено
  1. 3 2
      CHANGELOG.md
  2. 86 0
      authority/provisioners.go
  3. 83 0
      authority/provisioners_remote_attestation_test.go

+ 3 - 2
CHANGELOG.md

@@ -47,8 +47,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
   Google Cloud Attestation's root is embedded, so Confidential Space tokens
   verify without configured roots. The verified attestation, with the ACME
   account and the EAB key it was created with, is sent to webhooks as
-  `attestation` and given to templates as `.Attestation`. The challenge can be
-  configured in `ca.json` only for now.
+  `attestation` and given to templates as `.Attestation`. Remote management
+  carries the challenge and its configuration through linkedca's
+  `REMOTE_ATTEST_01` challenge type and `ACMERemoteAttestation` message.
 - The `attestation` package and its subpackages, which verify TDX quotes,
   SEV-SNP reports and Confidential Space tokens, and parse CMW records and
   configfs-tsm reports. The `device-attest-01` formats' verifiers (`apple`,

+ 86 - 0
authority/provisioners.go

@@ -16,6 +16,8 @@ import (
 	"github.com/smallstep/linkedca"
 	"go.step.sm/crypto/jose"
 
+	"github.com/smallstep/certificates/attestation"
+	"github.com/smallstep/certificates/attestation/confidentialspace"
 	"github.com/smallstep/certificates/authority/admin"
 	"github.com/smallstep/certificates/authority/config"
 	"github.com/smallstep/certificates/authority/policy"
@@ -893,6 +895,10 @@ func ProvisionerToCertificates(p *linkedca.Provisioner) (provisioner.Interface,
 		}, nil
 	case *linkedca.ProvisionerDetails_ACME:
 		cfg := d.ACME
+		remoteAttestation, err := remoteAttestationToCertificates(cfg.RemoteAttestation)
+		if err != nil {
+			return nil, err
+		}
 		return &provisioner.ACME{
 			ID:                 p.Id,
 			Type:               p.Type.String(),
@@ -905,6 +911,7 @@ func ProvisionerToCertificates(p *linkedca.Provisioner) (provisioner.Interface,
 			Challenges:         challengesToCertificates(cfg.Challenges),
 			AttestationFormats: attestationFormatsToCertificates(cfg.AttestationFormats),
 			AttestationRoots:   provisionerPEMToCertificates(cfg.AttestationRoots),
+			RemoteAttestation:  remoteAttestation,
 			Claims:             claims,
 			Options:            options,
 		}, nil
@@ -1184,6 +1191,7 @@ func ProvisionerToLinkedca(p provisioner.Interface) (*linkedca.Provisioner, erro
 						Challenges:         challengesToLinkedca(p.Challenges),
 						AttestationFormats: attestationFormatsToLinkedca(p.AttestationFormats),
 						AttestationRoots:   provisionerPEMToLinkedca(p.AttestationRoots),
+						RemoteAttestation:  remoteAttestationToLinkedca(p.RemoteAttestation),
 					},
 				},
 			},
@@ -1331,6 +1339,8 @@ func challengesToCertificates(challenges []linkedca.ACMEProvisioner_ChallengeTyp
 			ret = append(ret, provisioner.TLS_ALPN_01)
 		case linkedca.ACMEProvisioner_DEVICE_ATTEST_01:
 			ret = append(ret, provisioner.DEVICE_ATTEST_01)
+		case linkedca.ACMEProvisioner_REMOTE_ATTEST_01:
+			ret = append(ret, provisioner.REMOTE_ATTEST_01)
 		}
 	}
 	return ret
@@ -1350,6 +1360,82 @@ func challengesToLinkedca(challenges []provisioner.ACMEChallenge) []linkedca.ACM
 			ret = append(ret, linkedca.ACMEProvisioner_TLS_ALPN_01)
 		case provisioner.DEVICE_ATTEST_01:
 			ret = append(ret, linkedca.ACMEProvisioner_DEVICE_ATTEST_01)
+		case provisioner.REMOTE_ATTEST_01:
+			ret = append(ret, linkedca.ACMEProvisioner_REMOTE_ATTEST_01)
+		}
+	}
+	return ret
+}
+
+// remoteAttestationToCertificates converts the linkedca configuration of the
+// remote-attest-01 challenge to the provisioner's.
+func remoteAttestationToCertificates(ra *linkedca.ACMERemoteAttestation) (*provisioner.ACMERemoteAttestation, error) {
+	if ra == nil {
+		return nil, nil //nolint:nilnil // no configuration is not an error
+	}
+	ret := &provisioner.ACMERemoteAttestation{
+		Require:     ra.Require,
+		ClaimsHint:  ra.ClaimsHint,
+		TDXRoots:    ra.TdxRoots,
+		SEVSNPRoots: ra.SevSnpRoots,
+	}
+	for _, f := range ra.Formats {
+		ret.Formats = append(ret.Formats, attestation.Format(f))
+	}
+	if cs := ra.ConfidentialSpace; cs != nil {
+		ret.ConfidentialSpace = &provisioner.ACMEConfidentialSpace{
+			Roots:    cs.Roots,
+			Audience: cs.Audience,
+			Expectations: confidentialspace.Expectations{
+				ImageDigests:             cs.ImageDigests,
+				ImageSignerKeyIDs:        cs.ImageSignerKeyIds,
+				RequireSupportAttributes: cs.RequireSupportAttributes,
+				HWModels:                 cs.Hwmodels,
+				SWNames:                  cs.Swnames,
+				ProjectIDs:               cs.ProjectIds,
+				ServiceAccounts:          cs.ServiceAccounts,
+			},
+		}
+		if cs.MaxTokenAge != "" {
+			d, err := provisioner.NewDuration(cs.MaxTokenAge)
+			if err != nil {
+				return nil, fmt.Errorf("error parsing remote attestation maxTokenAge: %w", err)
+			}
+			ret.ConfidentialSpace.MaxTokenAge = d
+		}
+	}
+	return ret, nil
+}
+
+// remoteAttestationToLinkedca converts the provisioner's configuration of the
+// remote-attest-01 challenge to linkedca's.
+func remoteAttestationToLinkedca(ra *provisioner.ACMERemoteAttestation) *linkedca.ACMERemoteAttestation {
+	if ra == nil {
+		return nil
+	}
+	ret := &linkedca.ACMERemoteAttestation{
+		Require:     ra.Require,
+		ClaimsHint:  ra.ClaimsHint,
+		TdxRoots:    ra.TDXRoots,
+		SevSnpRoots: ra.SEVSNPRoots,
+	}
+	for _, f := range ra.Formats {
+		ret.Formats = append(ret.Formats, string(f))
+	}
+	if cs := ra.ConfidentialSpace; cs != nil {
+		ret.ConfidentialSpace = &linkedca.ACMEConfidentialSpace{
+			Roots:                    cs.Roots,
+			Audience:                 cs.Audience,
+			ImageDigests:             cs.ImageDigests,
+			ImageSignerKeyIds:        cs.ImageSignerKeyIDs,
+			RequireSupportAttributes: cs.RequireSupportAttributes,
+			Hwmodels:                 cs.HWModels,
+			Swnames:                  cs.SWNames,
+			ProjectIds:               cs.ProjectIDs,
+			ServiceAccounts:          cs.ServiceAccounts,
+		}
+		if cs.MaxTokenAge != nil {
+			ret.ConfidentialSpace.MaxTokenAge = cs.MaxTokenAge.String()
 		}
 	}
 	return ret

+ 83 - 0
authority/provisioners_remote_attestation_test.go

@@ -0,0 +1,83 @@
+package authority
+
+import (
+	"testing"
+	"time"
+
+	"github.com/smallstep/linkedca"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+
+	"github.com/smallstep/certificates/attestation"
+	"github.com/smallstep/certificates/attestation/confidentialspace"
+	"github.com/smallstep/certificates/authority/provisioner"
+)
+
+// TestProvisioner_remoteAttestation checks that an ACME provisioner with the
+// remote-attest-01 challenge and its configuration survives the conversions to
+// linkedca and back, which remote management goes through.
+func TestProvisioner_remoteAttestation(t *testing.T) {
+	ra := &provisioner.ACMERemoteAttestation{
+		Require:     true,
+		Formats:     []attestation.Format{attestation.FormatTDX, attestation.FormatConfidentialSpace},
+		ClaimsHint:  []string{"hwmodel"},
+		TDXRoots:    []byte("tdx roots"),
+		SEVSNPRoots: []byte("sev-snp roots"),
+		ConfidentialSpace: &provisioner.ACMEConfidentialSpace{
+			Roots:       []byte("roots"),
+			Audience:    "my-project",
+			MaxTokenAge: &provisioner.Duration{Duration: 5 * time.Minute},
+			Expectations: confidentialspace.Expectations{
+				ImageDigests:             []string{"sha256:00"},
+				ImageSignerKeyIDs:        []string{"c0ffee"},
+				RequireSupportAttributes: []string{"STABLE"},
+				HWModels:                 []string{"GCP_INTEL_TDX"},
+				SWNames:                  []string{"CONFIDENTIAL_SPACE"},
+				ProjectIDs:               []string{"my-project"},
+				ServiceAccounts:          []string{"workload@my-project.iam.gserviceaccount.com"},
+			},
+		},
+	}
+	p := &provisioner.ACME{
+		ID:                "acme-id",
+		Type:              "ACME",
+		Name:              "attested",
+		Challenges:        []provisioner.ACMEChallenge{provisioner.DNS_01, provisioner.REMOTE_ATTEST_01},
+		RemoteAttestation: ra,
+	}
+
+	lp, err := ProvisionerToLinkedca(p)
+	require.NoError(t, err)
+	acme := lp.GetDetails().GetACME()
+	require.NotNil(t, acme)
+	assert.Equal(t, []linkedca.ACMEProvisioner_ChallengeType{
+		linkedca.ACMEProvisioner_DNS_01, linkedca.ACMEProvisioner_REMOTE_ATTEST_01,
+	}, acme.Challenges)
+	require.NotNil(t, acme.RemoteAttestation)
+	assert.Equal(t, []string{"tdx", "confidential-space"}, acme.RemoteAttestation.Formats)
+	assert.Equal(t, "5m0s", acme.RemoteAttestation.ConfidentialSpace.MaxTokenAge)
+
+	got, err := ProvisionerToCertificates(lp)
+	require.NoError(t, err)
+	gotACME, ok := got.(*provisioner.ACME)
+	require.True(t, ok)
+	assert.Equal(t, p.Challenges, gotACME.Challenges)
+	assert.Equal(t, ra, gotACME.RemoteAttestation)
+
+	t.Run("no configuration", func(t *testing.T) {
+		lp, err := ProvisionerToLinkedca(&provisioner.ACME{Type: "ACME", Name: "plain"})
+		require.NoError(t, err)
+		assert.Nil(t, lp.GetDetails().GetACME().RemoteAttestation)
+		got, err := ProvisionerToCertificates(lp)
+		require.NoError(t, err)
+		assert.Nil(t, got.(*provisioner.ACME).RemoteAttestation)
+	})
+
+	t.Run("fail max token age", func(t *testing.T) {
+		lp, err := ProvisionerToLinkedca(p)
+		require.NoError(t, err)
+		lp.GetDetails().GetACME().RemoteAttestation.ConfidentialSpace.MaxTokenAge = "five minutes"
+		_, err = ProvisionerToCertificates(lp)
+		assert.ErrorContains(t, err, "error parsing remote attestation maxTokenAge")
+	})
+}