Skip to content

Commit 6ede073

Browse files
committed
add ReadOnlyRootFilesystem for postgres container and add needed env for nss_wrapper - cleanup
1 parent 1e686eb commit 6ede073

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

pkg/apis/cpo.opensource.cybertec.at/v1/operator_configuration_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type KubernetesMetaConfiguration struct {
6262
PodTerminateGracePeriod Duration `json:"pod_terminate_grace_period,omitempty"`
6363
SpiloPrivileged bool `json:"spilo_privileged,omitempty"`
6464
SpiloAllowPrivilegeEscalation *bool `json:"spilo_allow_privilege_escalation,omitempty"`
65-
ReadOnlyRootFilesystem *bool `json:"container_readonly_root_filesystem" default:"true"`
65+
ReadOnlyRootFilesystem *bool `json:"container_readonly_root_filesystem" default:"false"`
6666
SpiloRunAsUser *int64 `json:"spilo_runasuser,omitempty"`
6767
SpiloRunAsGroup *int64 `json:"spilo_runasgroup,omitempty"`
6868
SpiloFSGroup *int64 `json:"spilo_fsgroup,omitempty"`

pkg/cluster/k8sres.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ func generateContainer(
677677
volumeMounts []v1.VolumeMount,
678678
privilegedMode bool,
679679
privilegeEscalationMode *bool,
680+
readOnlyRootFilesystem *bool,
680681
additionalPodCapabilities *v1.Capabilities,
681682
) *v1.Container {
682683
return &v1.Container{
@@ -703,7 +704,7 @@ func generateContainer(
703704
SecurityContext: &v1.SecurityContext{
704705
AllowPrivilegeEscalation: privilegeEscalationMode,
705706
Privileged: &privilegedMode,
706-
ReadOnlyRootFilesystem: util.False(),
707+
ReadOnlyRootFilesystem: readOnlyRootFilesystem,
707708
Capabilities: additionalPodCapabilities,
708709
},
709710
}
@@ -878,7 +879,7 @@ func (c *Cluster) generatePodTemplate(
878879
addEmptyDirVolume(&podSpec, "exporter-tmp", "postgres-exporter", "/tmp")
879880
}
880881

881-
if c.OpConfig.ReadOnlyRootFilesystem != nil {
882+
if c.OpConfig.ReadOnlyRootFilesystem != nil && *c.OpConfig.ReadOnlyRootFilesystem {
882883
addRunVolume(&podSpec, "postgres-run", "postgres", "/run")
883884
addEmptyDirVolume(&podSpec, "postgres-tmp", "postgres", "/tmp")
884885
}
@@ -998,6 +999,19 @@ func (c *Cluster) generateSpiloPodEnvVars(
998999
Name: "HUMAN_ROLE",
9991000
Value: c.OpConfig.PamRoleName,
10001001
},
1002+
// NSS WRAPPER
1003+
{
1004+
Name: "LD_PRELOAD",
1005+
Value: "/usr/lib64/libnss_wrapper.so",
1006+
},
1007+
{
1008+
Name: "NSS_WRAPPER_PASSWD",
1009+
Value: "/tmp/nss_wrapper/passwd",
1010+
},
1011+
{
1012+
Name: "NSS_WRAPPER_GROUP",
1013+
Value: "/tmp/nss_wrapper/group",
1014+
},
10011015
}
10021016

10031017
if c.OpConfig.EnableSpiloWalPathCompat {
@@ -1484,6 +1498,7 @@ func (c *Cluster) generateStatefulSet(spec *cpov1.PostgresSpec) (*appsv1.Statefu
14841498
volumeMounts,
14851499
c.OpConfig.Resources.SpiloPrivileged,
14861500
c.OpConfig.Resources.SpiloAllowPrivilegeEscalation,
1501+
c.OpConfig.Resources.ReadOnlyRootFilesystem,
14871502
generateCapabilities(c.OpConfig.AdditionalPodCapabilities),
14881503
)
14891504

@@ -1806,6 +1821,7 @@ func (c *Cluster) generateRepoHostStatefulSet(spec *cpov1.PostgresSpec) (*appsv1
18061821
volumeMounts,
18071822
c.OpConfig.Resources.SpiloPrivileged,
18081823
c.OpConfig.Resources.SpiloAllowPrivilegeEscalation,
1824+
c.OpConfig.Resources.ReadOnlyRootFilesystem,
18091825
generateCapabilities(c.OpConfig.AdditionalPodCapabilities),
18101826
)
18111827

@@ -2818,6 +2834,7 @@ func (c *Cluster) generateLogicalBackupJob() (*batchv1.CronJob, error) {
28182834
[]v1.VolumeMount{},
28192835
c.OpConfig.SpiloPrivileged, // use same value as for normal DB pods
28202836
c.OpConfig.SpiloAllowPrivilegeEscalation,
2837+
util.False(),
28212838
nil,
28222839
)
28232840

@@ -3344,6 +3361,7 @@ func (c *Cluster) generatePgbackrestJob(backup *cpov1.Pgbackrest, repo *cpov1.Re
33443361
[]v1.VolumeMount{},
33453362
c.OpConfig.SpiloPrivileged, // use same value as for normal DB pods
33463363
c.OpConfig.SpiloAllowPrivilegeEscalation,
3364+
c.OpConfig.Resources.ReadOnlyRootFilesystem,
33473365
nil,
33483366
)
33493367

pkg/controller/operator_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *cpov1.OperatorConfigura
7575
result.PodTerminateGracePeriod = util.CoalesceDuration(time.Duration(fromCRD.Kubernetes.PodTerminateGracePeriod), "5m")
7676
result.SpiloPrivileged = fromCRD.Kubernetes.SpiloPrivileged
7777
result.SpiloAllowPrivilegeEscalation = util.CoalesceBool(fromCRD.Kubernetes.SpiloAllowPrivilegeEscalation, util.True())
78-
result.ReadOnlyRootFilesystem = util.CoalesceBool(fromCRD.Kubernetes.ReadOnlyRootFilesystem, util.True())
78+
result.ReadOnlyRootFilesystem = util.CoalesceBool(fromCRD.Kubernetes.ReadOnlyRootFilesystem, util.False())
7979
result.SpiloRunAsUser = fromCRD.Kubernetes.SpiloRunAsUser
8080
result.SpiloRunAsGroup = fromCRD.Kubernetes.SpiloRunAsGroup
8181
result.SpiloFSGroup = fromCRD.Kubernetes.SpiloFSGroup

pkg/util/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Resources struct {
3838
SpiloPrivileged bool `name:"spilo_privileged" default:"false"`
3939
SpiloAllowPrivilegeEscalation *bool `name:"spilo_allow_privilege_escalation" default:"true"`
4040
AdditionalPodCapabilities []string `name:"additional_pod_capabilities" default:""`
41-
ReadOnlyRootFilesystem *bool `name:"container_readonly_root_filesystem" default:"true"`
41+
ReadOnlyRootFilesystem *bool `name:"container_readonly_root_filesystem" default:"false"`
4242
ClusterLabels map[string]string `name:"cluster_labels" default:"application:cpo"`
4343
InheritedLabels []string `name:"inherited_labels" default:""`
4444
InheritedAnnotations []string `name:"inherited_annotations" default:""`

0 commit comments

Comments
 (0)