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

NETOBSERV-870 implement TokenReview #283

Merged
merged 3 commits into from
Mar 1, 2023
Merged

Conversation

jotak
Copy link
Member

@jotak jotak commented Feb 6, 2023

Requires operator PR to grant permission for TokenReviews: netobserv/network-observability-operator#263

  • 3 auth modes: check for cluster-admin, check for any user, no check (insecure; only for debugging/dev mode)
  • add tests
  • fix broken dev mode

jpinsonneau
jpinsonneau previously approved these changes Feb 6, 2023
Copy link
Contributor

@jpinsonneau jpinsonneau left a comment

Choose a reason for hiding this comment

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

LGTM in terms of code, just a small question on TokenChecker types

Comment on lines 104 to 123
type ValidBearerTokenChecker struct {
Checker
apiProvider client.APIProvider
}

func (c *ValidBearerTokenChecker) CheckAuth(ctx context.Context, header http.Header) error {
hlog.Debug("Checking authenticated user")
token, err := getUserToken(header)
if err != nil {
return err
}
hlog.Debug("Checking auth: token found")
if err = runTokenReview(ctx, c.apiProvider, token, []tokenReviewPredicate{mustBeAuthenticated}); err != nil {
return err
}

hlog.Debug("Checking auth: passed")
return nil
}

type AdminBearerTokenChecker struct {
Checker
apiProvider client.APIProvider
}

func (c *AdminBearerTokenChecker) CheckAuth(ctx context.Context, header http.Header) error {
hlog.Debug("Checking authenticated user")
token, err := getUserToken(header)
if err != nil {
return err
}
hlog.Debug("Checking auth: token found")
if err = runTokenReview(ctx, c.apiProvider, token, []tokenReviewPredicate{mustBeAuthenticated, mustBeClusterAdmin}); err != nil {
return err
}

hlog.Debug("Checking auth: passed")
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this code was duplicated for future improvments but at the end I don't see the value to do it.
[]tokenReviewPredicate could be passed as a simple argument with the apiProvider in NewChecker function. Is it going to be other differences than that ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I started with a slightly different implementation between the two checkers but after one or two iterations it ended up being almost the same, modulo predicates .. so yeah we can merge them into a single impl; if they diverge again later then we would split them back

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 perfect ! thanks

@openshift-ci openshift-ci bot added lgtm and removed lgtm labels Feb 6, 2023
@jpinsonneau
Copy link
Contributor

/lgtm

@jotak
Copy link
Member Author

jotak commented Feb 17, 2023

I changed it a little bit, to add a new mode (which is the default and the one used from operator) : "auto"
It will set to either "authenticated" or "admin" mode, depending on what is the loki auth-token mode: forward allows any authenticated user, whereas other modes lead to admins only.

This is necessary for the multi-tenancy work

@jotak
Copy link
Member Author

jotak commented Feb 17, 2023

cc @jpinsonneau ^

jpinsonneau
jpinsonneau previously approved these changes Feb 20, 2023
Copy link
Contributor

@jpinsonneau jpinsonneau left a comment

Choose a reason for hiding this comment

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

Code LGTM, thanks @jotak

@openshift-ci openshift-ci bot added the lgtm label Feb 20, 2023
Requires operator PR to grant permission for TokenReviews

- 3 auth modes: check for cluster-admin, check for any user, no check
  (insecure; only for debugging/dev mode)
- add tests
- fix broken dev mode
Auto mode acts either as admin or authenticated depending on the loki
authtoken mode (forward => authenticated)

Also improve loki errors hanfling
@openshift-ci
Copy link

openshift-ci bot commented Feb 21, 2023

New changes are detected. LGTM label has been removed.

@memodi
Copy link
Contributor

memodi commented Feb 28, 2023

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Feb 28, 2023
@github-actions
Copy link

New image: ["quay.io/netobserv/network-observability-console-plugin:11aa4b5"]. It will expire after two weeks.

@memodi
Copy link
Contributor

memodi commented Feb 28, 2023

/label qe-approved

@openshift-ci openshift-ci bot added the qe-approved QE has approved this pull request label Feb 28, 2023
@jotak
Copy link
Member Author

jotak commented Mar 1, 2023

/approve

@openshift-ci
Copy link

openshift-ci bot commented Mar 1, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jotak

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

@openshift-ci openshift-ci bot added the approved label Mar 1, 2023
@jotak jotak merged commit 04ae8b3 into netobserv:main Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. qe-approved QE has approved this pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants