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: Operator disable create usergroup if detect user enabled external auth #1297

Merged

Conversation

zdtsw
Copy link
Member

@zdtsw zdtsw commented Oct 11, 2024

Description

feat: Operator disable create usergroup if detect users enabled external auth

https://issues.redhat.com/browse/RHOAIENG-14214

How Has This Been Tested?

local build: quay.io/wenzhou/opendatahub-operator-catalog:v2.14214.8
1.

  • on a clean cluster, without odh-admins group, create
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
  name: opendatahub-operator
  namespace: openshift-operators
spec:
  channel: fast
  name: usergroup
  source: usergroup
  sourceNamespace: openshift-marketplace
  InstallPlanApproval: Manaual
---
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
  name: usergroup
  namespace: openshift-marketplace
spec:
  displayName: usergroup
  image: 'quay.io/wenzhou/opendatahub-operator-catalog:v2.14214.8'
  publisher: wen
  sourceType: grpc
  • check Auth CR cluster has type set to ""
  • create DSCI CR
  • check odh-admins group created
  • manually update Auth CR to set "IntegratedOAuth" as Type
  • delete odh-admins group
  • restart Operator pod
  • odh-admins group created

test on a cluster with external-auth setup

  • check Auth CR cluster has type set to "OIDC"
  • check no odh-admins group and cannot see Group form UI (user management)
  • install Opreator
  • create DSCI without servicemesh enabled
  • no user group created

Screenshot or short clip

Merge criteria

  • You have read the contributors guide.
  • Commit messages are meaningful - have a clear and concise summary and detailed explanation of what was changed and why.
  • Pull Request contains a description of the solution, a link to the JIRA issue, and to any dependent or related Pull Request.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

return true, fmt.Errorf("failed to get Authentication CR cluster: %w", err)
}

return (authenticationobj.Spec.Type == "IntegratedOAuth" || authenticationobj.Spec.Type == ""), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

it appears there is a constant for this configv1.AuthenticationTypeIntegratedOAuth

Copy link
Member Author

Choose a reason for hiding this comment

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

i was thinking to make it:
return (authenticationobj.Spec.Type != "OIDC"), nil

or should we only create if it is AuthenticationTypeIntegratedOAuth ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any strong opinion but sinceI don't know what are all the possible values (i.e. behind a feature flag like the OIDC one) I would check if the type is among the supported values IntegratedOAuth or "" to be on the safe side

@@ -83,6 +84,11 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
// Set platform
platform := currentOperatorRelease.Name

createUsergroup, err := cluster.IsDefaultAuthMethod(ctx, r.Client)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this can probably be moved closed where it is actually in use so i.e. if there's no DSCI, then there's no even need to retrieve the auth config. Same as if the reconcile request is not about the DSCI.

@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 13.63636% with 19 lines in your changes missing coverage. Please review.

Please upload report for BASE (incubation@fa63b4d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
.../dscinitialization/dscinitialization_controller.go 20.00% 10 Missing and 2 partials ⚠️
pkg/cluster/cluster_config.go 0.00% 7 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             incubation    #1297   +/-   ##
=============================================
  Coverage              ?   18.59%           
=============================================
  Files                 ?       30           
  Lines                 ?     2699           
  Branches              ?        0           
=============================================
  Hits                  ?      502           
  Misses                ?     2135           
  Partials              ?       62           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -212,11 +214,23 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re

return ctrl.Result{}, nil
default:
createUsergroup, err := cluster.IsDefaultAuthMethod(ctx, r.Client)
if err != nil {
if !k8serr.IsNotFound(err) { // only keep reconcile if real error but not missing CRD or missing CR
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it can probably be a single line if err != nil && !k8serr.IsNotFound(err)

// for now, HPC support "" "None" "IntegratedOAuth"(default) "OIDC"
// other offering support "" "None" "IntegratedOAuth"(default)
// we only create userGroups for "IntegratedOAuth" or "" and leave other or new supported type value in the future
return (authenticationobj.Spec.Type == configv1.AuthenticationTypeIntegratedOAuth || authenticationobj.Spec.Type == ""), nil
Copy link
Contributor

@lburgazzoli lburgazzoli Oct 14, 2024

Choose a reason for hiding this comment

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

nit: parentheses seems to be redundant

…nal auth

- use internal Authentication CR Type "" or IntegratedOAuth to indicate if Operator should create usergroup  or not
  CRD has validation to only allow "IntegratedOAuth", "", "None" or "OIDC"
- only grant "get, watch , list" as least permission
- remove duplicated rbac for "ingress", has been defined in other places
- add object into cache
- add CRD into unit-test
- add unit-test: since we dont have auth CR, it should not create usergroup

Signed-off-by: Wen Zhou <[email protected]>
Signed-off-by: Wen Zhou <[email protected]>
authenticationobj := &configv1.Authentication{}
if err := cli.Get(ctx, client.ObjectKey{Name: "cluster", Namespace: ""}, authenticationobj); err != nil {
if errors.Is(err, &meta.NoKindMatchError{}) { // when CRD is missing, conver error type
return false, k8serr.NewNotFound(configv1.Resource("authentications"), "cluster")
Copy link

Choose a reason for hiding this comment

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

nit: suggest using a constant for "cluster" , since its repeated a few times.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

Copy link

openshift-ci bot commented Oct 15, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lburgazzoli

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

@openshift-merge-bot openshift-merge-bot bot merged commit a5388ad into opendatahub-io:incubation Oct 15, 2024
10 checks passed
zdtsw added a commit to zdtsw-forking/rhods-operator that referenced this pull request Oct 15, 2024
… external auth

- manual cherry-pick from opendatahub-io#1297

Signed-off-by: Wen Zhou <[email protected]>
zdtsw added a commit to zdtsw-forking/rhods-operator that referenced this pull request Oct 15, 2024
… external auth

- manual cherry-pick from opendatahub-io#1297

Signed-off-by: Wen Zhou <[email protected]>
VaishnaviHire pushed a commit to VaishnaviHire/opendatahub-operator that referenced this pull request Oct 15, 2024
… external auth

- manual cherry-pick from opendatahub-io#1297

Signed-off-by: Wen Zhou <[email protected]>
(cherry picked from commit 5bed921)
zdtsw added a commit to zdtsw-forking/rhods-operator that referenced this pull request Oct 16, 2024
… external auth

- manual cherry-pick from opendatahub-io#1297

Signed-off-by: Wen Zhou <[email protected]>
(cherry picked from commit 5bed921)
Signed-off-by: Wen Zhou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants