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

Validate ServiceAccount for ClusterSet member list changes #4090

Merged
merged 1 commit into from
Aug 11, 2022

Conversation

luolanzone
Copy link
Contributor

@luolanzone luolanzone commented Aug 9, 2022

Since ClusterSet's member list is maintained by MemberClusterAnnounce
controller, mc-controller should deny ClusterSet member list updates by users
manually.

Signed-off-by: Lan Luo luola@vmware.com

@luolanzone luolanzone added the area/multi-cluster Issues or PRs related to multi cluster. label Aug 9, 2022
@luolanzone
Copy link
Contributor Author

/test-multicluster-e2e

@codecov
Copy link

codecov bot commented Aug 9, 2022

Codecov Report

Merging #4090 (967ee6a) into main (454df5d) will increase coverage by 0.86%.
The diff coverage is 52.94%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4090      +/-   ##
==========================================
+ Coverage   64.25%   65.12%   +0.86%     
==========================================
  Files         294      310      +16     
  Lines       44805    45555     +750     
==========================================
+ Hits        28789    29666     +877     
+ Misses      13687    13512     -175     
- Partials     2329     2377      +48     
Flag Coverage Δ
e2e-tests 58.34% <0.00%> (?)
integration-tests 35.47% <ø> (?)
kind-e2e-tests 43.57% <ø> (-6.72%) ⬇️
unit-tests 44.26% <52.94%> (-0.07%) ⬇️
Impacted Files Coverage Δ
...luster-controller/memberclusterannounce_webhook.go 63.33% <0.00%> (+8.33%) ⬆️
.../cmd/multicluster-controller/clusterset_webhook.go 60.41% <56.25%> (+1.04%) ⬆️
pkg/agent/proxy/endpointslicecache.go 0.00% <0.00%> (-83.60%) ⬇️
pkg/agent/secondarynetwork/cnipodcache/cache.go 0.00% <0.00%> (-77.56%) ⬇️
pkg/controller/egress/store/egressgroup.go 1.72% <0.00%> (-54.32%) ⬇️
...g/agent/controller/serviceexternalip/controller.go 35.83% <0.00%> (-45.74%) ⬇️
pkg/agent/secondarynetwork/podwatch/controller.go 0.00% <0.00%> (-39.02%) ⬇️
.../agent/flowexporter/connections/conntrack_linux.go 58.87% <0.00%> (-26.62%) ⬇️
pkg/ovs/ovsctl/ovsctl_others.go 53.84% <0.00%> (-25.65%) ⬇️
...nt/apiserver/handlers/serviceexternalip/handler.go 29.62% <0.00%> (-22.23%) ⬇️
... and 109 more

@jianjuns jianjuns changed the title Validate ServiceAccount if member list changed Validate ServiceAccount for ClusterSet member list changes Aug 9, 2022
Copy link
Contributor

@jianjuns jianjuns left a comment

Choose a reason for hiding this comment

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

Nits.

@@ -57,6 +63,22 @@ func (v *clusterSetValidator) Handle(ctx context.Context, req admission.Request)
klog.ErrorS(err, "the field 'clusterID' is immutable", "ClusterSet", klog.KObj(clusterSet))
return admission.Denied("the field 'clusterID' is immutable")
}

if isMemberListChanged(oldClusterSet.Spec.Members, clusterSet.Spec.Members) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think more efficient to check ServiceAccount name matches or not, before checking member list changes? Not sure.

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 think other users may still update other parts of ClusterSet, eg: add a label or an annotation etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant if checking ServiceAccount name is faster than checking member list, maybe we should check SA name first, also assuming more updates should be by MC controller.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean we allow user to create/delete ClusterSet, but for update, we assume it will only be done by MC controller?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I meant if the current code is more efficient or not:

		ui := req.UserInfo
		_, saName, err := serviceaccount.SplitUsername(ui.Username)
		if err != nil {
			klog.ErrorS(err, "Error getting ServiceAccount name", "ClusterSet", req.Namespace+"/"+req.Name)
			return admission.Errored(http.StatusBadRequest, err)
		}
		if saName != mcControllerSAName && isMemberListChanged(oldClusterSet.Spec.Members, clusterSet.Spec.Members) {
			return admission.Errored(http.StatusPreconditionFailed, fmt.Errorf("member list can only be updated by Antrea Multi-cluster Controller"))
		}

assuming most updates are by controller.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refined to check service account first.

@luolanzone
Copy link
Contributor Author

/test-multicluster-e2e

@@ -57,6 +63,22 @@ func (v *clusterSetValidator) Handle(ctx context.Context, req admission.Request)
klog.ErrorS(err, "the field 'clusterID' is immutable", "ClusterSet", klog.KObj(clusterSet))
return admission.Denied("the field 'clusterID' is immutable")
}

if isMemberListChanged(oldClusterSet.Spec.Members, clusterSet.Spec.Members) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No, I meant if the current code is more efficient or not:

		ui := req.UserInfo
		_, saName, err := serviceaccount.SplitUsername(ui.Username)
		if err != nil {
			klog.ErrorS(err, "Error getting ServiceAccount name", "ClusterSet", req.Namespace+"/"+req.Name)
			return admission.Errored(http.StatusBadRequest, err)
		}
		if saName != mcControllerSAName && isMemberListChanged(oldClusterSet.Spec.Members, clusterSet.Spec.Members) {
			return admission.Errored(http.StatusPreconditionFailed, fmt.Errorf("member list can only be updated by Antrea Multi-cluster Controller"))
		}

assuming most updates are by controller.

klog.ErrorS(err, "Error getting ServiceAccount name", "ClusterSet", req.Namespace+"/"+req.Name)
return admission.Errored(http.StatusBadRequest, err)
}
if saName == mcControllerSAName {
Copy link
Contributor

Choose a reason for hiding this comment

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

This block is useless and can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, removed it.

Since ClusterSet's member list will be updated by MemberClusterAnnounce
controller, mc controller should deny ClusterSet member list update by user
manually to avoid overwrites.

Signed-off-by: Lan Luo <luola@vmware.com>
@jianjuns
Copy link
Contributor

/test-multicluster-e2e
/test-integration

@jianjuns
Copy link
Contributor

/skip-all

@jianjuns jianjuns merged commit c54a715 into antrea-io:main Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/multi-cluster Issues or PRs related to multi cluster.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants