Skip to content

Commit b6ef3b4

Browse files
Use Policy field instead of PolicyIdentifiers in cert templates (spiffe#6074)
Co-authored-by: Marcos Yacob <[email protected]> Signed-off-by: Sorin Dumitru <[email protected]>
1 parent f448057 commit b6ef3b4

File tree

7 files changed

+174
-93
lines changed

7 files changed

+174
-93
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [1.12.2] - 2025-05-19
4+
5+
### Fixed
6+
7+
- Regression where PolicyCredentials set by CredentialComposer plugins were not correctly applied to CA certificates. (#6074)
8+
39
## [1.12.1] - 2025-05-06
410

511
### Added

pkg/server/ca/manager/manager_test.go

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ import (
1717
"github.com/sirupsen/logrus"
1818
"github.com/sirupsen/logrus/hooks/test"
1919
"github.com/spiffe/go-spiffe/v2/spiffeid"
20+
"github.com/spiffe/spire/pkg/common/catalog"
2021
"github.com/spiffe/spire/pkg/common/coretypes/x509certificate"
2122
telemetry_server "github.com/spiffe/spire/pkg/common/telemetry/server"
2223
"github.com/spiffe/spire/pkg/common/x509util"
2324
"github.com/spiffe/spire/pkg/server/ca"
2425
"github.com/spiffe/spire/pkg/server/credtemplate"
2526
"github.com/spiffe/spire/pkg/server/credvalidator"
2627
"github.com/spiffe/spire/pkg/server/datastore"
28+
"github.com/spiffe/spire/pkg/server/plugin/credentialcomposer"
2729
"github.com/spiffe/spire/pkg/server/plugin/keymanager"
2830
"github.com/spiffe/spire/pkg/server/plugin/notifier"
2931
"github.com/spiffe/spire/pkg/server/plugin/upstreamauthority"
@@ -153,6 +155,25 @@ func TestGetCurrentX509CASlot(t *testing.T) {
153155
})
154156
}
155157

158+
func TestCAPolicyIdentifiers(t *testing.T) {
159+
ctx := context.Background()
160+
161+
test := setupTest(t)
162+
test.initSelfSignedManager()
163+
policy, err := x509.ParseOID("1.2.3.4")
164+
require.NoError(t, err)
165+
test.cc.policies = append(test.cc.policies, policy)
166+
167+
t.Run("contains policy identifiers", func(t *testing.T) {
168+
require.NoError(t, test.m.PrepareX509CA(ctx))
169+
170+
currentSlot := test.m.GetCurrentX509CASlot()
171+
slot := currentSlot.(*x509CASlot)
172+
require.NotNil(t, slot.x509CA)
173+
require.Equal(t, slot.x509CA.Certificate.Policies, test.cc.policies)
174+
})
175+
}
176+
156177
func TestGetNextX509CASlot(t *testing.T) {
157178
ctx := context.Background()
158179

@@ -1206,6 +1227,7 @@ type managerTest struct {
12061227
km keymanager.KeyManager
12071228
ds *fakedatastore.DataStore
12081229
cat *fakeservercatalog.Catalog
1230+
cc fakeCC
12091231

12101232
m *Manager
12111233
}
@@ -1295,10 +1317,11 @@ func (m *managerTest) selfSignedConfig() Config {
12951317

12961318
func (m *managerTest) selfSignedConfigWithKeyTypes(x509CAKeyType, jwtKeyType keymanager.KeyType) Config {
12971319
credBuilder, err := credtemplate.NewBuilder(credtemplate.Config{
1298-
TrustDomain: testTrustDomain,
1299-
X509CASubject: pkix.Name{CommonName: "SPIRE"},
1300-
Clock: m.clock,
1301-
X509CATTL: testCATTL,
1320+
TrustDomain: testTrustDomain,
1321+
X509CASubject: pkix.Name{CommonName: "SPIRE"},
1322+
Clock: m.clock,
1323+
X509CATTL: testCATTL,
1324+
CredentialComposers: []credentialcomposer.CredentialComposer{&m.cc},
13021325
})
13031326
require.NoError(m.t, err)
13041327

@@ -1547,3 +1570,30 @@ func (s *fakeCA) SetJWTKey(jwtKey *ca.JWTKey) {
15471570
func (s *fakeCA) NotifyTaintedX509Authorities(taintedAuthorities []*x509.Certificate) {
15481571
s.taintedAuthoritiesCh <- taintedAuthorities
15491572
}
1573+
1574+
type fakeCC struct {
1575+
catalog.PluginInfo
1576+
1577+
policies []x509.OID
1578+
}
1579+
1580+
func (cc fakeCC) ComposeServerX509CA(_ context.Context, attributes credentialcomposer.X509CAAttributes) (credentialcomposer.X509CAAttributes, error) {
1581+
attributes.Policies = append(attributes.Policies, cc.policies...)
1582+
return attributes, nil
1583+
}
1584+
1585+
func (cc fakeCC) ComposeServerX509SVID(_ context.Context, attributes credentialcomposer.X509SVIDAttributes) (credentialcomposer.X509SVIDAttributes, error) {
1586+
return attributes, nil
1587+
}
1588+
1589+
func (cc fakeCC) ComposeAgentX509SVID(_ context.Context, _ spiffeid.ID, _ crypto.PublicKey, attributes credentialcomposer.X509SVIDAttributes) (credentialcomposer.X509SVIDAttributes, error) {
1590+
return attributes, nil
1591+
}
1592+
1593+
func (cc fakeCC) ComposeWorkloadX509SVID(_ context.Context, _ spiffeid.ID, _ crypto.PublicKey, attributes credentialcomposer.X509SVIDAttributes) (credentialcomposer.X509SVIDAttributes, error) {
1594+
return attributes, nil
1595+
}
1596+
1597+
func (cc fakeCC) ComposeWorkloadJWTSVID(_ context.Context, _ spiffeid.ID, attributes credentialcomposer.JWTSVIDAttributes) (credentialcomposer.JWTSVIDAttributes, error) {
1598+
return attributes, nil
1599+
}

pkg/server/credtemplate/builder.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func (b *Builder) BuildUpstreamSignedX509CACSR(ctx context.Context, params Upstr
202202
}
203203

204204
// Create the CertificateRequest from the Certificate template. The
205-
// PolicyIdentifiers field is ignored since that can be applied by the
205+
// Policies field is ignored since that can be applied by the
206206
// upstream signer and isn't a part of the native CertificateRequest type.
207207
// TODO: maybe revisit this if needed and embed the policy identifiers in
208208
// the extra extensions.
@@ -458,9 +458,9 @@ func (b *Builder) computeX509SVIDLifetime(parentChain []*x509.Certificate, ttl t
458458

459459
func x509CAAttributesFromTemplate(tmpl *x509.Certificate) credentialcomposer.X509CAAttributes {
460460
return credentialcomposer.X509CAAttributes{
461-
Subject: tmpl.Subject,
462-
PolicyIdentifiers: tmpl.PolicyIdentifiers,
463-
ExtraExtensions: tmpl.ExtraExtensions,
461+
Subject: tmpl.Subject,
462+
Policies: tmpl.Policies,
463+
ExtraExtensions: tmpl.ExtraExtensions,
464464
}
465465
}
466466
func x509SVIDAttributesFromTemplate(tmpl *x509.Certificate) credentialcomposer.X509SVIDAttributes {
@@ -473,7 +473,7 @@ func x509SVIDAttributesFromTemplate(tmpl *x509.Certificate) credentialcomposer.X
473473

474474
func applyX509CAAttributes(tmpl *x509.Certificate, attribs credentialcomposer.X509CAAttributes) {
475475
tmpl.Subject = attribs.Subject
476-
tmpl.PolicyIdentifiers = attribs.PolicyIdentifiers
476+
tmpl.Policies = attribs.Policies
477477
tmpl.ExtraExtensions = attribs.ExtraExtensions
478478
}
479479

0 commit comments

Comments
 (0)