Skip to content

Commit 302c150

Browse files
authored
Add tag protection to policy (#279)
* Update branch protection control description Signed-off-by: Adolfo Garcia Veytia (puerco) <[email protected]> * Add tag protection to generated policy This commit adds the tag protection entry to the generated policy when it is reported in the active controls. Signed-off-by: Adolfo Garcia Veytia (puerco) <[email protected]> --------- Signed-off-by: Adolfo Garcia Veytia (puerco) <[email protected]>
1 parent 8149757 commit 302c150

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

pkg/policy/policy.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ func (pe *PolicyEvaluator) CreateLocalPolicy(ctx context.Context, repo *models.R
276276
},
277277
},
278278
}
279+
280+
// If the controls returned
281+
controls := slsa.Controls(provPred.GetControls())
282+
tagHygiene := controls.GetControl(slsa.TagHygiene)
283+
if tagHygiene != nil {
284+
p.ProtectedTag = &ProtectedTag{
285+
Since: tagHygiene.GetSince(),
286+
TagHygiene: true,
287+
}
288+
}
279289
data, err := json.MarshalIndent(&p, "", " ")
280290
if err != nil {
281291
return "", err

pkg/slsa/slsa_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ type ControlRecommendedAction struct {
189189
// which are active in the set.
190190
func (cs *ControlSetStatus) GetActiveControls() *Controls {
191191
ret := Controls{}
192+
if cs == nil {
193+
return &ret
194+
}
192195
for _, c := range cs.Controls {
193196
if c.State == StateActive {
194197
ret.AddControl(&provenance.Control{

pkg/sourcetool/backends/vcs/github/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (b *Backend) ControlConfigurationDescr(branch *models.Branch, config models
201201
)
202202
case models.CONFIG_TAG_RULES:
203203
return fmt.Sprintf(
204-
"Enable push/update/delete protection for all tags in %s",
204+
"Enable force push/update/delete protection for all tags in %s",
205205
repo.Path,
206206
)
207207
default:

pkg/sourcetool/tool.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ func (t *Tool) createPolicy(r *models.Repository, branch *models.Branch, control
220220
},
221221
},
222222
}
223+
224+
// If the controls returned
225+
tagHygiene := controls.GetActiveControls().GetControl(slsa.TagHygiene)
226+
if tagHygiene != nil {
227+
p.ProtectedTag = &policy.ProtectedTag{
228+
Since: tagHygiene.GetSince(),
229+
TagHygiene: true,
230+
}
231+
}
223232
return p, nil
224233
}
225234

0 commit comments

Comments
 (0)