Add LAN-only aria2 downloads to Atlas

This commit is contained in:
Fabio Scotto di Santolo
2026-10-10 16:00:44 +02:00
parent 5f3792d603
commit 5ebf1c1eb6
10 changed files with 410 additions and 7 deletions

View File

@@ -207,12 +207,19 @@ The dotfile vars follow the same split: `desktop_common_dotfiles` carries mode-i
- Atlas qBittorrent is selected by `atlas_manage_qbittorrent` and managed with the
`qbittorrent` tag as the admin-owned rootless `atlas-qbittorrent.service` Quadlet.
Its Web UI is `http://192.168.178.55:8090` on the LAN and prepared for the manual
NPM HTTPS domain `downloads.fscotto.co`, trusting only Aegis for forwarded client
NPM HTTPS domain `torrent.fscotto.co`, trusting only Aegis for forwarded client
addresses. DNS and NPM configuration stay manual. Configuration lives in
`services/data/qbittorrent`, and only `Archive/Downloads` is writable as payload
storage. It uses the home Internet connection, not WireGuard or a VPN; no router
forwarding or published torrent peer port is configured. See `docs/atlas-qbittorrent.md`.
- Atlas HTTP downloads use the admin-owned rootless `atlas-aria2.service` and
`atlas-ariang.service` Quadlets, gated by `atlas_manage_aria2` and the `aria2` tag.
AriaNg is LAN-only at `http://192.168.178.55:8091`; RPC is LAN-only on TCP/6800
and requires a private target-generated token. State lives in `services/data/aria2`,
with payloads in `Archive/Downloads`; do not expose RPC through the existing
qBittorrent `torrent.fscotto.co` endpoint. See `docs/atlas-aria2.md`.
## Atlas NAS TODO
Completed validation: the existing RAIDZ2 pool and datasets, SELinux, LAN firewall, SSH, Cockpit with
the selected 45Drives plugins, encrypted SMB3 `Archive`, the Aegis-only NFSv4 `photobook` export, and the

View File

@@ -262,4 +262,9 @@ host_enabled_services:
atlas_manage_qbittorrent: true
atlas_qbittorrent_image: docker.io/qbittorrentofficial/qbittorrent-nox@sha256:92bfd78d731e254ba64f62b77b0696add6447a33642ee5feda106a26b285aa7f
atlas_qbittorrent_reverse_proxy_enabled: true
atlas_qbittorrent_public_domain: downloads.fscotto.co
atlas_qbittorrent_public_domain: torrent.fscotto.co
# LAN-only HTTP downloader; RPC secret is generated and retained privately on Atlas.
atlas_manage_aria2: true
atlas_aria2_image: docker.io/p3terx/aria2-pro@sha256:086d1a37c586edb07ec0fb956bf9edd89d1d38d138ad5309ff96d510c8c9a011
atlas_ariang_image: docker.io/p3terx/ariang@sha256:73849cf75fe9f959229222622e887310df505cbf868eb9c735e2af376523c010

View File

@@ -314,3 +314,11 @@ atlas_qbittorrent_web_settings:
- {key: 'WebUI\CSRFProtection', value: "true"}
- {key: 'WebUI\LocalHostAuth', value: "true"}
- {key: 'WebUI\AuthSubnetWhitelistEnabled', value: "false"}
atlas_manage_aria2: false
atlas_aria2_state_dir: "{{ atlas_app_data_mountpoint }}/aria2"
atlas_aria2_downloads_dir: "{{ atlas_archive_mountpoint }}/Downloads"
atlas_aria2_rpc_port: 6800
atlas_ariang_web_port: 8091
atlas_aria2_image: CHANGEME_PINNED_ARIA2_IMAGE
atlas_ariang_image: CHANGEME_PINNED_ARIANG_IMAGE

View File

@@ -0,0 +1,205 @@
---
- name: Manage Atlas LAN HTTP downloader
tags: [atlas, aria2]
when: atlas_manage_aria2 | bool
block:
- name: Require isolated state, shared Downloads and pinned images
ansible.builtin.assert:
that:
- atlas_manage_storage | bool
- atlas_aria2_state_dir == atlas_app_data_mountpoint ~ '/aria2'
- atlas_aria2_downloads_dir == atlas_archive_mountpoint ~ '/Downloads'
- atlas_aria2_image is search('@sha256:[0-9a-f]{64}$')
- atlas_ariang_image is search('@sha256:[0-9a-f]{64}$')
- atlas_aria2_rpc_port != atlas_ariang_web_port
- name: Inspect the existing downloader parent datasets
community.general.zfs_facts:
name: "{{ item.dataset }}"
properties: name,mounted,mountpoint
loop:
- dataset: "{{ atlas_zfs_pool }}/{{ atlas_zfs_dataset_archive }}"
mountpoint: "{{ atlas_archive_mountpoint }}"
- dataset: "{{ atlas_zfs_pool }}/{{ atlas_zfs_dataset_app_data }}"
mountpoint: "{{ atlas_app_data_mountpoint }}"
register: atlas_aria2_parents
- name: Require mounted downloader parent datasets
ansible.builtin.assert:
that:
- item.ansible_facts.ansible_zfs_datasets | length == 1
- item.ansible_facts.ansible_zfs_datasets[0].mounted == 'yes'
- item.ansible_facts.ansible_zfs_datasets[0].mountpoint == item.item.mountpoint
loop: "{{ atlas_aria2_parents.results }}"
loop_control:
label: "{{ item.item.dataset }}"
- name: Inspect shared Downloads without following links
ansible.builtin.stat:
path: "{{ atlas_aria2_downloads_dir }}"
follow: false
register: atlas_aria2_downloads
- name: Refuse unrelated or symlinked Downloads
ansible.builtin.assert:
that:
- >-
not atlas_aria2_downloads.stat.exists or
(atlas_aria2_downloads.stat.isdir | default(false) and
atlas_aria2_downloads.stat.uid | int == atlas_admin_uid | int)
- name: Create the private aria2 dataset
community.general.zfs:
name: "{{ atlas_zfs_pool }}/services/data/aria2"
state: present
extra_zfs_properties:
compression: zstd
mountpoint: "{{ atlas_aria2_state_dir }}"
- name: Prepare state, downloads and Quadlet directories
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
owner: "{{ atlas_admin_username }}"
group: "{{ atlas_admin_group }}"
mode: "{{ item.mode }}"
loop:
- {path: "{{ atlas_aria2_state_dir }}", mode: "0700"}
- {path: "{{ atlas_aria2_downloads_dir }}", mode: "0770"}
- {path: "{{ atlas_admin_home }}/.config/containers/systemd", mode: "0700"}
- name: Generate a private persistent RPC secret on Atlas only
become_user: "{{ atlas_admin_username }}"
ansible.builtin.command:
argv:
- python3
- -c
- >-
import os, secrets;
fd = os.open('{{ atlas_aria2_state_dir }}/rpc-secret',
os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600);
os.write(fd, (secrets.token_hex(32) + '\n').encode()); os.close(fd)
creates: "{{ atlas_aria2_state_dir }}/rpc-secret"
no_log: true
- name: Read the existing private RPC secret without displaying it
ansible.builtin.slurp:
src: "{{ atlas_aria2_state_dir }}/rpc-secret"
register: atlas_aria2_rpc_secret
no_log: true
when: not ansible_check_mode
- name: Require a strong RPC secret
ansible.builtin.assert:
that:
- atlas_aria2_rpc_secret.content | b64decode | trim is match('^[a-f0-9]{64}$')
no_log: true
when: not ansible_check_mode
- name: Initialize the session file without replacing saved downloads
ansible.builtin.copy:
content: ""
dest: "{{ atlas_aria2_state_dir }}/session"
owner: "{{ atlas_admin_username }}"
group: "{{ atlas_admin_group }}"
mode: "0600"
force: false
diff: false
no_log: true
- name: Render private aria2 configuration
ansible.builtin.template:
src: atlas-aria2.conf.j2
dest: "{{ atlas_aria2_state_dir }}/aria2.conf"
owner: "{{ atlas_admin_username }}"
group: "{{ atlas_admin_group }}"
mode: "0600"
register: atlas_aria2_config
no_log: true
diff: false
when: not ansible_check_mode
- name: Allow only the LAN to reach AriaNg and the token-protected API
ansible.posix.firewalld:
zone: "{{ atlas_firewalld_zone }}"
rich_rule: >-
rule family="ipv4" source address="{{ atlas_lan_subnet }}"
port port="{{ item }}" protocol="tcp" accept
permanent: true
immediate: true
state: enabled
loop:
- "{{ atlas_aria2_rpc_port }}"
- "{{ atlas_ariang_web_port }}"
- name: Keep the downloader user manager available at boot
ansible.builtin.command: "loginctl enable-linger {{ atlas_admin_username }}"
args:
creates: "/var/lib/systemd/linger/{{ atlas_admin_username }}"
- name: Render the downloader and static Web UI Quadlets
ansible.builtin.template:
src: "atlas-{{ item }}.container.j2"
dest: "{{ atlas_admin_home }}/.config/containers/systemd/atlas-{{ item }}.container"
owner: "{{ atlas_admin_username }}"
group: "{{ atlas_admin_group }}"
mode: "0644"
loop: [aria2, ariang]
register: atlas_aria2_quadlets
- name: Reload the user manager after downloader Quadlet changes
become_user: "{{ atlas_admin_username }}"
ansible.builtin.systemd:
scope: user
daemon_reload: true
environment:
XDG_RUNTIME_DIR: "/run/user/{{ atlas_admin_uid }}"
DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/{{ atlas_admin_uid }}/bus"
when:
- atlas_aria2_quadlets.changed
- not ansible_check_mode
- name: Start or update only the changed downloader service
become_user: "{{ atlas_admin_username }}"
ansible.builtin.systemd:
scope: user
name: "atlas-{{ item.item }}.service"
state: >-
{{ 'restarted' if item.changed or
(item.item == 'aria2' and atlas_aria2_config.changed | default(false))
else 'started' }}
loop: "{{ atlas_aria2_quadlets.results }}"
loop_control:
label: "atlas-{{ item.item }}.service"
environment:
XDG_RUNTIME_DIR: "/run/user/{{ atlas_admin_uid }}"
DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/{{ atlas_admin_uid }}/bus"
when: not ansible_check_mode
- name: Verify the LAN Web UI responds
ansible.builtin.uri:
url: "http://{{ ansible_host }}:{{ atlas_ariang_web_port }}/"
status_code: 200
register: atlas_ariang_http
retries: 15
delay: 2
until: atlas_ariang_http is succeeded
when: not ansible_check_mode
- name: Verify the authenticated RPC API
ansible.builtin.uri:
url: "http://{{ ansible_host }}:{{ atlas_aria2_rpc_port }}/jsonrpc"
method: POST
body_format: json
body:
jsonrpc: "2.0"
id: ansible
method: aria2.getVersion
params: ["token:{{ atlas_aria2_rpc_secret.content | b64decode | trim }}"]
return_content: true
register: atlas_aria2_rpc_probe
retries: 15
delay: 2
until: (atlas_aria2_rpc_probe.content | default('{}') | from_json).result.version is defined
no_log: true
when: not ansible_check_mode

View File

@@ -29,6 +29,9 @@
- name: Import Atlas torrent service
ansible.builtin.import_tasks: qbittorrent.yml
- name: Import Atlas LAN HTTP downloader
ansible.builtin.import_tasks: aria2.yml
- name: Import Atlas ZFS maintenance tasks
ansible.builtin.import_tasks: zfs_maintenance.yml

View File

@@ -0,0 +1,30 @@
# Managed by Ansible. Never expose this file: it contains the RPC secret.
dir=/downloads
input-file=/config/session
save-session=/config/session
save-session-interval=30
auto-save-interval=30
continue=true
allow-overwrite=false
auto-file-renaming=false
max-concurrent-downloads=1
max-connection-per-server=1
split=1
max-tries=20
retry-wait=10
connect-timeout=30
timeout=60
check-certificate=true
file-allocation=none
umask=007
enable-rpc=true
rpc-listen-all=true
rpc-listen-port=6800
rpc-allow-origin-all=true
rpc-secret={{ atlas_aria2_rpc_secret.content | b64decode | trim }}
rpc-max-request-size=2M
enable-dht=false
enable-dht6=false
enable-peer-exchange=false
bt-enable-lpd=false
console-log-level=warn

View File

@@ -0,0 +1,30 @@
# Managed by Ansible. Bypass upstream init, tracker updates and deletion hooks.
[Unit]
Description=Atlas rootless HTTP downloader
RequiresMountsFor={{ atlas_aria2_state_dir }} {{ atlas_aria2_downloads_dir }}
[Container]
ContainerName=atlas-aria2
Image={{ atlas_aria2_image }}
UserNS=keep-id
User={{ atlas_admin_uid }}
Group={{ atlas_admin_gid }}
Entrypoint=/usr/local/bin/aria2c
Exec=--conf-path=/config/aria2.conf
PublishPort={{ ansible_host }}:{{ atlas_aria2_rpc_port }}:6800
Volume={{ atlas_aria2_state_dir }}:/config:Z
Volume={{ atlas_aria2_downloads_dir }}:/downloads:z
ReadOnly=true
Tmpfs=/tmp:rw,nosuid,nodev
NoNewPrivileges=true
DropCapability=all
StopTimeout=60
[Service]
Restart=on-failure
RestartSec=10
TimeoutStartSec=900
TimeoutStopSec=90
[Install]
WantedBy=default.target

View File

@@ -0,0 +1,22 @@
# Managed by Ansible. Static frontend only; no host data or RPC secret mounted.
[Unit]
Description=Atlas AriaNg LAN Web UI
[Container]
ContainerName=atlas-ariang
Image={{ atlas_ariang_image }}
UserNS=keep-id
User={{ atlas_admin_uid }}
Group={{ atlas_admin_gid }}
PublishPort={{ ansible_host }}:{{ atlas_ariang_web_port }}:6880
ReadOnly=true
NoNewPrivileges=true
DropCapability=all
[Service]
Restart=on-failure
RestartSec=10
TimeoutStartSec=900
[Install]
WantedBy=default.target

86
docs/atlas-aria2.md Normal file
View File

@@ -0,0 +1,86 @@
# Atlas HTTP downloader: aria2 + AriaNg
Ansible manages two admin-owned rootless Quadlets, `atlas-aria2.service` and
`atlas-ariang.service`, with pinned images. The third-party aria2 image is used
only for its binary: its init scripts, tracker updates and automatic deletion
hooks are bypassed. The static frontend has no host-data or credential mounts.
- Web UI (LAN only): `http://192.168.178.55:8091`.
- RPC (LAN only, mandatory secret): `http://192.168.178.55:6800/jsonrpc`.
- Payloads: `/zpool/archive/Downloads`, shared with qBittorrent and SMB Archive.
- Private state: `zpool/services/data/aria2`, mounted at `/zpool/services/data/aria2`.
- The persistent 256-bit RPC secret is generated only on Atlas; it is not committed
or printed by Ansible. It is not a username/password: AriaNg passes it as an
RPC token. Whoever has it can control the downloader.
- No DNS/NPM/public exposure or WireGuard changes are performed. Never publish
the bare RPC port on the Internet. LAN HTTP does not encrypt the token; use
only a trusted LAN or an SSH tunnel.
## Deploy
From the repository root:
```sh
ansible-playbook ansible/site.yml --limit atlas --tags aria2 --check
ansible-playbook ansible/site.yml --limit atlas --tags aria2
```
Check mode validates storage and Quadlet/firewall changes but skips generation,
reading and rendering of secret-dependent configuration and runtime probes.
Boot startup uses admin lingering plus `WantedBy=default.target`; a host reboot
must be tested separately.
## First use
Open the LAN Web UI. In **AriaNg Settings -> RPC**, use:
- Protocol: HTTP (JSON-RPC)
- Host/address: `192.168.178.55`
- Port: `6800`
- Interface/path: `jsonrpc`
- Secret: privately read it in your terminal with:
```sh
ssh admin@192.168.178.55 'cat /zpool/services/data/aria2/rpc-secret'
```
Do not paste it into chat or share exported AriaNg settings, which may include
it. After saving settings the status should be Connected. Select **New**, add
one or more actual file URLs and start the download. One download/connection at
a time is the default, to reduce load and avoid excessive requests to Apple.
The UI may store the secret in browser-local settings. There is no additional
login for the static page; the RPC token protects the actual service. Do not
publish this interface on the qBittorrent endpoint (`torrent.fscotto.co`).
## Interrupted downloads and iCloud
The queue is saved every 30 seconds and on graceful shutdown. Keep both partial
payloads and `.aria2` control files for resume. Restarting restores pending tasks.
Resume requires server support and a valid link. Expired Apple links must be
refreshed; some downloads also require authenticated cookies or headers. Never
share full signed URLs or cookie files. Apple exports have not been tested until
new links are available. TLS certificate verification remains enabled.
No completion/error deletion hooks are enabled. Cancelling a task does not
implicitly clean payloads. Downloads remain inside the existing Archive backup
scope, including incomplete files. Session files contain URLs and are kept
private; their dataset inherits existing recursive backup/snapshot coverage.
References:
- <https://github.com/aria2/aria2>
- <https://github.com/mayswind/AriaNg>
- <https://github.com/P3TERX/Aria2-Pro-Docker>
## Verified on 2026-10-10
The pinned aria2 binary reports 1.36.0. The Web UI and authenticated RPC are
operational; RPC requests without a token are rejected. A second targeted
Ansible application reported `changed=0`, `failed=0`.
A real HTTPS smoke test downloaded the official curl 8.10.1 source archive
(2,726,748 bytes). After pausing at 1,048,576 bytes and restarting only
`atlas-aria2.service`, the saved task and partial progress were restored. The
completed file matched an independently downloaded reference by SHA-256.
Only the exact smoke-test task and its temporary payload/control files were
removed. A host reboot and authenticated Apple export downloads are not claimed.

View File

@@ -7,7 +7,7 @@ WireGuard configuration is unchanged.
- LAN Web UI: `http://192.168.178.55:8090` (LAN-only firewalld rule,
already including Aegis at `192.168.178.54`).
- Prepared public domain: `downloads.fscotto.co`, through NPM on Prometheus.
- Prepared public domain: `torrent.fscotto.co`, through NPM on Prometheus.
DNS and the NPM Proxy Host remain manual operations.
- Downloads: `/zpool/archive/Downloads`, available through SMB `Archive`.
- Private configuration dataset: `zpool/services/data/qbittorrent`.
@@ -72,7 +72,7 @@ for its persistent UPnP/NAT-PMP option.
## Manual public endpoint setup
Atlas is prepared for `downloads.fscotto.co`, with reverse-proxy support enabled
Atlas is prepared for `torrent.fscotto.co`, with reverse-proxy support enabled
and only `192.168.178.54` (the Aegis source-NAT gateway) trusted for forwarded
client addresses. Existing LAN access remains available. No new firewall opening
is required because the existing `192.168.178.0/24` rule includes Aegis.
@@ -83,12 +83,12 @@ the reverse proxy or disable CSRF/Host validation.
Namecheap:
- Type: A Record; Host: `downloads`; Value: `179.237.102.172` (Prometheus).
- Type: A Record; Host: `torrent`; Value: `179.237.102.172` (Prometheus).
- Do not point this record to Atlas' private LAN address.
NPM on Prometheus:
- Domain Names: `downloads.fscotto.co`
- Domain Names: `torrent.fscotto.co`
- Scheme: `http`
- Forward Hostname/IP: `192.168.178.55`
- Forward Port: `8090`
@@ -105,9 +105,16 @@ complete. Preparing the Web proxy does not change torrent peer connectivity.
### Reverse-proxy preparation verified on 2026-10-10
Atlas accepts `downloads.fscotto.co` with HTTPS forwarded headers from the NPM
The previous live domain `downloads.fscotto.co` was verified with HTTPS forwarded headers from the NPM
container on Prometheus through Aegis (HTTP 200). Unauthenticated API access is
still denied (403), and an unrelated Host is rejected (401). No DNS record,
NPM Proxy Host, certificate, router forwarding or WireGuard configuration was
changed. The existing LAN firewall rule already permits Aegis. A permanent
Web UI password still needs to be configured before public exposure.
The domain change to `torrent.fscotto.co` was subsequently applied to Atlas with
the targeted `qbittorrent` playbook tag. The old live Host allowlist caused HTTP
401 (Unauthorized) on the new public domain. After deployment, public HTTPS
returned 200 and unauthenticated API access remained denied (403). Credentials,
Host validation and CSRF protection were preserved; all existing Atlas services
remained active. DNS and NPM were not modified by this deployment.