Skip to main content

A Django app for remote execution of management commands.

Project description

Django Middle Management

It's usually a bad idea to connect to production servers to run one-off or repetitive maintenance commands. There may not be any auditing, commands and payloads can easily have mistakes, and a rogue developer could get away with almost anything. With django-middle-management, though, you don't have to allow shell access to your production servers while still being able to run commands on them.

This is a small library that makes it possible to securely and remotely execute Django management commands via POST requests. Commands must be merged into your code base before they're eligible to be used. They must also be listed in settings.py or they cannot be triggered. Finally, requests must be authenticated by your system before any command can be given.

Warning: This project runs management commands remotely but synchronously. Long-running commands will potentially block your server from responding to other requests. Using a task queue like Celery is recommend for anything that may take more than a few milliseconds.

Installation

pip install django-middle-management

Add the package to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...,
    "middle_management",
    ...
]

Add the URLs to your project's urls.py:

from middle_management.urls import manage_urls

urlpatterns = [
    ...
] + manage_urls

You'll need to write a new management command or select an existing one to expose. Finally, add that command name to an allowlist of commands in settings.py:

MANAGE_ALLOW_LIST = ["noop"]

Usage

To execute a management command, make a POST request to the /__manage__/<command name> endpoint with a payload similar to the following:

{
    "data": {
        "arg1": "value1",
        "arg2": "value2"
    }
}

Your POST must also contain a valid HTTP_AUTHORIZATION header with the value Bearer <token>. The final request will look something like:

curl -XPOST \
  -H 'Authorization: Bearer not-a-real-token' \
  -H "Content-type: application/json" \
  -d '{"data": { "arg1": "value1", "arg2": "value2" }}' \
  'https://example.com/__manage__/noop'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_middle_management-0.1.2.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_middle_management-0.1.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file django_middle_management-0.1.2.tar.gz.

File metadata

File hashes

Hashes for django_middle_management-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fe0f31e5ed5714953f587be97e6e1a691d70bf93bfb01f521ed92334c145dcd9
MD5 27c1aba6eb15f0ecc7893f0e7a5253a0
BLAKE2b-256 f05d51184d9ba1fafe6a82ef40be0e0e22c767d0e06d802a2634abf768d5cdd0

See more details on using hashes here.

File details

Details for the file django_middle_management-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_middle_management-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6e2f10d3088c12e2a80f0d5ffaf3b3de34ed67e746aeca62a4e883b7e7b453c6
MD5 6bc24e95503a0f9fcee20132c973d740
BLAKE2b-256 0924c79df8b0dbc0d1997b47e021a88bf0dd4bc433c52d39fc7e98cd85314ae0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page