;;; Copyright (c) 2021 Apple Inc.  All Rights reserved.
;;;
;;; WARNING: The sandbox rules in this file currently constitute
;;; Apple System Private Interface and are subject to change at any time and
;;; without notice.
;;;
(version 1)

(deny default)
(deny file-map-executable process-info* nvram*)
(deny dynamic-code-generation)
(deny mach-priv-host-port)

(import "system.sb")
(import "com.apple.corefoundation.sb")
(corefoundation)

(allow file-read* file-write*)

(allow process-info* (target self))
(allow process-info-pidinfo) ;; to display client name in logs

;; For resolving symlinks, realpath(3), and equivalents.
(allow file-read-metadata)

;; For validating the entitlements of clients.
(allow process-info-codesignature)

;; Your preference domain
(allow user-preference-read user-preference-write
    (preference-domain "com.apple.biomestreamtool"))

;; .GlobalPreferences
(allow user-preference-read
       (preference-domain "kCFPreferencesAnyApplication"))

;; Read for NSBundle
(allow file-read*
    (literal "/usr/local/bin")
    (literal "/usr/local/bin/biomestreamtool"))

;; Read/write access to HOME and suffixed darwin directories
(allow file-read* file-write*
       (subpath (param "HOME"))
       (subpath (param "DARWIN_USER_DIR"))
       (subpath (param "DARWIN_USER_TMP_DIR"))
       (subpath (param "DARWIN_USER_CACHE_DIR")))

;; Issue extensions to HOME
(allow file-issue-extension
    (require-all
        (subpath (param "HOME"))
        (extension-class "com.apple.app-sandbox.read" "com.apple.app-sandbox.read-write")))

(allow mach-lookup
    ;; Service lookup
    (global-name "com.apple.lsd.mapdb")
    (global-name "com.apple.lsd.modifydb")
    (global-name "com.apple.metadata.mds")

    ;; Allow connections to biome services
    (global-name "com.apple.coreduetd")
    (global-name "com.apple.coreduetd.knowledge")
    (global-name "com.apple.coreduetd.people")
    (global-name "com.apple.biome.access.system")
    (global-name "com.apple.biome.access.user")
    (global-name "com.apple.biome.compute.source")
    (global-name "com.apple.biome.compute.source.user")
    (global-name "com.apple.biome.compute.publisher.service")
    (global-name "com.apple.biome.compute.publisher.service.user"))

(allow iokit-open
    (iokit-user-client-class "AppleKeyStoreUserClient"))
