-
-
Notifications
You must be signed in to change notification settings - Fork 2
Design for installation & update process
Marek Rogalski edited this page Jun 27, 2023
·
12 revisions
- install with a single shell command
- install by downloading & running a single binary file
- entire config stored in a single file, easy to export from web UI
- APT-resistant update mechanism
- automatic updates by default
- opt-out of automatic updates (needs auth)
- install directory is always /opt/gatekeeper/
- OS services are always managed through systemd
Single command version:
curl https://github.com/mafik/gatekeeper/releases/gatekeeper-latest -o gatekeeper && chmod +x gatekeeper && sudo ./gatekeeper
- (if not root) Gain root privileges (execve sudo argv[0])
- (if not installed and
PORTABLE
not in env) Install- explain the process on STDOUT
- show 10-second countdown
- unpack embedded files to /opt/gatekeeper/
- link the systemd service
- start the service
- execve journalctl -fu gatekeeper
- Otherwise (root &
PORTABLE
or running from /opt/gatekeeper/) - proceed to Startup
- Show greeting on STDOUT
- Update /opt/gatekeeper/ based on embedded files
- Check each network interface and classify into (WAN, LAN, IGNORE)
- also find a free private IP subnet (preferably 10.0.0.1/16)
- (if not configured) Configure the WAN interface with DHCP
- (if not configured) Configure the LAN interface with 10.0.0.1/16
- Start DNS, DHCP & HTTP servers
- Notify systemd about completed startup, respond to watchdog pings
- Pick a random time uniformly between 0 and 24h, after specified time, and then after every 24h, perform Update
- Gatekeeper receives an update package (through regular polling or push message)
- HTTPS polling
- no-go due to reliance on additional actors that might exploit the network
- TCP Polling
- Periodically connect to a central server (TCP port 1338)
- Encrypt connection (hardcoded ECC key, then switch to AES-256)
- Client advertises its version
- Server may provide update package in the response
- [+] gradual rollouts with stability monitoring on the central server
- [-] centralized (single point of failure, ongoing maintenance costs) (at 1e6 clients, ~12 connections / second)
- Push message
- Gatekeeper instances form an overlay network
- All connections encrypted (DH + AES-256)
- Peers advertise their versions
- When a peer has a more recent version and more than 24 hours of uptime (maybe less for urgent updates), it pushes its update to other peers
- [+] distributed, arbitrary number of peers
- [-] self-supervised rollout (no monitoring, potential catastrophic failure on bad update)
- note: interesting library for overlay networks https://github.com/hmatuschek/libovlnet/tree/master/src
- HTTPS polling
- Update is verified against hardcoded ECC key
- Server replaces its own binary with the updated one and requests systemd restart
All configuration is done through environment variables. Default (read-only) values are stored at /opt/gatekeeper/gatekeeper.service
but may be overridden using systemctl edit
.
Gatekeeper persists its own configuration by altering /etc/systemd/system/gatekeeper.service.d/override.conf
(the same as systemctl edit
).
- Installation
- (optional) Function that restarts the current process as root (
execve sudo argv[0]
, also graphically - with something likegksu
) - Installation check (not running under
systemd
and noPORTABLE
in env) - Installation explainer & countdown
- Embed necessary files in the binary
- Extract embedded files during installation
-
systemctl enable --now /opt/gatekeeper/gatekeeper.service
during installation -
execve journalctl -fu gatekeeper
after installation completes
- (optional) Function that restarts the current process as root (
- Startup
- Classify network interfaces into LAN / WAN / IGNORE
- Find a free private IP subnet
- (if not configured) Configure WAN interface with DHCP
- (if not configured) Configure LAN interface
- Assign IP & network mask
- Bring interface up
- Enable IP forwarding
- Enable NAT masquerade
- Start DHCP, DNS & HTTP servers
- Notify systemd about completed startup
- Respond to watchdog pings
- (Proper, mesh-based) Update
- Functions for ECC crypto
- Functions for AES crypto
- Functions for signing ELF files with ECC keys & verifying signatures
- Functions for secure communication
- Update server & code for the client
- Schedule & periodically run updates
- Replace own binary & restart after update
- (Hacky, HTTP-based) Update
- Functions for ECC crypto
- Functions for signing ELF files with ECC keys & verifying signatures
- Well-known URL for distributing updates
- Schedule & periodically run updates
- Replace own binary & restart after update