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: Use ServiceAccount to generate token #10

Merged
merged 8 commits into from
Jul 20, 2023

Conversation

akrejcir
Copy link
Collaborator

What this PR does / why we need it:
This PR adds an alternate implementation of the proxy.

  • Tokens are generated by kubernetes
  • Tokens can be used with /vnc subreosurce on Kubevirt VirtualMachineInstance.

Release note:

Added another proxy implementation, that uses ServiceAccounts to generate tokens.

@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Mar 14, 2023
@openshift-ci
Copy link

openshift-ci bot commented Mar 14, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@akrejcir akrejcir force-pushed the use-sa-for-token branch 2 times, most recently from c89d272 to b39a234 Compare April 25, 2023 13:19
@akrejcir akrejcir force-pushed the use-sa-for-token branch 2 times, most recently from c79d26d to 77a1fd5 Compare April 28, 2023 12:38
@akrejcir akrejcir changed the title WIP: feat: Use ServiceAccount to generate token feat: Use ServiceAccount to generate token Apr 28, 2023
@akrejcir akrejcir marked this pull request as ready for review April 28, 2023 12:38
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 28, 2023
@akrejcir
Copy link
Collaborator Author

/cc @0xFelix @ksimon1 @codingben

}

namespace := request.PathParameter("namespace")
name := request.PathParameter("name")
Copy link
Member

Choose a reason for hiding this comment

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

I'd change it to vmName.

Copy link
Member

@codingben codingben left a comment

Choose a reason for hiding this comment

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

I've added a few comments. I'll review again next week.

@kubevirt-bot kubevirt-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 11, 2023
@akrejcir akrejcir added this to the v0.3.0 milestone Jul 18, 2023
Created a new package for the service files.

Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
The same setup will be useful for new tests added in a future commit.

Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
This will be useful in a future commit.

Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
Moved parameter reading to a method.

Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
The tokens are generated by kubernetes API server, and
they are bound to a service account.
They can be used to access VMI/vnc subresource.

/vnc endpoint was removed.

Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
@akrejcir akrejcir marked this pull request as ready for review July 19, 2023 14:48
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 19, 2023
@akrejcir
Copy link
Collaborator Author

@0xFelix, I have removed one commit from this PR to make it simpler. I will post the changes that you requested as a future PR.
Can you take another look?


authToken := getAuthToken(request)
if authToken == "" {
_ = response.WriteError(http.StatusUnauthorized, fmt.Errorf("authenticating token cannot be empty"))
Copy link
Member

Choose a reason for hiding this comment

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

IMO we should not give more info on 401. We could potentially log internally, but over the API I would not return more information to a potential attacker than necessary.


err = s.checkVncRbac(request.Request.Context(), authToken, params.name, params.namespace)
if err != nil {
_ = response.WriteError(http.StatusUnauthorized, err)
Copy link
Member

Choose a reason for hiding this comment

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

Same.

pkg/console/service/service.go Outdated Show resolved Hide resolved
Get(ctx context.Context, name string, opts metav1.GetOptions) (PT, error)
}

func createOrUpdate[PT interface {
Copy link
Member

Choose a reason for hiding this comment

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

Could this and L332 be part of a library? I see those kind of functions duplicated a lot across our projects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The retryOnConflict() function is nearly a copy of this one from k8s.io/client-go: https://github.com/kubernetes/client-go/blob/64a35f6a46ec8a791d437495fd91c87bcd01a5b5/util/retry/util.go#L48-L66

Where are they duplicated?

Copy link
Member

@0xFelix 0xFelix left a comment

Choose a reason for hiding this comment

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

I'm okay with this in general, but please address the comments in follow ups.

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 0xFelix

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

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 20, 2023
The /vnc endpoint functionality was removed.

Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
Changed documentation according to the new implementation.

Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
The example client connects to the kubevirt VMI/vnc endpoint.

Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
@akrejcir
Copy link
Collaborator Author

Thanks!
I've created an issue to track it: #20

Copy link
Member

@codingben codingben left a comment

Choose a reason for hiding this comment

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

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jul 20, 2023
@kubevirt-bot kubevirt-bot merged commit ea3ebe3 into kubevirt:main Jul 20, 2023
@akrejcir akrejcir deleted the use-sa-for-token branch July 21, 2023 07:02
@fabiand
Copy link
Member

fabiand commented Aug 9, 2023

Hooray!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants