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(backend): Support authentication with ServiceAccountTokens. Part of #5138 #5286

Merged

Conversation

elikatsis
Copy link
Member

Description of your changes:
The changes are described in detail in this comment: #5138 (comment)

In a nutshell:

  1. We make the authentication mechanisms extendable
  2. We extend the authentication mechanisms with an authenticator for ServiceAccountTokens
  3. The aforementioned authenticator expects ServiceAccountTokens
    • in a bearer token header: Authorization: Bearer <token>
    • with ml-pipeline as audience

/cc @Bobgy
/cc @yanniszark
/cc @StefanoFioravanzo
/assign @elikatsis

Checklist:

@Bobgy
Copy link
Contributor

Bobgy commented Mar 16, 2021

You also need to update ~/manifests/kustomize/base/installs/multi-user/api-service/cluster-role.yaml to include API server role changes for multi-user mode.

(being able to update it in the same PR thanks to @yanniszark's work for moving them here)

Copy link
Contributor

@Bobgy Bobgy left a comment

Choose a reason for hiding this comment

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

Thank you for the super useful contribution that many users are hoping for!

I'm leaving some early comments before I finish reading all the code. I'll try to finish review tomorrow.
Note, most of them are nit pickings, so feel free to discuss about them. I don't think they are blockers.

backend/src/apiserver/server/util.go Outdated Show resolved Hide resolved
backend/src/apiserver/server/experiment_server_test.go Outdated Show resolved Hide resolved
backend/src/apiserver/common/const.go Outdated Show resolved Hide resolved
backend/src/apiserver/auth/auth_util.go Outdated Show resolved Hide resolved
backend/src/apiserver/auth/auth_util.go Outdated Show resolved Hide resolved
Copy link
Member Author

@elikatsis elikatsis left a comment

Choose a reason for hiding this comment

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

@Bobgy thank you for your comments. They are to the point.
I've answered to each one of them and I'll push a few extra commits on top

backend/src/apiserver/server/experiment_server_test.go Outdated Show resolved Hide resolved
backend/src/apiserver/auth/auth_util.go Outdated Show resolved Hide resolved
backend/src/apiserver/auth/auth_util.go Outdated Show resolved Hide resolved
backend/src/apiserver/common/const.go Outdated Show resolved Hide resolved
backend/src/apiserver/server/util.go Outdated Show resolved Hide resolved
@elikatsis elikatsis force-pushed the feature-backend-authenticators branch from 0f55e91 to 2a8ca8a Compare March 17, 2021 18:02
@elikatsis
Copy link
Member Author

@Bobgy I rebased on top of latest master (there were some conflicts after the merge of #5231) adding extra commits to address your comments

Copy link
Contributor

@Bobgy Bobgy left a comment

Choose a reason for hiding this comment

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

Thank you! I've went through the PR, it's very well structured and well written.
I feel pretty confident about it, except for some very minor nitpickings

backend/src/apiserver/auth/auth.go Outdated Show resolved Hide resolved
backend/src/apiserver/auth/auth.go Outdated Show resolved Hide resolved
@google-oss-robot
Copy link

@Bobgy: GitHub didn't allow me to request PR reviews from the following users: elikatsis.

Note that only kubeflow members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

I'm not very familiar with concurrent programming in golang. Can this be a race condition?
e.g. the server runs as many go routines, and there can be two incoming requests triggering this method at the same time.

/cc @capri-xiyue @elikatsis

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@Bobgy
Copy link
Contributor

Bobgy commented Mar 18, 2021

Can you please resolve another conflict?

@Bobgy
Copy link
Contributor

Bobgy commented Mar 18, 2021

/lgtm

Extend the authenticators which the KFP apiserver applies on a request
with a TokenReview authenticator.

This authenticator expects a ServiceAccountToken in a header with the
format: 'Authorization: Bearer <token>'

Part of kubeflow#5138
Split the file into:
* auth.go: contains the main entrance from the outside of the package
* util.go: contains all utility functions used inside
Instead of using AuthenticateRequest to retrieve the user from the
request and then use it for the expected values, allocate a variable for
the username in the request and use that in the expected values.
This ensures we don't hide potential errors of AuthenticateRequest.
@elikatsis elikatsis force-pushed the feature-backend-authenticators branch from 5ef17ea to 3dc13dc Compare March 18, 2021 09:31
Have the HTTPHeaderAuthenticator first followed by the
TokenReviewAuthenticator
To avoid potential race conditions when initializing the Authenticators
variable, we move authenticators to a ResourceManager property and
initialize it along with the initialization of the manager.
@Bobgy
Copy link
Contributor

Bobgy commented Mar 18, 2021

/lgtm
Thanks! I feel this is ready, but I'd want to wait for @capri-xiyue's review too.
I think this can catch up with the release cut.

@capri-xiyue
Copy link
Contributor

/lgtm

@Bobgy
Copy link
Contributor

Bobgy commented Mar 19, 2021

/approve
@elikatsis thank you for the great contribution!

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Bobgy, elikatsis

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-robot google-oss-robot merged commit 5db66e0 into kubeflow:master Mar 19, 2021
@elikatsis elikatsis deleted the feature-backend-authenticators branch March 19, 2021 10:22
@elikatsis
Copy link
Member Author

@Bobgy and thank you for the quick and detailed review! I think the code is very improved now.

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.

4 participants