You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement Docker host integration for selecting codebases as scan targets. Add new API endpoints for listing running Docker containers and retrieving potential code paths from selected containers. Update documentation to reflect new features and security considerations for Docker socket access. Enhance project creation process to allow users to select codebases directly from local Docker containers, improving usability and efficiency.
For `asset_type` 'git_repository', this can be a Git URL or a local filesystem path to a codebase.
228
+
This includes host paths that are derived from inspecting Docker container volumes,
229
+
allowing direct filesystem scans of codebases running in local containers.
230
+
***`metadata`**: `JSONField(default=dict, blank=True, help_text="Type-specific additional details, e.g., {\"branch\": \"main\"} for git, or {\"source_docker_container_id\": \"abcdef123456\", \"source_docker_container_name\": \"my_app_container\", \"path_in_container\": \"/var/www/html\"} if the identifier path was derived from a Docker container volume.")`
228
231
* Description: Flexible field to store context-specific data for different asset types.
232
+
For assets derived from Docker containers, this could store the original container ID, name,
233
+
and the path within the container for traceability or display purposes.
229
234
***`description`**: `TextField(blank=True, null=True, help_text="Optional description for this target asset.")`
230
235
***`is_active`**: `BooleanField(default=True, help_text="Is this target asset currently active for scanning?")`
These endpoints enable the SecuLite backend (with appropriate permissions and configuration for Docker socket access) to retrieve information about Docker containers running locally on the host. This primarily serves the feature of selecting codebases from Docker volumes as scan targets.
541
+
542
+
**Prerequisites:**
543
+
- The SecuLite backend must be configured to access the host's Docker socket (see `05_docker_setup.md`).
544
+
- The calling user requires appropriate permissions (e.g., `IsAdminUser` or a more specific permission like `CanAccessDockerHostInfo`).
545
+
546
+
#### 3.10.1. List Running Docker Containers
547
+
548
+
*`GET /api/v1/dockerhost/containers/`
549
+
***Description:** Retrieves a list of Docker containers currently running on the host. The information returned should be relevant for identification and selection in the frontend.
* **Description:** For a specific Docker container, retrieves a list of host filesystem paths derived from its volume mounts that could potentially contain codebases. The backend analyzes the container's volume mounts and returns the corresponding host paths.
580
+
* **Path Parameter:**
581
+
* `container_id` (string, required): The ID of the Docker container.
582
+
* **Response Body (200 OK):**
583
+
```json
584
+
{
585
+
"container_id": "abcdef123456",
586
+
"container_name": "my_application_container_1",
587
+
"potential_code_paths": [
588
+
{
589
+
"host_path": "/path/on/host/to/volume_for_html",
590
+
"path_in_container": "/var/www/html",
591
+
"volume_type": "bind", // 'bind' or 'volume'
592
+
"description": "Potential codebase (e.g., web server root)"// Optional description
- E13.1.2. Update `docker-compose.yml` to mount the host's Docker socket (`/var/run/docker.sock`) into the backend container (reference: `05_docker_setup.md`). Document security implications.
194
+
- E13.1.3. Implement service logic in the backend to list running containers and inspect their volume mounts via the Docker API.
195
+
- E13.1.4. Develop and implement heuristics to identify potentially relevant host paths for codebases from volume mounts.
196
+
-**E13.2. Backend: New API Endpoints for Docker Host Interaction**:
197
+
- E13.2.1. Implement API endpoint `/api/v1/dockerhost/containers/` (List Running Docker Containers) as per `03_api_design.md`.
198
+
- Include filtering by name and status.
199
+
- Ensure endpoint is restricted to authorized users (e.g., Admins).
200
+
- E13.2.2. Implement API endpoint `/api/v1/dockerhost/containers/{container_id}/code-paths/` (Retrieve Potential Code Paths) as per `03_api_design.md`.
201
+
- Ensure endpoint is restricted to authorized users.
202
+
- E13.2.3. Write unit and integration tests for the new API endpoints and Docker interaction logic.
203
+
-**E13.3. Frontend: UI for Docker Container Selection in Project Creation/Editing**:
204
+
- E13.3.1. Design and implement UI elements in `ProjectCreateModal.vue` (or a dedicated component) to:
205
+
- Display an option/button to "Select codebase from local Docker container" (visible to authorized users only).
206
+
- Display a list of running Docker containers (fetched from the new API endpoint).
207
+
- Provide filtering capabilities for the container list.
208
+
- E13.3.2. On container selection, implement an API call to fetch potential code paths for that container.
209
+
- E13.3.3. Display a selection for the host paths provided by the backend.
210
+
- E13.3.4. Populate the selected host path into the project form's "Codebase Path or URL" (`codebase_path_or_url`) field.
211
+
- E13.3.5. Store metadata (e.g., container name, path in container) in the `TargetAsset`'s (or project's default configuration) `metadata` field when the project is created.
212
+
-**E13.4. Frontend: Backend API Integration**:
213
+
- E13.4.1. Create API service functions in the frontend to communicate with the new `/api/v1/dockerhost/...` endpoints.
214
+
- E13.4.2. Adapt frontend state management (Pinia/Vuex) to handle fetched container and path data if necessary.
215
+
- E13.4.3. Implement error handling for API calls.
216
+
-**E13.5. Documentation & Tests**:
217
+
- E13.5.1. Describe the new functionality in user and administrator documentation.
218
+
- E13.5.2. Create end-to-end tests for the "create project with codebase from Docker container" workflow (if E2E tests are within MVP scope).
219
+
187
220
This task breakdown provides a high-level roadmap. Each task will be further broken down into smaller, more manageable sub-tasks and potentially issues in a project tracking system as development commences.
- ./backend:/app # Mount backend code for development (live reload)
176
177
- backend_static_collected:/app/staticfiles_collected # Volume for collected static files
177
178
- backend_media_data:/app/media # Volume for user-uploaded media files
179
+
# NEW: Mount Docker socket
180
+
- /var/run/docker.sock:/var/run/docker.sock
178
181
ports:
179
182
- "8000:8000" # Expose Gunicorn port (mainly for Nginx to proxy to)
180
183
env_file:
@@ -205,6 +208,7 @@ services:
205
208
- `./backend:/app`: Mounts the local `backend` directory into `/app` in the container. This is crucial for development, allowing live code changes without rebuilding the image.
206
209
- `backend_static_collected:/app/staticfiles_collected`: A named volume for Django's `collectstatic` output. Nginx can potentially serve from this volume.
207
210
- `backend_media_data:/app/media`: A named volume for user-uploaded files (e.g., `ScanToolResult.raw_output_path`).
211
+
- `./var/run/docker.sock:/var/run/docker.sock`: Mounts the Docker socket to allow the backend to interact with Docker.
208
212
- **`ports: - "8000:8000"`**: Exposes port 8000. While Nginx will be the primary entry point from the outside on port 80/443, this can be useful for direct access during development or if Nginx is on the same host but not in Docker.
209
213
- **`env_file: - .env`**: Loads environment variables from the `.env` file (e.g., `DJANGO_SECRET_KEY`, `DJANGO_DEBUG`, database URL, Celery settings).
210
214
- **`depends_on`**: Ensures that the `db` and `redis` services are healthy before this service starts.
@@ -454,6 +458,47 @@ This `networks` definition is also placed at the root level of the `docker-compo
454
458
455
459
With this, the definition of all services, volumes, and networks for the `docker-compose.yml` file is complete.
456
460
461
+
### 3.10. Backend Access to the Host Docker Socket (for Container Analysis)
462
+
463
+
To enable the SecuLite backend to query the list of Docker containers running on the host and analyze their volume paths (as planned for the "Select Docker Container as Scan Target" feature), the `backend` container requires access to the host system's Docker socket.
464
+
465
+
This is typically achieved by mounting the Docker socket into the `backend` container.
466
+
467
+
**Update in `docker-compose.yml` for the `backend` service:**
* **High Privileges:** Access to the Docker socket (`/var/run/docker.sock`) essentially grants the container root-equivalent permissions over the host's Docker daemon. A process within the container with access to this socket can execute arbitrary Docker commands on the host, including starting, stopping, and manipulating containers, as well as accessing the host's file system via volume mounts in newly started containers.
490
+
* **Risk Mitigation:**
491
+
* **Trusted Code:** This functionality should only be implemented if the code accessing the Docker socket (in the SecuLite backend) is absolutely trustworthy and has been carefully vetted.
492
+
* **Minimal Usage:** Access to the socket should only be used for explicitly required operations (listing containers, inspecting configurations).
493
+
* **No Uncontrolled Command Execution:** The backend should not forward raw, user-supplied commands to the Docker socket.
494
+
* **Read-Only Access Preferred:** If possible, only read operations should be performed via the Docker API to retrieve configuration details.
495
+
* **Alternative (More Complex):** For environments with higher security requirements, a dedicated, minimally privileged "sidecar" container or an external microservice could be considered to act as a strictly controlled proxy for Docker API requests. However, for the MVP phase of SecuLite v2, direct socket mounting is pursued as a pragmatic approach, assuming SecuLite is operated on a trusted server.
496
+
* **User in Container:** If the backend process runs as a non-root user within the container, it must be ensured that this user has permission to access the mounted Docker socket. Often, the Docker socket on the host belongs to the `docker` group. The user in the container would then need to be a member of this group (same GID), or the socket would need to be mounted with appropriate permissions, increasing complexity. For the initial implementation, it is assumed that the process in the backend container (still) runs as root or has sufficient permissions. *This is an important point to consider when implementing a non-root user in the backend container.*
497
+
498
+
**Dependencies:**
499
+
500
+
* The `docker-py` (or a similar) Python library must be added to the backend's dependencies (`pyproject.toml`) to interact programmatically with the Docker API.
Copy file name to clipboardExpand all lines: docs/platform_plan/09_mvp_epics_user_stories.md
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -220,4 +220,31 @@ This document outlines high-level Epics and initial User Stories for the SecuLit
220
220
- As a new developer joining the project, I want a clear guide on how to set up my local development environment for the MVP.
221
221
- As a user/stakeholder, I want to see release notes or a changelog for each version of the MVP that is deployed, detailing what has changed.
222
222
223
+
## Epic 13: Docker Host Integration for Target Definition (New)
224
+
225
+
**Goal:** Enable authorized users to select codebases from Docker containers running locally on the server as scan targets, simplifying the target definition process.
226
+
227
+
**Initial User Stories:**
228
+
229
+
***As an Administrator (or authorized user), when creating or editing a project for an application hosted locally on the server via Docker, I want to have an option to select the codebase directly from one of the server's running Docker containers, so I don't have to manually find and copy host paths to the code volumes.**
230
+
**Acceptance Criteria:*
231
+
* In the project creation/editing form, a clear option (e.g., button, dropdown trigger) like "Select codebase from local Docker container" is available.
232
+
* This option is only visible and usable by users with the appropriate permissions.
233
+
234
+
***As an Administrator (or authorized user), after choosing to select a codebase from a Docker container, I want to see a filterable and searchable list of currently running Docker containers on the server (displaying at least name, ID, and image), so I can quickly identify and select the relevant container.**
235
+
**Acceptance Criteria:*
236
+
* The frontend fetches and displays the list of running containers from the backend API.
237
+
* The list includes essential identifying information: container name, ID, and image.
238
+
* The user can filter or search the list, for example, by container name.
239
+
240
+
***As an Administrator (or authorized user), after selecting a specific Docker container from the list, I want to be presented with a list of potential host filesystem paths that correspond to its volume mounts (especially those typically containing code, like `/var/www/html` or `/app` within the container), so I can choose the correct path to the application's codebase.**
241
+
**Acceptance Criteria:*
242
+
* The frontend fetches and displays the relevant host paths for the selected container from the backend API.
243
+
* The displayed paths are host paths, ideally with an indication of their corresponding path within the container and volume type.
244
+
245
+
***As an Administrator (or authorized user), after selecting a specific host path (derived from a Docker container's volume), I want this path to be automatically populated into the "Codebase Path or URL" field of the project form, so that the scan can be configured with the correct target.**
246
+
**Acceptance Criteria:*
247
+
* The selected host path is correctly entered into the designated form field for the codebase.
248
+
* Relevant metadata (e.g., the source Docker container name, the original path within the container) is optionally stored with the target asset information for traceability.
0 commit comments