revanth-3995/rl-devsecops-openenv
RL-Based DevSecOps OpenEnv
๐ Overview
This project implements a DevSecOps simulation environment properly packaged for the Meta PyTorch Hackathon x Scaler School of Technology. It simulates a CI/CD pipeline where an agent dynamically performs security actions (detecting secrets, triaging vulnerabilities) based on continuous risk levels and CVSS scores.
It natively supports a dual-pronged AI architecture:
- PyTorch TorchRL (PPO) architectures designed for offline local training, proving the environment is solvable and mathematically sound.
- OpenAI LiteLLM Proxies integrated directly into the
inference.pyscript, serving as a standardized benchmark to evaluate zero-shot frontier LLM reasoning capabilities in DevOps contexts.
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ LiteLLM / ActorCritic โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ action
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DevSecOps Gym Env โ
โ (task + CVSS state array) โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ reward + next state
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FastAPI Server (uvicorn) โ
โ /reset /step /state โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ HTTP
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Hugging Face Space (Docker)โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๐ Comprehensive Project Structure
Environment (env/)
env.py: Core Gymnasium environment, generating pipeline states and evaluating rewards bounded strictly by[0.01, 0.99].models.py: Pydantic BaseModels (ActionRequest,Observation) to enforce strict API typing.graders.py: Clamping and bounding logic functions ensuring compliance with Hackathon constraints.tasks.py: Helpers for randomly generating DevSecOps task assignments (Secret Scanning, CVE Triage).
API Server (server/)
app.py: FastAPI application wrapping the Gym environment to expose HTTP hooks (/reset,/step,/state). Contains themain()uvicorn entry point.
Agents (agent/)
policy.py: PyTorch model architectures (ActorCriticclasses).policy.pt: Serialized PyTorch weights from the baseline trained RL model.
Tooling & Inference
inference.py: Target validation script. Evaluates environment states using the injected Hackathon Proxy LLM (API_BASE_URLandHF_TOKEN) via theopenaiclient.train_ppo.py: Dedicated script to offline-train the PPO PyTorch agent against the DevSecOps Gym.validate-submission.sh: Local script for executing OpenEnv structural validation tests.openenv.yaml: OpenEnv multi-mode operational metadata.pyproject.toml/uv.lock: Project packaging definitions for rigorous dependency mapping (including FastApi, Uvicorn, Torch, and OpenAI).Dockerfile: OpenEnv Hugging Face image instruction.
๐ง DevSecOps Tasks Implemented
1. Secret Scanning
- Detect exposed credentials or misconfigured keys in code branches.
- Actions:
DETECT,REPORT,APPROVE
2. CVE Triage
- Analyze vulnerability severity via temporal and environmental heuristics.
- Actions:
BLOCK,PATCH,ESCALATE,APPROVE
3. Pipeline Security Audit
- Multi-stage decision-making across CI deployment stages.
- Actions:
BLOCK,PATCH,ESCALATE,APPROVE,ROLLBACK
โ๏ธ Action Space
["DETECT", "REPORT", "BLOCK", "PATCH", "ESCALATE", "APPROVE", "ROLLBACK"]๐ Observation Space
The environment tracks complex pipeline states by integrating mocked CVSS v3.1 vector calculations:
{
"task": "Discrete(3)",
"severity": "Box(1.0-10.0)",
"cvss_base": "Box(0.0-10.0)",
"cvss_temporal": "Box(0.0-10.0)",
"cvss_environmental": "Box(0.0-10.0)"
}๐ ๏ธ Usage
1. Initializing Environment
Use standard python virtual environments or uv to leverage the packaged pyproject.toml:
python -m venv .venv
source .venv/bin/activate
pip install -e .2. Running FastAPI Target Server
The server runs out of the modular structure utilizing uvicorn:
uvicorn server.app:app --host 0.0.0.0 --port 78603. Zero-Shot LLM Benchmark Inference
Execute the inference script to evaluate an integrated LLM via the proxy endpoint:
export API_BASE_URL="http://your-litellm-proxy..."
export HF_TOKEN="your-hf-token"
export MODEL_NAME="gpt-4.1-mini"
python inference.py(Handles missing `HF_TOKEN` gracefully to align with OpenEnv failure-fast testing)
4. Validating Structure Locally
Verify the environment packaging using the deployment checker:
bash validate-submission.sh