Implemented restricted task scheduler#947
Conversation
There was a problem hiding this comment.
Pull request overview
Implements a defense-in-depth, server-side allowlist for Django-Q scheduled tasks in Ghostwriter, reducing the risk of arbitrary callable execution via the Django admin scheduler.
Changes:
- Added server-enforced task/hook/argument policy validation for schedules, enqueue submissions, result hooks, and worker execution.
- Replaced Django-Q scheduler/worker entrypoints with restricted implementations and introduced an audit management command to detect/pause disallowed schedules.
- Updated admin UI, settings defaults, tests, and documentation to reflect the restricted scheduling model (including optional fixed-command execution).
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| ghostwriter/home/tests/test_django_q_policy.py | Comprehensive tests for task policy parsing/validation and restricted scheduler/worker behavior. |
| ghostwriter/home/management/commands/audit_django_q_policy.py | Adds an audit command to report and optionally pause disallowed schedules. |
| ghostwriter/home/django_q_tasks.py | Adds allowlisted task wrappers (e.g., session cleanup) and a fixed-command runner. |
| ghostwriter/home/django_q_policy.py | Implements policy schema, callable path validation, and argument parsing/validation. |
| ghostwriter/home/django_q_integration.py | Installs the enforcement hooks (signals + cluster overrides) and system checks. |
| ghostwriter/home/django_q_cluster.py | Provides restricted scheduler/worker implementations with policy enforcement. |
| ghostwriter/home/apps.py | Installs Django-Q restrictions during app initialization. |
| ghostwriter/home/admin.py | Restricts Django-Q admin to allowlisted functions/hooks and policy-aware task resubmission. |
| DOCS/features/background-tasks/scheduled-tasks.mdx | Documents allowlist-based scheduling, argument rules, fixed commands, and auditing guidance. |
| DOCS/features/background-tasks/prebuilt-tasks.mdx | Updates task docs (names/parameters) to match the allowlisted policy. |
| DOCS/features/background-tasks.mdx | Clarifies that only allowlisted functions can be scheduled. |
| DOCS/features/access-authentication-and-session-controls/session-management.mdx | Updates clearsessions scheduling guidance to use the allowlisted wrapper task. |
| DOCS/development/modifying-code.mdx | Notes that new queued/scheduled tasks must be added to the policy settings. |
| config/settings/base.py | Introduces default task/hook allowlists and internal task policy mappings. |
| CHANGELOG.md | Records the new Django-Q allowlist security feature and audit command. |
🤖 Augment PR SummarySummary: This PR introduces a server-controlled allowlist for Django Q scheduled tasks to prevent administrators from scheduling arbitrary Python callables or unsafe system commands. Changes:
🤖 Was this summary useful? React with 👍 or 👎 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #947 +/- ##
==========================================
- Coverage 93.97% 92.17% -1.81%
==========================================
Files 433 442 +9
Lines 32192 33794 +1602
==========================================
+ Hits 30252 31148 +896
- Misses 1940 2646 +706 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
ghostwriter/home/admin.py:124
- The keyword unpacking expression
**task.kwargs or {}is invalid Python syntax. Wrap theorexpression so the unpack uses the fallback dict whentask.kwargsis falsy.
**task.kwargs or {},
CHANGELOG
[Unreleased]
Security
audit_django_q_policyto identify or pause existing schedules that do not satisfy the configured policy