@@ -17,13 +17,15 @@ import (
17
17
"github.com/sirupsen/logrus"
18
18
"github.com/sirupsen/logrus/hooks/test"
19
19
"github.com/spiffe/go-spiffe/v2/spiffeid"
20
+ "github.com/spiffe/spire/pkg/common/catalog"
20
21
"github.com/spiffe/spire/pkg/common/coretypes/x509certificate"
21
22
telemetry_server "github.com/spiffe/spire/pkg/common/telemetry/server"
22
23
"github.com/spiffe/spire/pkg/common/x509util"
23
24
"github.com/spiffe/spire/pkg/server/ca"
24
25
"github.com/spiffe/spire/pkg/server/credtemplate"
25
26
"github.com/spiffe/spire/pkg/server/credvalidator"
26
27
"github.com/spiffe/spire/pkg/server/datastore"
28
+ "github.com/spiffe/spire/pkg/server/plugin/credentialcomposer"
27
29
"github.com/spiffe/spire/pkg/server/plugin/keymanager"
28
30
"github.com/spiffe/spire/pkg/server/plugin/notifier"
29
31
"github.com/spiffe/spire/pkg/server/plugin/upstreamauthority"
@@ -153,6 +155,25 @@ func TestGetCurrentX509CASlot(t *testing.T) {
153
155
})
154
156
}
155
157
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
+
156
177
func TestGetNextX509CASlot (t * testing.T ) {
157
178
ctx := context .Background ()
158
179
@@ -1206,6 +1227,7 @@ type managerTest struct {
1206
1227
km keymanager.KeyManager
1207
1228
ds * fakedatastore.DataStore
1208
1229
cat * fakeservercatalog.Catalog
1230
+ cc fakeCC
1209
1231
1210
1232
m * Manager
1211
1233
}
@@ -1295,10 +1317,11 @@ func (m *managerTest) selfSignedConfig() Config {
1295
1317
1296
1318
func (m * managerTest ) selfSignedConfigWithKeyTypes (x509CAKeyType , jwtKeyType keymanager.KeyType ) Config {
1297
1319
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 },
1302
1325
})
1303
1326
require .NoError (m .t , err )
1304
1327
@@ -1547,3 +1570,30 @@ func (s *fakeCA) SetJWTKey(jwtKey *ca.JWTKey) {
1547
1570
func (s * fakeCA ) NotifyTaintedX509Authorities (taintedAuthorities []* x509.Certificate ) {
1548
1571
s .taintedAuthoritiesCh <- taintedAuthorities
1549
1572
}
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
+ }
0 commit comments