-
Notifications
You must be signed in to change notification settings - Fork 380
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
Conversation
/test-multicluster-e2e |
Codecov Report
@@ 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
|
085096e
to
0936a90
Compare
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.
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) { |
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.
Do you think more efficient to check ServiceAccount name matches or not, before checking member list changes? Not sure.
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 think other users may still update other parts of ClusterSet, eg: add a label or an annotation etc.
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 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.
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.
You mean we allow user to create/delete ClusterSet, but for update, we assume it will only be done by MC controller?
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.
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.
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.
Refined to check service account first.
0936a90
to
17b408a
Compare
/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) { |
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.
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.
17b408a
to
92b890f
Compare
klog.ErrorS(err, "Error getting ServiceAccount name", "ClusterSet", req.Namespace+"/"+req.Name) | ||
return admission.Errored(http.StatusBadRequest, err) | ||
} | ||
if saName == mcControllerSAName { |
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.
This block is useless and can be removed.
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.
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 <[email protected]>
92b890f
to
967ee6a
Compare
/test-multicluster-e2e |
/skip-all |
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 [email protected]