Skip to content

FEAT: Security & Azure deployment for CoPyRIT GUI#1554

Open
adrian-gavrila wants to merge 169 commits intomicrosoft:mainfrom
adrian-gavrila:adrian-gavrila/frontend-attack-view
Open

FEAT: Security & Azure deployment for CoPyRIT GUI#1554
adrian-gavrila wants to merge 169 commits intomicrosoft:mainfrom
adrian-gavrila:adrian-gavrila/frontend-attack-view

Conversation

@adrian-gavrila
Copy link
Copy Markdown
Contributor

Description

Adds authentication, security middleware, Azure infrastructure-as-code, and a CI/CD pipeline for deploying the CoPyRIT GUI as an
Azure Container App.

Authentication

  • Frontend: MSAL PKCE auth via @azure/msal-browser — no client secrets needed. New AuthProvider and msalConfig components;
    Axios interceptor attaches Bearer tokens automatically.
  • Backend: FastAPI JWT middleware (pyrit/backend/middleware/auth.py) validates tokens against Entra ID JWKS. Supports multi-group
    authorization via allowedGroupObjectIds. Auth gracefully disables when env vars are unset (local dev).
  • Auth info endpoint (/api/auth/me) for the frontend to display the signed-in user.

Security middleware

  • SecurityHeadersMiddleware: CSP, HSTS (prod only), X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy,
    Cache-Control (no-store on API routes). Swagger disabled in production.

Infrastructure (Bicep)

  • infra/main.bicep + ARM template: provisions Container App Environment, ACR (optional), Log Analytics, Application Insights
    (opt-in OTel), User-Assigned Managed Identity, and VNet/Private Endpoint (opt-in).
  • Key Vault secret references for .env injection — no secrets baked into the container.
  • infra/README.md: full deployment guide covering prerequisites, Entra setup, RBAC grants, and post-deployment steps.

CI/CD

  • gui-deploy.yml: ADO pipeline — build → push to ACR → deploy to test → opt-in prod promotion.

Docker

  • Updated Dockerfile, start.sh, and docker-compose.yaml for managed identity auth on Azure and service principal auth locally.
  • .pyrit_conf_example with operator/operation label examples.

Tests and Documentation

  • frontend/src/App.test.tsx and frontend/src/services/api.test.ts updated to cover auth integration.
  • infra/README.md serves as the deployment guide with full prerequisites, step-by-step setup, post-deployment checklist, and
    teardown instructions.
  • docker/QUICKSTART.md updated with auth configuration and local dev workflow.
  • No Jupyter notebooks were added or modified; JupyText not applicable.

romanlutz and others added 30 commits February 28, 2026 14:49
- Add run_initializers_async to pyrit.setup for programmatic initialization
- Switch AIRTInitializer to Entra (Azure AD) auth, removing API key requirements
- Add --config-file flag to pyrit_backend CLI
- Use PyRIT configuration loader in FrontendCore and pyrit_backend
- Update AIRTTargetInitializer with new target types

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add conversation_stats model and attack_result extensions
- Add get_attack_results with filtering by harm categories, labels,
  attack type, and converter types to memory interface
- Implement SQLite-specific JSON filtering for attack results
- Add memory_models field for targeted_harm_categories
- Add prompt_metadata support to openai image/video/response targets
- Fix missing return statements in SQLite harm_category and label filters

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add attack CRUD routes with conversation management
- Add message sending with target dispatch and response handling
- Add attack mappers for domain-to-DTO conversion with signed blob URLs
- Add attack service with video remix support and piece persistence
- Expand target service and routes with registry-based target management
- Add version endpoint with database info

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add attack-centric chat UI with multi-conversation support
- Add conversation panel with branching and message actions
- Add attack history view with filtering
- Add labels bar for attack metadata
- Add target configuration with create dialog
- Add message mapper utilities for backend/frontend translation
- Add video playback support with signed blob URLs
- Add InputBox with attachment support and auto-expand
- Update dev.py with --detach, logs, and process management
- Add e2e tests for chat, config, and flow scenarios

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ssibility

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Rename supports_multiturn_chat to supports_multi_turn to align with TargetCapabilities field
- Use target_obj.capabilities.supports_multi_turn instead of isinstance check
- Update tests to set capabilities on mock targets

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…_async

Reverts the separate run_initializers_async function and restores the
original pattern where run_scenario_async calls initialize_pyrit_async
a second time with initializers. This avoids a larger refactor.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Catch ValueError in get_conversation_messages route, return 400
- Fix target_registry_name field description
- Simplify redundant except (ValueError, Exception) to except Exception
- Fix docstring: converter_classes -> converter_types
- Fix test assertions: converter_types -> converter_classes (matches memory API)
- Remove dead tests for deleted helper methods
- Restore azure_openai_video target config to match main

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Move _inject_video_id_from_history and _strip_video_pieces methods from
  AttackService to OpenAIVideoTarget where they belong
- Update _validate_request to accept video_path pieces and check for
  video_path+image_path conflicts
- Add ValueError when video_path is present but no video_id can be resolved
- Add 7 unit tests for the inject/strip logic
- Remove video-specific logic from attack_service._send_and_store_message

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
*/
export function getApiScopes(clientId: string): string[] {
if (!clientId) return ['openid', 'profile', 'email']
return [`${clientId}/access`]
Copy link
Copy Markdown
Contributor

@behnam-o behnam-o Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from our chat, I think this might be more optimal and cleaner, and also address my other comment:

  1. add back Microsoft Graph's User.Read delegated API permission to the app registration
  2. in getApiScopes in the frontend, request a token with this scope ["https://graph.microsoft.com/User.Read"]
  3. then group resolution will work okay (because the token that's sent to our backend will have graph as its audience)
  4. now you can remove access from "exposed APIs" of the app because it's not used anyways
  5. we can also remove the "App Roles" (Copyrit.Dev.All) , and instead assign those 2 groups to the ServicePrincipal (Enterprise Application) with the default role (we can do that even right now, because we don't check this role value in user claims)

Adrian Gavrila and others added 4 commits April 1, 2026 12:46
- Change getApiScopes to request https://graph.microsoft.com/User.Read
- Reuse shared getApiScopes in api.ts instead of duplicate
- Update backend token validation audience to graph.microsoft.com
- Update test assertions for new scope
- Enables groups overage resolution via Graph API

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adrian Gavrila and others added 4 commits April 2, 2026 15:18
- Replace toBeInTheDocument with toBeVisible for user-facing assertions
- Add afterEach restoreAllMocks for full test isolation
- Refactor AuthConfig from global cache to React Context
- Rename useMsal instance to msalInstance for clarity
- Extract _authenticate_request_async from dispatch method
- Replace magic number with removeprefix for Bearer token parsing
- Rename overage methods/comments for clarity
- Add _client_id usage comment in auth middleware
- Clarify .azure directory mount in Docker run script
- Standardize Entra ID vs Azure terminology in docs
- Expand acronyms and add links in infra README
- Add what-if preview section to infra README

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Extract AuthConfigContext to separate file (react-refresh/only-export-components)
- Replace ghcr.io/astral-sh/uv container image with install script to comply
  with Microsoft container security policy (CSSC)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants