CoolFace
Apppublic

revanth-3995/rl-devsecops-openenv-test

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

RL-Based DevSecOps OpenEnv Environment

๐Ÿš€ Overview

This project implements a DevSecOps simulation environment compatible with OpenEnv for reinforcement learning-based security decision-making.

It simulates a CI/CD pipeline where an agent performs security-related actions such as detecting secrets, triaging vulnerabilities, and making deployment decisions based on risk levels.


๐Ÿ—๏ธ Architecture

text
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚      RL Agent / Policy     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚ action
             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   DevSecOps Gym Env        โ”‚
โ”‚ (task + severity state)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚ reward + next state
             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   FastAPI Server (app.py)  โ”‚
โ”‚  /reset  /step  /state     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚ HTTP
             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Hugging Face Space (Docker)โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“‚ Project Structure

  • โ€”devsecops_env.py: Core Gymnasium environment defining state, actions, and rewards for the DevSecOps simulation.
  • โ€”app.py: FastAPI application exposing the environment via HTTP endpoints (/reset, /step, /state).
  • โ€”inference.py: Dummy inference script to demonstrate how an agent interacts with the environment.
  • โ€”openenv.yaml: OpenEnv metadata specification.
  • โ€”Dockerfile: Containerizes the FastAPI server for easy deployment (e.g., Hugging Face Spaces).

๐Ÿง  Tasks Implemented

1. Secret Scanning

  • โ€”Detect exposed credentials in code
  • โ€”Actions: DETECT, REPORT, APPROVE

2. CVE Triage

  • โ€”Analyze vulnerability severity and prioritize fixes
  • โ€”Actions: BLOCK, PATCH, ESCALATE, APPROVE

3. Pipeline Security Audit

  • โ€”Multi-stage decision-making across pipeline stages
  • โ€”Actions: BLOCK, PATCH, ESCALATE, APPROVE, ROLLBACK

โš™๏ธ Action Space

python
["DETECT", "REPORT", "BLOCK", "PATCH", "ESCALATE", "APPROVE", "ROLLBACK"]

๐Ÿ“Š Observation Space

json
{
  "task": "int (0โ€“2)",
  "severity": "float (1โ€“10)"
}

๐Ÿ› ๏ธ Installation & Usage

1. Local Setup

Create a virtual environment and install dependencies:

bash
python -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate
pip install -r requirements.txt

2. Running FastAPI Server

The application exposes a REST API to interact with the environment:

bash
uvicorn app:app --host 0.0.0.0 --port 7860

Endpoints:

  • โ€”POST /reset: Resets the environment state.
  • โ€”POST /step: Takes an action (e.g., {"action": 0}) and returns the next state, reward, and done flag.
  • โ€”GET /state: Retrieves the current state.

3. Running Dummy Inference

Test the environment locally using the dummy agent:

bash
python inference.py

4. Docker Deployment

You can also run this environment via Docker:

bash
docker build -t devsecops-env .
docker run -p 7860:7860 devsecops-env