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
1 change: 1 addition & 0 deletions changelog.d/added-workflow-approval-settings-control.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `governor.ci.auto_approve_workflows` and `governor.ci.auto_approve_workflow_actors` now have a Settings control (Features → Auto-merge → Workflow approval) and an admin-MCP write (`governor.feature_settings`: `ciAutoApproveWorkflows`, `ciAutoApproveWorkflowActors`), so a hosted hive can trust another bot such as `github-actions[bot]` without editing hive.yaml.
5 changes: 5 additions & 0 deletions src/docs/operator-reference/runtime-and-quota.md
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,11 @@ v5 and v6 spokes) tracking one repo all stay on webhook mode.
gated run on the head regardless of who pushed it — including commits a
fork collaborator pushed to the author's branch — so keep the actor list
to bot logins unless that is acceptable for a human login you add.
Both keys are on Settings → Features → Auto-merge → **Workflow approval**
(the actor list as comma-separated logins; blank restores the default,
`none` stores `[]`), and the admin MCP `governor.feature_settings`
operation writes them as `ciAutoApproveWorkflows` and
`ciAutoApproveWorkflowActors`; the sweep reads them every cycle.
Trusting the App as triggering actor
covers heads the App pushed itself (its own PRs, rebases, review-fix
commits), and only when the run's head repository is the PR's base
Expand Down
22 changes: 22 additions & 0 deletions src/pkg/adminmcp/adminmcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,28 @@ func mustJSON(t *testing.T, v any) string {
return string(b)
}

// governor.ci's workflow-approval keys are writable through
// governor.feature_settings, and the preview discloses turning approval on
// and changing who is trusted.
func TestFeatureSettingsWorkflowApproval(t *testing.T) {
preview, err := featureSettingsOp{}.Preview(context.Background(), map[string]any{"ciAutoApproveWorkflows": true, "ciAutoApproveWorkflowActors": "dependabot[bot], github-actions[bot]"})
if err != nil {
t.Fatal(err)
}
body := preview.Request.Body.(map[string]any)
if body["ciAutoApproveWorkflows"] != true || body["ciAutoApproveWorkflowActors"] != "dependabot[bot], github-actions[bot]" {
t.Fatalf("body = %#v", body)
}
for _, want := range []string{"ciAutoApproveWorkflows", "ciAutoApproveWorkflowActors"} {
if !strings.Contains(preview.WideningDisclosure, want) {
t.Fatalf("disclosure %q does not name %s", preview.WideningDisclosure, want)
}
}
if p, err := (featureSettingsOp{}).Preview(context.Background(), map[string]any{"ciAutoApproveWorkflows": false, "ciAutoApproveWorkflowActors": "none"}); err != nil || strings.Contains(p.WideningDisclosure, "ciAutoApprove") {
t.Fatalf("turning approval off and trusting no one is no widening: %q, %v", p.WideningDisclosure, err)
}
}

// Write-back containment's unsolicited knobs (Settings → Features →
// Write-back containment) are writable here too, and the preview names
// each change that lets the hive write to more items (#18846 follow-up).
Expand Down
13 changes: 12 additions & 1 deletion src/pkg/adminmcp/tools_fleet_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (planRejectOp) Preview(_ context.Context, args map[string]any) (WritePrevie

func (featureSettingsOp) Name() string { return WriteOpFeatureSettings }
func (featureSettingsOp) Description() string {
return "Update governor feature settings through PUT /api/config/governor/features. This includes write-back containment's unsolicited knobs (writeback.unsolicited: writebackMinLevel, writebackRequireLabels, writebackBackfill); the per-kind overrides have their own operation, writeback.kind_policy."
return "Update governor feature settings through PUT /api/config/governor/features. This includes workflow-run approval (governor.ci: ciAutoApproveWorkflows, ciAutoApproveWorkflowActors) and write-back containment's unsolicited knobs (writeback.unsolicited: writebackMinLevel, writebackRequireLabels, writebackBackfill); the per-kind overrides have their own operation, writeback.kind_policy."
}
func (featureSettingsOp) InputSchema() map[string]any {
props := map[string]any{}
Expand All @@ -165,6 +165,9 @@ func (featureSettingsOp) InputSchema() map[string]any {
}
props["triageSpecLabels"] = map[string]any{"type": "array", "items": stringSchema()}
props["triageFixLabels"] = map[string]any{"type": "array", "items": stringSchema()}
// governor.ci (Settings → Features → Auto-merge → Workflow approval).
props["ciAutoApproveWorkflows"] = map[string]any{"type": "boolean", "description": "governor.ci.auto_approve_workflows: approve the workflow runs GitHub holds behind \"Approve and run\" on trusted PR heads (default true)."}
props["ciAutoApproveWorkflowActors"] = map[string]any{"type": "string", "description": "governor.ci.auto_approve_workflow_actors as a comma-separated list of GitHub logins trusted besides the hive's App and dashboard-approved heads; blank restores the default (dependabot[bot], renovate[bot]), \"none\" trusts neither."}
props["otelHeaders"] = map[string]any{"type": "object", "additionalProperties": stringSchema()}
props["rotationProviders"] = map[string]any{"type": "object"}
props["rotationAgents"] = map[string]any{"type": "object", "additionalProperties": stringSchema()}
Expand Down Expand Up @@ -215,6 +218,14 @@ func capabilityWidens(mode string) bool {

func featureDisclosure(args map[string]any) string {
var warnings []string
// Approving held workflow runs lets a PR head's workflow files run on
// the repository's runners without a person's click.
if v, ok := args["ciAutoApproveWorkflows"].(bool); ok && v {
warnings = append(warnings, "ciAutoApproveWorkflows lets the hive approve held workflow runs on trusted PR heads, so their workflow files run on the repository's runners without a maintainer's click")
}
if v, ok := args["ciAutoApproveWorkflowActors"].(string); ok && !strings.EqualFold(strings.TrimSpace(v), "none") {
warnings = append(warnings, "ciAutoApproveWorkflowActors sets whose PRs get held workflow runs approved; a trusted author covers every run on the head, whoever pushed it")
}
for _, key := range []string{"ioscanEnabled", "checkpointSpecEnabled", "checkpointPlanEnabled", "checkpointImplementEnabled", "claimsEnabled"} {
if v, ok := args[key].(bool); ok && !v {
warnings = append(warnings, key+" disables a protection or coordination gate")
Expand Down
48 changes: 46 additions & 2 deletions src/pkg/dashboard/api_governor_features_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (

// featuresOpsBody is the part of the Features PUT that covers the operational
// hive.yaml blocks issues.*, jev.*, duplicate_sweep.*, policies.*, the
// turn.pr_follow_up / turn.reentrant knobs, good_first_issue.*, and the
// governor claim-mirroring and rotation headroom-source keys. Every field is a pointer so an
// turn.pr_follow_up / turn.reentrant knobs, good_first_issue.*, the
// governor claim-mirroring and rotation headroom-source keys, and
// governor.ci's workflow-approval keys. Every field is a pointer so an
// absent key leaves the config untouched. Durations travel as Go duration
// strings ("10m", "24h"); an empty string means the built-in default.
type featuresOpsBody struct {
Expand Down Expand Up @@ -77,6 +78,14 @@ type featuresOpsBody struct {
// governor.rotation.headroom_source: builtin (default) or ccleft. The
// rotation manager builds its probers at boot, so this needs a restart.
RotationHeadroomSource *string `json:"rotationHeadroomSource"`
// governor.ci (hivecommons/hive#16603): whether the hive approves the
// workflow runs GitHub holds behind "Approve and run" on trusted PR
// heads, and which authors / triggering actors it trusts besides its
// App and owner admissions, as a comma-separated list. Blank restores
// the default (dependabot[bot], renovate[bot]); "none" stores an
// explicit empty list. The approval sweep reads both every cycle.
CIAutoApproveWorkflows *bool `json:"ciAutoApproveWorkflows"`
CIAutoApproveWorkflowActors *string `json:"ciAutoApproveWorkflowActors"`
}

// envVarNamePattern is the shape of a POSIX environment variable name.
Expand Down Expand Up @@ -361,6 +370,25 @@ func (b featuresOpsBody) prepare(cur *config.Config) (func(*config.Config), erro
}
steps = append(steps, func(c *config.Config) { c.Governor.Rotation.HeadroomSource = v })
}
if b.CIAutoApproveWorkflows != nil {
v := *b.CIAutoApproveWorkflows
steps = append(steps, func(c *config.Config) { c.Governor.CI.AutoApproveWorkflows = &v })
}
if b.CIAutoApproveWorkflowActors != nil {
v := parseNeverClaimLabelsInput(*b.CIAutoApproveWorkflowActors)
for _, actor := range v {
if strings.ContainsAny(actor, " \t") {
return nil, fmt.Errorf("governor ci auto_approve_workflow_actors: %q is not a GitHub login", actor)
}
}
steps = append(steps, func(c *config.Config) {
if v == nil {
c.Governor.CI.AutoApproveWorkflowActors = nil
return
}
c.Governor.CI.AutoApproveWorkflowActors = &v
})
}

return func(c *config.Config) {
for _, step := range steps {
Expand Down Expand Up @@ -394,6 +422,9 @@ func featuresOpsResponse(cfg *config.Config) map[string]interface{} {
"claimsNeverClaimDefault": strings.Join(claims.DefaultNeverClaimLabels, ", "),
"rotationHeadroomSource": cfg.Governor.Rotation.EffectiveHeadroomSource(),
"rotationHeadroomSourceValues": []string{config.RotationHeadroomSourceBuiltin, config.RotationHeadroomSourceCCLeft},
"ciAutoApproveWorkflows": cfg.Governor.CI.AutoApproveWorkflowsEnabled(),
"ciAutoApproveWorkflowActors": ciAutoApproveActorsResponse(cfg.Governor.CI),
"ciAutoApproveActorsDefault": strings.Join(config.DefaultAutoApproveWorkflowActors, ", "),

"issuesCloseOnMerge": cfg.Issues.CloseOnMergeEnabled(),
"issuesCloseOnMergeInterval": settingsDurationString(cfg.Issues.CloseOnMergeInterval),
Expand Down Expand Up @@ -495,3 +526,16 @@ func parseNeverClaimLabelsInput(raw string) []string {
}
return out
}

// ciAutoApproveActorsResponse is governor.ci.auto_approve_workflow_actors in
// the Settings dialog's spelling: blank when unset (the default applies),
// "none" for an explicit empty list, otherwise the comma-separated logins.
func ciAutoApproveActorsResponse(ci config.GovernorCIConfig) string {
if ci.AutoApproveWorkflowActors == nil {
return ""
}
if len(*ci.AutoApproveWorkflowActors) == 0 {
return neverClaimLabelsOff
}
return strings.Join(*ci.AutoApproveWorkflowActors, ", ")
}
74 changes: 74 additions & 0 deletions src/pkg/dashboard/governor_settings_parity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,77 @@ func TestParityBatch7SettingsRenderEveryKey(t *testing.T) {
}
}
}

// governor.ci's workflow-approval keys (hivecommons/hive#16603) round-trip
// through the Features PUT: the flag, the actor list as typed, "none" for an
// explicit empty list and blank for the default.
func TestGovernorFeaturesWorkflowApprovalRoundTrip(t *testing.T) {
s := covApiServer(t)
if rec := doPut(s, opsFeaturesPath, map[string]any{"ciAutoApproveWorkflowActors": "dependabot[bot], some one"}); rec.Code != http.StatusBadRequest {
t.Fatalf("an actor with a space: expected 400, got %d", rec.Code)
}
if s.deps.Config.Governor.CI.AutoApproveWorkflowActors != nil {
t.Fatal("a rejected PUT changed the actor list")
}
if rec := doPut(s, opsFeaturesPath, map[string]any{
"ciAutoApproveWorkflows": false,
"ciAutoApproveWorkflowActors": " renovate[bot], github-actions[bot] ,",
}); rec.Code != http.StatusOK {
t.Fatalf("features PUT: %d — %s", rec.Code, rec.Body.String())
}
ci := s.deps.Config.Governor.CI
if ci.AutoApproveWorkflowsEnabled() {
t.Fatal("auto_approve_workflows not turned off")
}
if got := strings.Join(ci.WorkflowApprovalActors(), ","); got != "renovate[bot],github-actions[bot]" {
t.Fatalf("auto_approve_workflow_actors = %q", got)
}

rec := doGet(s, "/api/config/governor")
if rec.Code != http.StatusOK {
t.Fatalf("governor GET: %d", rec.Code)
}
var got struct {
Features map[string]any `json:"features"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil {
t.Fatal(err)
}
f := got.Features
if f["ciAutoApproveWorkflows"] != false || f["ciAutoApproveWorkflowActors"] != "renovate[bot], github-actions[bot]" || f["ciAutoApproveActorsDefault"] != "dependabot[bot], renovate[bot]" {
t.Fatalf("features response: %v / %v / %v", f["ciAutoApproveWorkflows"], f["ciAutoApproveWorkflowActors"], f["ciAutoApproveActorsDefault"])
}

if rec := doPut(s, opsFeaturesPath, map[string]any{"ciAutoApproveWorkflowActors": "none"}); rec.Code != http.StatusOK {
t.Fatalf("none PUT: %d — %s", rec.Code, rec.Body.String())
}
if a := s.deps.Config.Governor.CI.AutoApproveWorkflowActors; a == nil || len(*a) != 0 || len(s.deps.Config.Governor.CI.WorkflowApprovalActors()) != 0 {
t.Fatalf("\"none\" must store an explicit empty list, got %#v", a)
}
if rec := doPut(s, opsFeaturesPath, map[string]any{"ciAutoApproveWorkflowActors": " "}); rec.Code != http.StatusOK {
t.Fatalf("blank PUT: %d — %s", rec.Code, rec.Body.String())
}
if ci = s.deps.Config.Governor.CI; ci.AutoApproveWorkflowActors != nil || ci.WorkflowApprovalActors()[0] != "dependabot[bot]" {
t.Fatalf("blank must restore the default actors, got %#v", ci.AutoApproveWorkflowActors)
}
if ci.AutoApproveWorkflowsEnabled() {
t.Fatal("a PUT that did not carry the flag changed it")
}
}

// Both governor.ci keys render on Settings → Features with their YAML-key
// hint next to a control bound to the Features save path.
func TestWorkflowApprovalSettingsRender(t *testing.T) {
features := extractJSFunction(t, indexHTML(t), "renderGovFeatures")
for _, c := range []struct{ yaml, control string }{
{"governor.ci.auto_approve_workflows", `data-section="features" data-key="ciAutoApproveWorkflows"`},
{"governor.ci.auto_approve_workflow_actors", `data-arg1="ciAutoApproveWorkflowActors" data-arg-types="s,s,s"`},
} {
if !strings.Contains(features, "yamlHint('"+c.yaml+"')") {
t.Errorf("%s has no YAML-key hint", c.yaml)
}
if !strings.Contains(features, c.control) {
t.Errorf("%s has no Features control (%s)", c.yaml, c.control)
}
}
}
2 changes: 0 additions & 2 deletions src/pkg/dashboard/settings_parity_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,6 @@ governor.budget.coins.<key>.budget # TODO #11854
governor.budget.coins.<key>.label # TODO #11854
governor.budget.coins.<key>.tokens_per_coin # TODO #11854
governor.budget.coins.<key>.usd_per_coin # TODO #11854
governor.ci.auto_approve_workflow_actors[] # trusted workflow-approval actors (#16603); yaml-only
governor.ci.auto_approve_workflows # gated workflow auto-approval flag (#16603); yaml-only
governor.ci_failure_kick_cooldown_s # webhook CI-failure kick cooldown (#15291); yaml-only
governor.ci_failure_webhook_kick # webhook CI-failure kick flag (#15291); yaml-only
governor.dependency_bot_rebase_after_s # stranded dependency-bot PR window (bot_rebase_request); yaml-only
Expand Down
12 changes: 12 additions & 0 deletions src/pkg/dashboard/static-src/js/config-features.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/pkg/dashboard/static-src/js/config-state.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading