Skip to content

Commit 3f20505

Browse files
committed
validate: require commit pins for local servers
Signed-off-by: Jacob Howard <jacob.howard@docker.com>
1 parent d5b83ed commit 3f20505

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

cmd/validate/main.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ func run(name string) error {
4343
return err
4444
}
4545

46+
if err := isCommitPinnedIfNecessary(name); err != nil {
47+
return err
48+
}
49+
4650
if err := areSecretsValid(name); err != nil {
4751
return err
4852
}
@@ -115,6 +119,32 @@ func isDirectoryValid(name string) error {
115119
return nil
116120
}
117121

122+
var commitSHA1Pattern = regexp.MustCompile(`^[a-f0-9]{40}$`)
123+
124+
// isCommitPinnedIfNecessary ensures that every local server is pinned to a specific commit.
125+
func isCommitPinnedIfNecessary(name string) error {
126+
server, err := readServerYaml(name)
127+
if err != nil {
128+
return err
129+
}
130+
131+
if server.Type != "server" {
132+
fmt.Println("✅ Commit pin not required (non-local server)")
133+
return nil
134+
}
135+
136+
if server.Source.Commit == "" {
137+
return fmt.Errorf("local server must specify source.commit to pin the audited revision")
138+
}
139+
140+
if !commitSHA1Pattern.MatchString(strings.ToLower(server.Source.Commit)) {
141+
return fmt.Errorf("source.commit must be a 40-character lowercase SHA1 (got %q)", server.Source.Commit)
142+
}
143+
144+
fmt.Println("✅ Commit is pinned")
145+
return nil
146+
}
147+
118148
// secretNamePattern validates that secret names match the expected prefix.name
119149
// format requirement.
120150
var secretNamePattern = regexp.MustCompile(`^[A-Za-z0-9_-]+\.[A-Za-z0-9._-]+$`)

0 commit comments

Comments
 (0)