Let sandboxed agents use mktemp, and keep backups from waiting on prompts

macOS' mktemp uses the per-user temp folder in /var/folders, not TMPDIR,
so the sandbox now allows writing there. The sandbox's settings move out
of it, to Application Support, which the agent can't read or write.

Without Full Disk Access, reading Desktop, Documents, Downloads, other
apps' containers or Photos makes macOS ask, and restic waited for an
answer no one gives at night. The backup now leaves those out until it
has Full Disk Access, as configure backup already said it did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Young
2026-11-11 16:19:21 -07:00
co-authored by Claude Opus 5.5
parent eab26c0888
commit ad97e68db1
4 changed files with 36 additions and 9 deletions
+18 -7
View File
@@ -75,11 +75,17 @@ for file in "$USER_CONFIG/base.json" "$USER_CONFIG/$profile.json"; do
[ -f "$file" ] && configs+=("$file")
done
# Outside the folders the agent may change, so it can't change its own rules.
# Named after this process, as srt replaces it (exec below) and nothing is
# left to remove it afterwards; files whose process has ended are removed here.
SETTINGS_DIR="${TMPDIR:-/tmp}/federated-sandbox"
mkdir -m 700 "$SETTINGS_DIR" 2> /dev/null || [ -d "$SETTINGS_DIR" ] || exit 1
# Outside the folders the agent may change (or read), so it can't change its
# own rules; not in macOS' temp folder, which it may change (below). Named
# after this process, as srt replaces it (exec below) and nothing is left to
# remove it afterwards; files whose process has ended are removed here.
SETTINGS_DIR="$HOME/Library/Application Support/Federated Connector/sandbox-settings"
mkdir -p -m 700 "$SETTINGS_DIR" 2> /dev/null || [ -d "$SETTINGS_DIR" ] || exit 1
# macOS' mktemp, and other macOS tools, use your temp folder in /var/folders
# rather than TMPDIR (which srt points at one of its own), so the agent may
# change that folder too
USER_TEMP="$(getconf DARWIN_USER_TEMP_DIR 2> /dev/null)"
for old in "$SETTINGS_DIR"/*.json; do
pid="${old%.json}"
pid="${pid##*.}"
@@ -111,13 +117,18 @@ function run(argv) {
return a;
}
var out = argv[0], domains = argv[1].split(" ").filter(function (d) { return d; });
var config = argv.slice(2).reduce(function (c, path) { return merge(c, read(path)); }, {});
var userTemp = argv[2];
var config = argv.slice(3).reduce(function (c, path) { return merge(c, read(path)); }, {});
config.network = config.network || {};
merge(config.network, {allowedDomains: domains});
if (userTemp) {
config.filesystem = config.filesystem || {};
merge(config.filesystem, {allowWrite: [userTemp.replace(/\/$/, "")]});
}
if (!$(JSON.stringify(config, null, 2)).writeToFileAtomicallyEncodingError(out, true, $.NSUTF8StringEncoding, null)) {
throw new Error("could not write " + out);
}
}' "$settings" "$FEDERATED_SANDBOX_DOMAINS" "${configs[@]}" > /dev/null; then
}' "$settings" "$FEDERATED_SANDBOX_DOMAINS" "$USER_TEMP" "${configs[@]}" > /dev/null; then
echo "Couldn't read the sandbox config: ${configs[*]}"
exit 1
fi
+1 -1
View File
@@ -65,7 +65,7 @@ Each scenario runs on a fresh clone of Cirrus Labs' **vanilla** macOS image (def
macOS deliberately allows these only with a click, so test them by hand on a VM (`--keep`) or a Mac. Each scenario notes which apply to it as a `skip` line.
- **Installing the profile:** in System Settings > Profiles, choose "Federated Core (...)", then Install. Then check Mail, Calendar and Contacts against a real Core. `configure core` notices the profile was installed.
- **Full Disk Access for Federated Backup:** after granting it, `configure backup` says it can read all your files, and the backup log no longer has permission errors for Documents and Desktop.
- **Full Disk Access for Federated Backup:** after granting it, `configure backup` says it can read all your files, and the next backup includes Desktop, Documents and Downloads, which it leaves out without Full Disk Access (as macOS would otherwise stop it with a prompt).
- **Turning on macFUSE's file system extension**, if `85-sftp` couldn't do it with `pluginkit`: then mount an SFTP folder with `configure storage`. With the extension off, `85-sftp` checks that `add_sftp` gives up after 30 seconds rather than hanging.
- **Mounting a real SMB share:** the sign-in window, "Remember this password in my keychain", and whether `mount volume "smb://host"` without a share offers a list of shares.
- **Tailscale's VPN approval**, and **Nextcloud's sign-in** in the browser.
+2 -1
View File
@@ -4,7 +4,8 @@ TIER=quick
source "$CONNECTOR/configure.d/20-backup.sh"
DAV="$HOME/davroot"
SMOKE_FILE="$HOME/Documents/smoke-file.txt"
# Outside Documents, which a backup without Full Disk Access leaves out
SMOKE_FILE="$HOME/Projects/smoke-file.txt"
ran() {
grep -qE 'Backup (finished|failed)' "$BACKUP_LOG" 2> /dev/null
+15
View File
@@ -142,6 +142,21 @@ excludes=(
# Element's search index for encrypted messages, which it rebuilds
"$L/Application Support/Element/EventStore"
)
# Without Full Disk Access, reading these makes macOS ask you, and restic
# waits for the answer, which no one gives at night; the rest that Full Disk
# Access guards (Mail, Messages, Safari...) is just refused
if ! full_disk_access; then
excludes+=(
"$HOME/Desktop"
"$HOME/Documents"
"$HOME/Downloads"
"$L/Containers"
"$L/Group Containers"
# Photos asks too
"$L/Photos"
"$HOME/Pictures/*.photoslibrary"
)
fi
exclude_args=(--exclude-caches)
for path in "${excludes[@]}"; do
exclude_args+=(--exclude "$path")