mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #55806 from php-coder/cleanup_internal_effective_sc
Automatic merge from submit-queue (batch tested with PRs 54604, 55781, 55806, 55935, 55991). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. InternalDetermineEffectiveSecurityContext: remove unused function **What this PR does / why we need it**: This PR removes unused `InternalDetermineEffectiveSecurityContext` and `internalSecurityContextFromPodSecurityContext` functions. We stopped using it in the following commit: https://github.com/kubernetes/kubernetes/pull/52849/files#diff-291b8dd7d08cc034975ddb3925dbb08fL205 **Release note**: ```release-note NONE ``` PTAL @liggitt CC @simo5
This commit is contained in:
commit
ec693a6c5f
@ -21,7 +21,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HasPrivilegedRequest returns the value of SecurityContext.Privileged, taking into account
|
// HasPrivilegedRequest returns the value of SecurityContext.Privileged, taking into account
|
||||||
@ -165,83 +164,6 @@ func securityContextFromPodSecurityContext(pod *v1.Pod) *v1.SecurityContext {
|
|||||||
return synthesized
|
return synthesized
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove the duplicate code
|
|
||||||
func InternalDetermineEffectiveSecurityContext(pod *api.Pod, container *api.Container) *api.SecurityContext {
|
|
||||||
effectiveSc := internalSecurityContextFromPodSecurityContext(pod)
|
|
||||||
containerSc := container.SecurityContext
|
|
||||||
|
|
||||||
if effectiveSc == nil && containerSc == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if effectiveSc != nil && containerSc == nil {
|
|
||||||
return effectiveSc
|
|
||||||
}
|
|
||||||
if effectiveSc == nil && containerSc != nil {
|
|
||||||
return containerSc
|
|
||||||
}
|
|
||||||
|
|
||||||
if containerSc.SELinuxOptions != nil {
|
|
||||||
effectiveSc.SELinuxOptions = new(api.SELinuxOptions)
|
|
||||||
*effectiveSc.SELinuxOptions = *containerSc.SELinuxOptions
|
|
||||||
}
|
|
||||||
|
|
||||||
if containerSc.Capabilities != nil {
|
|
||||||
effectiveSc.Capabilities = new(api.Capabilities)
|
|
||||||
*effectiveSc.Capabilities = *containerSc.Capabilities
|
|
||||||
}
|
|
||||||
|
|
||||||
if containerSc.Privileged != nil {
|
|
||||||
effectiveSc.Privileged = new(bool)
|
|
||||||
*effectiveSc.Privileged = *containerSc.Privileged
|
|
||||||
}
|
|
||||||
|
|
||||||
if containerSc.RunAsUser != nil {
|
|
||||||
effectiveSc.RunAsUser = new(int64)
|
|
||||||
*effectiveSc.RunAsUser = *containerSc.RunAsUser
|
|
||||||
}
|
|
||||||
|
|
||||||
if containerSc.RunAsNonRoot != nil {
|
|
||||||
effectiveSc.RunAsNonRoot = new(bool)
|
|
||||||
*effectiveSc.RunAsNonRoot = *containerSc.RunAsNonRoot
|
|
||||||
}
|
|
||||||
|
|
||||||
if containerSc.ReadOnlyRootFilesystem != nil {
|
|
||||||
effectiveSc.ReadOnlyRootFilesystem = new(bool)
|
|
||||||
*effectiveSc.ReadOnlyRootFilesystem = *containerSc.ReadOnlyRootFilesystem
|
|
||||||
}
|
|
||||||
|
|
||||||
if containerSc.AllowPrivilegeEscalation != nil {
|
|
||||||
effectiveSc.AllowPrivilegeEscalation = new(bool)
|
|
||||||
*effectiveSc.AllowPrivilegeEscalation = *containerSc.AllowPrivilegeEscalation
|
|
||||||
}
|
|
||||||
|
|
||||||
return effectiveSc
|
|
||||||
}
|
|
||||||
|
|
||||||
func internalSecurityContextFromPodSecurityContext(pod *api.Pod) *api.SecurityContext {
|
|
||||||
if pod.Spec.SecurityContext == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
synthesized := &api.SecurityContext{}
|
|
||||||
|
|
||||||
if pod.Spec.SecurityContext.SELinuxOptions != nil {
|
|
||||||
synthesized.SELinuxOptions = &api.SELinuxOptions{}
|
|
||||||
*synthesized.SELinuxOptions = *pod.Spec.SecurityContext.SELinuxOptions
|
|
||||||
}
|
|
||||||
if pod.Spec.SecurityContext.RunAsUser != nil {
|
|
||||||
synthesized.RunAsUser = new(int64)
|
|
||||||
*synthesized.RunAsUser = *pod.Spec.SecurityContext.RunAsUser
|
|
||||||
}
|
|
||||||
|
|
||||||
if pod.Spec.SecurityContext.RunAsNonRoot != nil {
|
|
||||||
synthesized.RunAsNonRoot = new(bool)
|
|
||||||
*synthesized.RunAsNonRoot = *pod.Spec.SecurityContext.RunAsNonRoot
|
|
||||||
}
|
|
||||||
|
|
||||||
return synthesized
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddNoNewPrivileges returns if we should add the no_new_privs option.
|
// AddNoNewPrivileges returns if we should add the no_new_privs option.
|
||||||
func AddNoNewPrivileges(sc *v1.SecurityContext) bool {
|
func AddNoNewPrivileges(sc *v1.SecurityContext) bool {
|
||||||
if sc == nil {
|
if sc == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user