Security/csr approver identity binding audit logging - #2738
Open
nishantbkl3345-ship-it wants to merge 5 commits into
Open
Conversation
added 5 commits
August 3, 2026 00:26
…LeaderNodeLabelSelector is nil
…key mismatch in enhancement mode In gcPodsWhenRestart, KeyBuildInfo for pods fetched from the apiserver was missing the Version field. In enhancement mode, this produced keys like 'pods..core' instead of 'pods.v1.core', causing them to never match the cached keys from ListResourceKeysOfComponent. As a result, all cached pods appeared deleted, triggering the safety guard that skips GC entirely — making pod GC silently non-functional on restart. Added Version: 'v1' to the KeyBuildInfo and created gc_test.go with unit tests that prove the mismatch and verify the fix.
…bjWithObjs to prevent overflow In completeListObjWithObjs, resourceVersion was parsed using strconv.Atoi into a signed Go int, ignoring parsing errors. On 32-bit platforms (such as ARM32 linux/arm/v7 edge devices), signed int is 32-bit (max 2147483647). Any resourceVersion above 2^31-1 caused strconv.Atoi to return ErrRange and clamp to 2147483647. This produced corrupted resourceVersion strings on synthesized list responses, causing relist storms and 410 Gone errors on edge devices. Switched to strconv.ParseUint(rvStr, 10, 64) with uint64 listRv and added unit tests covering 64-bit uint64 resourceVersions and edge cases.
…for node certificates
…over
This commit enhances the CSR approver controller's security by making
identity binding validation explicit and adding security audit logging
for attempted privilege escalation attacks.
Problem:
--------
The isYurtHubNodeCert function's identity binding check was implicit
rather than explicit. While the existing logic did prevent attacks,
the security requirement was buried in boolean logic rather than being
clearly stated. Additionally, there was no audit trail when attacks
were attempted.
The old code (line 360-362):
```go
if strings.HasPrefix(csr.Spec.Username, "system:node:") && csr.Spec.Username != x509cr.Subject.CommonName {
return false
}
```
While this check works, it has issues:
- Security intent is not explicit
- No logging when attacks are attempted
- Future refactoring could accidentally break the implicit protection
- Difficult for security auditors to verify the protection
Solution:
---------
1. Make identity binding check explicit with clear structure
2. Add security warning logs when attacks are attempted
3. Add comprehensive comments explaining the security model
4. Maintain backward compatibility for legitimate use cases
New code:
```go
if strings.HasPrefix(csr.Spec.Username, "system:node:") {
if csr.Spec.Username != x509cr.Subject.CommonName {
klog.Warningf("CSR %s: requester username %q does not match requested CommonName %q",
csr.Name, csr.Spec.Username, x509cr.Subject.CommonName)
return false
}
}
```
Security Impact:
----------------
- ✅ Nodes can only request certificates for their own identity
- ✅ Bootstrap tokens can still request certs for initial node join
- ✅ Security audit trail for attempted privilege escalation
- ✅ Clear documentation of security requirements
- ✅ Zero functional impact on legitimate operations
Testing:
--------
Added three comprehensive test cases:
1. Attack scenario (mismatched identity) - properly rejected with warning
2. Legitimate renewal (matching identity) - properly approved
3. Bootstrap flow (token requesting node cert) - properly approved
All existing tests continue to pass.
Fixes: Security enhancement for CSR approval
Signed-off-by: Kiro AI <kiro@openyurt.io>
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
other Note