kcp icon indicating copy to clipboard operation
kcp copied to clipboard

:sparkles: PoC: Implement user warrants

Open sttts opened this issue 1 year ago • 3 comments

Summary

Needs https://github.com/kcp-dev/kubernetes/pull/145.

From Slack:

:thread: long ago @sur presented a problem (if I remember right) in our current auth model of serviceaccounts only being valid locally, and with that the inability to create workspaces through an APIExport virtual workspace. The steps are these:

  1. a user U creates a workspace W2 in logicalcluster L1 through an APIExport virtual workspace (that has a permission claim on Workspaces).
  2. the VW forwards the requests by impersonating its system:masters user with a fake system:kcp:admin serviceaccount (S1) for L1 named system:serviceaccount:default:rest.
  3. the forwarded requests hits kcp and kcp authorizes the workspace creation with that S1 serviceaccount. It uses that identity to authorize the use of workspace types. By giving use permission to everybody, this goes through.
  4. workspace admission sticks S1 as owner on the workspace object, to be used by initialization later.
  5. the workspace scheduler creates a logicalclusters L2 for W2 and gives S1 admin permissions through a clusterrole+binding.
  6. the initializers kick in and access the initializer VW for L2 where W2 has been scheduled to. Their requests are impersonated as S1 by the VW.
  7. these requests hit kcp and the authorizer denies access because S1 is a foreign service account :boom:

Now assume a modified system that

  • understands serviceaccounts from other workspaces, but does not give them permissions by default.
  • does not use a fake serviceaccount S1 identity to pass through the APIExport VW requests, but preserves the actual controller user and only attaches a warrant that gives the requires access of the claim.

The steps from above would turn into:

  1. a user U creates a workspace W2 in logicalcluster L1 through an APIExport virtual workspace (that has a permission claim on Workspaces).
  2. the VW forwards the requests by impersonating its system:masters user as U with a warrant for a fake system:kcp:admin serviceaccount (S1) for L1 named system:serviceaccount:default:rest.
  3. the forwarded requests hits kcp and kcp authorizes the workspace creation with that warrant S1 serviceaccount because U is not enough. It uses the U identity to authorize the use of workspace types. ~~By giving use permission to everybody, t~~This goes through.
  4. workspace admission sticks U with warrant S1 as owner on the workspace object, to be used by initialization later.
  5. the workspace scheduler creates a logicalclusters L2 for W2 and gives U with warrant S1 admin permissions through a clusterrole+binding.
  6. the initializers kick in and access the initializer VW for L2 where W2 has been scheduled to. Their requests are impersonated as U with warrant S1 by the VW.
  7. these requests hit kcp and the authorizer ~denies access because S1 is a foreign service account~ grants access because U with warrant S1 is admin in L2.

Now assume in addition that U is actually a controller serviceaccount S0 in workspace root. Step (7) would :collision: because S0 is foreign for L2. We further modify the system to authenticate serviceaccount as system:kcp:serviceaccount:<logicalcluster>:<ns>:<name> with a warrant for system:serviceaccount:<ns>:<name> restricted to their defining logicalcluster.

Now, U becomes system:kcp:serviceaccount:root:default:controller with warrant system:serviceaccount:default:controller restricted to root. With that (4) becomes

  1. workspace admission sticks system:kcp:serviceaccount:root:default:controller with warrant system:serviceaccount:default:controller restricted to root with warrant S1 as owner on the workspace object, to be used by initialization later.

I.e. the user has two warrants. With that (7) becomes:

  1. these requests hit kcp and the authorizer grants access because system:kcp:serviceaccount:root:default:controller with the TWO warrants including S1 is admin in L2.

Related issue(s)

Fixes #

Release Notes

Pass through original identity of controllers accessing a logical cluster through the APIExport virtual workspace. To get the required permissions, a warrant mechanism is added through user extra fields that attaches secondary user identities purely used for authorization.

sttts avatar Aug 22 '24 11:08 sttts

In general just a questions. looks good,

mjudeikis avatar Nov 23 '24 10:11 mjudeikis

/build-image

mjudeikis avatar Jan 10 '25 09:01 mjudeikis

/build-image

embik avatar Jan 22 '25 09:01 embik

/retest

looks like a flake to me.

embik avatar Jan 26 '25 13:01 embik

/retest /lgtm /approve /hold until @embik gets his question sorted :)

mjudeikis avatar Jan 26 '25 15:01 mjudeikis

LGTM label has been added.

Git tree hash: ec0e8108e30e6e12d6320ecebdfc209511d4b631

kcp-ci-bot avatar Jan 26 '25 15:01 kcp-ci-bot

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mjudeikis

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

kcp-ci-bot avatar Jan 26 '25 15:01 kcp-ci-bot

/hold cancel

embik avatar Jan 26 '25 16:01 embik