# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2026 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/4.0>,

include <tunables/global>

@{lib_dirs} = @{lib}/postgresql/@{version}/
@{bin_dirs} = @{lib_dirs}/bin

@{exec_path} = @{bin_dirs}/initdb
@{att} = /att/postgres-initdb/
profile postgres-initdb /{,usr/}lib{,exec,32,64}/postgresql/[0-9]{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{.[0-9]{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],},}{.[0-9]{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],}{[0-9],},}{-[0-9a-zA-Z]{[0-9a-zA-Z],}{[0-9a-zA-Z],}{[0-9a-zA-Z],}{[0-9a-zA-Z],}{[0-9a-zA-Z],}{[0-9a-zA-Z],}{[0-9a-zA-Z],}{[0-9a-zA-Z],}{[0-9a-zA-Z],},}/bin/initdb flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/attached/consoles>
  include <abstractions/attached/nameservice-strict>

  @{exec_path} mr,

  @{sh_path}           rix,
  @{bin_dirs}/postgres  px,

  /usr/share/postgresql/{,**} r,

  /etc/postgresql/{,**} r,

  owner /var/lib/postgresql/** rw,

  owner /dev/shm/PostgreSQL.@{int} rw,

  include if exists <local/postgres-initdb>
}

# vim:syntax=apparmor
