Skip to content

Commit

Permalink
remove code
Browse files Browse the repository at this point in the history
Signed-off-by: souravbiswassanto <[email protected]>
  • Loading branch information
souravbiswassanto committed Feb 9, 2024
1 parent dac61fd commit f33002b
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions apis/kubedb/v1alpha2/postgres_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,42 +337,9 @@ func (p *Postgres) setDefaultContainerSecurityContext(podTemplate *ofst.PodTempl
if podTemplate.Spec.SecurityContext.FSGroup == nil {
podTemplate.Spec.SecurityContext.FSGroup = pgVersion.Spec.SecurityContext.RunAsUser
}
p.setDefaultCapabilitiesForPostgres(podTemplate.Spec.ContainerSecurityContext)
p.assignDefaultContainerSecurityContext(podTemplate.Spec.ContainerSecurityContext, pgVersion)
}

func (p *Postgres) setDefaultCapabilitiesForPostgres(sc *core.SecurityContext) {
if sc.Capabilities == nil {
sc.Capabilities = &core.Capabilities{
Drop: []core.Capability{"ALL"},
}
} else if sc.Capabilities.Drop == nil && p.matchedPreviousCapabilities(sc) {
sc.Capabilities = &core.Capabilities{
Drop: []core.Capability{"ALL"},
}
}
}

func (p *Postgres) matchedPreviousCapabilities(sc *core.SecurityContext) bool {
caps := sc.Capabilities.Add
capPattern := []core.Capability{IPS_LOCK, SYS_RESOURCE}
if len(caps) != len(capPattern) {
return false
}
for i := range caps {
found := false
for _, capability := range capPattern {
if caps[i] == capability {
found = true
}
}
if !found {
return false
}
}
return true
}

func (p *Postgres) assignDefaultContainerSecurityContext(sc *core.SecurityContext, pgVersion *catalog.PostgresVersion) {
if sc.AllowPrivilegeEscalation == nil {
sc.AllowPrivilegeEscalation = pointer.BoolP(false)
Expand Down

0 comments on commit f33002b

Please sign in to comment.