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

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/appstreamcli
profile appstreamcli @{exec_path} flags=(complain) {
  include <abstractions/base>
  include <abstractions/consoles>
  include <abstractions/freedesktop.org>
  include <abstractions/nameservice-strict>

  capability dac_read_search,

  @{exec_path} mr,

  @{bin}/curl rCx -> curl,
  @{bin}/gzip rix,
  @{bin}/tar  rix,

  /usr/share/app-info/{,**} r,
  /usr/share/appdata/ r,
  /usr/share/metainfo/ r,
  /usr/share/metainfo/*.{metainfo,appdata}.xml r,
  /usr/share/swcatalog/{,**} r,

  /etc/appstream.conf r,

  /var/lib/app-info/ w,
  /var/lib/app-info/yaml/ r,
  /var/lib/app-info/yaml/*.yml.gz w,
  /var/lib/app-info/icons/ r,
  /var/lib/apt/lists/ r,
  /var/lib/apt/lists/*.gz r,
  /var/lib/flatpak/appstream/{,**} r,
  /var/lib/swcatalog/ rw,
  /var/lib/swcatalog/icons/{,**} rw,
  /var/lib/swcatalog/yaml/ rw,
  /var/lib/swcatalog/yaml/*_Components-*.yml.gz w,

        /var/cache/swcatalog/cache/{,**} rw,
        /var/log/cron-apt/temp w,
  owner /var/cache/app-info/{,**} rw,
  owner /var/cache/swcatalog/{,**} rw,
  
  owner @{user_cache_dirs}/ rw,
  owner @{user_cache_dirs}/appstream-cache-*.mdb rw,
  owner @{user_cache_dirs}/appstream/ rw,
  owner @{user_cache_dirs}/appstream/appcache-*.mdb rw,

  owner @{tmp}/appstream-cache-*.mdb rw,
  owner @{tmp}/appstream/ rw,
  owner @{tmp}/appstream/appcache-*.mdb rw,

  owner @{PROC}/@{pid}/fd/ r,

  # File Inherit
  deny network inet stream,
  deny network inet6 stream,

  profile curl {
    include <abstractions/base>
    include <abstractions/nameservice-strict>
    include <abstractions/ssl_certs>

    @{bin}/curl mr,

    include if exists <local/appstreamcli_curl>
  }

  include if exists <local/appstreamcli>
}
