How drghassen/pfe-mpssr works
1. Repo purpose
CloudSentinel is a DevSecOps framework for Azure that combines:
- shift-left preventive scanning and policy checks,
- shift-right drift detection and runtime remediation,
- OPA for decision logic,
- DefectDojo as the findings/exceptions backend,
- Azure Terraform infrastructure for the demo/deployment environment.
2. Top-level architecture
The repository is organized around three main planes:
- shift-left/: source, container, and IaC scanning before deployment.
- shift-right/: continuous drift/prowler/custodian enforcement after deployment.
- policies/ + config/: shared decision and exception definitions used by both planes.
3. Shift-left subsystem
This is the pre-deployment security pipeline. It includes scanners and normalizers for:
- Checkov custom Azure policy catalog,
- Trivy filesystem/config/image scanning,
- Gitleaks secret scanning,
- Cloud-init scanner for malicious initialization patterns,
- OPA gate decisions,
- report normalization and upload to DefectDojo.
The scripts under ci/scripts/shift-left/ orchestrate these steps in CI.
4. Shift-right subsystem
This is the runtime control loop for deployed Azure resources. It includes:
- drift-engine: detects configuration drift and builds remediation/detection reports,
- Prowler Azure checks for security posture,
- Custodian policies for enforcement/remediation,
- exception fetching and gate enforcement logic,
- uploads of drift/prowler results to DefectDojo.
The scripts under ci/scripts/shift-right/ connect the components into the runtime pipeline.
5. Policy and decision layer
The policies/opa/ tree is the central policy engine:
- gate/: pre-deploy approvals/denials and intent-based gating,
- drift/: drift classification, severity, exceptions, and remediation reasoning,
- prowler/: security finding evaluation and severity actions,
- system/: authorization rules for policy access.
Tests are colocated as .rego test files. These policies form the architecture’s “decision boundary” between raw scanner output and actionable security outcomes.
6. Exception and contract model
Exceptions are first-class artifacts, not ad hoc overrides:
- config/opa/data/exceptions.json and drift_exceptions.json feed policy evaluation,
- ci/contracts/*.json define artifact and integrity contracts,
- shift-left/opa/schema/exceptions_v2.schema.json and other schemas validate structure,
- verification/ contains runtime-state validation for shift-right integrity.
This means findings, exceptions, and remediation state are governed by explicit contracts.
7. Report normalization and data flow
Raw scanner outputs are normalized into CloudSentinel-specific schemas before policy evaluation or storage:
- shift-left/normalizer/ converts scanner results into a common report format,
- shift-right/drift-engine/utils/json_normalizer.py and related modules normalize drift/OPA outputs,
- schemas under shift-left/normalizer/schema/ and shift-right/drift-engine/schemas/ define the canonical shapes.
The architecture depends on normalization to keep scanners interchangeable.
8. Infrastructure boundary
infra/azure/ provides Terraform modules for the Azure environment:
- networking, identity, key vault, storage, database/cosmos, compute, container instances, RBAC, recovery, resource groups.
The compute module includes cloud-init templates, which ties infrastructure provisioning to the shift-left cloud-init scanner and the runtime drift model.
This is the main cloud boundary where the security framework is exercised.
9. Containerized toolchain
ci/images/ defines dedicated Docker images for repeatable CI/runtime execution:
- opa, prowler-tools, scan-tools, deploy-tools, custodian-tools, aci-runtime.
These images isolate scanner dependencies and make the CI pipeline deterministic. The GitLab CI files at the root orchestrate building and using those images.
10. Local integration and support tooling
docker-compose.yml, demosecrets/, and scripts/ support local demos and operational tasks:
- fetching exceptions from DefectDojo,
- creating risk acceptance artifacts,
- audit/notification utilities,
- bootstrap scripts for OPA auth and CA setup.
These are support boundaries around the core scanning/remediation flows.
11. Security taxonomy and mapping
Several directories exist to map findings into a unified security vocabulary:
- shift-right/drift-engine/utils/security_taxonomy.py,
- shift-left/normalizer/cs_norm_mappings.py,
- config/remediation-capabilities.json,
- ci/scripts/shift-right/correlation_mappings.json.
This indicates the architecture is designed to correlate different tools’ findings to common control, severity, and remediation categories.
12. Main end-to-end flows
- Shift-left flow: source/IaC/artifacts → scanner execution → normalization → OPA decisioning → contract checks / DefectDojo upload.
- Shift-right flow: live Azure state → drift/prowler/custodian evaluation → OPA decisions and exception matching → gate/remediation/enforcement → DefectDojo/reporting.
The architecture centers on these two loops, with OPA and normalized schemas acting as the integration backbone.
13. Operational emphasis
The presence of CI pipelines, build scripts, schemas, tests, and integrity contracts shows this repo is not just policy code; it is a full operational framework with strong emphasis on reproducibility, policy governance, and traceable security state.
Main entry points: shift-left CI scripts · shift-right Shift-right OPA · opa Shift-left OPA · azure Azure infra
Components 21
Shift-left
Pre-deployment scanning, normalization, policy gating, and report upload.
- CI scripts · Shift-left CI entrypoints that sequence scanners, normalization, OPA checks, and DefectDojo upload.
ci/scripts/shift-left - Checkov · Custom Azure Checkov policy catalog for infrastructure checks.
shift-left/checkov - Trivy · Filesystem, config, and image scanning with Azure-focused mappings.
shift-left/trivy - Gitleaks · Secret scanning and suppression handling for source and configs.
shift-left/gitleaks - Cloud-init scan · Detects malicious cloud-init and initialization patterns tied to compute templates.
shift-left/cloudinit-scanner - Normalizer · Converts scanner outputs into a common CloudSentinel report schema.
shift-left/normalizer - Shift-left OPA · Fetches exceptions and evaluates pre-deploy gate decisions.
shift-left/opa
Shift-right
Post-deployment drift detection, posture checks, remediation, and reporting.
- Runtime scripts · Shift-right pipeline entrypoints for drift, posture, enforcement, and reporting.
ci/scripts/shift-right - Drift engine · Detects drift, normalizes state, enriches findings, and builds reports.
shift-right/drift-engine - Prowler · Azure security posture detection for runtime findings.
shift-right/prowler - Custodian · Policy-based enforcement and autofix for Azure resources.
shift-right/custodian - Shift-right OPA · Evaluates drift and prowler findings against exceptions and actions.
ci/scripts/shift-right
Policy layer
OPA decision logic and shared exception/config inputs.
- Gate policies · Pre-deploy approval, deny, and warning logic.
policies/opa/gate - Drift policies · Drift classification, severity, exception matching, and remediation reasoning.
policies/opa/drift - Prowler policies · Evaluates posture findings and maps them to actions and severity.
policies/opa/prowler - System authz · Authorization boundary for policy access and execution.
policies/opa/system - Exceptions · Canonical exception and remediation inputs consumed by both planes.
config/opa/data
Platform
Azure infrastructure, container images, and contract/verification support.
- Contracts · Artifact and integrity contracts for CI and runtime data exchange.
ci/contracts - Verification · Runtime-state validation for shift-right integrity.
verification - Azure infra · Terraform-managed Azure environment exercised by the security framework.
infra/azure - Tool images · Deterministic CI/runtime images for scanners, policy, deployment, and remediation tools.
ci/images
Connections 25
- CI scripts → Checkov: runs · Orchestrates infrastructure policy checks.
- CI scripts → Trivy: runs · Triggers filesystem/config/image scans.
- CI scripts → Gitleaks: runs · Triggers secret scanning.
- CI scripts → Cloud-init scan: runs · Triggers cloud-init pattern analysis.
- CI scripts → Normalizer: normalizes · Converts raw outputs to the common report schema.
- Normalizer → Shift-left OPA: feeds · Provides normalized findings for gate evaluation.
- Shift-left OPA → Gate policies: evaluates · Uses gate rules to approve, deny, or warn.
- Shift-left OPA → Exceptions: loads · Consumes exception data for gate decisions.
- CI scripts → Contracts: checks · Validates artifact and integrity contracts in CI.
- CI scripts → Tool images: uses · Runs inside dedicated scanner/tool images.
- Runtime scripts → Drift engine: runs · Coordinates drift detection and report generation.
- Runtime scripts → Prowler: runs · Triggers Azure posture checks.
- Runtime scripts → Custodian: runs · Executes enforcement and remediation policies.
- Runtime scripts → Shift-right OPA: gates · Evaluates runtime findings and gate conditions.
- Drift engine → Shift-right OPA: feeds · Provides normalized drift findings and context.
- Prowler → Shift-right OPA: feeds · Provides security posture findings for evaluation.
- Shift-right OPA → Drift policies: evaluates · Uses drift rules for classification and remediation reasoning.
- Shift-right OPA → Prowler policies: evaluates · Uses prowler rules for severity and action mapping.
- Shift-right OPA → Exceptions: loads · Consumes shared exceptions for runtime gating.
- Custodian → Azure infra: remediates · Enforces resource-state changes in Azure.
- Azure infra → Cloud-init scan: defines · Compute templates include cloud-init content that is scanned pre-deploy.
- Azure infra → Drift engine: observed by · Live Azure state is compared against desired state and plans.
- Contracts → Verification: supports · Contracts define the runtime integrity checks and expected artifacts.
- System authz → Shift-left OPA: authorizes · Controls access to policy evaluation paths.
- System authz → Shift-right OPA: authorizes · Controls access to runtime policy evaluation paths.