Skip to content

fix: scope automation management to the org instead of the owner - #399

Merged
VascoSch92 merged 1 commit into
mainfrom
vasco/org-scoped-automation-management
Aug 28, 2026
Merged

VascoSch92 merged 1 commit into
mainfrom
vasco/org-scoped-automation-management

Conversation

@VascoSch92

Copy link
Copy Markdown
Member

Fixes the scoping half of #396.

Problem

Management endpoints filtered on user_id AND org_id, while event matching filtered on org_id alone and the scheduler on neither. An automation created by one account therefore fired for its whole org — acting on the org's repos under the org's bot identity — while being invisible and unmanageable to every other member of that org: it was absent from GET /automations, DELETE returned 404, and cancel returned 403. With no org-wide listing endpoint, it read as "already deleted" while still running.

This is easy to hit with a shared or service account that owns an org's automations, and the only remedies were authenticating as that exact account or writing to the database.

Change

list, get, patch, delete, tarball, dispatch, runs and cancel_run now resolve by org_id. _get_user_automation becomes _get_org_automation; the user_id predicate is dropped from the list query and from the cancel_run ownership check.

Authorization is unchanged: every one of these routes already depends on require_permission("manage_automations"), which is org-scoped, so dropping the owner predicate does not leave them ungated. user_id is still recorded on create — it just no longer governs access.

Template dedupe (find_existing_template_automation) is org-scoped to match, so enabling a template twice in one org returns the existing automation rather than creating a per-member duplicate.

complete_run and report_run_phase are callbacks from inside the sandbox rather than user actions, so they keep the owner check.

No schema change and no migration — org_id is already present and indexed.

Tests

  • test_list_automations_includes_other_org_members — a teammate's automation is listed
  • test_delete_other_org_members_automation — a member can delete a teammate's automation
  • test_cancel_same_org_other_users_run — a member can cancel a teammate's run
  • test_cancel_other_users_run_returns_403 renamed to test_cancel_other_orgs_run_returns_403; it was always cross-org, and cross-org rejection is unchanged

Full unit suite passes (1483). Pre-commit clean: ruff format, ruff lint, pycodestyle, pyright.

Deliberately not included

The last_triggered_at observability problem also described in #396 — the event path never writes it, so event-triggered automations report NULL forever and any query ranking by it to find active automations silently misses them. That is a separate concern; keeping this PR to the access-control change.

Follow-up worth considering

The list response has no owner field, so the UI will now show automations without indicating who created them. A small agent-canvas change to surface the owner would help.

Management endpoints filtered on user_id AND org_id, while event matching
filtered on org_id alone and the scheduler on neither. An automation created
by one account therefore ran for its whole org while being invisible and
unmanageable to every other member: list omitted it, delete returned 404 and
cancel returned 403.

List, get, patch, delete, tarball, dispatch, runs and cancel now resolve by
org_id, gated by the manage_automations permission that already guarded these
routes. Template dedupe is org-scoped to match.

complete_run and report_run_phase are callbacks from inside the sandbox rather
than user actions, so they keep the owner check.

Refs #396
@github-actions github-actions Bot added the type: fix A bug fix label Aug 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage

@VascoSch92
VascoSch92 marked this pull request as ready for review August 28, 2026 07:29
@VascoSch92
VascoSch92 requested review from malhotra5 and tofarr August 28, 2026 07:29
@all-hands-bot

Copy link
Copy Markdown
Contributor

👋 This PR needs a couple of things fixed before OpenHands can review it:

  • the PR description's HUMAN: section needs at least 20 characters describing what you tested, not just the template placeholder

Push an update once this is addressed and this check re-runs automatically.

This is an automated check - no AI was used to generate this comment.

2 similar comments
@all-hands-bot

Copy link
Copy Markdown
Contributor

👋 This PR needs a couple of things fixed before OpenHands can review it:

  • the PR description's HUMAN: section needs at least 20 characters describing what you tested, not just the template placeholder

Push an update once this is addressed and this check re-runs automatically.

This is an automated check - no AI was used to generate this comment.

@all-hands-bot

Copy link
Copy Markdown
Contributor

👋 This PR needs a couple of things fixed before OpenHands can review it:

  • the PR description's HUMAN: section needs at least 20 characters describing what you tested, not just the template placeholder

Push an update once this is addressed and this check re-runs automatically.

This is an automated check - no AI was used to generate this comment.

@tofarr tofarr 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.

🍰

@VascoSch92
VascoSch92 merged commit 96dbdbc into main Aug 28, 2026
9 checks passed
@openhands-release-bot openhands-release-bot Bot added the released: 1.9.1 Shipped in 1.9.1 label Aug 28, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.9.1.

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

Labels

released: 1.9.1 Shipped in 1.9.1 type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants