display page for this readme
https://unaveragetech.github.io/flask-container-management/
# Flask Python Environment Container Management
## Overview
This project is a Flask-based web application that allows you to create, manage, and monitor isolated Python environments in Docker containers. Each container is sandboxed from others and the host system, ensuring safe and independent execution environments for users. The containers are accessible via webhooks, allowing users to interact with their Python environments through a web interface. The system also provides an admin dashboard for monitoring HTTP/HTTPS requests, managing resources, and setting limits on each container.
## Features
### 1. **Container Management**
- Create fully isolated Python containers.
- Each container is pre-configured with basic tools, including `pip`, allowing users to install verified Python packages.
- Containers are spun up using Docker, each running its own Python environment.
- Container isolation ensures that no user can access or interfere with another container.
- Containers have resource limits (memory and CPU), configurable by the admin.
### 2. **Monitored Webhooks**
- HTTP/HTTPS requests sent from containers are monitored and sanitized to ensure security.
- All outgoing requests are logged, including details such as method, URL, headers, and body content.
- Admins can review all monitored requests through a web-based interface.
### 3. **Resource Control**
- Admins can configure limits for each container, including memory (`mem_limit`) and CPU (`cpu_quota`).
- Containers are restricted from accessing the internet except for verified sources when installing `pip` packages.
### 4. **Admin Dashboard**
- The system includes an admin panel where admins can:
- View the status of all active containers.
- Monitor and review all HTTP/HTTPS requests sent by the containers.
- Set or modify resource limits for each container.
### 5. **Pip Package Verification**
- The system supports installing Python packages via `pip`, but only verified packages can be installed.
- Admins can maintain a list of allowed packages, ensuring that users cannot install potentially harmful or unverified packages.
## Getting Started
### Prerequisites
Before you start, ensure that Docker is installed on your system, and that you have Python 3.9+ and `pip` installed.
### Setup Instructions
1. **Clone the repository**:
```bash
git clone https://github.com/unaveragetech/flask-container-management.git
cd flask-container-management-
Install the required Python dependencies:
pip install -r requirements.txt
-
Build the Docker image:
Run the following command to build the Docker image. This image is based on Python 3.9 and includes
pippre-installed.docker build -t my-python-container . -
Run the Flask app:
After building the image, start the Flask application using:
python app.py
-
Access the Admin Dashboard:
- Admin Monitoring (JSON):
http://localhost:5000/admin/monitoring - Admin Monitoring (HTML):
http://localhost:5000/admin/monitoring/page
Use these pages to monitor all outgoing HTTP/HTTPS requests and manage the system.
- Admin Monitoring (JSON):
- Containers are created with Docker’s
python:3.9-slimbase image. - Each container is configured with 512MB of memory and a CPU limit of 0.5 cores by default. These values can be adjusted by the system admin.
- Containers can be created, started, and stopped through the Flask API. The admin can manage container resources using the
/admin/container/<container_id>/limitsendpoint.
- All outgoing requests from containers are intercepted and logged.
- Admins can view these requests in both JSON and HTML formats.
- The logs include information such as:
- HTTP method (GET, POST, etc.)
- URL requested
- Headers and body content
- Timestamp of the request
- The system allows the admin to set limits on container memory and CPU usage. This ensures that no container consumes excessive resources.
- Admins can update container limits through the
/admin/container/<container_id>/limitsroute.
- By default, containers have limited access to external networks to ensure security.
- However, verified
pippackages can still be installed within containers. The list of verified packages is managed within the system.
- Network Isolation: Containers are restricted to a specific network, limiting external communication.
- Request Monitoring: Outgoing HTTP/HTTPS requests are sanitized and logged, allowing for auditability.
- Pip Package Control: Only verified packages can be installed, ensuring that users cannot install arbitrary or harmful software.
| Endpoint | Method | Description |
|---|---|---|
/create_container |
POST | Create a new Python environment container. |
/install_package |
POST | Install a verified pip package in a container. |
/container/<container_id>/status |
GET | Retrieve the status of a container. |
/admin/monitoring |
GET | View logs of monitored HTTP/HTTPS requests (JSON). |
/admin/monitoring/page |
GET | View logs of monitored HTTP/HTTPS requests (HTML). |
/admin/container/<container_id>/limits |
POST | Set memory and CPU limits for a container. |
To create a new container, send a POST request to /create_container with the following JSON body:
{
"name": "python_container_1"
}To install a verified pip package, send a POST request to /install_package with the following JSON body:
{
"container_id": "your-container-id",
"package_name": "requests"
}Feel free to open issues or submit pull requests if you have improvements, bug fixes, or other suggestions for this project.
This project is licensed under the MIT License.
You can clone the project from the repository here:
#(https://github.com/unaveragetech/flask-container-management.git)
(https://github.com/unaveragetech/flask-container-management.git)