Scheduled jobs on OPNsense through the cron API: every cron job of config.xml is read with who owns it, any job can be enabled and disabled, and an application's own jobs can be written and deleted. A job's command is a configd action, validated against what configd offers.
Changes
New napalm_opnsense/scheduled_jobs.py with OPNsenseScheduledJobsMixin, mixed into OPNsenseDriver.
get_scheduled_jobs(): one GET /api/cron/settings/get (it carries the selected configd action; search_jobs shows its display text). key=opnsense:<uuid>, kind=cron, source=config.xml, run_as=root, schedule_kind=cron. Origin other than cron is platform; a description starting with napalm-scheduled-job: <name> is application (name and the rest as description); everything else admin. An answer without its jobs raises ValueError. time_zone is None (the driver does not read the system settings).
manage_scheduled_job(): enable/disable via toggle_job/<uuid>/1|0 + cron/service/reconfigure. run is in no job's actions and is refused: the API cannot run a configd action now.
put_scheduled_job(): command is a configd action (longest one configd offers that the command starts with), the words after it its parameters; unknown actions, @reboot, run_as other than root, multi-line commands and parameters with blanks, quotes or backslashes are refused (ScheduledJobRefused). The schedule is written as its five fields, aliases expanded, month/weekday names as numbers (OPNsense's field masks take no names). OPNsense validation errors become ScheduledJobRefused.
delete_scheduled_job(): only application jobs, via del_job/<uuid> + reconfigure.
get_scheduled_job_commands(): the configd actions a job can run (GET /api/cron/settings/get_job, blank job), [{"command", "description"}]; an empty list raises (configd did not answer).
Every write reads the job again and raises ScheduledJobChanged when its digest differs.
napalm-device-types>=4.26.0; README method table and a short section; CHANGELOG.
opnsense.py stays at its recorded size: the redundant import re as _re in manage_service goes.
tests/unit/test_scheduled_jobs.py: 61 tests over synthetic API answers in the shape of OPNsense 26.7 (admin, IDS-registered, application, with parameters, invalid marker); new module at 100% coverage, suite 549 passed, 85% total.
ruff format/check, mypy (strict for the new module), napalm-standard check and ratchet, bandit: clean.
Not tried on a firewall yet.
## Summary
Scheduled jobs on OPNsense through the cron API: every cron job of config.xml is read with who owns it, any job can be enabled and disabled, and an application's own jobs can be written and deleted. A job's command is a configd action, validated against what configd offers.
## Changes
- New `napalm_opnsense/scheduled_jobs.py` with `OPNsenseScheduledJobsMixin`, mixed into `OPNsenseDriver`.
- `get_scheduled_jobs()`: one `GET /api/cron/settings/get` (it carries the selected configd action; `search_jobs` shows its display text). `key=opnsense:<uuid>`, `kind=cron`, `source=config.xml`, `run_as=root`, `schedule_kind=cron`. Origin other than `cron` is `platform`; a description starting with `napalm-scheduled-job: <name>` is `application` (name and the rest as description); everything else `admin`. An answer without its jobs raises `ValueError`. `time_zone` is `None` (the driver does not read the system settings).
- `manage_scheduled_job()`: enable/disable via `toggle_job/<uuid>/1|0` + `cron/service/reconfigure`. `run` is in no job's `actions` and is refused: the API cannot run a configd action now.
- `put_scheduled_job()`: `command` is a configd action (longest one configd offers that the command starts with), the words after it its parameters; unknown actions, `@reboot`, `run_as` other than root, multi-line commands and parameters with blanks, quotes or backslashes are refused (`ScheduledJobRefused`). The schedule is written as its five fields, aliases expanded, month/weekday names as numbers (OPNsense's field masks take no names). OPNsense validation errors become `ScheduledJobRefused`.
- `delete_scheduled_job()`: only `application` jobs, via `del_job/<uuid>` + `reconfigure`.
- `get_scheduled_job_commands()`: the configd actions a job can run (`GET /api/cron/settings/get_job`, blank job), `[{"command", "description"}]`; an empty list raises (configd did not answer).
- Every write reads the job again and raises `ScheduledJobChanged` when its digest differs.
- `napalm-device-types>=4.26.0`; README method table and a short section; CHANGELOG.
- `opnsense.py` stays at its recorded size: the redundant `import re as _re` in `manage_service` goes.
## Related Issue
Closes #43
Part of NetOrk/netork#1933
## Testing
- `tests/unit/test_scheduled_jobs.py`: 61 tests over synthetic API answers in the shape of OPNsense 26.7 (admin, IDS-registered, application, with parameters, invalid marker); new module at 100% coverage, suite 549 passed, 85% total.
- ruff format/check, mypy (strict for the new module), `napalm-standard check` and `ratchet`, bandit: clean.
- Not tried on a firewall yet.
OPNsense keeps its cron jobs in its configuration and runs each as a
configd action, so the POSIX implementation does not fit: the driver has
no shell, and a job's command is not a shell line. The cron API reads and
writes them instead.
get_scheduled_jobs reads every job in one request (/api/cron/settings/get,
which carries the selected action rather than its display text). A job
another component registered is platform, one written by
put_scheduled_job carries the napalm-scheduled-job marker in its
description and is application, the rest admin. Every job can be enabled
and disabled; only an application's job is edited or deleted.
put_scheduled_job takes a configd action as command and refuses one
configd does not offer; get_scheduled_job_commands lists them. Running a
job now is refused: the API cannot run a configd action. Every write
reads the job again and refuses one whose digest changed.
Parameters are written one per line and only without blanks, quotes or
backslashes: OPNsense up to 26.1 splits them as a shell would, 26.7 takes
a line per argument, and only such arguments mean the same to both.
Requires napalm-device-types 4.26.0.
Closes#43
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Scheduled jobs on OPNsense through the cron API: every cron job of config.xml is read with who owns it, any job can be enabled and disabled, and an application's own jobs can be written and deleted. A job's command is a configd action, validated against what configd offers.
Changes
napalm_opnsense/scheduled_jobs.pywithOPNsenseScheduledJobsMixin, mixed intoOPNsenseDriver.get_scheduled_jobs(): oneGET /api/cron/settings/get(it carries the selected configd action;search_jobsshows its display text).key=opnsense:<uuid>,kind=cron,source=config.xml,run_as=root,schedule_kind=cron. Origin other thancronisplatform; a description starting withnapalm-scheduled-job: <name>isapplication(name and the rest as description); everything elseadmin. An answer without its jobs raisesValueError.time_zoneisNone(the driver does not read the system settings).manage_scheduled_job(): enable/disable viatoggle_job/<uuid>/1|0+cron/service/reconfigure.runis in no job'sactionsand is refused: the API cannot run a configd action now.put_scheduled_job():commandis a configd action (longest one configd offers that the command starts with), the words after it its parameters; unknown actions,@reboot,run_asother than root, multi-line commands and parameters with blanks, quotes or backslashes are refused (ScheduledJobRefused). The schedule is written as its five fields, aliases expanded, month/weekday names as numbers (OPNsense's field masks take no names). OPNsense validation errors becomeScheduledJobRefused.delete_scheduled_job(): onlyapplicationjobs, viadel_job/<uuid>+reconfigure.get_scheduled_job_commands(): the configd actions a job can run (GET /api/cron/settings/get_job, blank job),[{"command", "description"}]; an empty list raises (configd did not answer).ScheduledJobChangedwhen its digest differs.napalm-device-types>=4.26.0; README method table and a short section; CHANGELOG.opnsense.pystays at its recorded size: the redundantimport re as _reinmanage_servicegoes.Related Issue
Closes #43
Part of NetOrk/netork#1933
Testing
tests/unit/test_scheduled_jobs.py: 61 tests over synthetic API answers in the shape of OPNsense 26.7 (admin, IDS-registered, application, with parameters, invalid marker); new module at 100% coverage, suite 549 passed, 85% total.napalm-standard checkandratchet, bandit: clean.