Skip to content

Restrict deleting a fleet to global admins - #50271

Open
nulmete wants to merge 2 commits into
mainfrom
restrict-delete-fleet-to-global-admin
Open

Restrict deleting a fleet to global admins#50271
nulmete wants to merge 2 commits into
mainfrom
restrict-delete-fleet-to-global-admin

Conversation

@nulmete

@nulmete nulmete commented Jul 30, 2026

Copy link
Copy Markdown
Member

Checklist for submitter

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • Bug Fixes
    • Restricted fleet deletion to users with global write permissions, including global administrators and GitOps.
    • Corrected team deletion authorization to require global write access.
    • Prevented global technicians, team technicians, and observer-level users from deleting teams.
    • Updated authorization behavior to consistently enforce the required access level.

A fleet-scoped admin could delete their own assigned fleet via the
API even though they cannot create one. DeleteTeam now requires the
same global-scope write check as team creation.
Copilot AI review requested due to automatic review settings July 30, 2026 22:49
@nulmete
nulmete marked this pull request as ready for review July 30, 2026 22:51
@nulmete
nulmete requested a review from a team as a code owner July 30, 2026 22:51
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ada722b8-ce04-49f5-ab4c-29c677c37605

📥 Commits

Reviewing files that changed from the base of the PR and between ace39f0 and 6eea1b1.

📒 Files selected for processing (2)
  • changes/restrict-delete-fleet-to-global-admin
  • server/service/teams_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • changes/restrict-delete-fleet-to-global-admin

Walkthrough

Fleet deletion authorization now targets the generic team resource for write access instead of a team-specific resource. Tests validate global-write failures for technician and observer-plus roles, and the changelog documents the global-write requirement, including global administrators and GitOps.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes the changes-file and testing confirmations but omits the required issue reference and most applicable checklist sections. Add the related issue or mark it NA, complete applicable checklist items, and include relevant testing and validation details.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary change to restrict fleet deletion to globally authorized users.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch restrict-delete-fleet-to-global-admin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@changes/restrict-delete-fleet-to-global-admin`:
- Line 1: Update the changelog entry to state that fleet deletion requires
global write permissions, reflecting the authorization behavior and test
coverage that allow global GitOps as well as global admins; do not describe the
restriction as limited to global admins.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 08599080-c139-4476-9f3d-ae05565bfeec

📥 Commits

Reviewing files that changed from the base of the PR and between 3660b54 and ace39f0.

📒 Files selected for processing (3)
  • changes/restrict-delete-fleet-to-global-admin
  • ee/server/service/teams.go
  • server/service/teams_test.go

Comment thread changes/restrict-delete-fleet-to-global-admin Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

  • Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.

Pull request overview

This PR aims to restrict deletion of a fleet/team so that only global admins can perform the operation, and updates authorization tests accordingly.

Changes:

  • Updated EE DeleteTeam authorization to authorize writes at the global scope (via an empty fleet.Team object).
  • Updated TestTeamAuth to assert DeleteTeam uses “global write” authorization expectations.
  • Added a changes entry file (content excluded by policy).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
server/service/teams_test.go Adjusts the team auth test to use a global-write expectation for DeleteTeam.
ee/server/service/teams.go Changes the DeleteTeam authorization check to authorize against an empty team object (global-scope write).
changes/restrict-delete-fleet-to-global-admin Changes entry (content excluded by policy).
Files excluded by content exclusion policy (1)
  • changes/restrict-delete-fleet-to-global-admin

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +922 to 923
if err := svc.authz.Authorize(ctx, &fleet.Team{}, fleet.ActionWrite); err != nil {
return err
Comment on lines 234 to +235
err = svc.DeleteTeam(ctx, 1)
checkAuthErr(t, tt.shouldFailTeamWrite, err)
checkAuthErr(t, tt.shouldFailGlobalWrite, err)
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.17%. Comparing base (db323dc) to head (6eea1b1).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #50271   +/-   ##
=======================================
  Coverage   68.16%   68.17%           
=======================================
  Files        3935     3935           
  Lines      250976   250985    +9     
  Branches    13443    13443           
=======================================
+ Hits       171089   171098    +9     
+ Misses      64554    64551    -3     
- Partials    15333    15336    +3     
Flag Coverage Δ
backend 69.45% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The changes file said "global admins" but the fix (matching team
creation) also allows global GitOps. Reworded to "global write
permissions" and added explicit test coverage for technician and
observer_plus (global and team-scoped), the two roles missing from
the existing auth table, confirming they're blocked too.
Copilot AI review requested due to automatic review settings July 30, 2026 23:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

  • Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated no new comments.

Files excluded by content exclusion policy (1)
  • changes/restrict-delete-fleet-to-global-admin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants