Skip to content

CA-406402/XSI-2128: Ignore RBAC when destroying internal tasks#6885

Merged
robhoes merged 1 commit intoxapi-project:masterfrom
BengangY:private/bengangy/xsi-2128
Feb 5, 2026
Merged

CA-406402/XSI-2128: Ignore RBAC when destroying internal tasks#6885
robhoes merged 1 commit intoxapi-project:masterfrom
BengangY:private/bengangy/xsi-2128

Conversation

@BengangY
Copy link
Contributor

@BengangY BengangY commented Feb 4, 2026

When calling VDI.copy or VDI.pool_migrate with vm_power_admin role, xapi may forward the operation to a remote host. In this case, xapi creates a pool session on the remote host and create a new task. When the operation completes, try_internal_async uses the user's session to destroy the task that was created by an internal pool session, but the user doesn’t have the permission to destory other user’s task (task.destroy/any), so it fails.

Solution:
This is an internal cleanup operation, so it doesn’t need user RBAC restriction and checking. Ignore RBAC when destroying internal tasks by calling Db_actions.DB_Action.Task.destroy directly.

@lindig
Copy link
Contributor

lindig commented Feb 4, 2026

How can we be sure this is only used for internal tasks?

Copy link
Member

@robhoes robhoes left a comment

Choose a reason for hiding this comment

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

I think this is correct. The task is indeed created on the remote host, so a non-root context on the coordinator would not be allowed to destroy it. Nice discovery!

@lindig
Copy link
Contributor

lindig commented Feb 4, 2026

I looked at the code again. It is explicit that this is an internal async operation - hence, something that needs a task, which must be cleaned up. I now also believe that this is correct. The code that is being called is:

let destroy ~__context task_id =
  let@ __context = Context.with_tracing ~__context __FUNCTION__ in
  if not (Ref.is_dummy task_id) then (
    assert_op_valid ~ok_if_no_session_in_context:true ~__context task_id ;
    Db_actions.DB_Action.Task.destroy ~__context ~self:task_id
  )

@robhoes comment suggests this could be simplified to Db.Task.destroy as well.

When calling `VDI.copy` or `VDI.pool_migrate` with `vm_power_admin` role,
xapi may forward the operation to a remote host. In this case, xapi creates
a pool session on the remote host and create a new task. When the
operation completes, `try_internal_async` uses the user's session to
destroy the task that was created by an internal pool session, but the
user doesn't have the permission to destory other user's task
(task.destroy/any), so it fails.

Solution:
This is an internal cleanup operation, so it doesn't need user RBAC
restriction and checking. Ignore RBAC when destroying internal tasks by
calling Db_actions.DB_Action.Task.destroy directly.

Signed-off-by: Bengang Yuan <bengang.yuan@citrix.com>
@BengangY BengangY force-pushed the private/bengangy/xsi-2128 branch from 09975cc to 57adc22 Compare February 5, 2026 13:58
@BengangY BengangY marked this pull request as ready for review February 5, 2026 14:11
@BengangY
Copy link
Contributor Author

BengangY commented Feb 5, 2026

@robhoes comment suggests this could be simplified to Db.Task.destroy as well.
Thanks. I updated it to Db.Task.destroy.

@robhoes robhoes added this pull request to the merge queue Feb 5, 2026
Merged via the queue into xapi-project:master with commit 2a7acb5 Feb 5, 2026
16 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Feb 5, 2026
When calling `VDI.copy` or `VDI.pool_migrate` with `vm_power_admin`
role, xapi may forward the operation to a remote host. In this case,
xapi creates a pool session on the remote host and create a new task.
When the operation completes, `try_internal_async` uses the user's
session to destroy the task that was created by an internal pool
session, but the user doesn't have the permission to destory other
user's task (task.destroy/any), so it fails.

Solution:
This is an internal cleanup operation, so it doesn't need user RBAC
restriction and checking. Ignore RBAC when destroying internal tasks by
calling Db_actions.DB_Action.Task.destroy directly.

Backport the [PR](#6885)
(cherry picked from commit
[57adc22](57adc22))
@BengangY BengangY changed the title XSI-2128: Ignore RBAC when destroying internal tasks CA-406402/XSI-2128: Ignore RBAC when destroying internal tasks Feb 6, 2026
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