# NetBox Plugin Store A self-hosted catalogue and installer for NetBox plugins. It syncs plugin repositories, lets an administrator review and approve releases, and installs approved releases on a NetBox host through a separate privileged agent. | | | |---|---| | **Type** | PHP web application, NetBox plugin and Linux host agent | | **NetBox** | `4.6.5` – `4.6.8` (plugin) | | **PHP** | `>=8.3` (store) | | **Repository** | | ## Components | Path | Purpose | | --- | --- | | `store/` | Standalone PHP store served directly by Apache. Syncs Forgejo/GitHub repositories, renders README files and provides the curated API catalogue. | | `netbox_plugin/` | NetBox UI for the catalogue, installation and plugin life cycle. Supports NetBox 4.6.5 to 4.6.8. | | `host_agent/` | Small privileged Linux component that verifies approved artefacts, builds source archives into wheels locally and applies the changes on the NetBox host. | For NetBox hosts there is also [`install.sh`](install.sh). This interactive installer sets up the plugin, host agent, systemd socket, requirements and the managed block in `configuration.py` in one run. It starts in dry-run mode by default, makes backups before any change and requires an additional explicit confirmation for real life-cycle changes. The store uses a local JSON file by default; MariaDB is optional. The configured default source is considered approved by the operator; further sources are added as pending in the admin area. Automatically discovered plugins and releases only appear in the public catalogue after explicit approval. ## Features - Sync of Forgejo/Gitea and GitHub repositories, including private GitHub metadata with a token - Plugin detail pages rendered from the README of a pinned commit - Separate review and approval of sources, plugins and releases - Public, approved-only catalogue API - Source candidates for projects without a wheel release, pinned to the exact commit - NetBox plugin for browsing, installing and managing plugins - Privileged host agent that re-checks approval, size and SHA-256 before every change ## Installation of the store (Apache and JSON) Docker is not required. The primary deployment is a regular PHP application under Apache. Requirements: - PHP 8.3 or newer with CLI and Apache module/FPM (tested with PHP 8.4); - PHP extensions cURL, DOM/XML, intl, JSON, mbstring and PDO; `pdo_mysql` additionally for MariaDB; - Composer 2; - Apache 2.4 with `mod_rewrite`; `mod_headers` is recommended for the extra headers from `.htaccess`. On Debian/Ubuntu the main packages are, for example: ```text sudo apt install apache2 composer libapache2-mod-php8.3 php8.3-cli \ php8.3-curl php8.3-intl php8.3-mbstring php8.3-mysql php8.3-xml sudo a2enmod rewrite headers expires ``` Package names differ on other distributions. With PHP-FPM, configure Apache with the matching FPM handler instead. ### Application and configuration This example uses `/var/www/netbox-plugin-store` as the repository path. Only `store/public` may be published by Apache. Check out the repository as a regular deployment user first, then move it into place: ```text git clone https://git.mrblake.cc/MrBlake/Netbox-Store.git netbox-plugin-store sudo mv netbox-plugin-store /var/www/netbox-plugin-store sudo chown -R "$(id -un):$(id -gn)" /var/www/netbox-plugin-store cd /var/www/netbox-plugin-store/store composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader cp .env.example .env ``` Generate an admin password hash and an independent session secret: ```text php bin/console hash-password 'A-LONG-RANDOM-PASSWORD' php -r 'echo bin2hex(random_bytes(32)), PHP_EOL;' ``` In practice, pass the plain-text password from a temporary, unlogged shell variable. Replace at least the following values in `store/.env`. The Argon2id hash is in single quotes so its `$` characters stay intact: ```dotenv APP_ENV=production STORE_PUBLIC_URL=https://plugins.example.com STORE_COOKIE_SECURE=true STORE_ADMIN_USERNAME=my-admin STORE_ADMIN_PASSWORD_HASH='$argon2id$...' STORE_SESSION_SECRET=... STORE_DB_DRIVER=json STORE_JSON_PATH=/var/www/netbox-plugin-store/store/data/store.json ``` On a plain-HTTP test system, the URL and `STORE_COOKIE_SECURE=false` must match. A publicly reachable production instance should terminate TLS directly in Apache. The application code stays root-owned; only `.env` is readable by the Apache group and only `store/data` is writable by the web/scheduler user: ```text sudo chown -R root:root /var/www/netbox-plugin-store sudo chown root:www-data /var/www/netbox-plugin-store/store/.env sudo chmod 0640 /var/www/netbox-plugin-store/store/.env sudo install -d -o www-data -g www-data -m 0750 \ /var/www/netbox-plugin-store/store/data sudo chown -R www-data:www-data /var/www/netbox-plugin-store/store/data ``` ### Apache virtual host The virtual host points directly to `store/public`. `AllowOverride All` is required so the bundled `.htaccess` can enable the front-controller rewrite: ```apache ServerName plugins.example.com DocumentRoot /var/www/netbox-plugin-store/store/public Options -Indexes AllowOverride All Require all granted ErrorLog ${APACHE_LOG_DIR}/netbox-plugin-store-error.log CustomLog ${APACHE_LOG_DIR}/netbox-plugin-store-access.log combined ``` Save it, for example, as `/etc/apache2/sites-available/netbox-plugin-store.conf` and enable it: ```text sudo a2ensite netbox-plugin-store.conf sudo apache2ctl configtest sudo systemctl reload apache2 ``` For production, use the same document root in a TLS virtual host. Neither the repository root nor `store/` itself may serve as document root, since they hold configuration and runtime data. ### Initialisation and first import CLI and Apache must manage the JSON state with the same UID, so bootstrap and sync run as the Apache user: ```text cd /var/www/netbox-plugin-store/store sudo -u www-data php bin/console bootstrap sudo -u www-data php bin/console sync ``` The website and `/healthz` are then reachable. The admin login is at `/admin`. Imported candidates stay hidden from the public API catalogue until they are reviewed and approved manually. ### Regular synchronisation The preferred way is watch mode as a separate systemd service. Example `/etc/systemd/system/netbox-plugin-store-sync.service`: ```ini [Unit] Description=NetBox Plugin Store repository sync After=network-online.target apache2.service Wants=network-online.target [Service] Type=simple User=www-data Group=www-data WorkingDirectory=/var/www/netbox-plugin-store/store ExecStart=/usr/bin/php /var/www/netbox-plugin-store/store/bin/console sync --watch --interval=900 Restart=on-failure RestartSec=10 UMask=0077 NoNewPrivileges=true PrivateTmp=true ProtectHome=true ProtectSystem=strict ReadWritePaths=/var/www/netbox-plugin-store/store/data [Install] WantedBy=multi-user.target ``` ```text sudo systemctl daemon-reload sudo systemctl enable --now netbox-plugin-store-sync.service sudo systemctl status netbox-plugin-store-sync.service ``` Alternatively, `www-data` can run the one-off command from cron. Open `sudo crontab -u www-data -e` and add the following line; `flock` prevents overlapping runs: ```cron */15 * * * * /usr/bin/flock -n /var/www/netbox-plugin-store/store/data/sync-cron.lock /bin/sh -c 'cd /var/www/netbox-plugin-store/store && /usr/bin/php bin/console sync' 2>&1 | /usr/bin/logger -t netbox-plugin-store-sync ``` The store itself also rejects any concurrent sync run. By default, each run is limited to 900 seconds, 2,500 HTTP requests, 1 GiB of downloads, 2,000 repositories and 1,000 releases in total. Adjust these with `STORE_SYNC_MAX_SECONDS`, `STORE_SYNC_MAX_REQUESTS`, `STORE_SYNC_MAX_BYTES`, `STORE_SYNC_MAX_REPOSITORIES` and `STORE_SYNC_MAX_RELEASES` in `store/.env`. ### MariaDB option JSON and MariaDB are alternative state stores. Switching the driver does not migrate existing approvals automatically. After creating a dedicated database and a restricted database user, set these values in `store/.env`: ```dotenv STORE_DB_DRIVER=mariadb STORE_MARIADB_DSN=mysql:host=127.0.0.1;port=3306;dbname=netbox_store;charset=utf8mb4 STORE_MARIADB_USER=netbox_store STORE_MARIADB_PASSWORD=A-RANDOM-PASSWORD ``` The required table is created on bootstrap, sync or the first web request; the database account needs privileges on exactly this database. `STORE_JSON_PATH` is not used in MariaDB mode. ## Installation of the store (Docker Compose) Alternatively, the same Apache/PHP store can run in a container. The default stack binds its port to localhost only and uses a named JSON volume: ```text cp .env.example .env docker compose build store ``` On Windows, use `copy .env.example .env` instead of `cp`. Set your own admin credentials in the root `.env` before starting. Without a complete admin configuration, login stays disabled; there is no default password. Generate the hash and session secret with the built image: ```text docker compose run --rm --no-deps -e STORE_SCHEDULER_ENABLED=false store php bin/console hash-password 'A-LONG-RANDOM-PASSWORD' docker compose run --rm --no-deps -e STORE_SCHEDULER_ENABLED=false store php -r 'echo bin2hex(random_bytes(32)), PHP_EOL;' ``` Then: ```text docker compose up -d --build ``` The scheduler in the container runs the first import immediately; follow it with `docker compose logs -f store`. For manual sync only, set `STORE_SCHEDULER_ENABLED=false` first and then run `docker compose exec store php bin/console sync`. The store is available at `http://127.0.0.1:8080` by default. For MariaDB, set at least `MARIADB_PASSWORD` and `MARIADB_ROOT_PASSWORD` to different random values in `.env` and enable the overlay: ```text docker compose -f compose.yaml -f compose.mariadb.yaml up -d --build ``` MariaDB gets no host port and is only reachable inside the Compose network. The store waits for the database health check. ## Usage ### Synchronisation and approval The preset Forgejo import reads repositories from the configured default source (`https://git.mrblake.cc`). GitHub is implemented as a second provider and can be added in the admin area through the same source management. With a token, metadata and READMEs of private GitHub repositories can be synced too. Private artefacts are intentionally not installable in API v1, because the host agent receives no provider credentials. Public projects do not need a release: if a wheel release is missing, the store creates a source candidate for the exact current commit, which is approved separately. The normal flow is: 1. The scheduler or `php bin/console sync` reads repository metadata, manifest/packaging configuration, releases and the README of a fixed commit SHA. 2. New records, or records whose install-relevant fields changed, get the status `pending`. 3. An administrator reviews source, package/import name, NetBox compatibility, artefact URL, size and SHA-256. 4. Source, plugin and release are approved separately. Approval is never an automatic result of a sync. 5. Only active, complete and approved records appear under `/api/v1/plugins/`. The detail page is generated from the stored README. Relative links and images are resolved against the synced commit; HTML is sanitised before output. If an artefact or install-relevant metadata changes, the release must be reviewed again. ### Installing on the NetBox host The recommended way is the interactive root installer. It installs the NetBox plugin and the separate host agent, detects the service account and NetBox version, sets up requirements and systemd and manages a clearly marked block in `configuration.py`. ```text curl -fsSLo /tmp/netbox-store-install.sh \ https://git.mrblake.cc/MrBlake/Netbox-Store/raw/branch/main/install.sh less /tmp/netbox-store-install.sh sudo bash /tmp/netbox-store-install.sh ``` The script offers two modes: - **Safe test mode:** life-cycle jobs remain dry runs and change no plugins. - **Production mode:** real changes run exclusively through the host agent. In addition to the summary, the operator must confirm by typing exactly `ECHT INSTALLIEREN`. All components loaded during a run are pinned to the same displayed commit. Existing files are backed up under `/var/backups/netbox-plugin-store//`. The script can be re-run for updates: it only replaces its own marked configuration block and its own requirement entries. After setup, the installer checks the agent socket as the NetBox service account. A real plugin installation must show `Dry-Run: Nein` (dry run: no) in the audit. Newly installed plugins stay disabled at first and are enabled with a separate action. ### Manual plugin installation The plugin in `netbox_plugin/` is limited to NetBox 4.6.5–4.6.8. Build a wheel and install it into the NetBox virtualenv: ```text cd netbox_plugin python -m build /opt/netbox/venv/bin/pip install dist/netbox_plugin_store-0.1.3-py3-none-any.whl ``` Also record the package in `/opt/netbox/local_requirements.txt`. In `configuration.py`, set it up in safe dry-run mode first: ```python PLUGINS = [ "netbox_plugin_store", ] PLUGINS_CONFIG = { "netbox_plugin_store": { "store_url": "https://plugins.example.com", "allowed_store_urls": ["https://plugins.example.com"], "allowed_artifact_urls": [ "https://plugins.example.com", "https://git.example.com", ], "execution_mode": "dry_run", }, } ``` Then run the usual NetBox upgrade steps: migration, `collectstatic` and a restart of the web and RQ services. Details and all settings are in [`netbox_plugin/README.md`](netbox_plugin/README.md). ### Manual production setup: host agent For real installations, `execution_mode = "agent"` provides the intended separation: the NetBox web process stays unprivileged and sends a small job over the Unix socket `/run/netbox-store-agent/agent.sock`. The agent fetches plugin and release from the store again, compares the approval marker and verifies wheel, file size and SHA-256 before every change. On the Linux NetBox host: 1. Install the package from `host_agent/` into an administrative Python environment. 2. Copy `host_agent/examples/agent.toml` to `/etc/netbox-store-agent/agent.toml`, adjust all hosts, paths, UIDs/GIDs and the NetBox version, and protect the file as root-owned with mode `0600`. 3. Copy both files from `host_agent/systemd/` to `/etc/systemd/system/`. In particular, `SocketGroup` must match the NetBox service group. 4. Include the agent-managed plugin list in `configuration.py` once: ```python from netbox.store_plugins import STORE_PLUGINS PLUGINS += STORE_PLUGINS ``` 5. Enable the socket and test in the default dry-run mode first: ```text systemctl daemon-reload systemctl enable --now netbox-store-agent.socket netbox-store-agent capabilities ``` 6. Only after successful catalogue and life-cycle tests, set `dry_run = false` in the root-protected agent configuration and restart the service. Then extend the NetBox configuration: ```python PLUGINS_CONFIG["netbox_plugin_store"].update({ "execution_mode": "agent", "agent_socket_path": "/run/netbox-store-agent/agent.sock", "agent_timeout": 30, }) ``` The agent installs only approved, immutable artefacts. Source archives are verified against their commit, built into a wheel locally and offline, and persisted as a hashed file under `/opt/netbox/.netbox-store-wheels`. Dependencies and build back-ends must already be provided by the operator. Full security and recovery notes are in [`host_agent/README.md`](host_agent/README.md). ### API v1 The public, approved-only catalogue provides these endpoints: ```text GET /api/v1/plugins/ GET /api/v1/plugins/{slug}/ GET /api/v1/plugins/{slug}/releases/{version}/ ``` A plugin contains, among others, `package_name`, `import_name`, `min_netbox_version`, `max_netbox_version` and `releases`. An installable release contains `download_url`, artefact `sha256`, `artifact_size`, `immutable` and the opaque approval marker `approved_payload_sha256`. The data flow and trust boundaries are described in [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md). ## Development and tests Each component has its own checks; they run without touching a production NetBox or host: ```text cd store && composer install && composer test cd host_agent && python -m pip install -e ".[dev]" && pytest cd netbox_plugin && python -m unittest discover -s tests -v ```