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

✨ wire more controllers cross-shard and authz #2562

Merged
merged 18 commits into from
Jan 11, 2023

Conversation

sttts
Copy link
Member

@sttts sttts commented Jan 6, 2023

  • replicate ClusterRoles+ClusterBindings that are labeled to be replicated
  • added replication label controllers for ClusterRoles+Bindings relevant to APIExport authorization
  • allow deep SAR again the cache server data

@sttts sttts changed the title ✨ wire cross-shard authorization ✨ Wire cross-shard authorization Jan 6, 2023
@sttts sttts changed the title ✨ Wire cross-shard authorization WIP: ✨ Wire cross-shard authorization Jan 6, 2023
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 6, 2023
globalAPIResourceSchemaIndexer: globalKcpInformers.Apis().V1alpha1().APIResourceSchemas().Informer().GetIndexer(),
globalShardIndexer: globalKcpInformers.Core().V1alpha1().Shards().Informer().GetIndexer(),
globalWorkspaceTypeIndexer: globalKcpInformers.Tenancy().V1alpha1().WorkspaceTypes().Informer().GetIndexer(),
globalClusterRoleIndexer: globalKubeInformers.Rbac().V1().ClusterRoles().Informer().GetIndexer(),
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to replicate cr and crb ?

Copy link
Member Author

Choose a reason for hiding this comment

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

As explained in gmeet: these are required to authorize binding of APIExports, and for maximum permission policy, for now. There will be more reasons for other cross-workspace authorizations.

@openshift-ci openshift-ci bot added the kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API label Jan 9, 2023
@sttts sttts force-pushed the sttts-global-authz branch 4 times, most recently from 65c6de3 to 3759c6f Compare January 9, 2023 11:38
@sttts sttts changed the title WIP: ✨ Wire cross-shard authorization WIP ✨ wire more controllers cross-shard and authz Jan 9, 2023
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 9, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 10, 2023
@@ -0,0 +1,254 @@
/*
Copyright 2022 The KCP Authors.
Copy link
Contributor

Choose a reason for hiding this comment

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

its 2023

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

applies to other places as well

)

const (
ControllerName = "kcp-apiexport-replication-clusterrolebinding"
Copy link
Contributor

Choose a reason for hiding this comment

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

apiexport ?

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed to kcp-apis-replication-clusterrolebinding

Copy link
Contributor

Choose a reason for hiding this comment

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

applies to the other controller as well

cluster, _, name, err := kcpcache.SplitMetaClusterNamespaceKey(key)
if err != nil {
runtime.HandleError(err)
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

why not to return the err?

Copy link
Member Author

Choose a reason for hiding this comment

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

then it would be requeued. Doesn't help here to fix the problem.

return true
}

func (c *controller) process(ctx context.Context, key string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

change the signature of this method to ctx context.Context, crb *rbacv1.ClusterRoleBinding, rename to reconcile and move it to a separate file - it would unify with the rest of the controllers and allow for easier unit testing

Copy link
Member Author

Choose a reason for hiding this comment

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

done

}

logger.V(4).Info("patching ClusterRoleBinding", "patch", patch)
_, err = c.kubeClusterClient.Cluster(cluster.Path()).RbacV1().ClusterRoleBindings().Patch(ctx, crb.Name, types.MergePatchType, []byte(patch), metav1.PatchOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

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

wondering if we could use committer.NewCommitter

Copy link
Member Author

Choose a reason for hiding this comment

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

no, I can't. But I wrote one I can use. Stay tuned :)

@@ -26,6 +26,11 @@ const (
//
// If this annotation exists, the system will maintain the annotation value.
LogicalClusterPathAnnotationKey = "kcp.io/path"

// ReplicateAnnotationKey is the annotation key used to indicate that a ClusterRole should be replicated.
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please remind me why it is a list?

Copy link
Member Author

Choose a reason for hiding this comment

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

there can be multiple controllers that contribute to this annotation. E.g. from another Api group.

func(cluster logicalcluster.Name, _, name string) (interface{}, bool, error) {
obj, err := c.localClusterRoleBindingLister.Cluster(cluster).Get(name)
if err != nil {
return obj, true, err
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 this line causes the panic, replace with return nil, false, err

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't obj nil then?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

func(cluster logicalcluster.Name, _, name string) (interface{}, bool, error) {
obj, err := c.localClusterRoleLister.Cluster(cluster).Get(name)
if err != nil {
return obj, true, err
Copy link
Contributor

Choose a reason for hiding this comment

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

same here (re panic), replace with return nil, false, err

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 10, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 10, 2023
@sttts sttts force-pushed the sttts-global-authz branch 2 times, most recently from 32dde53 to 5d8654c Compare January 10, 2023 14:03
@sttts sttts changed the title WIP ✨ wire more controllers cross-shard and authz ✨ wire more controllers cross-shard and authz Jan 10, 2023
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 10, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 11, 2023
@p0lyn0mial
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 11, 2023
@sttts
Copy link
Member Author

sttts commented Jan 11, 2023

/retest

@sttts
Copy link
Member Author

sttts commented Jan 11, 2023

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 11, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sttts

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-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 11, 2023
@openshift-merge-robot openshift-merge-robot merged commit ca40e16 into kcp-dev:main Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants