Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit 9ae61a3

Browse files
committed
Generate CheckOpts for verification of the new bundle format
Signed-off-by: Cody Soyland <[email protected]>
1 parent 1b9864a commit 9ae61a3

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

pkg/webhook/validator.go

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"github.com/sigstore/policy-controller/pkg/webhook/registryauth"
4646
rekor "github.com/sigstore/rekor/pkg/client"
4747
"github.com/sigstore/rekor/pkg/generated/client"
48+
"github.com/sigstore/sigstore-go/pkg/root"
4849
"github.com/sigstore/sigstore/pkg/cryptoutils"
4950
"github.com/sigstore/sigstore/pkg/fulcioroots"
5051
"github.com/sigstore/sigstore/pkg/signature"
@@ -1338,10 +1339,10 @@ func normalizeArchitecture(cf *v1.ConfigFile) string {
13381339
func checkOptsFromAuthority(ctx context.Context, authority webhookcip.Authority, remoteOpts ...ociremote.Option) (*cosign.CheckOpts, error) {
13391340
ret := &cosign.CheckOpts{
13401341
RegistryClientOpts: remoteOpts,
1342+
NewBundleFormat: authority.SignatureFormat == "bundle",
13411343
}
13421344

1343-
// Add in the identities for verification purposes, as well as Fulcio URL
1344-
// and certificates
1345+
// Add in the identities for verification purposes
13451346
if authority.Keyless != nil {
13461347
for _, id := range authority.Keyless.Identities {
13471348
ret.Identities = append(ret.Identities,
@@ -1351,6 +1352,67 @@ func checkOptsFromAuthority(ctx context.Context, authority webhookcip.Authority,
13511352
IssuerRegExp: id.IssuerRegExp,
13521353
SubjectRegExp: id.SubjectRegExp})
13531354
}
1355+
}
1356+
1357+
if ret.NewBundleFormat {
1358+
// The new bundle format is only supported for keyless authorities
1359+
// and the trustRootRef must be set.
1360+
if authority.Keyless == nil {
1361+
// TODO: Support the new bundle format for non-keyless authorities
1362+
return nil, fmt.Errorf("when using the new bundle format, the authority must be keyless")
1363+
}
1364+
trustRootRef := authority.Keyless.TrustRootRef
1365+
if trustRootRef != "" {
1366+
// Set up TrustedMaterial
1367+
sigstoreKeys, err := sigstoreKeysFromContext(ctx, trustRootRef)
1368+
if err != nil {
1369+
return nil, fmt.Errorf("getting SigstoreKeys: %w", err)
1370+
}
1371+
sk, ok := sigstoreKeys.SigstoreKeys[trustRootRef]
1372+
if !ok {
1373+
return nil, fmt.Errorf("trustRootRef %s not found", trustRootRef)
1374+
}
1375+
ret.TrustedMaterial, err = root.NewTrustedRootFromProtobuf(sk)
1376+
if err != nil {
1377+
return nil, fmt.Errorf("failed to create trusted root from protobuf: %w", err)
1378+
}
1379+
} else {
1380+
var err error
1381+
ret.TrustedMaterial, err = root.FetchTrustedRoot()
1382+
if err != nil {
1383+
return nil, fmt.Errorf("failed to fetch trusted root: %w", err)
1384+
}
1385+
}
1386+
if authority.Keyless.InsecureIgnoreSCT != nil && *authority.Keyless.InsecureIgnoreSCT {
1387+
ret.IgnoreSCT = *authority.Keyless.InsecureIgnoreSCT
1388+
}
1389+
1390+
// Check for custom TSA
1391+
tsa := authority.RFC3161Timestamp
1392+
if tsa != nil {
1393+
if tsa.TrustRootRef != authority.Keyless.TrustRootRef {
1394+
return nil, fmt.Errorf("when using the new bundle format, the trustRootRef for the TSA must be the same as the trustRootRef for the Keyless authority")
1395+
}
1396+
ret.UseSignedTimestamps = true
1397+
}
1398+
1399+
// Check for custom Rekor
1400+
tlog := authority.CTLog
1401+
if tlog != nil {
1402+
if tlog.TrustRootRef != authority.Keyless.TrustRootRef {
1403+
return nil, fmt.Errorf("when using the new bundle format, the trustRootRef for the TLog must be the same as the trustRootRef for the Keyless authority")
1404+
}
1405+
// Only require the TLog if we're not using signed timestamps
1406+
if ret.UseSignedTimestamps {
1407+
ret.IgnoreTlog = true
1408+
}
1409+
}
1410+
return ret, nil
1411+
}
1412+
1413+
// If we're not using the new bundle verifier (TrustedMaterial), we need to assemble the other CheckOpts (Fulcio, Rekor, TSA, etc.)
1414+
1415+
if authority.Keyless != nil {
13541416
fulcioRoots, fulcioIntermediates, ctlogKeys, err := fulcioCertsFromAuthority(ctx, authority.Keyless)
13551417
if err != nil {
13561418
return nil, fmt.Errorf("getting Fulcio certs: %s: %w", authority.Name, err)

0 commit comments

Comments
 (0)