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

Get the actual k8s username for automatic role creation and CLI display #9

Merged
merged 2 commits into from
Nov 18, 2021

Conversation

kieron-dev
Copy link

Does this PR modify CLI v6, CLI v7, or CLI v8?

v7

Description of the Change

Up to this point, the current user when using cf-on-k8s has returned the name of the user entry selected on login from the kube config file. This is not the actual logged-on user name.

cf create-space, for example, needs the correct user name in order to send create role requests to the API. Also, most commands print the current user. This change enables correct role creation, and fixes the command output at the same time.

In order to determine the k8s user name, we need to ask k8s, since we might for example be sending an opaque token. Therefore we have introduced a /whoami endpoint in the API, and we invoke that, passing the authentication client cert or token, and receive a response with the username and kind - i.e. User or ServiceAccount.

Since this logic involves the API, we have introduced GetCurrentUser() into the Actor interface. This is implemented by the defaultAuthActor for standard CF, and by the kubernetesAuthActor for cf-on-k8s. The default actor defers to the config method, whereas the k8s actor invokes /whoami.

In order to fix the username presented in the command output, we have modified calls to cmd.Config.CurrentUser() to cmd.Actor.GetCurrentUser() through the command/v7 package, which was a trivial but large change to many files and tests.

cc @mnitchev, @cloudfoundry/eirini

Why Is This PR Valuable?

Why Should This Be In Core?

Applicable Issues

How Urgent Is The Change?

Other Relevant Parties

Kieron Browne and others added 2 commits November 11, 2021 17:26
Previously, CurrentUser[Name]() implementation was split in the config
area for standard CF and CF-on-k8s. It would have been great to update
the k8s version to call /whoami, but the cloud controller logic doesn't
seem to belong in the config area.

So instead, GetCurrentUser() has been added to the actor interface, and
also to the AuthActor interface. This has a standard CF and a k8s CF
implementation. The standard implementation just defers to the config
method, whereas the k8s implementation invokes the new /whoami endpoint
on the cloud controller.

This commit also introduces handling that endpoint.

Issue: cloudfoundry/korifi#147
Copy link
Collaborator

@jdgonzaleza jdgonzaleza left a comment

Choose a reason for hiding this comment

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

LGTM
Tons of files changed, hopefully I didn't miss anything

@gcapizzi gcapizzi merged commit ab319eb into master Nov 18, 2021
@gcapizzi gcapizzi deleted the real-k8s-username branch November 18, 2021 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants