Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add git refs to go witness git attestor #265

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/verify-schemagen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ permissions:
contents: read

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

steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: "1.21.x"
go-version: "1.22.x"
- run: ./schemagen/verify.sh
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"
Loading