-
Notifications
You must be signed in to change notification settings - Fork 29
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
Implement authorization for Raw InferenceGraphs #499
Implement authorization for Raw InferenceGraphs #499
Conversation
Skipping CI for Draft Pull Request. |
cb3c634
to
9068707
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added some comments
} | ||
|
||
// Bind the required privileges to the Service Account | ||
err = addAuthPrivilegesToGraphServiceAccount(ctx, clientset, graph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
err = addAuthPrivilegesToGraphServiceAccount(ctx, clientset, graph) | |
err = addAuthPrivilegesToGraphServiceAccount(ctx, clientset, graph, saName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, do you prefer sending it as an argument rather than re-getting it inside the func?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, would avoid having to re-get. but it's only a nit :)
return err | ||
} | ||
} else { | ||
err := removeAuthPrivilegesFromGraphServiceAccount(ctx, clientset, graph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
err := removeAuthPrivilegesFromGraphServiceAccount(ctx, clientset, graph) | |
err := removeAuthPrivilegesFromGraphServiceAccount(ctx, clientset, graph, saName) |
return err | ||
} | ||
|
||
err = deleteGraphServiceAccount(ctx, clientset, graph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
err = deleteGraphServiceAccount(ctx, clientset, graph) | |
err = deleteGraphServiceAccount(ctx, clientset, graph, saName) |
if err != nil { | ||
return ctrl.Result{}, errors.Wrapf(err, "fails to reconcile resources for auth verification") | ||
} | ||
|
||
// Create inference graph resources such as deployment, service, hpa in raw deployment mode | ||
deployment, url, err := handleInferenceGraphRawDeployment(r.Client, r.Clientset, r.Scheme, graph, routerConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the controller flow from here, handleInferenceGraphRawDeployment
-> NewRawKubeReconciler
-> NewDeploymentReconciler
-> createRawDeploymentODH
where we have
if val, ok := componentMeta.Labels[constants.ODHKserveRawAuth]; ok && val == "true" {
err := addOauthContainerToDeployment(clientset, deployment, componentMeta, componentExt, podSpec)
if err != nil {
return nil, err
}
}
Does this mean that if the graph has the ODHKserveRawAuth
label, the graph deployment will get the oauth-proxy
container. Not sure if I'm missing something 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my testings it didn't get oauth-proxy. It could be because of RHOAIENG-20326 which we discussed today.
Most likely, when RHOAIENG-20326 is fixed, the IG will get the proxy. If that's the case, I'll appreciate you create a follow-up ticket for fixing it (although you'd be kind if you fix it as part of RHOAIENG-20326 😄 ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me this feels like more in scope with this PR whereas https://issues.redhat.com/browse/RHOAIENG-20326 should IMO be limited to making the switch from label to annotation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not fit here, nor in RHOAIENG-20326. With the current code, there is nothing to fix in this PR. This is my motivation for that to be a follow-up Jira.
By doing any fix here, I'd need to ensure no regression, and also, I'd need to implement RHOAIENG-20326, just to ensure that the fix will actually work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue created: https://issues.redhat.com/browse/RHOAIENG-21300
// checkRequestIsAuthorized verifies that the user in the provided tokenReviewResult has privileges to query the | ||
// Kubernetes API and get the InferenceGraph resource that belongs to this pod. If so, the request is considered | ||
// as allowed and `true` is returned. Otherwise, the HTTP response is sent rejecting the request and setting | ||
// a meaningful status code along with a reason (if available). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question:
What happens if the token has get
privileges for the IG but not 1 or more of the ISVCs in the IG? Should we be verifying that the token has the correct privileges for the IG + all the ISVCs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The token needs to have privileges for both the IG and the ISVC. The IG is doing only its check.
Later, the token is forwarded to the ISVC, so that it also can do its own check. This, effectively, delegates such check to the ISVC.
This may not be optimal, if the auth-protected ISVC is the last one on the IG and the previous ones are not protected. The request would fail after wasting resources. But I think current implementation is good enough, given we are not sure how users will use InferenceGraph. So, I'd say that we should optimize once we are sure.
@@ -173,9 +178,53 @@ func (r *InferenceGraphReconciler) Reconcile(ctx context.Context, req ctrl.Reque | |||
return reconcile.Result{}, errors.Wrapf(err, "fails to create DeployConfig") | |||
} | |||
|
|||
// name of our custom finalizer | |||
finalizerName := "inferencegraph.finalizers" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe move it to the constants section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is moved to a constant.
9068707
to
3d6f8ee
Compare
@Jooho do you want to take a look before merging? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
I just leave something not directly related to this PR :) so I can defer to Vedant because his comments are not solved yet.
a10ec75
to
8fdaaeb
Compare
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: israel-hdez, VedantMahabaleshwarkar 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 |
/lgtm |
@israel-hdez: The following tests failed, say
Full PR test history. Your PR dashboard. 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-sigs/prow repository. I understand the commands that are listed here. |
Authorization is implemented by using the TokenReview and the SubjectAccessReview Kubernetes APIs. A Middleware function is setup when some arguments are specified that trigger plugging-in the middleware func. Some additional reconciliation is added toInferenceGraph controller to: * Switch to a different ServiceAccount so that privileges for using the cluster APIs are granted. * Creating the needed ServiceAccount for the auth-protected InferenceGraph to run. * Managing a ClusterRoleBinding to give the required privileges for auth verification. Signed-off-by: Edgar Hernández <[email protected]>
Fix comment
Signed-off-by: Edgar Hernández <[email protected]>
8fdaaeb
to
383dda7
Compare
/lgtm |
b2b599f
into
opendatahub-io:release-v0.14
* Implement authorization for Raw InferenceGraphs Authorization is implemented by using the TokenReview and the SubjectAccessReview Kubernetes APIs. A Middleware function is setup when some arguments are specified that trigger plugging-in the middleware func. Some additional reconciliation is added toInferenceGraph controller to: * Switch to a different ServiceAccount so that privileges for using the cluster APIs are granted. * Creating the needed ServiceAccount for the auth-protected InferenceGraph to run. * Managing a ClusterRoleBinding to give the required privileges for auth verification. Signed-off-by: Edgar Hernández <[email protected]> * Feedback: Jooho Fix comment * Fix unit test Signed-off-by: Edgar Hernández <[email protected]> --------- Signed-off-by: Edgar Hernández <[email protected]>
* Implement authorization for Raw InferenceGraphs Authorization is implemented by using the TokenReview and the SubjectAccessReview Kubernetes APIs. A Middleware function is setup when some arguments are specified that trigger plugging-in the middleware func. Some additional reconciliation is added toInferenceGraph controller to: * Switch to a different ServiceAccount so that privileges for using the cluster APIs are granted. * Creating the needed ServiceAccount for the auth-protected InferenceGraph to run. * Managing a ClusterRoleBinding to give the required privileges for auth verification. Signed-off-by: Edgar Hernández <[email protected]> * Feedback: Jooho Fix comment * Fix unit test Signed-off-by: Edgar Hernández <[email protected]> --------- Signed-off-by: Edgar Hernández <[email protected]>
* Implement authorization for Raw InferenceGraphs Authorization is implemented by using the TokenReview and the SubjectAccessReview Kubernetes APIs. A Middleware function is setup when some arguments are specified that trigger plugging-in the middleware func. Some additional reconciliation is added toInferenceGraph controller to: * Switch to a different ServiceAccount so that privileges for using the cluster APIs are granted. * Creating the needed ServiceAccount for the auth-protected InferenceGraph to run. * Managing a ClusterRoleBinding to give the required privileges for auth verification. * Feedback: Jooho Fix comment * Fix unit test --------- Signed-off-by: Edgar Hernández <[email protected]>
What this PR does / why we need it:
Authorization is implemented by using the TokenReview and the SubjectAccessReview Kubernetes APIs. A Middleware function is setup when some arguments are specified that trigger plugging-in the middleware func.
Some additional reconciliation is added toInferenceGraph controller to:
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes https://issues.redhat.com/browse/RHOAIENG-17832
Type of changes
Please delete options that are not relevant.
Feature/Issue validation/testing:
Checklist: