-
Notifications
You must be signed in to change notification settings - Fork 128
🐛 fail fast on MTU mismatch before SelfSubjectAccessReview #1319
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,22 +1,60 @@ | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| package helpers | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||||
| "net" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| authorizationv1 "k8s.io/api/authorization/v1" | ||||||||||||||||||||||||||||||||||||||||||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||||||||||||||||||||||||||||||||||||||
| "k8s.io/client-go/kubernetes" | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| func detectLocalMTU() (int, error) { | ||||||||||||||||||||||||||||||||||||||||||
| ifaces, err := net.Interfaces() | ||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to clarify system permission it needs to execute this command.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good catch. net.Interfaces() relies on standard OS networking APIs and does not require elevated privileges in typical container environments, but this should be documented. |
||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| return 0, err | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| maxMTU := 0 | ||||||||||||||||||||||||||||||||||||||||||
| for _, iface := range ifaces { | ||||||||||||||||||||||||||||||||||||||||||
| if iface.Flags&net.FlagUp == 0 { | ||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if iface.MTU > maxMTU { | ||||||||||||||||||||||||||||||||||||||||||
| maxMTU = iface.MTU | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if maxMTU == 0 { | ||||||||||||||||||||||||||||||||||||||||||
| return 0, fmt.Errorf("unable to detect MTU") | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return maxMTU, nil | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: loopback MTU will cause false positives (as previously flagged). This function returns the maximum MTU across all "up" interfaces, including loopback (typically 65536 on Linux). The validation at line 44 ( As noted in the previous review, you must either:
Based on previous review feedback on this PR. |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| func CreateSelfSubjectAccessReviews( | ||||||||||||||||||||||||||||||||||||||||||
| ctx context.Context, | ||||||||||||||||||||||||||||||||||||||||||
| kubeClient kubernetes.Interface, | ||||||||||||||||||||||||||||||||||||||||||
| selfSubjectAccessReviews []authorizationv1.SelfSubjectAccessReview) (bool, *authorizationv1.SelfSubjectAccessReview, error) { | ||||||||||||||||||||||||||||||||||||||||||
| selfSubjectAccessReviews []authorizationv1.SelfSubjectAccessReview, | ||||||||||||||||||||||||||||||||||||||||||
| ) (bool, *authorizationv1.SelfSubjectAccessReview, error) { | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| mtu, err := detectLocalMTU() | ||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would put this mtu detection in a separated func instead of calling inside CreateSelfSubjectAccessReviews
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree that MTU detection shouldn’t be embedded directly inside CreateSelfSubjectAccessReviews. |
||||||||||||||||||||||||||||||||||||||||||
| if err == nil && mtu > 1500 { | ||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if local MTU is larger than 1500 and remote is also larger?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You’re right, local MTU alone is only a heuristic. |
||||||||||||||||||||||||||||||||||||||||||
| return false, nil, fmt.Errorf( | ||||||||||||||||||||||||||||||||||||||||||
| "MTU mismatch detected: managed cluster MTU (%d) exceeds typical hub path MTU (1500). "+ | ||||||||||||||||||||||||||||||||||||||||||
| "This can cause TLS handshake timeouts during bootstrap or certificate rotation. "+ | ||||||||||||||||||||||||||||||||||||||||||
| "Please align MTU values between hub and managed cluster.", | ||||||||||||||||||||||||||||||||||||||||||
| mtu, | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+43
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's read the ssar.go file to see the full context
cat -n pkg/common/helpers/ssar.goRepository: open-cluster-management-io/ocm Length of output: 6793 🏁 Script executed: # Find logging patterns used in this package and broader codebase
rg -n 'klog\.|logr\.|zap\.|fmt\.Printf|log\.' --type=go pkg/common/helpers/ | head -20Repository: open-cluster-management-io/ocm Length of output: 355 🏁 Script executed: # Also check for logging in the parent package
rg -n 'klog\.|logr\.|zap\.|fmt\.Printf|log\.' --type=go pkg/common/ | head -30Repository: open-cluster-management-io/ocm Length of output: 591 Silent error handling masks MTU detection failures. When
Since the codebase uses 💡 Suggested enhancement mtu, err := detectLocalMTU()
+ if err != nil {
+ klog.Warningf("MTU detection failed: %v. Skipping MTU validation check.", err)
+ } else if mtu > 1500 {
return false, nil, fmt.Errorf(
"MTU mismatch detected: managed cluster MTU (%d) exceeds typical hub path MTU (1500). "+
"This can cause TLS handshake timeouts during bootstrap or certificate rotation. "+
"Please align MTU values between hub and managed cluster.",
mtu,
)
}This maintains the fail-open behavior while providing operator visibility into why the check was skipped. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| for i := range selfSubjectAccessReviews { | ||||||||||||||||||||||||||||||||||||||||||
| subjectAccessReview := selfSubjectAccessReviews[i] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ssar, err := kubeClient.AuthorizationV1().SelfSubjectAccessReviews().Create(ctx, &subjectAccessReview, metav1.CreateOptions{}) | ||||||||||||||||||||||||||||||||||||||||||
| ssar, err := kubeClient.AuthorizationV1(). | ||||||||||||||||||||||||||||||||||||||||||
| SelfSubjectAccessReviews(). | ||||||||||||||||||||||||||||||||||||||||||
| Create(ctx, &subjectAccessReview, metav1.CreateOptions{}) | ||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
| return false, &subjectAccessReview, err | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -127,6 +165,9 @@ func generateSelfSubjectAccessReviews(resource authorizationv1.ResourceAttribute | |||||||||||||||||||||||||||||||||||||||||
| Verb: verb, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+168
to
+170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unnecessary trailing whitespace. The added blank lines serve no purpose and should be removed. ♻️ Remove the blank lines })
}
return reviews
}
-
-
- 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| return reviews | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
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.
Fix import ordering per gci linter.
The imports should be properly grouped and ordered according to the gci linter rules (standard library, external packages, local packages).
Run the following to fix:
🧰 Tools
🪛 golangci-lint (2.5.0)
[error] 1-1: File is not properly formatted
(gci)
🤖 Prompt for AI Agents