-
Notifications
You must be signed in to change notification settings - Fork 14
add auth schema with auth providers order #499
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aborilov 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 |
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.
See my comments about schema/order in the associated Issue.
/retest |
/retest |
@@ -70,5 +71,40 @@ func (r *KubeCarrierWebhookHandler) validateCreate(kubeCarrier *operatorv1alpha1 | |||
if kubeCarrier.Name != constants.KubeCarrierDefaultName { | |||
return fmt.Errorf("KubeCarrier object name should be 'kubecarrier', found: %s", kubeCarrier.Name) | |||
} | |||
auth := map[string]bool{} |
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.
I think in go, we use map[string]struct{} as set in common cases
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 looks much nicer with map[string]bool{}
then map[string]strunct{}{}
.
also with bool
as a value we can do if auth['anonymous']
but with struct
you will have to do if _, ok := auth['anonymous']; ok{
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.
I've gone over the whole PR again. Please address the comment, I've left a few of my own. Afterward, I'll lgtm it; it's almost done except for a few nits/legibility here and there.
) | ||
supportedAuth = append(supportedAuth, "Htpasswd") | ||
var supportedAuth []string | ||
for _, auth := range c.Spec.Authentication { |
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.
for _, auth := range c.Spec.Authentication { | |
var supportedAuth []string | |
present := make(map[string]struct{}) | |
for i, auth := range c.Spec.Authentication { | |
if auth.StaticUsers != nil { | |
if _, ok := present["statik"]; ok { | |
return nil, fmt.Errorf("statik config redefined") | |
} | |
present["statik"] = struct{}{} | |
if err := addStatikConfig(auth.StaticUsers, &deploymentPatch.Spec.Template.Spec); err != nil { | |
return nil, err | |
} | |
supportedAuth = append(supportedAuth, "Statik") | |
} | |
if len(supportedAuth) != (i + 1) { | |
return nil, fmt.Errorf("only a single auth provider can be defined per statement. got %v", supportedAuth[i + 1:]) | |
} | |
... | |
} |
perhaps extract each auth provider to its own method; it's easier to read and follow the main function. Also, you're missing the checks if only a single one is non-nil.
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.
Also, you're missing the checks if only a single one is non-nil.
we have this check in the kubecarrier_webhook
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.
defense in depth.
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.
add we have if-else
here, so only the first one will be added
I think I've done all of them except defaulting webhook, as for now, we have only validation webhook? do you think it's a good idea to change it to defaulting webhook in this PR? |
/retest |
/retest |
/retest |
1 similar comment
/retest |
I'm still worried about validation and error handling. Currently, only in the kubecarrier CRD, the API server validation is being checked. Not in the API Server CRD, which the user can create, nor in the What I'm suggesting is creating: (maybe placing those functions close to the API definitions, or even make them member function for the operatorv1alpha1.APIServerSpec object?
What do you think? Otherwise, this is a great PR, well written, and tested! |
@nmiculinic The worrying is completely valid, and I agree that this may become an issue in the future, but for now I think it is fine. The reason are as following:
|
I don't like to overcomplicate things, in our case users don't interact with APIserver configuration directly, so I don't think we need to add webhooks to apiserver operator. I will add defaulting webhook for KubeCarrier operator and I like the idea of |
@aborilov , that's what I meant, adding APIserver webhooks is too much for this PR. Adding checks in |
yep, that's done |
/retest |
1 similar comment
/retest |
/lgtm |
LGTM label has been added. Git tree hash: 1d3f7dbb1bee08642bd23348761c2d31829d6a69
|
What this PR does / why we need it:
configure auth provider ordering explicitly by the user
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 #470
Special notes for your reviewer:
Documentation:
Does this PR introduce a user-facing change?: