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

Rhoaieng 14232 add auth crd #1452

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

StevenTobin
Copy link
Contributor

Description

Add Auth controller and CRD.

Functionality

  • Create Auth singleton instance if none exists.
  • Copy groups from odhDashboardConfig into auth cr.
  • Create Roles for admin and allowed groups.
  • Create rolebinding binding required role to each group in list.
  • Delete the rolebinding for any group removed from the list.

RHOAIENG-14231

How Has This Been Tested?

Creation of CR and Rolebindings

  • Deploy operator and create a DSCi CR.
  • Verify the auth CR is created automatically.
  • Verify the Auth CR contains the default groups of odh-admins and system:authenticated.
  • Verify the roles admingroups-role and allowedgroups-role exist in the applications namespace.
  • Verify the rolebinding admingroups-rolebinding and allowedgroups-rolebinding exist in the applications namespace.
  • Add a group to the Auth CR and verify the role and rolebinding are created for the new group.
  • Delete a group and confirm the rolebinding is deleted for that group.

Copying info from dashboardConfig

  • Delete auth CR.
  • Create dashboardConfig with different groups defined.
  • Stop - start operator to force a reconciliation.
  • Verify the groups from the dashboardConfig are copied into the Auth CR

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

Copy link

openshift-ci bot commented Dec 13, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from steventobin. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

Copy link
Contributor

This PR can't be merged just yet 😢

Please run make generate manifests api-docs and commit the changes.

For more info: https://github.com/opendatahub-io/opendatahub-operator/actions/runs/12318824711

Copy link
Contributor

This PR can't be merged just yet 😢

Please run make generate manifests api-docs and commit the changes.

For more info: https://github.com/opendatahub-io/opendatahub-operator/actions/runs/12318856499

pkg/cluster/gvk/gvk.go Outdated Show resolved Hide resolved
Copy link
Contributor

This PR can't be merged just yet 😢

Please run make generate manifests api-docs and commit the changes.

For more info: https://github.com/opendatahub-io/opendatahub-operator/actions/runs/12349540685

@StevenTobin StevenTobin force-pushed the RHOAIENG-14232_Add_auth_crd branch from c440ea7 to 7a0feef Compare December 16, 2024 14:38
@StevenTobin
Copy link
Contributor Author

/retest

@StevenTobin StevenTobin force-pushed the RHOAIENG-14232_Add_auth_crd branch 2 times, most recently from 9c70e5b to 326ebe9 Compare December 17, 2024 09:36
@StevenTobin
Copy link
Contributor Author

@lburgazzoli as per the slack conversation I added a watch in the DSCI so if the Auth CR is deleted the DSCI will recreate it.

@StevenTobin
Copy link
Contributor Author

/retest

2 similar comments
@StevenTobin
Copy link
Contributor Author

/retest

@lburgazzoli
Copy link
Contributor

/retest

@StevenTobin
Copy link
Contributor Author

/retest

@StevenTobin StevenTobin force-pushed the RHOAIENG-14232_Add_auth_crd branch 2 times, most recently from cb6c462 to 8648a17 Compare December 19, 2024 16:50
if newGroups {
err := rr.Client.Update(ctx, ai)
if err != nil {
return errors.New("error adding groups to Auth CR")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should such errors be wrapped?

@ykaliuta
Copy link
Contributor

I doubt commit message with progress commits makes any sense. Would it be possible to put PR's description there?

@StevenTobin StevenTobin force-pushed the RHOAIENG-14232_Add_auth_crd branch from 8648a17 to 60b39f6 Compare December 20, 2024 08:46
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 12.56281% with 174 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@326e4fc). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...ntrollers/services/auth/auth_controller_actions.go 0.00% 143 Missing ⚠️
controllers/services/auth/auth_controller.go 0.00% 24 Missing ⚠️
.../dscinitialization/dscinitialization_controller.go 76.66% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1452   +/-   ##
=======================================
  Coverage        ?   18.92%           
=======================================
  Files           ?      161           
  Lines           ?    10603           
  Branches        ?        0           
=======================================
  Hits            ?     2007           
  Misses          ?     8370           
  Partials        ?      226           

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

@StevenTobin StevenTobin force-pushed the RHOAIENG-14232_Add_auth_crd branch from 60b39f6 to cf8067f Compare January 6, 2025 13:06
@StevenTobin
Copy link
Contributor Author

/retest

@VaishnaviHire
Copy link
Member

When only DSCI is created, without DSC, we see following error

{"level":"error","ts":"2025-01-06T17:06:09Z","msg":"Reconciler error","controller":"auth","controllerGroup":"services.platform.opendatahub.io","controllerKind":"Auth","Auth":{"name":"auth"},"namespace":"","name":"auth","reconcileID":"c88a3850-579a-463f-82cd-c3ddcd257c00","error":"no matches for kind \"OdhDashboardConfig\" in version \"opendatahub.io/v1alpha\"","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\t/opt/app-root/src/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:329\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/opt/app-root/src/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\t/opt/app-root/src/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227"}

Should we have default values instead or update error message for users stating they need to enable dashboard?


const (
AuthServiceName = "auth"
AuthInstanceName = "auth"
Copy link
Member

Choose a reason for hiding this comment

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

nit: we have been using the naming format default-*(e.g default-dsc, default-dsci, default-monitoring) , can we update the name here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially used that naming of default-auth, but @andrewballantyne made the point that it seems strange to use default-auth when it's intended to be a singleton and I agree. There will only ever be one, the system doesn't allow two. A prefix of default seemed strange. It implies that there might be other non-default auth instances or that we are creating a default because the user didn't provide an auth instance.

Copy link
Contributor

Choose a reason for hiding this comment

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

@VaishnaviHire wonder if the same case should be made against components ?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah Andrew's and Steven's points make sense. I do not remember the reason why we went with default- prefix. I am okay with removing the default, but we will have to have upgrade logic to update the names for components and dsc/dsci in ODH releases

Copy link
Member

Choose a reason for hiding this comment

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

i guess: we have default-dsc/default-dsci, we carried this "default-" to the component CRs.
and it is easier to have the pattern as filter.

@VaishnaviHire
Copy link
Member

When I delete DSCI and DSC the Auth CR remains, is this expected?

@lburgazzoli
Copy link
Contributor

When only DSCI is created, without DSC, we see following error

{"level":"error","ts":"2025-01-06T17:06:09Z","msg":"Reconciler error","controller":"auth","controllerGroup":"services.platform.opendatahub.io","controllerKind":"Auth","Auth":{"name":"auth"},"namespace":"","name":"auth","reconcileID":"c88a3850-579a-463f-82cd-c3ddcd257c00","error":"no matches for kind \"OdhDashboardConfig\" in version \"opendatahub.io/v1alpha\"","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\t/opt/app-root/src/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:329\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/opt/app-root/src/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:266\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\t/opt/app-root/src/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227"}

Should we have default values instead or update error message for users stating they need to enable dashboard?

Seems a case for dynamic watching since the OdhDashboardConfig won't be available till the dashboard component is enabled. Thinking a little bit more, we may also need to check if the dahboard is enabled or not ? i.e. the OdhDashboardConfig may be present, but the component may be marked as removed, in such case I guess we should ignore the OdhDashboardConfig.

The other option (that I don't know if it is feasible at thist stage) would be to do the migration only once at startup time

@StevenTobin
Copy link
Contributor Author

StevenTobin commented Jan 7, 2025

When only DSCI is created, without DSC, we see following error
Should we have default values instead or update error message for users stating they need to enable dashboard?

Seems a case for dynamic watching since the OdhDashboardConfig won't be available till the dashboard component is enabled. Thinking a little bit more, we may also need to check if the dahboard is enabled or not

I'll add a check for the kind existing to catch that. If the dashboardConfig doesn't exist we shouldn't do anything but continue. We don't need it to exist we just need to read the content if it does.

@lburgazzoli
Copy link
Contributor

When only DSCI is created, without DSC, we see following error
Should we have default values instead or update error message for users stating they need to enable dashboard?

Seems a case for dynamic watching since the OdhDashboardConfig won't be available till the dashboard component is enabled. Thinking a little bit more, we may also need to check if the dahboard is enabled or not

I'll add a check for the kind existing to catch that. If the dashboardConfig doesn't exist we shouldn't do anything but continue. We don't need it to exist we just need to read the content if it does.

Wonder if we should also watch the OdhDashboardConfig type ? my understanding is that as today, the Auth reconcile won't be triggered in case something changes on the OdhDashboardConfig or if it is created/removed.

@StevenTobin
Copy link
Contributor Author

Wonder if we should also watch the OdhDashboardConfig type ? my understanding is that as today, the Auth reconcile won't be triggered in case something changes on the OdhDashboardConfig or if it is created/removed.

Yeah great point. I'll add that.

@StevenTobin
Copy link
Contributor Author

/retest

@StevenTobin StevenTobin force-pushed the RHOAIENG-14232_Add_auth_crd branch 2 times, most recently from dc1497a to 3574f73 Compare January 8, 2025 12:36
@StevenTobin
Copy link
Contributor Author

When I delete DSCI and DSC the Auth CR remains, is this expected?

@VaishnaviHire I hadn't really considered it, but in the future the Auth CR may handle Auth concerns beyond the DSC and DSCi so I think it sticking around isn't a big issue. It's similar behaviour to the dashboardConfig and is similarly expected to be user configuration.

@StevenTobin
Copy link
Contributor Author

/retest

Functionality

Create Auth singleton instance if none exists.
Copy groups from odhDashboardConfig into auth cr.
Create Roles for admin and allowed groups.
Create CLusterRole for admin groups.
Create required rolebindings for each group in both lists.
Create requires clusterROlebinding for each admin group.
Delete the rolebinding or clusterrolebinding for any group removed from either list.
add dynamic watch for dashboardConfig, fix labels and move functions into seperate file
remove gvk watch for dashboardconfig
@StevenTobin StevenTobin force-pushed the RHOAIENG-14232_Add_auth_crd branch from d360014 to 0f87a2c Compare January 8, 2025 17:49
Copy link

openshift-ci bot commented Jan 8, 2025

@StevenTobin: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/opendatahub-operator-e2e 0f87a2c link true /test opendatahub-operator-e2e

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.

Comment on lines +53 to +58
WatchesGVK(
gvk.CustomResourceDefinition,
reconciler.WithEventHandler(handlers.ToNamed(serviceApi.AuthInstanceName)),
reconciler.WithPredicates(predicate.NewPredicateFuncs(func(object client.Object) bool {
return object.GetName() == odhDashboardConfigCRDName
}))).
Copy link
Member

Choose a reason for hiding this comment

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

wonder: why we need to watch this CRD.
dashboard can update this CRD, but Auth CR only care about value from adminGroups and allowedGroups.
so the change to other part of the CRD should not trigger reconcile for Auth CR,
right?

Copy link
Contributor

@lburgazzoli lburgazzoli Jan 9, 2025

Choose a reason for hiding this comment

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

This is to trigger the dynamic watching when the OdhDashbaordConfig CRD gets deployed as consequence of the dashboard installation. Without this, the controller won't notice the existence of the OdhDashbaordConfig resource.

}))).
WatchesGVK(
gvk.OdhDashboardConfig,
reconciler.Dynamic(shouldWatchDashboardConfig),
Copy link
Member

Choose a reason for hiding this comment

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

if we are locking down changes in odh-dashboard-config (as read-only) for groupsConfig block, do we still need to watch this object? as if the change is done for .spec.dashboardConfig.disalbeModelMesh should reconcile be triggered.

Copy link
Contributor

Choose a reason for hiding this comment

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

We have two options:

  1. we do sync OdhDashbaordConfig only once when creating the Auth instance
  2. we do sync OdhDashbaordConfig as part of the reconcile loop.

As today, it is done as part of the reconcile loop (2), so we must watch the resource to be consistent, otherwise the sync would happen by chance i.e, if the controller gets restarted. I guess that when the auth stanza in the OdhDashbaordConfig will be made read-only, we can probably switch to option (1), but that's something for @StevenTobin and @csams to clarify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

9 participants