Docker Namespace Injector
This Python script allows you to inject commands into specified Docker namespaces of a running or healthy Docker container. It is operated through various command-line options.
Overview
The Docker Namespace Injector script offers the following functionalities:
- Identifying a target Docker container using labels.
- Validation checks to ensure that the Docker container state is either 'healthy' or 'running'.
- The ability to set
SIGINTandSIGTERMsignal handlers for graceful shutdown upon user request. - Command injections into specified Docker namespaces of the target Docker container.
- Monitoring the running state of the Docker container and the injected process, and terminating the process when necessary.
Usage
You can control the script execution via the command line:
--label: Specify the label used to identify the target Docker container. This parameter can be defined in either the 'label' or 'label=value' or 'label:value' formats.--require: Set the requirement for the Docker container’s state. This should be either 'healthy' or 'running'.--ns: Specify the namespaces to inject. These should be divided by a comma (e.g., '--ns=net,uts').--proc: Path to the proc filesystem. The default setting is '/proc'.--cmd: Define the command to run in the Docker container’s namespace.
Most of the command-line parameters can be defined using environment variables:
INJECTOR_LABELINJECTOR_REQUIREINJECTOR_NSINJECTOR_PROCINJECTOR_CMD
Code Structure
The script comprises several functions, each one providing a specific operational feature:
target_valid(target: docker.models.containers.Container, require: str) -> bool: This function checks if the Docker container meets the specified requirement.handle_stop(sig_num, frame): Handles the stop signal (SIGINT or SIGTERM) and triggers the required processes.setup_signals(): Sets up signal handlers for SIGINT and SIGTERM signals.shutdown_child(process: subprocess.Popen): Ensures a graceful shutdown of a child process that has been triggered by the script.
The inject(label, require, ns, proc, cmd) function initiates the main functionality of the script, using all the helper functions defined above.
Running the Code
Run the script using the following command:
```bash python3 script.py --label=label=value --require=healthy --ns=net --proc=/proc --cmd="command_to_run" ```
Make sure to replace the label=value parameter with the label of your target Docker container, net with the namespace to inject the commands, and command_to_run with the specific command you want to run in the selected namespace.
Metadata
Release files for docker-injector 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| docker_injector-0.1.9.tar.gz | 3.8 kB | Without provenance | Details for docker_injector-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| docker_injector-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for docker_injector-0.1.9-py3-none-any.whl |
Total release size: 8.6 kB
Release files / docker_injector-0.1.9.tar.gz
| Download URL | docker_injector-0.1.9.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
39493992a80e4ad860e87ab8882ba067900e3de1602a414127bbe9bd3d1762b5
|
|
BLAKE2b-256 checksum How to use checksums |
9a15b1c0fe9d1695e490b0ccab26b419b3c01994707aedcc20311246d633c3cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Release files / docker_injector-0.1.9-py3-none-any.whl
| Download URL | docker_injector-0.1.9-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
de6253b28a50f5d9612518a368f4db6b9e99cb24bcab8649b6f83f045e07b0e7
|
|
BLAKE2b-256 checksum How to use checksums |
7e10ff8540705ee89b4dd4949aa4c4f52538ddd596a30b51bf9a1295e460a6d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Security for docker-injector 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.