Skip to content

Commit

Permalink
feat: add git refs to go witness git attestor
Browse files Browse the repository at this point in the history
this enables witness to track git refs

Co-authored-by: Nick Kane <nkanedev@gmail.com>
  • Loading branch information
kriscoleman and nkane committed Jun 5, 2024
1 parent 94c5d38 commit 8455496
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/verify-schemagen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ permissions:
contents: read

jobs:
docgen:
name: Verify Docgen
verify-schema:
name: Verify Schema
runs-on: ubuntu-latest

steps:
Expand Down
10 changes: 10 additions & 0 deletions attestation/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type Attestor struct {
Refs []string `json:"refs,omitempty"`
Remotes []string `json:"remotes,omitempty"`
Tags []Tag `json:"tags,omitempty"`
RefNameShort string `json:"branch,omitempty"`
}

func New() *Attestor {
Expand Down Expand Up @@ -184,6 +185,7 @@ func (a *Attestor) Attest(ctx *attestation.AttestationContext) error {
a.CommitDate = commit.Author.When.String()
a.CommitMessage = commit.Message
a.Signature = commit.PGPSignature
a.RefNameShort = head.Name().Short()

for _, parent := range commit.ParentHashes {
a.ParentHashes = append(a.ParentHashes, parent.String())
Expand Down Expand Up @@ -289,6 +291,14 @@ func (a *Attestor) Subjects() map[string]cryptoutil.DigestSet {
subjects[subjectName] = ds
}

// add refname short
subjectName = fmt.Sprintf("refnameshort:%v", a.RefNameShort)
ds, err = cryptoutil.CalculateDigestSetFromBytes([]byte(a.RefNameShort), hashes)
if err != nil {
return nil
}
subjects[subjectName] = ds

return subjects
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/letsencrypt/boulder v0.0.0-20240226214708-a97e074b5a3e // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI=
github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand Down
14 changes: 13 additions & 1 deletion schemagen/gcp-iit.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@
"$ref": "#/$defs/ObjectIdentifier"
},
"type": "array"
},
"Policies": {
"items": {
"$ref": "#/$defs/OID"
},
"type": "array"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -291,7 +297,8 @@
"PermittedURIDomains",
"ExcludedURIDomains",
"CRLDistributionPoints",
"PolicyIdentifiers"
"PolicyIdentifiers",
"Policies"
]
},
"Extension": {
Expand Down Expand Up @@ -464,6 +471,11 @@
"ExtraNames"
]
},
"OID": {
"properties": {},
"additionalProperties": false,
"type": "object"
},
"ObjectIdentifier": {
"items": {
"type": "integer"
Expand Down
3 changes: 3 additions & 0 deletions schemagen/git.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
"$ref": "#/$defs/Tag"
},
"type": "array"
},
"branch": {
"type": "string"
}
},
"additionalProperties": false,
Expand Down
14 changes: 13 additions & 1 deletion schemagen/github.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@
"$ref": "#/$defs/ObjectIdentifier"
},
"type": "array"
},
"Policies": {
"items": {
"$ref": "#/$defs/OID"
},
"type": "array"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -291,7 +297,8 @@
"PermittedURIDomains",
"ExcludedURIDomains",
"CRLDistributionPoints",
"PolicyIdentifiers"
"PolicyIdentifiers",
"Policies"
]
},
"Extension": {
Expand Down Expand Up @@ -464,6 +471,11 @@
"ExtraNames"
]
},
"OID": {
"properties": {},
"additionalProperties": false,
"type": "object"
},
"ObjectIdentifier": {
"items": {
"type": "integer"
Expand Down
14 changes: 13 additions & 1 deletion schemagen/gitlab.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@
"$ref": "#/$defs/ObjectIdentifier"
},
"type": "array"
},
"Policies": {
"items": {
"$ref": "#/$defs/OID"
},
"type": "array"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -291,7 +297,8 @@
"PermittedURIDomains",
"ExcludedURIDomains",
"CRLDistributionPoints",
"PolicyIdentifiers"
"PolicyIdentifiers",
"Policies"
]
},
"Extension": {
Expand Down Expand Up @@ -464,6 +471,11 @@
"ExtraNames"
]
},
"OID": {
"properties": {},
"additionalProperties": false,
"type": "object"
},
"ObjectIdentifier": {
"items": {
"type": "integer"
Expand Down
14 changes: 13 additions & 1 deletion schemagen/jwt.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@
"$ref": "#/$defs/ObjectIdentifier"
},
"type": "array"
},
"Policies": {
"items": {
"$ref": "#/$defs/OID"
},
"type": "array"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -285,7 +291,8 @@
"PermittedURIDomains",
"ExcludedURIDomains",
"CRLDistributionPoints",
"PolicyIdentifiers"
"PolicyIdentifiers",
"Policies"
]
},
"Extension": {
Expand Down Expand Up @@ -458,6 +465,11 @@
"ExtraNames"
]
},
"OID": {
"properties": {},
"additionalProperties": false,
"type": "object"
},
"ObjectIdentifier": {
"items": {
"type": "integer"
Expand Down
2 changes: 1 addition & 1 deletion schemagen/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tmpdir2=$(mktemp -d)
cp ./schemagen/*.json "$tmpdir2/"
go run ./schemagen --dir "$tmpdir"
echo "###########################################"
echo "If diffs are found, run: make docgen"
echo "If diffs are found, run: make schema"
echo "###########################################"
diff -Nau "$tmpdir" "$tmpdir2"
rm -rf "$tmpdir" "$tmpdir2"

0 comments on commit 8455496

Please sign in to comment.