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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/dhcpcd
profile dhcpcd @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/nameservice-strict>

  capability dac_override,
  capability dac_read_search,
  capability kill,
  capability net_admin,
  capability net_bind_service,
  capability net_raw,
  capability setgid,
  capability setuid,
  capability sys_chroot,

  network inet dgram,
  network inet raw,
  network inet6 dgram,
  network inet6 raw,
  network netlink raw,
  network packet raw,
  
  @{exec_path} mr,

  @{sh_path}                      rix,
  @{bin}/cat                      rix,
  @{bin}/chmod                    rix,
  @{bin}/cmp                      rix,
  @{bin}/mkdir                    rix,
  @{bin}/rm                       rix,
  @{bin}/sed                      rix,
  @{lib}/dhcpcd/dhcpcd-run-hooks  rix,

  /etc/dhcpcd.conf r,
  /etc/resolv.conf rw,

  /var/lib/dhcpcd/** rw,

  @{run}/dhcpcd/** rwk,

  @{run}/udev/data/n@{int} r,

  @{sys}/devices/@{pci}/uevent r,
  @{sys}/devices/virtual/dmi/id/product_uuid r,
  @{sys}/devices/virtual/net/**/{tun_flags,uevent} r,

        @{PROC}/sys/kernel/hostname r,
        @{PROC}/sys/net/ipv{4,6}/conf/** r,
        @{PROC}/sys/net/ipv{4,6}/conf/*/accept_ra rw,
        @{PROC}/sys/net/ipv{4,6}/conf/*/hop_limit w,
        @{PROC}/sys/net/ipv{4,6}/neigh/*/{base_reachable_time_ms,retrans_time_ms} w,
  owner @{PROC}/@{pid}/net/if_inet6 r,
  owner @{PROC}/@{pid}/stat r,

  /dev/tty rw,

  include if exists <local/dhcpcd>

}

# vim:syntax=apparmor
