Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(internal/request): add missing impersonate groups for serviceaccounts #350

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

maxgio92
Copy link
Collaborator

@maxgio92 maxgio92 commented Nov 30, 2023

What it does

This PR adds missing impersonate groups for ServiceAccounts.

Context

When clients request to impersonate user, the group impersonation should be done only when also clients request explicitely to impersonate group.

The problem

Nevertheless, an exception should be considered for service accounts.
With service account built-in authenticator, requests made with service account token are authenticated as:

  • user name: system:serviceaccount:<namespace>:<serviceaccount_name>
  • groups:
    • system:serviceaccounts
    • system:serviceaccounts:<namespace>
    • system:authenticated (included for all authenticated users)

The solution

This patch considers the case of service accounts adding the mentioned groups to the list of impersonate groups, when requests try to impersonate a service account's user.

Related issue

Fixes #349

Additional info

More details in the official documentation about service account authenticator [1] and user impersonation [2].

  1. https://kubernetes.io/docs/reference/access-authn-authz/authentication/#service-account-tokens
  2. https://kubernetes.io/docs/reference/access-authn-authz/authentication/#user-impersonation

@maxgio92 maxgio92 changed the title fix(internal): add missing impersonate groups for serviceaccounts Add missing impersonate groups for serviceaccounts Nov 30, 2023
…unts

When clients request to impersonate user, the group impersonation should
be done only when also clients request explicitely to impersonate group.

Nevertheless, an excpetion should be considered for service accounts.
With service account built-in authenticator, requests made with service
account token are authenticated as:
- user name: system:serviceaccount:<namespace>:<serviceaccount_name>
- groups:
  - system:serviceaccounts
  - system:serviceaccounts:<namespace>
  - system:authenticated (included for all authenticated users)

This patch considers the case of service accounts adding the mentioned groups
to the list of impersonate groups, when requests try to impersonate a
service account's user.

More details in the official documentation about service account
authenticator [1] and user impersonation [2].

1. https://kubernetes.io/docs/reference/access-authn-authz/authentication/#service-account-tokens
2. https://kubernetes.io/docs/reference/access-authn-authz/authentication/#user-impersonation

Signed-off-by: Massimiliano Giovagnoli <[email protected]>
Co-authored-by: Dario Tranchitella <[email protected]>
@maxgio92
Copy link
Collaborator Author

maxgio92 commented Nov 30, 2023

JFI @prometherion I've made a change as the block was on the wrong path (in the impersonate group condition, which in this specific case was never taken. I've moved it inside the impersonate user condition block.

@maxgio92 maxgio92 changed the title Add missing impersonate groups for serviceaccounts fix: add missing impersonate groups for serviceaccounts Dec 1, 2023
@maxgio92 maxgio92 marked this pull request as ready for review December 1, 2023 19:01
@maxgio92 maxgio92 changed the title fix: add missing impersonate groups for serviceaccounts fix(internal/request): add missing impersonate groups for serviceaccounts Dec 1, 2023
Copy link
Collaborator

@oliverbaehler oliverbaehler left a comment

Choose a reason for hiding this comment

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

Thanks for your awesome work @maxgio92 ! 🚀

@oliverbaehler oliverbaehler merged commit d188f12 into projectcapsule:main Dec 6, 2023
8 of 10 checks passed
@oliverbaehler oliverbaehler added this to the v0.4.7 milestone Dec 8, 2023
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.

user/serviceaccount/groups impersonation fails
2 participants