Skip to content

Security/csr approver identity binding audit logging - #2738

Open
nishantbkl3345-ship-it wants to merge 5 commits into
openyurtio:masterfrom
nishantbkl3345-ship-it:security/csr-approver-identity-binding-audit-logging
Open

Security/csr approver identity binding audit logging#2738
nishantbkl3345-ship-it wants to merge 5 commits into
openyurtio:masterfrom
nishantbkl3345-ship-it:security/csr-approver-identity-binding-audit-logging

Conversation

@nishantbkl3345-ship-it

Copy link
Copy Markdown

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespace from that line:
/kind bug
/kind documentation
/kind enhancement
/kind good-first-issue
/kind feature
/kind question
/kind design
/sig ai
/sig iot
/sig network
/sig storage

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

APPLE added 5 commits August 3, 2026 00:26
…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.
…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>
Copilot AI lite review requested due to automatic review settings August 8, 2026 20:19
@nishantbkl3345-ship-it
nishantbkl3345-ship-it requested a review from a team as a code owner August 8, 2026 20:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

sonarqubecloud Bot commented Aug 8, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants