File size: 13,931 Bytes
762be3a 547b872 762be3a 547b872 762be3a 547b872 762be3a 547b872 762be3a 547b872 762be3a 547b872 762be3a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | # βοΈπ‘οΈ CloudSecurityAuditor β OpenEnv Environment
## Complete Application Documentation
---
## 1. What Is This Application?
**CloudSecurityAuditor** is a standardized AI agent environment that simulates real-world cloud security auditing scenarios. It is built using the [OpenEnv](https://github.com/openenv) specification β an open standard for creating reproducible, programmable environments where AI agents can be trained, tested, and benchmarked.
Think of it as a **virtual cybersecurity lab**: instead of risking real cloud infrastructure, an AI agent (or a human) can interact with a mock cloud environment that contains intentional security vulnerabilities. The agent must discover, analyze, and remediate those vulnerabilities to earn a reward.
### Who Is This For?
| Audience | Use Case |
|---|---|
| **AI Researchers** | Benchmark LLM-based security agents on structured tasks |
| **Security Engineers** | Practice cloud audit workflows in a safe sandbox |
| **Students** | Learn about S3 public buckets, EC2 security groups, and IAM log analysis |
| **Hackathon Participants** | Demonstrate agent-environment interaction for Meta/OpenEnv challenges |
---
## 2. Architecture Overview
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BROWSER (UI) β
β ββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Sidebar β β Resource Gridβ β Execution Logβ β
β β (Tasks) β β (S3 / EC2) β β (Terminal) β β
β ββββββββββββ ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ
β HTTP (REST)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Server (app.py) β
β βββββββββββ ββββββββββββ βββββββββββββββββββββ β
β β /reset β β /step β β /state / /docs β β
β ββββββ¬βββββ ββββββ¬ββββββ βββββββββββββββββββββ β
β β β β
β βΌ βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββ β
β β CloudAuditEnv (environment.py) β β
β β βββββββββββ ββββββββββ ββββββββββββββββ β β
β β β S3 Data β βEC2 Dataβ β Auth Logs β β β
β β βββββββββββ ββββββββββ ββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
---
## 3. File Structure
```
scaler/
βββ server/
β βββ app.py # FastAPI entry point, static file serving
β βββ environment.py # Core environment logic (reset, step, state)
β βββ models.py # Pydantic/dataclass models (Action, Observation, State)
β βββ tasks.py # Task definitions (Easy, Medium, Hard)
β βββ static/
β βββ index.html # Dashboard UI layout
β βββ index.css # Dark-mode cybersecurity theme
β βββ app.js # Frontend logic & API interaction
βββ scripts/
β βββ baseline_inference.py # Example agent that solves the Easy task
βββ openenv.yaml # OpenEnv specification file
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker deployment configuration
βββ README.md # Quick-start guide
```
---
## 4. The Environment Engine (`environment.py`)
The heart of the application is the `CloudAuditEnv` class. It implements three methods required by the OpenEnv spec:
### `reset(task_id) β Observation`
- Reinitializes the mock infrastructure (S3 buckets, EC2 instances, auth logs).
- Sets the active task (easy, medium, or hard).
- Returns an initial observation with status info.
### `step(action) β Observation`
- Accepts a `CloudAction` and executes it against the mock infrastructure.
- Returns an updated `CloudObservation` containing discovered resources, details, logs, and a reward signal.
- Automatically terminates the episode after 20 steps (truncation).
### `state() β CloudState`
- Returns internal metadata: episode ID, step count, task ID, completion status, and cumulative score.
---
## 5. Mock Infrastructure
The environment simulates the following cloud resources:
### S3 Buckets (3 total)
| ID | Region | Public? | Environment |
|---|---|---|---|
| `prod-data-001` | us-east-1 | β
Yes | prod |
| `prod-logs-002` | us-east-1 | β No | prod |
| `dev-test-01` | us-west-2 | β
Yes | dev |
### EC2 Instances (2 total)
| ID | Type | State | Environment | Open Ports |
|---|---|---|---|---|
| `i-0abcdef1234567890` | t2.micro | running | dev | 22 (SSH), **3389 (RDP)** β οΈ |
| `i-0987654321fedcba0` | m5.large | running | prod | 443 (HTTPS) |
### Auth Logs (`auth-logs`)
| Timestamp | User | Action | IP |
|---|---|---|---|
| 2026-04-05T10:00:00Z | admin | Login | 1.1.1.1 |
| 2026-04-05T10:15:00Z | iam-role-01 | **DeleteStorage** β οΈ | **192.168.1.50** |
| 2026-04-05T10:30:00Z | user-02 | ListBuckets | 2.2.2.2 |
---
## 6. Action Space
The agent interacts with the environment using a `CloudAction` object. Available action types:
| Action | Parameters | Description |
|---|---|---|
| `list` | `resource_type` (s3, ec2) | Lists all resources of a given type |
| `describe` | `resource_id` | Returns full details for a specific resource |
| `modify` | `resource_id`, `patch` | Updates resource configuration (e.g., security group rules) |
| `logs` | `resource_id` (e.g., auth-logs) | Fetches log entries for a service |
| `submit` | `answer` | Submits the final answer for grading |
### Example Actions (via Dashboard or API)
```bash
# List all S3 buckets
list s3
# Describe an EC2 instance
describe i-0abcdef1234567890
# Fetch authentication logs
logs auth-logs
# Submit an answer for Easy task
submit prod-data-001
# Submit an answer for Hard task
submit 192.168.1.50
```
---
## 7. Observation Space
Every `step()` and `reset()` returns a `CloudObservation`:
| Field | Type | Description |
|---|---|---|
| `resources` | `List[Dict]` | List of discovered resource records |
| `details` | `Dict` | Full metadata for a single described resource |
| `logs` | `List[Dict]` | Log entries (timestamp, user, action, IP) |
| `status` | `str` | Human-readable status message |
| `info` | `str` | Additional context (e.g., grading feedback) |
| `reward` | `float` | Scalar reward (0.0 to 1.0) |
| `done` | `bool` | Whether the episode has ended |
---
## 8. Tasks & Grading
### Task 1: Easy β S3 Public Audit
**Goal:** Identify all S3 buckets that are both `public: true` AND tagged `env: prod`.
| Step | Action | Expected Result |
|---|---|---|
| 1 | `list s3` | Returns 3 buckets |
| 2 | Filter for public + prod | `prod-data-001` |
| 3 | `submit prod-data-001` | Reward: **1.0** β
|
---
### Task 2: Medium β EC2 Security Patch
**Goal:** Find EC2 instance `i-0abcdef1234567890` which has port 3389 (RDP) open to `0.0.0.0/0`, and close it by modifying the security group to only allow port 22.
| Step | Action | Expected Result |
|---|---|---|
| 1 | `list ec2` | Returns 2 instances |
| 2 | `describe i-0abcdef1234567890` | Shows RDP port open |
| 3 | `modify i-0abcdef1234567890` with patch `{"rules": [{"port": 22, "cidr": "0.0.0.0/0"}]}` | Reward: **1.0** β
|
---
### Task 3: Hard β IAM Log Forensic
**Goal:** A rogue IAM role (`iam-role-01`) has performed unauthorized actions. Analyze the `auth-logs` to identify the IP address that performed `DeleteStorage`.
| Step | Action | Expected Result |
|---|---|---|
| 1 | `logs auth-logs` | Returns 3 log entries |
| 2 | Find `DeleteStorage` action | IP: `192.168.1.50` |
| 3 | `submit 192.168.1.50` | Reward: **1.0** β
|
---
## 9. API Reference
Base URL: `http://localhost:7860`
### `POST /reset`
Reset the environment to a specific task.
**Request:**
```json
{ "task_id": "easy" }
```
**Response:**
```json
{
"observation": {
"resources": null,
"details": null,
"status": null,
"logs": null,
"info": "Environment reset. Task: easy"
},
"reward": 0.0,
"done": false
}
```
### `POST /step`
Execute an action in the environment.
**Request:**
```json
{
"action": {
"action": "list",
"resource_type": "s3"
}
}
```
**Response:**
```json
{
"observation": {
"resources": [
{ "id": "prod-data-001", "region": "us-east-1", "public": true, "tags": { "env": "prod" } },
{ "id": "prod-logs-002", "region": "us-east-1", "public": false, "tags": { "env": "prod" } },
{ "id": "dev-test-01", "region": "us-west-2", "public": true, "tags": { "env": "dev" } }
],
"status": "Listed 3 s3 resources."
},
"reward": 0.0,
"done": false
}
```
### `GET /state`
Get internal environment state.
**Response:**
```json
{
"episode_id": "a1b2c3d4-...",
"step_count": 3,
"task_id": "easy",
"is_completed": false,
"score": 0.0
}
```
### `GET /docs`
Interactive Swagger UI for API exploration.
### `GET /`
Dashboard UI (the web interface).
---
## 10. Dashboard UI
The application includes a premium dark-mode cybersecurity dashboard accessible at `http://localhost:7860`.
### Features
- **Sidebar Task Selector** β Switch between Easy, Medium, and Hard challenges with one click.
- **Infrastructure Overview** β Visual resource cards for S3 buckets and EC2 instances. Vulnerable resources are highlighted with red borders and blinking status dots.
- **Execution Log** β Terminal-style console showing timestamped action logs with color-coded entries (blue for actions, green for system, yellow for rewards, red for errors).
- **Manual Command Input** β Type commands like `list s3`, `describe i-0abcdef1234567890`, `logs auth-logs`, or `submit prod-data-001` directly in the dashboard.
- **Live Stats HUD** β Displays current task name, cumulative reward, and environment status (Active/Completed).
### Design
- **Theme:** Cyber-noir dark mode with deep navy background (#0a0e14)
- **Accents:** Neon cyan (#00f5ff) for primary elements
- **Typography:** Inter (body), Outfit (headings), JetBrains Mono (code/logs)
- **Effects:** Glassmorphism panels, fade-in card animations, pulsing vulnerability indicators
---
## 11. Running the Application
### Local Development
```bash
# Install dependencies
pip install -r requirements.txt
# Start the server
python -m server.app
# Open in browser
open http://localhost:7860
```
### Running the Baseline Agent
```bash
# Solves the Easy task automatically
python scripts/baseline_inference.py
```
### Docker Deployment
```bash
# Build the image
docker build -t cloud-security-auditor .
# Run the container
docker run -p 7860:7860 cloud-security-auditor
```
### Hugging Face Spaces Deployment
1. Create a new Space on Hugging Face.
2. Select **Docker** as the SDK.
3. Upload the repository contents (including `openenv.yaml` and `Dockerfile`).
4. The entrypoint is automatically set via `openenv.yaml`.
---
## 12. Technology Stack
| Component | Technology |
|---|---|
| Backend | Python 3.10, FastAPI, Uvicorn |
| Environment | openenv-core β₯ 0.1.1 |
| Data Models | Python dataclasses |
| Frontend | Vanilla HTML/CSS/JS |
| Fonts | Google Fonts (Inter, Outfit, JetBrains Mono) |
| Deployment | Docker, Hugging Face Spaces |
---
## 13. OpenEnv Specification (`openenv.yaml`)
```yaml
name: cloud-security-auditor
version: "0.2.0"
description: "A real-world cloud security audit environment for AI agents."
hardware:
tier: "cpu-small"
vCPU: 2
RAM: 4Gi
port: 7860
entrypoint: "uvicorn server.app:app --host 0.0.0.0 --port 7860"
tags:
- security
- cloud
- task-based
evaluation:
tasks:
- id: "easy"
name: "S3 Public Audit"
difficulty: "easy"
- id: "medium"
name: "EC2 Security Patch"
difficulty: "medium"
- id: "hard"
name: "IAM Log Forensic"
difficulty: "hard"
```
---
## 14. Extending the Environment
### Adding a New Task
1. Add the task definition to `server/tasks.py`.
2. Add the corresponding mock data to `_initialize_state()` in `environment.py`.
3. Add the grading logic to the `step()` method under `CloudActionType.SUBMIT`.
4. Add a new task button to `index.html` in the sidebar.
### Adding a New Resource Type
1. Add the resource data to `self.resources` in `environment.py`.
2. Add a handler for `CloudActionType.LIST` and `CloudActionType.DESCRIBE` for the new type.
3. Update `detectResourceType()` in `app.js` to render the correct card icon/label.
---
*Built for the Meta Hackathon / OpenEnv Challenge β’ April 2026*
|