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

feat(bff): user info endpoint #630

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

ederign
Copy link
Member

@ederign ederign commented Dec 9, 2024

Create a new user endpoint to allow frontend to see if kubeflow-userid header is a cluster admin.

Description

This PR is a FUP of discussion, and it allows the frontend to enable and disable the namespace selector on the UI.

In this PR:

  • clients/ui/bff/internal/api/app.go: added the GET /v1/user endpoint;
  • clients/ui/bff/internal/api/middleware.go: skip the SAR on this endpoint. This operation is, in my point of view safe because it just provide the logged user email address and a boolean telling if it's a cluster admin or not;
  • clients/ui/bff/internal/api/user_handler.go and clients/ui/bff/internal/api/user_handler_test.go: respective handler and it's tests;
  • clients/ui/bff/internal/integrations/k8s.go: add the functionality to see if a user is a cluster admin. I want you to know that I didn't check intentionally if the user is part of a group of cluster admins (for performance reasons). If necessary, we can include this complimentary check in the future;
  • clients/ui/bff/internal/mocks/k8s_mock.go: I've added in our mocks:
    [email protected] as cluster admin;
    [email protected] as a regular user;
    created dora-namespace (to add services for this scope)
  • clients/ui/bff/internal/mocks/k8s_mock_test.go: tests;
  • clients/ui/bff/internal/models/user.go : user model
  • clients/ui/bff/internal/repositories/user.go: user repository

How Has This Been Tested?

curl -i -H "kubeflow-userid: [email protected]" localhost:4000/api/v1/user                                                         (kind-kubeflow/default)
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Mon, 09 Dec 2024 15:21:39 GMT
Content-Length: 75

{
	"data": {
		"user-id": "[email protected]",
		"cluster-admin": true
	}
}
curl -i -H "bad-header: [email protected]" localhost:4000/api/v1/user                                                      (kind-kubeflow/default)
HTTP/1.1 500 Internal Server Error
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Mon, 09 Dec 2024 15:23:14 GMT
Content-Length: 119

{
	"error": {
		"code": "500",
		"message": "the server encountered a problem and could not process your request"
	}
}
curl -i -H "kubeflow-userid: [email protected]" localhost:4000/api/v1/user                                                 (kind-kubeflow/default)
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Mon, 09 Dec 2024 15:22:32 GMT
Content-Length: 84

{
	"data": {
		"user-id": "[email protected]",
		"cluster-admin": false
	}
}

Merge criteria:

  • All the commits have been signed-off (To pass the DCO check)
  • The commits have meaningful messages; the author will squash them after approval or in case of manual merges will ask to merge with squash.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work.
  • Code changes follow the kubeflow contribution guidelines.

Signed-off-by: Eder Ignatowicz <[email protected]>
Co-authored-by: Griffin Sullivan <[email protected]>
Signed-off-by: Eder Ignatowicz <[email protected]>
Copy link
Contributor

@lucferbux lucferbux left a comment

Choose a reason for hiding this comment

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

/lgtm

Tested and working, will do a follow up

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lucferbux

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

@google-oss-prow google-oss-prow bot merged commit 1449fb3 into kubeflow:main Dec 11, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants