Skip to content

feat: hardened default SecurityContext for sidecar container#70

Open
ermakov-oleg wants to merge 1 commit into
operasoftware:mainfrom
ermakov-oleg:feat/default-security-context
Open

feat: hardened default SecurityContext for sidecar container#70
ermakov-oleg wants to merge 1 commit into
operasoftware:mainfrom
ermakov-oleg:feat/default-security-context

Conversation

@ermakov-oleg
Copy link
Copy Markdown

Summary

Port of upstream #225

Problem: When no securityContext was specified in the Archive CRD, the sidecar container ran with no security restrictions (nil SecurityContext).

Fix: When securityContext is not explicitly configured, the plugin now applies a hardened default instead of nil:

  • allowPrivilegeEscalation: false
  • runAsNonRoot: true
  • privileged: false
  • readOnlyRootFilesystem: true
  • seccompProfile: RuntimeDefault
  • capabilities: drop ALL

Users can still override by setting securityContext explicitly in the Archive spec. All sidecar writable paths are already on volumes, so readOnlyRootFilesystem does not affect normal operation.

Disable pgbackrest file logging

pgbackrest writes logs to /var/log/pgbackrest/ by default. With readOnlyRootFilesystem: true this path is not writable, so every operation (backup, stanza-create, expire) produces a warning:

WARN: unable to open log file '...stanza-expire.log': No such file or directory

Added --log-level-file off to disable file logging. All pgbackrest output already goes through stderr into container logs.

Open question: is there a reason to keep file logging enabled? An alternative would be --log-path /controller/tmp to redirect logs to a writable dir.

Signed-off-by: ermakov-oleg <ermakovolegs@gmail.com>
@Agalin
Copy link
Copy Markdown
Collaborator

Agalin commented May 20, 2026

Good question about the file log. I'd say it's left here mostly because it didn't break anything in a read-only setup. We missed setting hardened defaults here because... our clusters already enforce those and inject secure defaults if missing. Although I wonder if hardcoding it like this still allows an override for people who'd like to redirect those logs to a PV for debugging. 🤔

I'm not sure about the approach, ideally we'd define defaults in the schema and separately for each security context entry. I'd need to check if kubebuilder enables doing so cleanly.

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