-
Notifications
You must be signed in to change notification settings - Fork 55
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
Update SCC and RBAC handling for DevWorkspaces #954
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4bd0bc5
Begin process of deprecating previous role and rolebinding functionality
amisevsk 9a16d1f
Add new way of handling workspace RBAC that supports SCCs
amisevsk d77a80b
Add function to clean up old roles and rolebindings
amisevsk 08a0106
Switch to using updated RBAC syncing process
amisevsk 776dd45
Stop adding workspace SA to SCC and don't use SA finalizer
amisevsk 4674388
Update DevWorkspace operator clusterrole
amisevsk 930b7bc
Update cache filter for roles and rolebindings, update migrate process
amisevsk 6ba10cd
Add tests for role/rolebinding provisioning
amisevsk 8c9c624
Fix RBAC provisioning after rebase (changes to SA name package)
amisevsk da3ce11
Fix RBAC tests to accomodate serviceaccount changes.
amisevsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) 2019-2022 Red Hat, Inc. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package rbac | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/devfile/devworkspace-operator/pkg/common" | ||
"github.com/devfile/devworkspace-operator/pkg/provision/sync" | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
k8sErrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
// cleanupDeprecatedRBAC removes old Roles and RoleBindings created by an earlier version | ||
// of the DevWorkspace Operator. These earlier roles and rolebindings are no longer used | ||
// and need to be removed directly as there is no usual mechanism for their removal. | ||
// TODO: Remove this functionality for DevWorkspace Operator v0.19 | ||
func cleanupDeprecatedRBAC(namespace string, api sync.ClusterAPI) error { | ||
role := &rbacv1.Role{} | ||
roleNN := types.NamespacedName{ | ||
Name: common.OldWorkspaceRoleName(), | ||
Namespace: namespace, | ||
} | ||
err := api.Client.Get(api.Ctx, roleNN, role) | ||
switch { | ||
case err == nil: | ||
if err := api.Client.Delete(api.Ctx, role); err != nil { | ||
return err | ||
} | ||
return &RetryError{fmt.Errorf("deleted deprecated DevWorkspace Role")} | ||
case k8sErrors.IsNotFound(err): | ||
break | ||
default: | ||
return err | ||
} | ||
rolebinding := &rbacv1.RoleBinding{} | ||
rolebindingNN := types.NamespacedName{ | ||
Name: common.OldWorkspaceRolebindingName(), | ||
Namespace: namespace, | ||
} | ||
err = api.Client.Get(api.Ctx, rolebindingNN, rolebinding) | ||
switch { | ||
case err == nil: | ||
if err := api.Client.Delete(api.Ctx, rolebinding); err != nil { | ||
return err | ||
} | ||
return &RetryError{fmt.Errorf("deleted deprecated DevWorkspace RoleBinding")} | ||
case k8sErrors.IsNotFound(err): | ||
break | ||
default: | ||
return err | ||
} | ||
return nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Want to ask why does it return
RetryError
when deletion succeeds? Is there a reason for restarting the reconciliation instead of continuing it?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's the general flow we follow for most things. Here it's likely safe to continue the reconcile, but in general the operator works by doing one thing at a time (i.e. given a cluster state, what's the next step towards moving it towards the intended state?). In other words, we're treating "no deprecated DevWorkspace Role exists" as a precondition for continuing with creating the new DevWorkspace Role.
The benefit of doing this is that it should be possible to track what each reconcile did to the cluster (e.g. you would see "reconciling DevWorkspace (...) deleted deprecated DevWorkspace Role".
Though, you make a good point. We could probably get away with just logging that we deleted the role here. I'll update the PR.
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.
On further thought -- the tests use this error to verify migration is proceeding as expected, so I think it's better to leave for now. The current plan is to remove code related to cleaning up old resources around the DWO 0.19.0 or 0.20.0 timeframe.
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 see thank you @amisevsk , I was just curious, sounds good 👍