flask-container-management

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
  1. Install the required Python dependencies:

    pip install -r requirements.txt
    
  2. Build the Docker image:

    Run the following command to build the Docker image. This image is based on Python 3.9 and includes pip pre-installed.

    docker build -t my-python-container .
    
  3. Run the Flask app:

    After building the image, start the Flask application using:

    python app.py
    
  4. 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.

Detailed Features

Container Lifecycle

Monitored HTTP/HTTPS Requests

Resource Management

Verified Pip Packages

Security Measures

API Endpoints

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.

Example: Creating a New Container

To create a new container, send a POST request to /create_container with the following JSON body:

{
  "name": "python_container_1"
}

Example: Installing a Verified Package

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"
}

Contributing

Feel free to open issues or submit pull requests if you have improvements, bug fixes, or other suggestions for this project.

License

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)