-
Notifications
You must be signed in to change notification settings - Fork 44
Feature: permit running anything-sync-daemon as an unprivileged user #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tomeon
wants to merge
124
commits into
graysky2:master
Choose a base branch
from
tomeon:unprivileged-operation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
124 commits
Select commit
Hold shift + click to select a range
14fb655
feat: add Nix integration
tomeon 18df262
feat(nix): add Nix derivation
tomeon 9003067
feat(nix): add `services.asd` NixOS module
tomeon b54532d
feat(nix): add NixOS test
tomeon 90be242
fix: use portable shebang
tomeon 59bc5e7
feat: add fancy PS4
tomeon c8f49b7
refactor: add truthiness-testing function
tomeon 5bc4b27
feat: add logging functions
tomeon 38b4d0c
fix: don't recheck `DEBUG` upon each `debug` call
tomeon dbab74f
feat: add (?:un)?mounting helper script
tomeon c1ed2de
feat: enable "strict mode"
tomeon 0237e52
chore: issue message upon ERR but do not bail out
tomeon b67c2df
chore: consolidate dependency checks
tomeon 3addfde
feat: improve (f)locking logic
tomeon f17efca
feat: remove asd.conf syntax check
tomeon 4f0ae1e
chore: s/\./source/
tomeon f0ed7dc
feat: make shellcheck find asd.conf next to asd
tomeon 943dd86
chore: simplify variable assignments
tomeon fd78ba2
chore: remove unneeded `""` in `debug ""`
tomeon 20b2b2d
chore: s/true/:/
tomeon a9d2428
fix: handle unset WHATTOSYNC array
tomeon b0dcca4
fix: suppress errors re-enforcing extglob setting
tomeon 42c5010
fix: handle unset `VOLATILE` variable
tomeon 09dc29d
chore: put "VOLATILE is tmpfs/zram" check in func
tomeon 88d5b30
chore: simplify "can I use OverlayFS?" check
tomeon 086ed9a
feat: more portable "using systemd?" check
tomeon 57effb9
chore: simplify distro check and header definition
tomeon 4155fbf
feat: add function for running cmds verbosely
tomeon 7b19f26
feat: add a for-each-WHATTOSYNC-dir function
tomeon 45c5437
feat: add "running as root?" function
tomeon 122c522
feat: add "do I need/have sudo?" functions
tomeon 8660e02
feat: permit running asd as non-root user
tomeon 42f0666
feat: respect the `NO_COLOR` env var
tomeon c911632
chore: miscellaneous linting and formatting
tomeon 3961066
fix(init/asd.service): persist RuntimeDirectory
tomeon 007908c
feat: user-settable `ASD{CONF,RUN}DIR` env vars
tomeon f765c21
fix: restore `ASDCONF` and `VOLATILE` defaults
tomeon 2f131a4
fix(nixos): set `ASDNOV1PATHS=yes`
tomeon 30f3947
fix: stop asd.conf from redefining important vars
tomeon f3a2d75
chore: ignore `.nixos-test-history`
tomeon 1c82868
docs(asd.conf): note that file is a Bash script
tomeon 04ab680
feat(nix): add user unit NixOS test cases
tomeon d619142
feat(ci): add NixOS systems tests workflow
tomeon af22224
feat: enforce timeout sourcing `asd.conf`
tomeon 51b66ca
chore(asd): s/Overlayfs/OverlayFS/g
tomeon 06911aa
docs: add USAGE.md
tomeon 5a89795
docs(USAGE): rework structure and add links
tomeon 033fffb
docs(README): rework structure and add links
tomeon 2984800
feat: build asd manpage from USAGE.md with pandoc
tomeon 83e5952
chore: regenerate manpage
tomeon fd2318d
fix: check mountpoints in ungraceful state check
tomeon dee6e6b
chore(asd): move negation outside `[[ ... ]]`
tomeon 19b1835
feat(checks): add ungraceful state subtests
tomeon 34c9465
feat(nix): rework test node into example profile
tomeon 7d11ff5
feat: add `nixos-shell` for running a dev VM
tomeon 073e68e
refactor(asd): add `main` function
tomeon dcf85cb
fix(nix): rework crash-recovery subtest
tomeon c33d8e0
refactor: move setup steps into functions
tomeon f884ac2
feat: obtain lock in-process
tomeon 76c2ad7
fix: check that `WHATTOSYNC` is declared
tomeon a97d365
feat: support sourcing `anything-sync-daemon`
tomeon 6468ca4
chore: use printf builtin for crash file dates
tomeon b4cf6e4
chore(ci): remove `shellcheck` workflow
tomeon 582e0f2
refactor: add `run_systemd` function
tomeon 30e4b3e
feat: detect systemd units besides `asd.service`
tomeon c79bac4
feat: display systemd unit name
tomeon a80aed3
refactor: use internal-only settings
tomeon f89d6be
fix: respect `DEBUG` definition from `asd.conf`
tomeon b49fc81
refactor: add `for_each_dir_with_crasharr` func
tomeon bf53f5d
docs: add BleachBit link
tomeon 82f543f
docs: describe `DEBUG` variable
tomeon da37d29
docs: describe significant environment variables
tomeon 60ceeb7
feat(devshell): add gnumake and gzip
tomeon 9403fe1
chore: regenerate man page
tomeon 49fc256
chore: git-ignore generated script
tomeon ab2e225
feat(Makefile): install systemd user unit files
tomeon ec5d321
fix(Makefile): install conf directory
tomeon 3041783
fix(Makefile): overwrite compressed manpage
tomeon 5fdb3e6
docs(INSTALL): flesh out prereqs list
tomeon 5eecdf5
fix(INSTALL): correct typos and out-of-date info
tomeon 628cf42
fix(nix): describe `configFile` option
tomeon 1a451d1
feat(nix): add `docs` package
tomeon f7c93c2
feat(nix): add devshell command to generate docs
tomeon 543b68e
docs: add NixOS module docs
tomeon e87c40a
feat(nix): add "docs up-to-date?" check
tomeon afdb722
docs(INSTALL): describe Nix package, NixOS module
tomeon 51eef7e
feat(ci): parallelize jobs
tomeon 56ed032
feat(devshell): install act
tomeon f460885
fix(ci): empty Nix `build-users-group`
tomeon 1b34fb6
fix(ci): use local flake.nix for building nix conf
tomeon a282b65
fix(ci): don't cache Nix store in local runs
tomeon f4dffa8
feat(ci): build NixOS test driver for debugging
tomeon ef774eb
fix(nix): don't wait for `multi-user.target`
tomeon bb1cd6b
feat: generic path-cleaning implementation
tomeon 0951084
feat: support shell expansions in whatToSync opt
tomeon 424b786
feat: deduplicate sync targets
tomeon c7fee38
feat: add debugging output re mount state
tomeon 112a52c
feat: issue warnings upon unexpected mounts
tomeon c5bee08
feat: add yellow color
tomeon 2551b58
fix: explicitly pass `--list` to `findmnt`
tomeon baef54f
fix: find only *first* matching mount
tomeon 95e9685
fix: reliably identify canonical bind mount source
tomeon 8c419c9
chore: move `verbosely` to `run_mount_helper`
tomeon 6f7e783
chore: shell-quote commands in `verbosely`
tomeon 7123dfb
chore: use `verbosely` instead of `set -x`
tomeon cc1daf6
fix: remove symlink-listing tempfile on error
tomeon af9f946
feat: use NUL separator between symlink names
tomeon e530936
fix(checks): block until flag file exists
tomeon 92c799a
chore(ci): split checks into "system" and "user"
tomeon 4d6b86b
fix(asd.service): comment out `RuntimeDirectory`
tomeon ef4e525
feat: add Vagrant configuration
tomeon 8d4a7df
fix: handle > 1 {CONFIGURATION,RUNTIME}_DIRECTORY
tomeon 6086c7d
docs: add changelog
tomeon ceb7e8f
feat: warn about the use of V1 paths
tomeon 565b3a3
docs: further usage updates and clarifications
tomeon 3551f5a
chore(gitignore): ignore Vagrant state
tomeon 14aa871
doc(treewide): s/symlink/bind-mount/
tomeon ef319c6
refactor: lib for generators, options, and modules
tomeon 030a0ae
feat(nix): add Home Manager module
tomeon c003cf9
WIP on Nix installation instructions
tomeon 4b977c9
docs: add myself as a contributor
tomeon b9664be
fix(nix): add more `asd` prereq packages
tomeon de1e3a0
docs: document home-manager module
tomeon f0435de
chore: add `_file` annotations to modules
tomeon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: NixOS flake checks | ||
|
|
||
| on: | ||
| push: | ||
| pull_request: | ||
|
|
||
| jobs: | ||
| nix: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| system: | ||
| - x86_64-linux | ||
| check: | ||
| - treefmt | ||
| - docs | ||
| - anything-sync-daemon-system | ||
| - anything-sync-daemon-user | ||
| - anything-sync-daemon-home-manager | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Install Nix | ||
| uses: nixbuild/nix-quick-install-action@v25 | ||
| with: | ||
| # Empty `build-users-group` definition required in order to test this | ||
| # under `act`, at least when using "medium size" images. | ||
| nix_conf: | | ||
| system-features = benchmark big-parallel kvm nixos-test | ||
| keep-derivations = true | ||
| keep-outputs = true | ||
| build-users-group = | ||
| env: | ||
| # Don't bother using `gh` to fetch `flake.nix`, as it's (a) | ||
| # unnecessary and (b) problematic when running under `act` (`gh` | ||
| # bails out, saying that login is required). | ||
| # https://github.com/nixbuild/nix-quick-install-action/blob/d96491740839e162d9448daa5446f14dd88a52b2/read-nix-config-from-flake.sh#L17-L29 | ||
| flake_file: "${{ github.workspace }}/flake.nix" | ||
| - name: Restore and cache Nix store | ||
| # Don't restore/cache when running locally. | ||
| # https://github.com/nektos/act#skipping-steps | ||
| if: "${{ !env.ACT }}" | ||
| uses: nix-community/cache-nix-action@v4 | ||
| with: | ||
| key: "cache-${{ matrix.system }}-${{ hashFiles('**/*.nix', 'flake.lock') }}" | ||
| restore-keys: | | ||
| cache-${{ matrix.system }}- | ||
| purge-caches: true | ||
| purge-created: true | ||
| purge-key: "cache-${{ matrix.system }}-" | ||
| # Build the test driver for debugging purposes. To run the driver, enter | ||
| # the `act` container (`docker exec act-<...> bash`) and execute | ||
| # `./driver/bin/nixos-test-driver -I`. | ||
| - name: Build NixOS test driver | ||
| # Only build when running locally. | ||
| # https://github.com/nektos/act#skipping-steps | ||
| if: "${{ env.ACT }}" | ||
| # Not all checks have a `driver` attribute; ignore errors. | ||
| run: "nix build -o driver -L '.#checks.${{ matrix.system }}.${{ matrix.check }}.driver' 2>/dev/null || :" | ||
| - name: Run flake check | ||
| run: "nix build -L '.#checks.${{ matrix.system }}.${{ matrix.check }}'" |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Script rendered from `common/anything-sync-daemon.in` | ||
| common/anything-sync-daemon | ||
|
|
||
| # `nix build` and friends' output links | ||
| result | ||
| result-* | ||
| repl-result-* | ||
|
|
||
| # From using `nixos-test-driver` | ||
| .nixos-test-history | ||
|
|
||
| # Disk images from using `nixos-shell` | ||
| *.qcow2 | ||
|
|
||
| # Vagrant state | ||
| /.vagrant/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # Changelog for `anything-sync-daemon` | ||
|
|
||
| All notable changes to this project will be documented in this file. | ||
|
|
||
| ## [Unreleased] | ||
|
|
||
| ### Added | ||
|
|
||
| - Support running as an unprivileged user. | ||
| - Document usage in [a Markdown file](/USAGE.md) readable in GitHub's web UI. | ||
| - Document significant environment variables in the manual page. | ||
| - Add [a Nix derivation](/nix/packages.nix) for `anything-sync-daemon`. | ||
| - Add [NixOS modules](/nix/nixos-modules.nix) for managing | ||
| `anything-sync-daemon`. | ||
| - Support OverlayFS when running as an unprivileged user by managing mounts | ||
| through the new [`asd-mount-helper`](/common/asd-mount-helper) script. | ||
| For this to work, the user in question must be able to run `asd-mount-helper` | ||
| as root via `sudo` without entering a password. | ||
| - Install the example systemd unit files to the `/user/` unit file hierarchy | ||
| when executing the `install-systemd` Make target. | ||
|
|
||
| ### Fixed | ||
|
|
||
| - Only unmount bind mounts if they have the expected source, and only unmount | ||
| volatile paths if they are OverlayFS mountpoints. | ||
| - Ensure that `asd.conf`'s parent directory exists before attempt to copy | ||
| `asd.conf` into it. | ||
| - Deduplicate sync targets (entries in the `WHATTOSYNC` array). This means | ||
| testing for string equality on said targets' canonicalized representations, | ||
| as determined by `realpath -m` or `readlink -m`, if those commands are | ||
| available and respect the `-m` ("canonicalize missing") option, or otherwise | ||
| by a native shell routine that simply removes trailing slashes. | ||
| `anything-sync-daemon` issues a non-fatal warning if it detects duplicate | ||
| sync targets. | ||
| - Ensure that all intended mount points are mounted as expected when performing | ||
| the "ungraceful state" check. This means checking that bind mounts exist and | ||
| have the expected source (e.g. `/foo/bar/.baz-backup_asd-old` has the source | ||
| `/foo/bar/baz`) and that (when `USE_OVERLAYFS` is in effect) overlay mount | ||
| targets have the same mount options as their mount sources. This makes it | ||
| possible for `asd` to recover from partial mount states -- that is, to | ||
| sensibly re-mount intended mount points before performing re-synchronization. | ||
| - In the "ungraceful state" check, only unmount intended mountpoints if they | ||
| are mounted as expected (in the manner described immediately above). This | ||
| means that `asd` is no longer liable to unmount other filesystems that may | ||
| happen to be mounted in the relevant locations. | ||
| - Install the `asd.conf` parent directory before attempting to copy `asd.conf` | ||
| into place. | ||
|
|
||
| ### Changed | ||
|
|
||
| - **BREAKING CHANGE**: Load `asd.conf` in a subprocess. This is a breaking | ||
| change for configurations that attempt to inspect or modify the | ||
| `anything-sync-daemon` script's internal state. | ||
| - **BREAKING CHANGE**: Enforce a timeout of configurable | ||
| duration on loading `asd.conf` operation. This is a breaking change for | ||
| configurations that do not load within said timeout, though this can be | ||
| addressed by specifying a longer timeout in the `ASDCONFTIMEOUT` environment | ||
| variable. | ||
| - **BREAKING CHANGE**: Use the portable shebang `#!/usr/bin/env bash` rather | ||
| than using `#!/bin/bash`. This is a breaking change for any setups that (a) | ||
| have a `bash` under an entry in `PATH` that takes precedence over | ||
| `/bin/bash`, and (b) are compatible with `/bin/bash` but not the | ||
| higher-precedence `bash`. It is also incompatible with setups that lack | ||
| `/bin` in `PATH`. | ||
| - Respect [the `NO_COLOR` environment variable](https://no-color.org); that is, | ||
| do not colorize output if `NO_COLOR` is set to a non-empty value. | ||
| - **BREAKING CHANGE**: Attempt to obtain an exclusive lock in-process (via | ||
| `flock -n <file-descriptor>`) rather than by re-executing when the `FLOCKER` | ||
| environment variable is unset or empty. This breaks setups that bypass | ||
| locking by setting `FLOCKER` to a non-empty value. | ||
| - **BREAKING CHANGE**: detect the presence of `asd.service` by running | ||
| `systemd list-unit-files asd.service`, in addition to checking for the unit | ||
| file at `/usr/lib/systemd/system/asd.service` (or, if running `asd` as a | ||
| non-root user, `/usr/lib/systemd/user/asd.service`). This makes `asd` liable | ||
| to conclude that it is being run under systemd when previously it would have | ||
| concluded otherwise. | ||
| - **BREAKING CHANGE**: detect the `INVOCATION_ID` environment variable and, if | ||
| it is present, determine the name of the corresponding systemd service, if | ||
| one exists. If a service is detected, assume that `asd` is running under | ||
| systemd. As with the item just above, this makes `asd` liable to conclude | ||
| that it is being run under systemd when previously it would have concluded | ||
| otherwise. | ||
|
|
||
| ### Removed | ||
|
|
||
| - Removed the `asd.conf` "syntax check". Now, `anything-sync-daemon` accepts | ||
| any valid Bash code in `asd.conf`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,22 @@ | ||
| # Anything-sync-daemon | ||
| Anything-sync-daemon (asd) is a tiny pseudo-daemon designed to manage user defined dirs in tmpfs and to periodically sync back to the physical disc (HDD/SSD). This is accomplished via a symlinking step and an innovative use of rsync to maintain back-up and synchronization between the two. One of the major design goals of asd is a completely transparent user experience. | ||
|
|
||
| Anything-sync-daemon (asd) is a tiny pseudo-daemon designed to manage user | ||
| defined dirs in tmpfs and to periodically sync back to the physical disc | ||
| (HDD/SSD). This is accomplished via a bind-mounting step and an innovative use | ||
| of rsync to maintain back-up and synchronization between the two. One of the | ||
| major design goals of asd is a completely transparent user experience. | ||
|
|
||
| ## Documentation | ||
| Consult the man page or the wiki page: https://wiki.archlinux.org/index.php/Anything-sync-daemon | ||
|
|
||
| Consult the `asd(1)` man page (available [here](/USAGE.md)) or | ||
| [the Arch Linux `asd` wiki page](https://wiki.archlinux.org/index.php/Anything-sync-daemon). | ||
tomeon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Installation from Source | ||
| To build from source, see the included INSTALL text document. | ||
|
|
||
| To build from source, see [the included INSTALL](/INSTALL) text document. | ||
|
|
||
| ## Installation from Distro Packages | ||
| * Arch: in the [AUR](https://aur.archlinux.org/packages/anything-sync-daemon). | ||
|
|
||
| - Arch: in the [AUR](https://aur.archlinux.org/packages/anything-sync-daemon). | ||
|
|
||
| ## Installation with the [Nix package manager](https://nixos.org) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.