mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 12:32:03 +00:00
auth: don't allow kubelet to from modify ResourceClaimStatuses
The status determines which claims kubelet is allowed to access when claims get created from a template. Therefore kubelet must not be allowed to modify that part of the status, because otherwise it could add an entry and then gain access to a claim it should have access to.
This commit is contained in:
parent
1db11c07ff
commit
4121c1fc79
@ -288,6 +288,9 @@ func (p *Plugin) admitPodStatus(nodeName string, a admission.Attributes) error {
|
||||
if !labels.Equals(oldPod.Labels, newPod.Labels) {
|
||||
return admission.NewForbidden(a, fmt.Errorf("node %q cannot update labels through pod status", nodeName))
|
||||
}
|
||||
if !resourceClaimStatusesEqual(oldPod.Status.ResourceClaimStatuses, newPod.Status.ResourceClaimStatuses) {
|
||||
return admission.NewForbidden(a, fmt.Errorf("node %q cannot update resource claim statues", nodeName))
|
||||
}
|
||||
return nil
|
||||
|
||||
default:
|
||||
@ -295,6 +298,29 @@ func (p *Plugin) admitPodStatus(nodeName string, a admission.Attributes) error {
|
||||
}
|
||||
}
|
||||
|
||||
func resourceClaimStatusesEqual(statusA, statusB []api.PodResourceClaimStatus) bool {
|
||||
if len(statusA) != len(statusB) {
|
||||
return false
|
||||
}
|
||||
// In most cases, status entries only get added once and not modified.
|
||||
// But this cannot be guaranteed, so for the sake of correctness in all
|
||||
// cases this code here has to check.
|
||||
for i := range statusA {
|
||||
if statusA[i].Name != statusB[i].Name {
|
||||
return false
|
||||
}
|
||||
claimNameA := statusA[i].ResourceClaimName
|
||||
claimNameB := statusB[i].ResourceClaimName
|
||||
if (claimNameA == nil) != (claimNameB == nil) {
|
||||
return false
|
||||
}
|
||||
if claimNameA != nil && *claimNameA != *claimNameB {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// admitPodEviction allows to evict a pod if it is assigned to the current node.
|
||||
func (p *Plugin) admitPodEviction(nodeName string, a admission.Attributes) error {
|
||||
switch a.GetOperation() {
|
||||
|
Loading…
Reference in New Issue
Block a user