Skip to content

Implemented restricted task scheduler#947

Merged
chrismaddalena merged 8 commits into
masterfrom
feature/scheduler-allowlist
Jul 24, 2026
Merged

Implemented restricted task scheduler#947
chrismaddalena merged 8 commits into
masterfrom
feature/scheduler-allowlist

Conversation

@chrismaddalena

Copy link
Copy Markdown
Collaborator

CHANGELOG

[Unreleased]

Security

  • Restricted Django Q scheduled tasks to a server-controlled allowlist (Closes [Feature] Allowlist for Scheduled Tasks #911)
    • The admin panel now exposes only approved functions, Slack notification hooks, and validated task arguments
    • Optional system commands must be configured as fixed argument vectors on the server and run without a shell
    • Schedule saves, queue submissions, result hooks, and worker execution enforce the policy independently
    • Added audit_django_q_policy to identify or pause existing schedules that do not satisfy the configured policy

Copilot AI review requested due to automatic review settings July 23, 2026 21:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread ghostwriter/home/django_q_integration.py Outdated
Comment thread ghostwriter/home/django_q_policy.py Outdated
Comment thread ghostwriter/home/admin.py Outdated
@augmentcode

augmentcode Bot commented Jul 23, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: 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:

  • Adds settings-based policy mappings for allowed schedule tasks, internal tasks, permitted result hooks, and optional fixed system commands.
  • Implements restricted Django Q scheduler/worker wrappers that validate schedules and queued tasks before import and execution.
  • Installs policy enforcement via Django signals (schedule pre-save validation, task pre-enqueue validation) and a guarded result-hook dispatcher.
  • Replaces the Django Q admin views for Schedule/Success/Failure with restricted versions that only expose allowlisted functions/hooks and support policy-aware resubmission.
  • Adds a fixed command runner task that executes configured argv vectors with shell=False and a constrained environment.
  • Adds audit_django_q_policy management command to report and optionally pause disallowed existing schedules.
  • Updates background-task documentation to describe the allowlist model and how to configure/audit it.
  • Adds tests covering policy parsing/validation, admin restrictions, scheduler/worker enforcement, hook restrictions, and fixed-command execution.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread ghostwriter/home/django_q_policy.py
Comment thread DOCS/features/background-tasks/scheduled-tasks.mdx Outdated
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.01865% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.17%. Comparing base (941325e) to head (6d217bb).

Files with missing lines Patch % Lines
ghostwriter/home/django_q_policy.py 96.51% 9 Missing ⚠️
ghostwriter/home/django_q_cluster.py 93.49% 8 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI review requested due to automatic review settings July 23, 2026 23:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the or expression so the unpack uses the fallback dict when task.kwargs is falsy.
                **task.kwargs or {},

Comment thread ghostwriter/home/admin.py Outdated
Copilot AI review requested due to automatic review settings July 24, 2026 00:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Comment thread ghostwriter/home/admin.py
Comment thread ghostwriter/home/django_q_cluster.py
@chrismaddalena
chrismaddalena merged commit a13046e into master Jul 24, 2026
9 of 11 checks passed
@chrismaddalena
chrismaddalena deleted the feature/scheduler-allowlist branch July 24, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Allowlist for Scheduled Tasks

2 participants