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
17 changes: 17 additions & 0 deletions pkg/sourcetool/backends/vcs/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ func (b *Backend) GetBranchControlsAtCommit(ctx context.Context, branch *models.
}
}

carryOverDynamicControls(status, activeControls)

// The only control which can be in in_progress state in GitHub is
// provenance generation when the PR is open but not merged. We check
// here and report back the status.
Expand Down Expand Up @@ -300,6 +302,21 @@ func (b *Backend) GetBranchControlsAtCommit(ctx context.Context, branch *models.
return status, nil
}

// carryOverDynamicControls adds to the status the active controls which are
// not part of the fixed list of controls of the framework, such as the checks
// required to merge into the branch (GH_REQUIRED_CHECK_*). These have no entry
// to enable in a new control set and would be dropped otherwise.
func carryOverDynamicControls(status, activeControls *slsa.ControlSet) {
for _, c := range activeControls.Controls {
if c == nil || status.GetControl(c.GetName()) != nil {
continue
}
dynamic := *c
dynamic.State = slsa.StateActive
status.AddControl(&dynamic)
}
}

// controlImplementationMessage returns an implementation message to populate the
// status message when controls are active.
func (b *Backend) controlImplementationMessage(ctrlName slsa.ControlName) string {
Expand Down
42 changes: 42 additions & 0 deletions pkg/sourcetool/backends/vcs/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ package github

import (
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/slsa-framework/source-tool/pkg/attest"
"github.com/slsa-framework/source-tool/pkg/ghcontrol"
"github.com/slsa-framework/source-tool/pkg/slsa"
"github.com/slsa-framework/source-tool/pkg/sourcetool/models"
)

Expand Down Expand Up @@ -42,3 +45,42 @@ func TestWithVerifierIgnoresNil(t *testing.T) {

require.NotNil(t, backend.verifier)
}

func TestCarryOverDynamicControls(t *testing.T) {
t.Parallel()
since := time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC)
checkName := ghcontrol.CheckNameToControlName("ci / ci")

activeControls := &slsa.ControlSet{}
activeControls.AddControl(
// A framework control, it already has an entry in the status
&slsa.Control{Name: slsa.SLSA_SOURCE_SCS_CONTINUITY, Since: &since},
// A required check, not part of the framework controls
&slsa.Control{Name: checkName, Since: &since},
nil,
)

status := slsa.NewControlSet()
frameworkControls := len(status.Controls)
require.Nil(t, status.GetControl(checkName))

carryOverDynamicControls(status, activeControls)

// Only the required check is added and it is added as active
require.Len(t, status.Controls, frameworkControls+1)
check := status.GetControl(checkName)
require.NotNil(t, check)
require.Equal(t, slsa.StateActive, check.State)
require.Equal(t, &since, check.GetSince())
require.NotNil(t, status.GetActiveControls().GetControl(checkName))

// The framework control is left for the caller to enable
require.Equal(t, slsa.StateNotEnabled, status.GetControl(slsa.SLSA_SOURCE_SCS_CONTINUITY).State)

// The control in the status is a copy
require.NotSame(t, activeControls.GetControl(checkName), check)

// Carrying the controls over again does not duplicate them
carryOverDynamicControls(status, activeControls)
require.Len(t, status.Controls, frameworkControls+1)
}
Loading