Skip to content
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 sourcetool/pkg/attest/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type SourceProvenancePred struct {

// Summary of a summary
type VsaSummary struct {
SourceRefs []string `json:"source_refs"`
VerifiedLevels []string `json:"verifiedLevels"`
SourceRefs []string `json:"source_refs"`
VerifiedLevels []slsa_types.ControlName `json:"verifiedLevels"`
}

type TagProvenancePred struct {
Expand Down Expand Up @@ -311,7 +311,7 @@ func (pa ProvenanceAttestor) CreateTagProvenance(ctx context.Context, commit, re
VsaSummaries: []VsaSummary{
{
SourceRefs: vsaRefs,
VerifiedLevels: vsaPred.VerifiedLevels,
VerifiedLevels: slsa_types.StringsToControlNames(vsaPred.VerifiedLevels),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion sourcetool/pkg/attest/provenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestCreateTagProvenance(t *testing.T) {
VsaSummaries: []VsaSummary{
{
SourceRefs: []string{"refs/some/ref"},
VerifiedLevels: []string{"TEST_LEVEL"},
VerifiedLevels: []slsa_types.ControlName{"TEST_LEVEL"},
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion sourcetool/pkg/attest/vsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func CreateUnsignedSourceVsa(repoUri, ref, commit string, verifiedLevels slsa_ty
ResourceUri: resourceUri,
Policy: &vpb.VerificationSummary_Policy{Uri: policy},
VerificationResult: "PASSED",
VerifiedLevels: verifiedLevels,
VerifiedLevels: slsa_types.ControlNamesToStrings(verifiedLevels),
}

predJson, err := protojson.Marshal(vsaPred)
Expand Down
47 changes: 47 additions & 0 deletions sourcetool/pkg/gh_control/checklevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ func (ghc *GitHubConnection) commitActivity(ctx context.Context, commit, targetR
return nil, fmt.Errorf("could not find repo activity for commit %s and ref %s", commit, targetRef)
}

type RequiredCheck struct {
// The name of the required status check as reported in the GitHub UI/API.
Name string
// How long that check has been required.
Since time.Time
}

type GhControlStatus struct {
// The time the commit we're evaluating was pushed.
CommitPushTime time.Time
Expand Down Expand Up @@ -178,6 +185,39 @@ func (ghc *GitHubConnection) computeReviewControl(ctx context.Context, rules []*
return nil, nil
}

func checkNameToControlName(checkName string) slsa_types.ControlName {
return slsa_types.ControlName(fmt.Sprintf("ORG_CONTROL_%s", checkName))
}

func (ghc *GitHubConnection) computeRequiredChecks(ctx context.Context, ghCheckRules []*github.RequiredStatusChecksBranchRule) ([]*slsa_types.Control, error) {
// Only return the checks we're happy about.
// For now that's only stuff from the GitHub Actions app.
requiredChecks := []*slsa_types.Control{}
for _, ghCheckRule := range ghCheckRules {
ruleset, _, err := ghc.Client().Repositories.GetRuleset(ctx, ghc.Owner(), ghc.Repo(), ghCheckRule.RulesetID, false)
if err != nil {
return nil, err
}
if ruleset.Enforcement != "active" {
// Only look at rules being enforced.
continue
}

for _, check := range ghCheckRule.Parameters.RequiredStatusChecks {
if check.IntegrationID == nil || *check.IntegrationID != GitHubActionsIntegrationId {
// Ignore untrusted integration id.
continue
}
requiredChecks = append(requiredChecks, &slsa_types.Control{
Name: checkNameToControlName(check.Context),
// TODO: get the time that indicates how long it's been enforced
Since: ruleset.UpdatedAt.Time,
})
}
}
return requiredChecks, nil
}

func (ghc *GitHubConnection) getOldestActiveRule(ctx context.Context, rules []*github.BranchRuleMetadata) (*github.RepositoryRuleset, error) {
var oldestActive *github.RepositoryRuleset
for _, rule := range rules {
Expand Down Expand Up @@ -231,6 +271,13 @@ func (ghc *GitHubConnection) GetBranchControls(ctx context.Context, commit, ref
}
controlStatus.Controls.AddControl(reviewControl)

requiredCheckControls, err := ghc.computeRequiredChecks(ctx, branchRules.RequiredStatusChecks)
if err != nil {
return nil, fmt.Errorf("could not populate RequiredChecks: %w", err)
}
controlStatus.Controls.AddControl(requiredCheckControls...)

// Check the tag rules.
allRulesets, _, err := ghc.Client().Repositories.GetAllRulesets(ctx, ghc.Owner(), ghc.Repo(), true)
if err != nil {
return nil, err
Expand Down
Loading