Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Conversation

aborilov
Copy link
Contributor

@aborilov aborilov commented Jul 2, 2020

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?:

NONE

@kubermatic-bot kubermatic-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Denotes that all commits in the pull request have the valid DCO signoff message. labels Jul 2, 2020
@kubermatic-bot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubermatic-bot kubermatic-bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 2, 2020
Copy link
Contributor

@nmiculinic nmiculinic left a 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.

@kubermatic-bot kubermatic-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 6, 2020
@kubermatic-bot kubermatic-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 7, 2020
@aborilov
Copy link
Contributor Author

aborilov commented Jul 7, 2020

/retest

@aborilov
Copy link
Contributor Author

aborilov commented Jul 7, 2020

/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{}
Copy link
Contributor

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

Copy link
Contributor Author

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{

Copy link
Contributor

@nmiculinic nmiculinic 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 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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

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

defense in depth.

Copy link
Contributor Author

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

@aborilov
Copy link
Contributor Author

aborilov commented Jul 7, 2020

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.

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?

@aborilov
Copy link
Contributor Author

aborilov commented Jul 7, 2020

/retest

@kubermatic-bot kubermatic-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 8, 2020
@kubermatic-bot kubermatic-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 8, 2020
@aborilov
Copy link
Contributor Author

aborilov commented Jul 8, 2020

/retest

@aborilov
Copy link
Contributor Author

aborilov commented Jul 8, 2020

/retest

1 similar comment
@aborilov
Copy link
Contributor Author

aborilov commented Jul 8, 2020

/retest

@nmiculinic
Copy link
Contributor

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 apiserver.Manifests resource generation. If no/multiple auth options are specified per line in any one of those the failure shall be silent and ignored --> the most bite you in the ass type.

What I'm suggesting is creating: func validateAPIServerSpec(*operatorv1alpha1.APIServerSpec) error and defaultAPIServerSpec(*operatorv1alpha1.APIServerSpec) error helper functions which can and should be used in 3 places:

(maybe placing those functions close to the API definitions, or even make them member function for the operatorv1alpha1.APIServerSpec object? .Validate() error .Default() error)

  • Kubecarrier CRD webooks
  • API Server CRD webhooks (this doesn't exists for now)
  • apiserver.Manifests function (especially here, since it's the last point before silent failure)

What do you think?

Otherwise, this is a great PR, well written, and tested!

@kubermatic-bot kubermatic-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 8, 2020
@jiachengxu
Copy link
Contributor

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 apiserver.Manifests resource generation. If no/multiple auth options are specified per line in any one of those the failure shall be silent and ignored --> the most bite you in the ass type.

@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:

  1. In the usecase that we offer KubeCarrier, users don't have permission to interact with operator API group, so this should be fine.
  2. In the usercase that someone install KubeCarrier, and play around with it. Mistakes in APIServerCRD and also in apiserver.Manifests will be kind of "ignored" , this is because KubeCarrier operator controller will reconcile the object with the default KubeCarrer config from CLI, and for that one we have a webhook to reject all mistakes.

@aborilov
Copy link
Contributor Author

aborilov commented Jul 9, 2020

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 Default and Validate methods for APIServiceSpec, will also do that. Later, if we decide to add webhooks for APIserver operator, we can easily use them

@nmiculinic
Copy link
Contributor

@aborilov , that's what I meant, adding APIserver webhooks is too much for this PR. Adding checks in apiserver.Manifests should be all I ask for. Those validate functions shall be called in two places -- kubecarrier webook and apiserver.Manifests and all is good!

@kubermatic-bot kubermatic-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 9, 2020
@aborilov
Copy link
Contributor Author

aborilov commented Jul 9, 2020

@aborilov , that's what I meant, adding APIserver webhooks is too much for this PR. Adding checks in apiserver.Manifests should be all I ask for. Those validate functions shall be called in two places -- kubecarrier webook and apiserver.Manifests and all is good!

yep, that's done

@aborilov
Copy link
Contributor Author

aborilov commented Jul 9, 2020

/retest

1 similar comment
@aborilov
Copy link
Contributor Author

aborilov commented Jul 9, 2020

/retest

@nmiculinic
Copy link
Contributor

/lgtm

@kubermatic-bot kubermatic-bot added the lgtm Indicates that a PR is ready to be merged. label Jul 10, 2020
@kubermatic-bot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 1d3f7dbb1bee08642bd23348761c2d31829d6a69

@kubermatic-bot kubermatic-bot merged commit 88784df into master Jul 10, 2020
@kubermatic-bot kubermatic-bot deleted the auth-schema branch July 10, 2020 07:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Denotes that all commits in the pull request have the valid DCO signoff message. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Server CRD auth schema
4 participants