ophix-server-base 2026.10.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. ophix_server_base-2026.10.4.1/PKG-INFO +355 -0
  2. ophix_server_base-2026.10.4.1/README.md +317 -0
  3. ophix_server_base-2026.10.4.1/pyproject.toml +71 -0
  4. ophix_server_base-2026.10.4.1/setup.cfg +4 -0
  5. ophix_server_base-2026.10.4.1/src/ophix/OPHIX_RELEASE_NOTES.md +645 -0
  6. ophix_server_base-2026.10.4.1/src/ophix/__init__.py +2 -0
  7. ophix_server_base-2026.10.4.1/src/ophix/_version.py +2 -0
  8. ophix_server_base-2026.10.4.1/src/ophix/asgi.py +11 -0
  9. ophix_server_base-2026.10.4.1/src/ophix/core/__init__.py +33 -0
  10. ophix_server_base-2026.10.4.1/src/ophix/core/admin.py +592 -0
  11. ophix_server_base-2026.10.4.1/src/ophix/core/apps.py +60 -0
  12. ophix_server_base-2026.10.4.1/src/ophix/core/audit.py +166 -0
  13. ophix_server_base-2026.10.4.1/src/ophix/core/auth.py +124 -0
  14. ophix_server_base-2026.10.4.1/src/ophix/core/context_processors.py +24 -0
  15. ophix_server_base-2026.10.4.1/src/ophix/core/deploy_templates/backup.sh.j2 +140 -0
  16. ophix_server_base-2026.10.4.1/src/ophix/core/deploy_templates/env.sample.j2 +190 -0
  17. ophix_server_base-2026.10.4.1/src/ophix/core/deploy_templates/gunicorn.service.j2 +40 -0
  18. ophix_server_base-2026.10.4.1/src/ophix/core/deploy_templates/nginx.conf.j2 +86 -0
  19. ophix_server_base-2026.10.4.1/src/ophix/core/deploy_templates/update.sh.j2 +89 -0
  20. ophix_server_base-2026.10.4.1/src/ophix/core/docs/access-auditing.md +87 -0
  21. ophix_server_base-2026.10.4.1/src/ophix/core/docs/client-quickstart.md +172 -0
  22. ophix_server_base-2026.10.4.1/src/ophix/core/docs/how-we-built-ophix.md +12 -0
  23. ophix_server_base-2026.10.4.1/src/ophix/core/docs/sections.yaml +5 -0
  24. ophix_server_base-2026.10.4.1/src/ophix/core/docs/server-backup.md +284 -0
  25. ophix_server_base-2026.10.4.1/src/ophix/core/docs/server-installation.md +389 -0
  26. ophix_server_base-2026.10.4.1/src/ophix/core/management/__init__.py +0 -0
  27. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/__init__.py +0 -0
  28. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/apply_updates.py +104 -0
  29. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/archive_access_logs.py +159 -0
  30. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/check_updates.py +311 -0
  31. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/configure_database.py +589 -0
  32. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/configure_install.py +769 -0
  33. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/create_backup_script.py +128 -0
  34. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/create_update_script.py +97 -0
  35. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/export_clients.py +134 -0
  36. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/export_env.py +176 -0
  37. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/export_hosts.py +118 -0
  38. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/generate_config.py +757 -0
  39. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/import_clients.py +225 -0
  40. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/import_env.py +201 -0
  41. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/import_hosts.py +220 -0
  42. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/list_plugins.py +119 -0
  43. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/prune_access_logs.py +95 -0
  44. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/run_install.py +737 -0
  45. ophix_server_base-2026.10.4.1/src/ophix/core/management/commands/run_uninstall.py +91 -0
  46. ophix_server_base-2026.10.4.1/src/ophix/core/middleware.py +31 -0
  47. ophix_server_base-2026.10.4.1/src/ophix/core/migrations/0001_initial.py +96 -0
  48. ophix_server_base-2026.10.4.1/src/ophix/core/migrations/0002_hash_client_tokens.py +70 -0
  49. ophix_server_base-2026.10.4.1/src/ophix/core/migrations/0003_packageupdaterecord_description.py +22 -0
  50. ophix_server_base-2026.10.4.1/src/ophix/core/migrations/0004_rename_api_token_to_token_hash.py +44 -0
  51. ophix_server_base-2026.10.4.1/src/ophix/core/migrations/__init__.py +0 -0
  52. ophix_server_base-2026.10.4.1/src/ophix/core/models.py +361 -0
  53. ophix_server_base-2026.10.4.1/src/ophix/core/oidc.py +16 -0
  54. ophix_server_base-2026.10.4.1/src/ophix/core/serializers.py +29 -0
  55. ophix_server_base-2026.10.4.1/src/ophix/core/static/admin/custom.css +360 -0
  56. ophix_server_base-2026.10.4.1/src/ophix/core/static/admin/custom.js +134 -0
  57. ophix_server_base-2026.10.4.1/src/ophix/core/templates/admin/base_site.html +32 -0
  58. ophix_server_base-2026.10.4.1/src/ophix/core/templates/admin/index.html +25 -0
  59. ophix_server_base-2026.10.4.1/src/ophix/core/templates/admin/login.html +57 -0
  60. ophix_server_base-2026.10.4.1/src/ophix/core/templates/admin/ophix_core/client/change_form.html +84 -0
  61. ophix_server_base-2026.10.4.1/src/ophix/core/templates/admin/ophix_core/client/change_token_confirm.html +150 -0
  62. ophix_server_base-2026.10.4.1/src/ophix/core/templates/admin/ophix_core/client/token_created.html +192 -0
  63. ophix_server_base-2026.10.4.1/src/ophix/core/templates/admin/ophix_core/packageupdaterecord/change_list.html +14 -0
  64. ophix_server_base-2026.10.4.1/src/ophix/core/utils.py +136 -0
  65. ophix_server_base-2026.10.4.1/src/ophix/core/views.py +268 -0
  66. ophix_server_base-2026.10.4.1/src/ophix/manage.py +116 -0
  67. ophix_server_base-2026.10.4.1/src/ophix/settings/__init__.py +19 -0
  68. ophix_server_base-2026.10.4.1/src/ophix/settings/base.py +465 -0
  69. ophix_server_base-2026.10.4.1/src/ophix/settings/plugins.py +194 -0
  70. ophix_server_base-2026.10.4.1/src/ophix/settings/utils.py +85 -0
  71. ophix_server_base-2026.10.4.1/src/ophix/urls/__init__.py +34 -0
  72. ophix_server_base-2026.10.4.1/src/ophix/urls/base.py +54 -0
  73. ophix_server_base-2026.10.4.1/src/ophix/urls/plugins.py +33 -0
  74. ophix_server_base-2026.10.4.1/src/ophix/wsgi.py +11 -0
  75. ophix_server_base-2026.10.4.1/src/ophix_server_base.egg-info/PKG-INFO +355 -0
  76. ophix_server_base-2026.10.4.1/src/ophix_server_base.egg-info/SOURCES.txt +78 -0
  77. ophix_server_base-2026.10.4.1/src/ophix_server_base.egg-info/dependency_links.txt +1 -0
  78. ophix_server_base-2026.10.4.1/src/ophix_server_base.egg-info/entry_points.txt +2 -0
  79. ophix_server_base-2026.10.4.1/src/ophix_server_base.egg-info/requires.txt +16 -0
  80. ophix_server_base-2026.10.4.1/src/ophix_server_base.egg-info/top_level.txt +1 -0
@@ -0,0 +1,355 @@
1
+ Metadata-Version: 2.4
2
+ Name: ophix-server-base
3
+ Version: 2026.10.4.1
4
+ Summary: Shared Django base for Ophix fleet management servers
5
+ Author: Ophix Project
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://ophix.io
8
+ Project-URL: Documentation, https://github.com/ophixproject/ophix-server-base#readme
9
+ Project-URL: Source, https://github.com/ophixproject/ophix-server-base
10
+ Keywords: django,ophix,fleet management,server
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Web Environment
13
+ Classifier: Framework :: Django
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
23
+ Classifier: Topic :: System :: Systems Administration
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ Requires-Dist: Django<6.0,>=4.2; python_version < "3.12"
27
+ Requires-Dist: Django>=4.2; python_version >= "3.12"
28
+ Requires-Dist: djangorestframework>=3.14
29
+ Requires-Dist: ophix-admin-interface>=2026.06.08.04
30
+ Requires-Dist: ophix-admin-settings>=2026.06.08.03
31
+ Requires-Dist: django-colorfield>=0.11
32
+ Requires-Dist: django-apptemplates>=1.5
33
+ Requires-Dist: python-dotenv>=1.0
34
+ Requires-Dist: Jinja2>=3.0
35
+ Requires-Dist: gunicorn>=21.0
36
+ Requires-Dist: markdown>=3.4
37
+ Requires-Dist: cryptography>=41.0
38
+
39
+ # ophix-server-base
40
+
41
+ **The shared foundation every [Ophix](https://ophix.io) server is built on** — a modular, self-hosted fleet management platform.
42
+
43
+ Managing a fleet of servers usually means picking between a heavyweight all-in-one agent that phones home to someone else's cloud, or stitching together your own scripts for credentials, configs, certificates, and scheduled tasks across every box. Ophix takes a different approach: install only the domains you actually need — credential distribution, configuration management, certificate issuance, task scheduling, DNS management — each running as its own lightweight, independently deployable server and client pair, sharing nothing but this common foundation.
44
+
45
+ `ophix-server-base` is that foundation: host/client registration, token + IP authentication, the plugin system every domain and extension is built on, and the guided installer that gets a server running.
46
+
47
+ This package is automatically included in every Ophix server, no need to separately install it.
48
+
49
+ ---
50
+
51
+ ## Installation
52
+
53
+ Installed automatically with any Ophix domain package (`ophix-creds`, `ophix-tasks`, etc.). To install explicitly:
54
+
55
+ ```bash
56
+ pip install ophix-server-base
57
+ ```
58
+
59
+ Install one domain plugin and a database engine plugin alongside it, with recommended extras:
60
+
61
+ ```bash
62
+ pip install ophix-creds ophix-dbengine-mariadb ophix-docs venv-cmds
63
+ ```
64
+
65
+ - `ophix-dbengine-mariadb` — MariaDB/MySQL driver; install the matching `ophix-dbengine-*`
66
+ plugin instead if you're using a different engine (Postgres, SQL Server, Oracle, CockroachDB).
67
+ Every engine needs its plugin installed explicitly — none is bundled by default.
68
+ - `ophix-docs` — inline documentation in the admin UI
69
+ - `venv-cmds` — lists available venv commands and checks for package updates
70
+
71
+ ---
72
+
73
+ ## Guided installation
74
+
75
+ The recommended way to deploy a new server is the three-step guided installer.
76
+ The examples below use `credserver` / `ophix-creds` — substitute your domain slug
77
+ and package name (`confserver`, `certserver`, etc.) as appropriate. The pattern is
78
+ identical for every domain.
79
+
80
+ ### Step 1 — configure
81
+
82
+ ```bash
83
+ ophix-manage configure_install credserver
84
+ ```
85
+
86
+ Interactive wizard. Prompts for install directory, hostname, TLS certificate paths
87
+ (with CN/SAN validation), database connection (with live connection test), superuser
88
+ credentials, and admin theme. Domain plugins contribute additional prompts — for
89
+ example `ophix-creds` prompts to generate a `CRED_ENCRYPTION_KEY`.
90
+
91
+ Writes two files:
92
+
93
+ - `.credserver.conf` — machine-readable install config used by the next step
94
+ - `.env` — complete environment file ready for use
95
+
96
+ Safe to re-run: existing values are offered as defaults so you can update individual
97
+ settings without re-entering everything.
98
+
99
+ ### Step 2 — install
100
+
101
+ ```bash
102
+ ophix-manage run_install credserver
103
+ ```
104
+
105
+ Reads `.credserver.conf` and performs all non-root steps:
106
+
107
+ - Creates the install directory structure (`logs/`, `ssl/`, `static/`, etc.)
108
+ - Copies TLS certificate, key, and CA bundle into place
109
+ - Generates `credserver.nginx.conf` and `credserver.service` (systemd unit)
110
+ - Generates `credserver_sudo_install.sh` and `credserver_sudo_uninstall.sh`
111
+ - Runs plugin setup hooks (e.g. writes encryption keys to `.env`)
112
+ - Runs `migrate`, `collectstatic`, and creates the superuser
113
+ - Activates the configured theme and sets the admin title
114
+
115
+ Options: `--skip-migrate`, `--skip-collectstatic`, `--skip-superuser`
116
+
117
+ ### Step 3 — system integration (as root)
118
+
119
+ ```bash
120
+ sudo bash credserver_sudo_install.sh
121
+ ```
122
+
123
+ Sets file ownership, installs the nginx config and systemd service, and starts the
124
+ server. After this completes the admin UI is available at `https://your.hostname/admin/`.
125
+
126
+ ---
127
+
128
+ ## Routine upgrades
129
+
130
+ ```bash
131
+ pip install --upgrade ophix-server-base ophix-creds # upgrade packages
132
+ ophix-manage migrate # apply new migrations
133
+ ophix-manage collectstatic --noinput # update static files
134
+ sudo systemctl restart credserver # restart service
135
+ ```
136
+
137
+ Or use the convenience command that runs all three steps in order:
138
+
139
+ ```bash
140
+ ophix-manage apply_updates
141
+ ```
142
+
143
+ If the upgrade added new `.env` settings, pull them in first:
144
+
145
+ ```bash
146
+ ophix-manage generate_config --append
147
+ ```
148
+
149
+ Do not re-run `configure_install` for routine upgrades — it rewrites `.env` from
150
+ scratch.
151
+
152
+ ---
153
+
154
+ ## Configuration
155
+
156
+ `.env` is generated by `configure_install` (see above). Key variables:
157
+
158
+ | Variable | Default | Purpose |
159
+ | --- | --- | --- |
160
+ | `SERVER_NAME` | *(slug)* | Short name for this server instance |
161
+ | `SERVER_VERSION` | *(domain version)* | Shown in the admin footer |
162
+ | `INSTALL_DIR` | *(prompted)* | Root for runtime data: logs, media, ssl, static |
163
+ | `ALLOWED_HOSTS` | *(hostname)* | Comma-separated hostnames this server accepts |
164
+ | `DEBUG` | `False` | Enable only during development — never in production |
165
+ | `SERVER_READ_ONLY_MODE` | `False` | Reject all API write requests. Use during migration change windows: set on the source server before exporting, leave unset on the target, then update DNS. |
166
+ | `DB_ENGINE` | `mariadb` | `mariadb` \| `mysql` \| `postgres` \| `sqlserver` \| `cockroachdb` |
167
+ | `DB_HOST` | `localhost` | Database host |
168
+ | `DB_PORT` | `3306` | Database port |
169
+ | `DB_NAME` | `ophix_db` | Database name |
170
+ | `DB_USER` | `ophixuser` | Database user |
171
+ | `DB_PASSWORD` | — | Database password |
172
+ | `DB_SSL_CA` | — | Path to DB CA cert — enables TLS for the database connection |
173
+ | `CA_CERT_FILE` | — | Path to internal CA cert served to clients unauthenticated |
174
+ | `TIME_ZONE` | `UTC` | Server timezone. UTC is strongly recommended. If set to a non-UTC value and using MariaDB or MySQL, the database timezone tables must be populated — see [Audit logging](src/ophix/core/docs/server-installation.md#audit-logging) in the installation docs. |
175
+ | `LANGUAGE_CODE` | `en-au` | Django language code |
176
+ | `AUTH_LEAK_INFO` | `False` | Include error detail in API responses — development only |
177
+ | `MINIMUM_TOKEN_ROTATE_TIME` | `3600` | Minimum seconds between token rotations |
178
+ | `OPHIX_DISABLE` | — | Comma-separated plugin modules to suppress |
179
+
180
+ Domain plugins add their own variables (e.g. `CRED_ENCRYPTION_KEY` from [ophix-creds](https://github.com/ophixproject/ophix-creds)).
181
+
182
+ ---
183
+
184
+ ## Documentation
185
+
186
+ If `ophix-docs` is installed, documentation for all installed packages is loaded
187
+ automatically at the end of `run_install`. No further action is needed for a fresh install.
188
+
189
+ To load or refresh docs manually after upgrading packages, run `list_docs_sources`
190
+ to see which app module names to include, then:
191
+
192
+ ```bash
193
+ ophix-manage update_docs --include-app-docs ophix.core,ophix_creds,ophix_docs
194
+ ```
195
+
196
+ Substitute the module list for your server type — see
197
+ [ophix-docs](https://github.com/ophixproject/ophix-docs) for per-server examples and
198
+ the full list of documentation management commands.
199
+
200
+ ---
201
+
202
+ ## Management commands
203
+
204
+ ### Guided installer
205
+
206
+ | Command | Purpose |
207
+ | --- | --- |
208
+ | `configure_install <slug>` | Interactive wizard — collects all settings, tests the DB connection, writes `.env` and `.<slug>.conf`. Idempotent; safe to re-run. |
209
+ | `run_install <slug>` | Reads `.<slug>.conf`; creates the directory structure, copies TLS files, runs `migrate` / `collectstatic` / superuser, activates the theme, loads docs. |
210
+ | `run_uninstall <slug>` | Regenerates or prints the sudo uninstall script. Data directory is never removed automatically. |
211
+
212
+ See [Guided installation](#guided-installation) above for the full three-step walkthrough.
213
+
214
+ ---
215
+
216
+ ### Manual / legacy deployment
217
+
218
+ These commands underpin `configure_install` / `run_install` and remain available for scripted or customised deployments.
219
+
220
+ **`generate_config`** — generates deployment files from templates:
221
+
222
+ | Flag | Output |
223
+ | --- | --- |
224
+ | `--env` | `.env.sample` (base settings + all installed plugin env fragments appended) |
225
+ | `--nginx` | `<slug>.nginx.conf` (HTTP redirect + HTTPS reverse proxy) |
226
+ | `--systemd` | `<slug>.service` (gunicorn systemd unit) |
227
+ | `--all` | All three of the above |
228
+ | `--append` | Appends any missing plugin variables to the existing `.env`. Use after installing a new plugin. Never modifies existing values. |
229
+
230
+ ```bash
231
+ ophix-manage generate_config --all \
232
+ --server-hostname credserver.example.com \
233
+ --service-user ophix
234
+
235
+ # After installing a new plugin into an existing deployment:
236
+ ophix-manage generate_config --append
237
+ ```
238
+
239
+ **`configure_database`** — interactive prompt to configure and live-test the database connection, then write the result to `.env`. Live-tests all six supported engines: MariaDB, MySQL, PostgreSQL, CockroachDB, SQL Server, and Oracle. Optional TLS and mutual TLS (not applicable to SQL Server or Oracle — see the driver plugin READMEs).
240
+
241
+ ```bash
242
+ ophix-manage configure_database
243
+ ```
244
+
245
+ ---
246
+
247
+ ### Operations
248
+
249
+ **`list_plugins`** — lists all installed Ophix plugins discovered via the `ophix.plugins` entry point group, plus `ophix-server-base` itself.
250
+
251
+ ```bash
252
+ ophix-manage list_plugins # names only
253
+ ophix-manage list_plugins --details # name, package, module, version
254
+ ```
255
+
256
+ **`check_updates`** — checks all installed Ophix plugins against the configured pip index and reports whether newer versions are available. Results are stored in `PackageUpdateRecord` and shown in the admin UI.
257
+
258
+ ```bash
259
+ ophix-manage check_updates
260
+ ophix-manage check_updates --quiet # suppress output; suitable for cron
261
+ ```
262
+
263
+ **`apply_updates`** — convenience wrapper that runs `migrate`, `collectstatic --noinput`, and `generate_config --append` in sequence, then prints a reminder to restart the service. Run this after `pip install --upgrade`.
264
+
265
+ ```bash
266
+ ophix-manage apply_updates
267
+ ```
268
+
269
+ **`prune_access_logs`** — deletes `AccessLog` records older than N days. Intended to be run periodically via cron.
270
+
271
+ ```bash
272
+ ophix-manage prune_access_logs # default: 90 days
273
+ ophix-manage prune_access_logs --days 30
274
+ ophix-manage prune_access_logs --days 30 --dry-run
275
+ ```
276
+
277
+ **`archive_access_logs`** — exports `AccessLog` records to a file for long-term retention or compliance. Use `--append` for incremental cron runs (writes newline-delimited JSON). Combine with `prune_access_logs` to archive-then-purge:
278
+
279
+ ```bash
280
+ ophix-manage archive_access_logs --output-file archive.ndjson --days 90 --append
281
+ ophix-manage prune_access_logs --days 90
282
+ ```
283
+
284
+ ---
285
+
286
+ ### Host and client backup
287
+
288
+ **`export_hosts`** / **`import_hosts`** — transfer Host records between servers. Idempotent (matched by name). Both support `--dry-run` and `--quiet`; `import_hosts` supports `--force` to bypass IP conflict checks.
289
+
290
+ **`export_clients`** / **`import_clients`** — backup and restore Client records including tokens, enabling fleet clients to reconnect to a rebuilt server without re-registering. `export_clients` accepts `--passphrase` to encrypt tokens at rest; `import_clients` requires the same passphrase when the file is encrypted. Both support `--dry-run` and `--quiet`; `import_clients` supports `--force`.
291
+
292
+ Run `import_hosts` before `import_clients` when doing a full server restore.
293
+
294
+ ---
295
+
296
+ ### Standard Django commands
297
+
298
+ ```bash
299
+ # Using the installed entry point
300
+ ophix-manage migrate
301
+ ophix-manage collectstatic
302
+ ophix-manage createsuperuser
303
+
304
+ # Or via Python
305
+ python -m ophix.manage migrate
306
+ ```
307
+
308
+ Always set `DJANGO_SETTINGS_MODULE=ophix.settings` (the default).
309
+
310
+ ---
311
+
312
+ ## Plugin system
313
+
314
+ Any pip-installable package that registers under the `ophix.plugins`
315
+ entry point group is automatically added to `INSTALLED_APPS` and its
316
+ URLs are included.
317
+
318
+ ```toml
319
+ # In your plugin's pyproject.toml:
320
+ [project.entry-points."ophix.plugins"]
321
+ my_plugin = "my_plugin_module"
322
+ ```
323
+
324
+ To suppress an installed plugin without uninstalling it:
325
+
326
+ ```bash
327
+ OPHIX_DISABLE=my_plugin_module
328
+ ```
329
+
330
+ ---
331
+
332
+ ## Standard API endpoints
333
+
334
+ Every OPS server exposes these regardless of installed plugins:
335
+
336
+ | Method | Path | Auth | Purpose |
337
+ | --- | --- | --- | --- |
338
+ | `GET` | `/api/server/ca-cert/` | None | Download internal CA cert |
339
+ | `POST` | `/api/register/` | None | Register a new client |
340
+ | `GET` | `/api/client/self/` | Token | Client self-inspection |
341
+ | `PATCH` | `/api/client/self/update/` | Token | Update venv/deployment info |
342
+ | `POST` | `/api/client/self/rotate-token/` | Token | Rotate API token |
343
+
344
+ ---
345
+
346
+ ## Authentication
347
+
348
+ All authenticated endpoints require:
349
+
350
+ ```text
351
+ Authorization: Token <64-char hex token>
352
+ ```
353
+
354
+ Requests are also validated against the client's registered Host IP.
355
+ Both conditions must pass. See `ophix.core.auth.ClientTokenAuthentication`.
@@ -0,0 +1,317 @@
1
+ # ophix-server-base
2
+
3
+ **The shared foundation every [Ophix](https://ophix.io) server is built on** — a modular, self-hosted fleet management platform.
4
+
5
+ Managing a fleet of servers usually means picking between a heavyweight all-in-one agent that phones home to someone else's cloud, or stitching together your own scripts for credentials, configs, certificates, and scheduled tasks across every box. Ophix takes a different approach: install only the domains you actually need — credential distribution, configuration management, certificate issuance, task scheduling, DNS management — each running as its own lightweight, independently deployable server and client pair, sharing nothing but this common foundation.
6
+
7
+ `ophix-server-base` is that foundation: host/client registration, token + IP authentication, the plugin system every domain and extension is built on, and the guided installer that gets a server running.
8
+
9
+ This package is automatically included in every Ophix server, no need to separately install it.
10
+
11
+ ---
12
+
13
+ ## Installation
14
+
15
+ Installed automatically with any Ophix domain package (`ophix-creds`, `ophix-tasks`, etc.). To install explicitly:
16
+
17
+ ```bash
18
+ pip install ophix-server-base
19
+ ```
20
+
21
+ Install one domain plugin and a database engine plugin alongside it, with recommended extras:
22
+
23
+ ```bash
24
+ pip install ophix-creds ophix-dbengine-mariadb ophix-docs venv-cmds
25
+ ```
26
+
27
+ - `ophix-dbengine-mariadb` — MariaDB/MySQL driver; install the matching `ophix-dbengine-*`
28
+ plugin instead if you're using a different engine (Postgres, SQL Server, Oracle, CockroachDB).
29
+ Every engine needs its plugin installed explicitly — none is bundled by default.
30
+ - `ophix-docs` — inline documentation in the admin UI
31
+ - `venv-cmds` — lists available venv commands and checks for package updates
32
+
33
+ ---
34
+
35
+ ## Guided installation
36
+
37
+ The recommended way to deploy a new server is the three-step guided installer.
38
+ The examples below use `credserver` / `ophix-creds` — substitute your domain slug
39
+ and package name (`confserver`, `certserver`, etc.) as appropriate. The pattern is
40
+ identical for every domain.
41
+
42
+ ### Step 1 — configure
43
+
44
+ ```bash
45
+ ophix-manage configure_install credserver
46
+ ```
47
+
48
+ Interactive wizard. Prompts for install directory, hostname, TLS certificate paths
49
+ (with CN/SAN validation), database connection (with live connection test), superuser
50
+ credentials, and admin theme. Domain plugins contribute additional prompts — for
51
+ example `ophix-creds` prompts to generate a `CRED_ENCRYPTION_KEY`.
52
+
53
+ Writes two files:
54
+
55
+ - `.credserver.conf` — machine-readable install config used by the next step
56
+ - `.env` — complete environment file ready for use
57
+
58
+ Safe to re-run: existing values are offered as defaults so you can update individual
59
+ settings without re-entering everything.
60
+
61
+ ### Step 2 — install
62
+
63
+ ```bash
64
+ ophix-manage run_install credserver
65
+ ```
66
+
67
+ Reads `.credserver.conf` and performs all non-root steps:
68
+
69
+ - Creates the install directory structure (`logs/`, `ssl/`, `static/`, etc.)
70
+ - Copies TLS certificate, key, and CA bundle into place
71
+ - Generates `credserver.nginx.conf` and `credserver.service` (systemd unit)
72
+ - Generates `credserver_sudo_install.sh` and `credserver_sudo_uninstall.sh`
73
+ - Runs plugin setup hooks (e.g. writes encryption keys to `.env`)
74
+ - Runs `migrate`, `collectstatic`, and creates the superuser
75
+ - Activates the configured theme and sets the admin title
76
+
77
+ Options: `--skip-migrate`, `--skip-collectstatic`, `--skip-superuser`
78
+
79
+ ### Step 3 — system integration (as root)
80
+
81
+ ```bash
82
+ sudo bash credserver_sudo_install.sh
83
+ ```
84
+
85
+ Sets file ownership, installs the nginx config and systemd service, and starts the
86
+ server. After this completes the admin UI is available at `https://your.hostname/admin/`.
87
+
88
+ ---
89
+
90
+ ## Routine upgrades
91
+
92
+ ```bash
93
+ pip install --upgrade ophix-server-base ophix-creds # upgrade packages
94
+ ophix-manage migrate # apply new migrations
95
+ ophix-manage collectstatic --noinput # update static files
96
+ sudo systemctl restart credserver # restart service
97
+ ```
98
+
99
+ Or use the convenience command that runs all three steps in order:
100
+
101
+ ```bash
102
+ ophix-manage apply_updates
103
+ ```
104
+
105
+ If the upgrade added new `.env` settings, pull them in first:
106
+
107
+ ```bash
108
+ ophix-manage generate_config --append
109
+ ```
110
+
111
+ Do not re-run `configure_install` for routine upgrades — it rewrites `.env` from
112
+ scratch.
113
+
114
+ ---
115
+
116
+ ## Configuration
117
+
118
+ `.env` is generated by `configure_install` (see above). Key variables:
119
+
120
+ | Variable | Default | Purpose |
121
+ | --- | --- | --- |
122
+ | `SERVER_NAME` | *(slug)* | Short name for this server instance |
123
+ | `SERVER_VERSION` | *(domain version)* | Shown in the admin footer |
124
+ | `INSTALL_DIR` | *(prompted)* | Root for runtime data: logs, media, ssl, static |
125
+ | `ALLOWED_HOSTS` | *(hostname)* | Comma-separated hostnames this server accepts |
126
+ | `DEBUG` | `False` | Enable only during development — never in production |
127
+ | `SERVER_READ_ONLY_MODE` | `False` | Reject all API write requests. Use during migration change windows: set on the source server before exporting, leave unset on the target, then update DNS. |
128
+ | `DB_ENGINE` | `mariadb` | `mariadb` \| `mysql` \| `postgres` \| `sqlserver` \| `cockroachdb` |
129
+ | `DB_HOST` | `localhost` | Database host |
130
+ | `DB_PORT` | `3306` | Database port |
131
+ | `DB_NAME` | `ophix_db` | Database name |
132
+ | `DB_USER` | `ophixuser` | Database user |
133
+ | `DB_PASSWORD` | — | Database password |
134
+ | `DB_SSL_CA` | — | Path to DB CA cert — enables TLS for the database connection |
135
+ | `CA_CERT_FILE` | — | Path to internal CA cert served to clients unauthenticated |
136
+ | `TIME_ZONE` | `UTC` | Server timezone. UTC is strongly recommended. If set to a non-UTC value and using MariaDB or MySQL, the database timezone tables must be populated — see [Audit logging](src/ophix/core/docs/server-installation.md#audit-logging) in the installation docs. |
137
+ | `LANGUAGE_CODE` | `en-au` | Django language code |
138
+ | `AUTH_LEAK_INFO` | `False` | Include error detail in API responses — development only |
139
+ | `MINIMUM_TOKEN_ROTATE_TIME` | `3600` | Minimum seconds between token rotations |
140
+ | `OPHIX_DISABLE` | — | Comma-separated plugin modules to suppress |
141
+
142
+ Domain plugins add their own variables (e.g. `CRED_ENCRYPTION_KEY` from [ophix-creds](https://github.com/ophixproject/ophix-creds)).
143
+
144
+ ---
145
+
146
+ ## Documentation
147
+
148
+ If `ophix-docs` is installed, documentation for all installed packages is loaded
149
+ automatically at the end of `run_install`. No further action is needed for a fresh install.
150
+
151
+ To load or refresh docs manually after upgrading packages, run `list_docs_sources`
152
+ to see which app module names to include, then:
153
+
154
+ ```bash
155
+ ophix-manage update_docs --include-app-docs ophix.core,ophix_creds,ophix_docs
156
+ ```
157
+
158
+ Substitute the module list for your server type — see
159
+ [ophix-docs](https://github.com/ophixproject/ophix-docs) for per-server examples and
160
+ the full list of documentation management commands.
161
+
162
+ ---
163
+
164
+ ## Management commands
165
+
166
+ ### Guided installer
167
+
168
+ | Command | Purpose |
169
+ | --- | --- |
170
+ | `configure_install <slug>` | Interactive wizard — collects all settings, tests the DB connection, writes `.env` and `.<slug>.conf`. Idempotent; safe to re-run. |
171
+ | `run_install <slug>` | Reads `.<slug>.conf`; creates the directory structure, copies TLS files, runs `migrate` / `collectstatic` / superuser, activates the theme, loads docs. |
172
+ | `run_uninstall <slug>` | Regenerates or prints the sudo uninstall script. Data directory is never removed automatically. |
173
+
174
+ See [Guided installation](#guided-installation) above for the full three-step walkthrough.
175
+
176
+ ---
177
+
178
+ ### Manual / legacy deployment
179
+
180
+ These commands underpin `configure_install` / `run_install` and remain available for scripted or customised deployments.
181
+
182
+ **`generate_config`** — generates deployment files from templates:
183
+
184
+ | Flag | Output |
185
+ | --- | --- |
186
+ | `--env` | `.env.sample` (base settings + all installed plugin env fragments appended) |
187
+ | `--nginx` | `<slug>.nginx.conf` (HTTP redirect + HTTPS reverse proxy) |
188
+ | `--systemd` | `<slug>.service` (gunicorn systemd unit) |
189
+ | `--all` | All three of the above |
190
+ | `--append` | Appends any missing plugin variables to the existing `.env`. Use after installing a new plugin. Never modifies existing values. |
191
+
192
+ ```bash
193
+ ophix-manage generate_config --all \
194
+ --server-hostname credserver.example.com \
195
+ --service-user ophix
196
+
197
+ # After installing a new plugin into an existing deployment:
198
+ ophix-manage generate_config --append
199
+ ```
200
+
201
+ **`configure_database`** — interactive prompt to configure and live-test the database connection, then write the result to `.env`. Live-tests all six supported engines: MariaDB, MySQL, PostgreSQL, CockroachDB, SQL Server, and Oracle. Optional TLS and mutual TLS (not applicable to SQL Server or Oracle — see the driver plugin READMEs).
202
+
203
+ ```bash
204
+ ophix-manage configure_database
205
+ ```
206
+
207
+ ---
208
+
209
+ ### Operations
210
+
211
+ **`list_plugins`** — lists all installed Ophix plugins discovered via the `ophix.plugins` entry point group, plus `ophix-server-base` itself.
212
+
213
+ ```bash
214
+ ophix-manage list_plugins # names only
215
+ ophix-manage list_plugins --details # name, package, module, version
216
+ ```
217
+
218
+ **`check_updates`** — checks all installed Ophix plugins against the configured pip index and reports whether newer versions are available. Results are stored in `PackageUpdateRecord` and shown in the admin UI.
219
+
220
+ ```bash
221
+ ophix-manage check_updates
222
+ ophix-manage check_updates --quiet # suppress output; suitable for cron
223
+ ```
224
+
225
+ **`apply_updates`** — convenience wrapper that runs `migrate`, `collectstatic --noinput`, and `generate_config --append` in sequence, then prints a reminder to restart the service. Run this after `pip install --upgrade`.
226
+
227
+ ```bash
228
+ ophix-manage apply_updates
229
+ ```
230
+
231
+ **`prune_access_logs`** — deletes `AccessLog` records older than N days. Intended to be run periodically via cron.
232
+
233
+ ```bash
234
+ ophix-manage prune_access_logs # default: 90 days
235
+ ophix-manage prune_access_logs --days 30
236
+ ophix-manage prune_access_logs --days 30 --dry-run
237
+ ```
238
+
239
+ **`archive_access_logs`** — exports `AccessLog` records to a file for long-term retention or compliance. Use `--append` for incremental cron runs (writes newline-delimited JSON). Combine with `prune_access_logs` to archive-then-purge:
240
+
241
+ ```bash
242
+ ophix-manage archive_access_logs --output-file archive.ndjson --days 90 --append
243
+ ophix-manage prune_access_logs --days 90
244
+ ```
245
+
246
+ ---
247
+
248
+ ### Host and client backup
249
+
250
+ **`export_hosts`** / **`import_hosts`** — transfer Host records between servers. Idempotent (matched by name). Both support `--dry-run` and `--quiet`; `import_hosts` supports `--force` to bypass IP conflict checks.
251
+
252
+ **`export_clients`** / **`import_clients`** — backup and restore Client records including tokens, enabling fleet clients to reconnect to a rebuilt server without re-registering. `export_clients` accepts `--passphrase` to encrypt tokens at rest; `import_clients` requires the same passphrase when the file is encrypted. Both support `--dry-run` and `--quiet`; `import_clients` supports `--force`.
253
+
254
+ Run `import_hosts` before `import_clients` when doing a full server restore.
255
+
256
+ ---
257
+
258
+ ### Standard Django commands
259
+
260
+ ```bash
261
+ # Using the installed entry point
262
+ ophix-manage migrate
263
+ ophix-manage collectstatic
264
+ ophix-manage createsuperuser
265
+
266
+ # Or via Python
267
+ python -m ophix.manage migrate
268
+ ```
269
+
270
+ Always set `DJANGO_SETTINGS_MODULE=ophix.settings` (the default).
271
+
272
+ ---
273
+
274
+ ## Plugin system
275
+
276
+ Any pip-installable package that registers under the `ophix.plugins`
277
+ entry point group is automatically added to `INSTALLED_APPS` and its
278
+ URLs are included.
279
+
280
+ ```toml
281
+ # In your plugin's pyproject.toml:
282
+ [project.entry-points."ophix.plugins"]
283
+ my_plugin = "my_plugin_module"
284
+ ```
285
+
286
+ To suppress an installed plugin without uninstalling it:
287
+
288
+ ```bash
289
+ OPHIX_DISABLE=my_plugin_module
290
+ ```
291
+
292
+ ---
293
+
294
+ ## Standard API endpoints
295
+
296
+ Every OPS server exposes these regardless of installed plugins:
297
+
298
+ | Method | Path | Auth | Purpose |
299
+ | --- | --- | --- | --- |
300
+ | `GET` | `/api/server/ca-cert/` | None | Download internal CA cert |
301
+ | `POST` | `/api/register/` | None | Register a new client |
302
+ | `GET` | `/api/client/self/` | Token | Client self-inspection |
303
+ | `PATCH` | `/api/client/self/update/` | Token | Update venv/deployment info |
304
+ | `POST` | `/api/client/self/rotate-token/` | Token | Rotate API token |
305
+
306
+ ---
307
+
308
+ ## Authentication
309
+
310
+ All authenticated endpoints require:
311
+
312
+ ```text
313
+ Authorization: Token <64-char hex token>
314
+ ```
315
+
316
+ Requests are also validated against the client's registered Host IP.
317
+ Both conditions must pass. See `ophix.core.auth.ClientTokenAuthentication`.