Application ArchitectureΒΆ
Table of ContentsΒΆ
Executive SummaryΒΆ
SG Provisioner is an enterprise-grade AWS Security Group provisioning and management tool built for cloud infrastructure teams. It automates the creation, validation, and lifecycle management of Security Groups using a scenario-based, configuration-driven approach backed by AWS CloudFormation.
Rather than requiring engineers to manually define individual firewall rules, SG Provisioner provides pre-built scenario templates for common application architectures (3-tier web, 2-tier web, database-specific variants). Engineers select a scenario, apply overrides for their specific requirements, and the tool generates a validated CloudFormation template that provisions all Security Groups with correct cross-tier references.
Key Capabilities:
9 pre-built scenarios covering common 2-tier and 3-tier architectures
Override system for port changes and additional ingress/egress rules per tier
Workload discriminator for deploying multiple SG sets in the same environment
CloudFormation-based provisioning with automatic circular dependency resolution
Security validation blocking dangerous patterns (open DB ports, SSH/RDP from public)
Pre-deployment review reports with override highlighting
Post-deployment reports with real Security Group IDs
SSM Parameter Store integration for downstream resource discovery
AWS Marketplace license validation
Docker containerization with Cython-compiled core modules for IP protection
System ContextΒΆ
SG Provisioner is one of four provisioners in the mlops-infra-suite β a suite of infrastructure automation tools designed to work together to provision complete AWS environments for ML workloads.
Position in the SuiteΒΆ
βββββββββββββββββββββββββββββββββββββββββββββββββ
β mlops-infra-suite β
β β
β βββββββββββββββββββ βββββββββββββββββββ β
β β VPC Provisioner βββββΆβ SG Provisioner β β
β β β β β β
β β Provisions VPC, β β Provisions β β
β β subnets, NAT, β β Security Groups β β
β β route tables β β per tier β β
β βββββββββββββββββββ ββββββββββ¬βββββββββ β
β β β
β βββββββββββββββββββ ββββββββββΌβββββββββ β
β β S3 Provisioner β β SEC Provisioner β β
β β β β β β
β β Provisions S3 β β Provisions IAM β β
β β buckets and β β roles and β β
β β folder structureβ β policies β β
β βββββββββββββββββββ βββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββ
Dependency OrderΒΆ
SG Provisioner depends on the VPC Provisioner β it requires a VPC to exist before Security Groups can be created. The typical provisioning order is:
VPC Provisioner β creates VPC, subnets, gateways, stores VPC ID in SSM
SG Provisioner β reads VPC ID from SSM, creates Security Groups, stores SG IDs in SSM
SEC Provisioner β creates IAM roles and policies
S3 Provisioner β creates S3 buckets and folder structures
SSM Parameter Store as Integration BackboneΒΆ
All provisioners use AWS SSM Parameter Store as the integration backbone β each provisioner stores its outputs so downstream provisioners and application workloads can discover resources without hardcoding IDs:
/vpc/{vpc-name}/VPCId β consumed by SG Provisioner
/sg/{sg-name}/{tier}/SecurityGroupId β consumed by EC2, RDS, ECS, Lambda, SageMaker
/s3/{bucket-name}/BucketName β consumed by application workloads
/security/{stem}/StackId β consumed by application workloads
External DependenciesΒΆ
Service |
Purpose |
|---|---|
AWS CloudFormation |
Stack-based provisioning and lifecycle management |
AWS EC2 |
Security Group resource creation |
AWS SSM Parameter Store |
VPC ID resolution (input) and SG ID storage (output) |
AWS Marketplace |
License validation |
Component ArchitectureΒΆ
Module OverviewΒΆ
sg_provisioner/
βββ cli.py # CLI entry point, action dispatch
βββ __main__.py # Python module execution entry
β
βββ config/
β βββ loader.py (.so) # Configuration loading and validation
β βββ app_config.yaml # Application-level settings (dirs, timeouts)
β
βββ core/
β βββ sg_manager.py (.so) # Core orchestration and AWS operations
β
βββ generators/
β βββ cfn_generator.py (.so) # CloudFormation template generation
β
βββ scenarios/
β βββ loader.py (.so) # Scenario loading and override application
β βββ validator.py (.so) # Security rule validation
β
βββ models/
β βββ scenario.py # Scenario, Tier data models
β βββ security_group.py # SecurityGroup, SecurityGroupRule data models
β
βββ license/
β βββ validator.py (.so) # AWS Marketplace license validation
β
βββ utils/
βββ html_generator.py (.so) # Deployment HTML report generation
βββ review_report.py (.so) # Pre-deployment review report generation
common/ (shared library)
βββ cli/
β βββ base_cli.py # Base CLI with --config, --action, --force flags
βββ logger/
β βββ base_logger.py # Shared logging setup
βββ utils/
β βββ aws_helpers.py # AWS credential verification and region validation
β βββ aws_retry.py # Retry logic with exponential backoff
β βββ class_helpers.py # Class utility functions
β βββ config_helpers.py # YAML configuration parsing utilities
β βββ dry_run_helpers.py # Dry-run mode decorator
β βββ timing_helpers.py # Performance timing decorators
βββ validation/
βββ config_validator.py # JSON schema validation engine
Module ResponsibilitiesΒΆ
cli.py β Entry Point
Validates AWS Marketplace license before any action
Parses CLI arguments (
-con,-act,--force,--verbose)Instantiates
SgManagerand dispatches the requested actionHandles top-level exceptions with user-friendly messages
config/loader.py β Configuration Management
Loads and parses the customer YAML configuration file
Validates against JSON schema (
schemas/validation-schema.yaml)Computes derived values: SG name, stack name, log file path, template path
Initialises AWS clients (EC2, CloudFormation, SSM)
core/sg_manager.py β Core Orchestration
Central orchestrator for all 12 CLI actions
Manages the full SG lifecycle: validate β generate β deploy β monitor β delete
Handles CloudFormation stack operations with waiter pattern for async completion
Stores and deletes SG IDs in SSM Parameter Store
Generates pre-deployment and post-deployment HTML reports
generators/cfn_generator.py β CloudFormation Template Generation
Builds the complete CloudFormation template dict from a
ScenarioobjectGenerates
AWS::EC2::SecurityGroupresources per tierResolves cross-tier references as standalone
AWS::EC2::SecurityGroupIngress/AWS::EC2::SecurityGroupEgressresources to avoid circular dependenciesGenerates
AWS::SSM::Parameterresources to store SG IDs at deployment timeBuilds CloudFormation Outputs and Exports per tier
scenarios/loader.py β Scenario Management
Loads scenario YAML files from
schemas/scenarios/Builds
Scenario/Tier/SecurityGroupobject graphsApplies customer overrides: port substitutions, additional ingress/egress rules
scenarios/validator.py β Security Validation
Validates scenario rules before template generation
Blocks dangerous patterns as ERRORs: database ports open to
0.0.0.0/0or::/0, missing rule descriptions, references to non-existent tiersWarns on risky patterns: SSH (22) or RDP (3389) open to the world
models/ β Data Models
Scenario,Tierβ represent the scenario structureSecurityGroup,SecurityGroupRuleβ represent individual SG rules withport/port_range,source/source_tier,destination/destination_tierfields
license/validator.py β License Validation
Validates AWS Marketplace product subscription before any action executes
Calls AWS Marketplace Metering API to verify entitlement
utils/html_generator.py β Deployment Report
Generates post-deployment HTML report with real SG IDs, stack outputs, and deployment metadata
utils/review_report.py β Pre-Deployment Report
Generates pre-deployment review YAML (
templates/) and HTML (reports/) with override highlighting
Key Architecture DecisionsΒΆ
ADR-001: CloudFormation over Direct Boto3 Resource CreationΒΆ
Decision: Use AWS CloudFormation for Security Group provisioning.
Alternatives Considered: Direct boto3 API calls for each resource.
Rationale:
Atomic Operations β CloudFormation treats all Security Groups as a single unit, ensuring all-or-nothing deployment
Automatic Rollback β Failed deployments automatically roll back to the previous state
Dependency Management β CloudFormation handles resource dependencies automatically
State Management β CloudFormation maintains resource state, enabling updates, change preview, and drift detection
Change Sets β Preview changes before applying them via
show-changesaction
Consequences:
β Simplified error handling and recovery
β Built-in drift detection via
check-driftactionβ Change preview via CloudFormation ChangeSets
β Async operations handled via boto3 waiter pattern β provides reliable completion detection with configurable polling interval and timeout
ADR-002: Scenario-Based ArchitectureΒΆ
Decision: All Security Group topologies defined as pre-built YAML scenario files.
Rationale:
Separation of Concerns β Network topology (data) separated from provisioning logic (code)
Reusability β Common architectures templated and reused across clients
Override System β Clients customise scenarios without modifying core files
Validation β Scenarios validated for security issues before deployment
Extensibility β New scenarios added by dropping a YAML file into
schemas/scenarios/
Consequences:
β Consistent security posture across deployments
β Easy to add new architecture patterns
β Overrides keep customisations minimal and auditable
β Fundamentally different architectures are captured as new named scenarios β promoting reuse and standardisation
ADR-003: Standalone Cross-Tier Rules to Avoid Circular DependenciesΒΆ
Decision: Cross-tier Security Group references are generated as standalone AWS::EC2::SecurityGroupIngress / AWS::EC2::SecurityGroupEgress resources rather than inline rules.
Context: In a 3-tier scenario, the web SG references the app SG and vice versa. If both are defined as inline rules within their respective AWS::EC2::SecurityGroup resources, CloudFormation detects a circular dependency and fails.
Rationale:
Standalone ingress/egress resources break the circular dependency by decoupling the rule from the SG resource definition
CloudFormation can then resolve the dependency graph correctly
Consequences:
β No circular dependency errors regardless of scenario complexity
β Transparent to the client β handled automatically by
CfnGeneratorβ Additional standalone resources per cross-tier rule keep the template clean and explicit
ADR-004: Cython Compilation for Code ProtectionΒΆ
Decision: Compile core Python modules to .so binary files using Cython.
Modules Compiled:
config/loader.py,core/sg_manager.py,generators/cfn_generator.pyscenarios/loader.py,scenarios/validator.py,license/validator.pyutils/html_generator.py,utils/review_report.py
Rationale:
IP Protection β Core business logic not exposed as plain text
Tamper Resistance β Binary files harder to modify
AWS Marketplace Standard β Common practice for commercial containerised products
Consequences:
β Protected intellectual property
β
cli.pyand__init__.pyremain as plain Python for entry point compatibilityβ Platform-specific binaries optimised for Linux x86_64 β the standard deployment environment
Security ArchitectureΒΆ
Code ProtectionΒΆ
Core modules are compiled to .so binary files via Cython, protecting intellectual property and preventing reverse engineering. Only cli.py and __init__.py are distributed as plain Python β these are entry points with no business logic.
License ValidationΒΆ
Every action β including local-only operations like validate-config β requires a valid AWS Marketplace subscription. License validation runs before any business logic executes. If validation fails, the tool exits immediately with a clear error message.
Container SecurityΒΆ
Control |
Implementation |
|---|---|
Non-root execution |
Container runs as |
Read-only credentials |
|
Read-only config |
|
No exposed ports |
Container exposes no network services |
No privileged mode |
Standard Docker execution |
Minimal base image |
|
Multi-stage build |
Build dependencies excluded from runtime image |
Credential ManagementΒΆ
No credentials hardcoded in code or container image
AWS credentials provided at runtime via volume mount or environment variables
IAM roles (EC2/ECS instance metadata) supported β no credentials needed
Temporary credentials (STS AssumeRole, SSO) fully supported
Input ValidationΒΆ
All configuration files validated against JSON schema before any AWS operation
Config filenames cannot contain path separators (path traversal prevention)
Scenario validator blocks dangerous security group rules before template generation
Port values validated to be within 1-65535 range
IAM Least PrivilegeΒΆ
The generated IAM policy (create-policy action) follows least privilege principles:
EC2 permissions scoped to the deployment region and account
SSM permissions split into two statements:
Read-only on
/vpc/path β to resolve VPC IDFull CRUD on
/sg/path β to store and delete SG IDs
CloudFormation permissions scoped to the specific stack name pattern
Known VulnerabilitiesΒΆ
See SECURITY.md for the current vulnerability status of the base Docker image.
Deployment ArchitectureΒΆ
Docker ContainerΒΆ
SG Provisioner is distributed as a Docker container via AWS Marketplace. The container is built using a multi-stage build to keep the runtime image minimal and secure.
Multi-Stage Build:
Stage 1: Builder
- Base: python:3.13-slim
- Installs uv package manager
- Resolves and installs all Python dependencies into .venv
Stage 2: Runtime
- Base: python:3.13-slim (clean image)
- Copies only the installed packages from Stage 1
- Copies Cython-compiled sg_provisioner package (.so files)
- Removes source .py files for compiled modules (IP protection)
- Copies common library, schemas, templates, and HTML documentation
- Runs as non-root user (sguser, UID 1000)
Container ContentsΒΆ
Path |
Contents |
|---|---|
|
Compiled application modules (.so files) |
|
Shared library (plain Python) |
|
Validation schema and scenario YAML files |
|
CloudFormation template placeholders |
|
Built HTML documentation (Sphinx) |
|
Mount point for customer configuration files |
|
Mount point for generated IAM policies |
|
Mount point for logs and HTML reports |
Volume MountsΒΆ
Host Path |
Container Path |
Mode |
Purpose |
|---|---|---|---|
|
|
|
AWS credentials |
|
|
|
Customer configuration files |
|
|
|
Generated IAM policies |
|
|
|
Generated CloudFormation templates |
|
|
|
Execution logs and HTML reports |
EntrypointΒΆ
The container entrypoint (entrypoint.sh) invokes the SG Provisioner CLI, which:
Validates the AWS Marketplace license
Parses CLI arguments (
-con,-act,--force,--verbose)Instantiates
SgManagerand executes the requested action
Health CheckΒΆ
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD python -c "import sys; sys.exit(0)" || exit 1
Deployment ModelsΒΆ
Interactive (Developer):
docker run --rm \
-v ~/.aws:/home/sguser/.aws:ro \
-v $(pwd)/sg/configs:/app/configs:ro \
-v $(pwd)/sg/reports:/app/reports \
sg-provisioner:latest \
-con my-config.yaml -act validate-config
CI/CD Pipeline:
- name: Deploy security groups
run: |
docker run --rm \
-v ~/.aws:/home/sguser/.aws:ro \
-v $(pwd)/sg/configs:/app/configs:ro \
-v $(pwd)/sg/templates:/app/templates \
-v $(pwd)/sg/reports:/app/reports \
sg-provisioner:latest \
-con my-config.yaml -act create-security-groups --force
EC2/ECS with IAM Role:
docker run --rm \
-v $(pwd)/sg/configs:/app/configs:ro \
-v $(pwd)/sg/reports:/app/reports \
sg-provisioner:latest \
-con my-config.yaml -act create-security-groups --force
Copyright Β© 2025 Axon Tech Labs. All rights reserved.
See LICENSE.txt for terms and conditions.