GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — security(ci): assert the DR identity against parsed allow-list entrie… · devantler-tech/platform@349d318

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • scripts/validate-dr-signing
    • main.go
    • main_test.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎scripts/validate-dr-signing/main.go‎

Copy file name to clipboardExpand all lines: scripts/validate-dr-signing/main.go
+80-3Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ import (
3737
// DR-published artifact.
3838
const drIdentitySubject = `^https://github\.com/devantler-tech/platform/\.github/workflows/dr-rebuild\.yaml@refs/heads/main$`
3939

40+
// drIdentityIssuer is the OIDC issuer half of that identity. cosign matches an
41+
// identity on the issuer/subject PAIR, so a correct subject under a different
42+
// issuer does not admit the DR signature and must not satisfy this gate.
43+
const drIdentityIssuer = `^https://token\.actions\.githubusercontent\.com$`
44+
4045
// cdContractGateJob is the cd.yaml job that runs this validator on the
4146
// direct-push production path. Named once so the wiring check and the workflow
4247
// cannot drift apart silently.
@@ -238,13 +243,85 @@ func describePublicationStep(step map[string]any, index int) string {
238243
return fmt.Sprintf("publication action step %d", index)
239244
}
240245

246+
// clusterVerifyConfig mirrors only the fragment of the KSail cluster config this
247+
// gate reads: the cosign allow-list at spec.workload.flux.verify, which is the
248+
// path KSail renders onto the root OCIRepository. Decoding the exact path is
249+
// what makes a block sitting anywhere else a failure rather than a pass, because
250+
// such a block yields zero entries here.
251+
//
252+
// Decoding reads the FIRST YAML document only, which is what a KSail cluster
253+
// config is. A verify block hidden in a later document would therefore yield no
254+
// entries and FAIL this gate rather than satisfy it — the safe direction, and the
255+
// same direction every other shape below fails in.
256+
type clusterVerifyConfig struct {
257+
Spec struct {
258+
Workload struct {
259+
Flux struct {
260+
Verify struct {
261+
MatchOIDCIdentity []struct {
262+
Issuer string `yaml:"issuer"`
263+
Subject string `yaml:"subject"`
264+
} `yaml:"matchOIDCIdentity"`
265+
} `yaml:"verify"`
266+
} `yaml:"flux"`
267+
} `yaml:"workload"`
268+
} `yaml:"spec"`
269+
}
270+
271+
// validateVerifyAllowList checks that the cluster's cosign allow-list actually
272+
// admits the DR rebuild identity.
273+
//
274+
// 🔴 THE CONFIG IS PARSED, NOT SCANNED, for the same reason validateCDWiring
275+
// parses workflows rather than scanning them — this is the config half of that
276+
// same correction. Four ways a text scan says "allowed" about an allow-list that
277+
// is not in effect, each reproduced as an ablation in the tests:
278+
//
279+
// 1. The identity appears in a COMMENT. A comment has no effect on the cluster,
280+
// so the gate certifies an allow-list that does not exist. Measured on the
281+
// scanning version: removing the real matcher and re-adding the identical
282+
// regex as `# …` returned "contract passed", exit 0.
283+
// 2. The whole verify block sits at a path KSail DISCARDS — spec.cluster.verify
284+
// is exactly the #2627 outage. The bytes are in the file, so a scan finds
285+
// them; KSail never renders them onto the OCIRepository.
286+
// 3. A subject that merely CONTAINS this identity satisfies a substring match,
287+
// and that direction is the dangerous one: `^dr$|^attacker$` contains the DR
288+
// identity while also admitting a second signer.
289+
// 4. The right subject under the WRONG ISSUER. cosign matches on the
290+
// issuer/subject pair, so such an entry does not admit the DR signature — but
291+
// a scan looking only for the subject line accepts it.
292+
//
293+
// An allow-list entry that is inert, discarded, over-broad, or issued by someone
294+
// else does not make a DR-published artifact verifiable, which is the one failure
295+
// that is unrecoverable by hand during an incident.
241296
func validateVerifyAllowList(config string) error {
242-
if !containsLine(config, drIdentitySubject) {
297+
var parsed clusterVerifyConfig
298+
if err := yaml.Unmarshal([]byte(config), &parsed); err != nil {
299+
return fmt.Errorf(
300+
"cluster config does not parse, so its verification allow-list cannot be established: %w", err,
301+
)
302+
}
303+
304+
entries := parsed.Spec.Workload.Flux.Verify.MatchOIDCIdentity
305+
if len(entries) == 0 {
243306
return errors.New(
244-
"cosign matchOIDCIdentity does not allow the DR rebuild identity, so a DR-published artifact stays unverifiable",
307+
"no cosign matchOIDCIdentity entries at spec.workload.flux.verify, the path KSail renders onto the root " +
308+
"OCIRepository, so a DR-published artifact stays unverifiable; a verify block at any other path " +
309+
"(spec.cluster.verify in particular) is discarded and does not count",
245310
)
246311
}
247-
return nil
312+
313+
for _, entry := range entries {
314+
if entry.Issuer == drIdentityIssuer && entry.Subject == drIdentitySubject {
315+
return nil
316+
}
317+
}
318+
319+
return fmt.Errorf(
320+
"cosign matchOIDCIdentity at spec.workload.flux.verify has %d entries but none is exactly the DR rebuild "+
321+
"identity, so a DR-published artifact stays unverifiable; add an entry with issuer %s and subject %s "+
322+
"(both compared exactly — a wider regex containing this one is not accepted)",
323+
len(entries), drIdentityIssuer, drIdentitySubject,
324+
)
248325
}
249326

250327
// validateCDWiring checks that the direct-push production path cannot deploy
Collapse file

‎scripts/validate-dr-signing/main_test.go‎

Copy file name to clipboardExpand all lines: scripts/validate-dr-signing/main_test.go
+90Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,96 @@ func TestVerifyAllowListRejectsAMissingDRIdentity(t *testing.T) {
10201020
}
10211021
}
10221022

1023+
// allowListConfig builds a minimal cluster config carrying one matchOIDCIdentity
1024+
// entry at the given dotted path, so the path tests below differ in exactly one
1025+
// variable: where the verify block sits.
1026+
func allowListConfig(path string, issuer string, subject string) string {
1027+
var builder strings.Builder
1028+
builder.WriteString("apiVersion: ksail.io/v1alpha1\nkind: Cluster\n")
1029+
indent := ""
1030+
for _, key := range strings.Split(path, ".") {
1031+
builder.WriteString(indent + key + ":\n")
1032+
indent += " "
1033+
}
1034+
builder.WriteString(indent + "provider: cosign\n")
1035+
builder.WriteString(indent + "matchOIDCIdentity:\n")
1036+
builder.WriteString(indent + " - issuer: '" + issuer + "'\n")
1037+
builder.WriteString(indent + " subject: '" + subject + "'\n")
1038+
return builder.String()
1039+
}
1040+
1041+
// This is the positive control for the three path/shape ablations that follow.
1042+
// Without it, any of them could pass merely because the synthetic YAML is
1043+
// malformed — a rejection for the wrong reason is indistinguishable from a
1044+
// rejection for the right one.
1045+
func TestVerifyAllowListAcceptsTheDRIdentityAtThePathKSailReads(t *testing.T) {
1046+
t.Parallel()
1047+
1048+
config := allowListConfig("spec.workload.flux.verify", drIdentityIssuer, drIdentitySubject)
1049+
if err := validateVerifyAllowList(config); err != nil {
1050+
t.Fatalf("the DR identity at the path KSail reads was rejected: %v", err)
1051+
}
1052+
}
1053+
1054+
// The bypass #2945 measured: a comment has no effect on the cluster, so a gate
1055+
// satisfied by one certifies an allow-list that is not in effect.
1056+
func TestVerifyAllowListRejectsACommentedDRIdentity(t *testing.T) {
1057+
t.Parallel()
1058+
1059+
config := repoFile(t, "ksail.prod.yaml")
1060+
removed := strings.ReplaceAll(config, drIdentitySubject, `^https://example\.invalid$`)
1061+
if removed == config {
1062+
t.Fatal("ablation changed nothing — the DR identity is not present to remove")
1063+
}
1064+
bypassed := removed + "\n# " + drIdentitySubject + "\n"
1065+
if err := validateVerifyAllowList(bypassed); err == nil {
1066+
t.Fatal("a commented-out DR identity was accepted as an allow-list entry")
1067+
}
1068+
}
1069+
1070+
// The second shape #2945 records: the whole block at a path KSail discards.
1071+
// spec.cluster.verify is exactly the #2627 outage.
1072+
func TestVerifyAllowListRejectsAVerifyBlockAtAPathKSailDiscards(t *testing.T) {
1073+
t.Parallel()
1074+
1075+
config := allowListConfig("spec.cluster.verify", drIdentityIssuer, drIdentitySubject)
1076+
err := validateVerifyAllowList(config)
1077+
if err == nil {
1078+
t.Fatal("a verify block at spec.cluster.verify — a path KSail discards — was accepted")
1079+
}
1080+
// Assert WHICH failure this is. Without this the test would also pass if the
1081+
// synthetic config were merely malformed, which would prove nothing about the
1082+
// path being discarded.
1083+
if !strings.Contains(err.Error(), "no cosign matchOIDCIdentity entries") {
1084+
t.Fatalf("rejected for the wrong reason — expected zero entries at the read path, got: %v", err)
1085+
}
1086+
}
1087+
1088+
// A substring match is blind in the LENGTHENING direction, and that direction is
1089+
// dangerous here: `^dr$|^evil$` contains the DR identity and also allows a
1090+
// second signer.
1091+
func TestVerifyAllowListRejectsASubjectThatMerelyContainsTheDRIdentity(t *testing.T) {
1092+
t.Parallel()
1093+
1094+
widened := drIdentitySubject + `|^https://github\.com/attacker/repo/\.github/workflows/x\.yaml@refs/heads/main$`
1095+
config := allowListConfig("spec.workload.flux.verify", drIdentityIssuer, widened)
1096+
if err := validateVerifyAllowList(config); err == nil {
1097+
t.Fatal("a widened subject regex that merely contains the DR identity was accepted")
1098+
}
1099+
}
1100+
1101+
// An OIDC identity is the issuer/subject PAIR. A correct subject under a
1102+
// different issuer does not match the DR signature, so it must not satisfy the
1103+
// gate either.
1104+
func TestVerifyAllowListRejectsTheDRSubjectUnderTheWrongIssuer(t *testing.T) {
1105+
t.Parallel()
1106+
1107+
config := allowListConfig("spec.workload.flux.verify", `^https://accounts\.google\.com$`, drIdentitySubject)
1108+
if err := validateVerifyAllowList(config); err == nil {
1109+
t.Fatal("the DR subject under a non-GitHub issuer was accepted")
1110+
}
1111+
}
1112+
10231113
func TestRunReportsSuccessAndFailure(t *testing.T) {
10241114
t.Parallel()
10251115

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.