Application ArchitectureΒΆ
System architecture documentation for the SEC Provisioner.
Table of ContentsΒΆ
Introduction and ContextΒΆ
PurposeΒΆ
The SEC Provisioner is a config-driven IAM provisioning tool that manages AWS IAM groups, roles, and policies via CloudFormation. It transforms a single YAML configuration file into a complete IAM security infrastructure deployed as a single CloudFormation stack.
Problem StatementΒΆ
Setting up IAM infrastructure for ML teams is complex, error-prone, and time-consuming:
Multiple groups with overlapping but distinct permissions
Service roles with trust policies for SageMaker, Lambda, Glue, CodeBuild
Cross-function assumable roles for temporary access elevation
Cross-account roles for CI/CD pipelines and monitoring
Least-privilege policies scoped to specific AWS services and actions
Consistency across dev/staging/prod environments
SolutionΒΆ
A tiered, config-driven approach where:
All IAM resources are defined in a single YAML configuration
Pre-built policy templates provide least-privilege access for 9 AWS service categories
Three tiers (startup/medium/enterprise) offer progressive feature availability
CloudFormation manages the entire lifecycle as a single stack
Export actions enable review and audit before deployment
ScopeΒΆ
The SEC Provisioner manages:
IAM Groups with inline policies and managed policy attachments
Service Roles for AWS services (SageMaker, Lambda, Glue, CodeBuild, CI/CD)
Assumable Roles (cross-function mirrors and elevation roles)
Cross-Account Roles with external ID verification
Standalone Managed Policies from policy templates
SSM Parameter Store entries for cross-provisioner discovery
It does not manage:
IAM Users (users are added to groups manually or via external tooling)
AWS Organizations or SCPs
VPC or S3 infrastructure (handled by VPC and S3 Provisioners)
Architectural RepresentationΒΆ
System ContextΒΆ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Client Host β
β β
β configs/ Docker Container β
β ββββββββββββ βββββββββββββββββββββββββββββββββ β
β β YAML ββββββΆ β SEC Provisioner β β
β β Config β β ββββββββββ βββββββββββββββ β β
β ββββββββββββ β β CLI βββΆ β SecManager β β β
β β ββββββββββ ββββββββ¬βββββββ β β
β policies/ β β β β
β βββββββββββββββββ β βββββββββββββββββββββ β β
β β JSON β β β Policy Templates ββ β β
β ββββββββββββ β βββββββββββββββββββββ β β
β β βΌ β β
β templates/ β ββββββββββββββββ β β
β βββββββββββββββββ β β CFN Template β β β
β β YAML β β βββββββ¬βββββββββ β β
β ββββββββββββ ββββββββββββββββββββββΌβββββββββββ β
β β β
β reports/ βΌ β
β ββββββββββββ ββββββββββββββ β
β β LOG/HTML β β AWS APIs β β
β ββββββββββββ ββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Processing FlowΒΆ
YAML Config βββΆ Schema Validation βββΆ Config Parsing βββΆ Resource Generation
β
βββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββ βββββββββββββ βββββββββββββ
β Policies β β Roles β β Groups β
β (31 YAML β β (service, β β (inline β
β templates)β β assumable,β β policies, β
βββββββ¬ββββββ β xacct) β β role ARNs)β
β βββββββ¬ββββββ βββββββ¬ββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β CloudFormation Template β
β (single YAML with all IAM resources) β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββ
β
ββββββββββββββΌβββββββββββββ
βΌ βΌ βΌ
TemplateBody S3 Upload ChangeSet
(startup) (med/ent) (show-changes)
β β
βΌ βΌ
βββββββββββββββββββββββ
β CloudFormation β
β Stack Deploy β
βββββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββββββ
β SSM Parameter β
β Store β
βββββββββββββββββββββββ
Technical Strategy and DecisionsΒΆ
Single Stack ArchitectureΒΆ
All IAM resources are managed in a single CloudFormation stack per environment. This ensures:
Atomic deployment β all resources created or none
Consistent rollback on failure
Single point of management for drift detection
Simplified cleanup via stack deletion
Config-Driven DesignΒΆ
The YAML configuration is the single source of truth. The code generates all resources from the config β no hardcoded resource definitions. This enables:
Customization without code changes
Tier-specific schemas for validation
Reproducible deployments across environments
Policy Template SystemΒΆ
Pre-built YAML policy templates (31 files across 9 service categories) provide least-privilege access patterns. Benefits:
Audited and tested policy definitions
Consistent permission levels across deployments
Placeholder substitution for tenant-scoped resources (
${company_prefix},${env},${tenant_id})New services added by dropping YAML files into
policy-templates/
Tiered Access ControlΒΆ
Three tiers with build-time injection:
Startup-5: 5 groups, 4 service roles, 1 assumable role, 0 cross-account roles
Medium-10: 10 groups, 5 service roles, 6 assumable roles, 1 cross-account role
Enterprise-12: 12 groups, 5 service roles, 7 assumable roles, 2 cross-account roles
The tier is injected into app_config.yaml at Docker build time via sed in the Makefile. The same codebase serves all tiers β the security profile in the config controls which resources are enabled.
Template Size StrategyΒΆ
Startup: Template < 51,200 bytes β deployed via CloudFormation TemplateBody (inline)
Medium/Enterprise: Template > 51,200 bytes β uploaded to S3, deployed via TemplateURL
This is handled automatically based on template size at deploy time.
Cython CompilationΒΆ
Core modules are compiled to .so files via Cython for:
Source code protection in commercial distribution
Modest performance improvement for template generation
IP protection for policy generation logic
Compiled modules: sec_manager.py, loader.py, validator.py, html_generator.py
Component ArchitectureΒΆ
Package StructureΒΆ
sec_provisioner/
βββ cli.py # CLI entry point (SecProvisionerCLI)
βββ __main__.py # Module entry point
βββ __init__.py
βββ config/
β βββ loader.py # AppConfig class, load_app_config()
β βββ app_config.yaml # Embedded app configuration (tier injected at build)
βββ core/
β βββ sec_manager.py # SecManager β all business logic (2,960 lines)
βββ license/
β βββ validator.py # AWS Marketplace license validation
βββ utils/
βββ html_generator.py # HTML report generation (template + deployment + policy)
Supporting AssetsΒΆ
schemas/ # Tier-specific JSON schemas
βββ validation-schema-startup.yaml
βββ validation-schema-medium.yaml
βββ validation-schema-enterprise.yaml
policy-templates/ # 31 pre-built IAM policy templates
βββ s3/ # level1, level2, level3
βββ ecr/ # level1, level2, level3
βββ sagemaker/ # level1, level1-prod, level2, level3, level4-ci
βββ pipeline/ # level1, level2, level3
βββ lambda/ # level1, level2
βββ bedrock/ # level1, level2
βββ kms/ # level1
βββ trusted-advisor/ # level1
βββ combined/ # ops-services-read-only, mlops-services-a/b/c
SecManager ClassΒΆ
The SecManager class (2,960 lines) is the core business logic. Key method groups:
Initialization:
__init__β config loading, schema validation, AWS client setup_load_and_validate_config_earlyβ YAML parsing and schema validation_flatten_config_to_attributesβ config dict β instance attributes_ensure_aws_accessβ AWS credential and connectivity validation
Resource Generation:
_generate_iam_groupsβ_generate_iam_groupβ group with inline policies + assumable role ARNs_generate_service_rolesβ_generate_service_roleβ role with trust policy + managed policies_generate_cross_function_rolesβ roles that mirror group policies viamirrors_group_generate_elevation_rolesβ roles with custom IAM permissions_generate_cross_account_rolesβ_generate_cross_account_roleβ roles with external ID_generate_service_policiesβ standalone managed policies from templates_generate_prov_templateβ orchestrates all generators into single CFN template_generate_outputsβ CloudFormation outputs for all resources
Export Actions:
_export_iam_policyβ operator IAM policy scoped to config_export_service_policiesβ service policy JSONs_export_iam_groupsβ group definition JSONs_export_service_roles,_export_cross_function_roles,_export_elevation_roles,_export_cross_account_rolesβ role JSONs
Infrastructure Operations:
_create_prov_template_fileβ generate and save CFN template_validate_prov_templateβ local template validation (YAML, refs, structure)_show_changesβ CloudFormation ChangeSet preview_check_driftβ drift detection against deployed stack_test_deployβ deploy with random suffix_deployβ production deployment + SSM parameter storage_delete_stackβ stack deletion + SSM parameter cleanup
Action Dispatch:
_execute_actionβ maps action strings to method callsexecuteβ top-level entry point called by CLI
Data ArchitectureΒΆ
Input DataΒΆ
Configuration File (YAML):
6 top-level sections: tier, client, environment, deployment, security, tags
Security section contains: iam_groups, service_roles, assumable_roles, cross_account_roles, security_profiles
Validated against tier-specific JSON schema
Policy Templates (YAML):
31 files across 9 service directories
Each defines an IAM policy document with placeholder variables
Placeholders:
${company_prefix},${env},${tenant_id},${account_id},${region}
Output DataΒΆ
CloudFormation Template (YAML):
Single template containing all IAM resources
Startup: ~30KB (TemplateBody compatible)
Medium: ~69KB (requires S3 upload)
Enterprise: ~85KB (requires S3 upload)
Exported JSON Files:
IAM policy:
{stem}-iam-policy.jsonService policies:
{prefix}-policy-{service}-{level}.jsonGroups:
{prefix}-group-{name}.jsonRoles:
{prefix}-role-{name}.jsonor{prefix}-xacct-{name}.json
Reports:
Log files:
{stem}-{action}-{timestamp}.logHTML reports: template documentation, deployment results, policy documentation
SSM Parameters:
Path:
/security/{stem}/{output_key}Contains ARNs for all deployed resources
Enables cross-provisioner resource discovery
Naming ConventionsΒΆ
All resource names derive from the stem: {company_prefix}-{env}-{tenant_id}-{region}-{tier_name}-sec
Example stem: edge-prod-b001-us-west-1-medium-sec
Resource Type |
Pattern |
Example |
|---|---|---|
Stack |
|
|
Group |
|
|
Service Role |
|
|
Assumable Role |
|
|
Cross-Account Role |
|
|
Managed Policy |
|
|
See NAMING_CONVENTIONS.md for complete naming reference.
Security ArchitectureΒΆ
Container SecurityΒΆ
Non-root user:
secuser(UID 1000)No exposed ports: container has no network listeners
Health check: configured for orchestrator compatibility
Multi-stage build: builder stage discarded, minimal runtime image
Cython compilation: core modules compiled to
.soβ source code not included in imageRead-only config mount: configs mounted with
:roflag
IAM Security ModelΒΆ
Least Privilege:
31 policy templates with scoped permissions per service and level
Resource ARNs scoped to tenant:
arn:aws:s3:::{prefix}-{env}-{tenant_id}-*No wildcard resources except where AWS requires it (IAM global actions)
Separation of Concerns:
Groups define team membership and permission boundaries
Service roles define what AWS services can do
Assumable roles provide temporary cross-function access
Cross-account roles isolate external access with external ID verification
Audit Trail:
All assumable role usage logged via CloudTrail (
sts:AssumeRole)SSM parameters provide discoverable resource inventory
Export actions enable pre-deployment security review
HTML reports document deployed configuration
Credential HandlingΒΆ
AWS credentials mounted read-only from host
No credentials stored in the container image
License validation uses AWS Marketplace API (requires credentials)
Environment variable credentials supported but discouraged
Deployment ArchitectureΒΆ
Docker Image StructureΒΆ
/app/
βββ sec_provisioner/ # Compiled application code (.so + .py)
βββ common/ # Shared library
βββ schemas/ # Tier-specific validation schemas
βββ policy-templates/ # 31 IAM policy YAML templates
βββ templates/ # Pre-generated sample templates
βββ configs/ # Master config templates per tier
βββ docs/ # Sphinx HTML documentation
βββ entrypoint.sh # Container entry point
βββ configs/ # Mount point for client configs
βββ policies/ # Mount point for exported policies
βββ groups/ # Mount point for exported groups
βββ roles/ # Mount point for exported roles
βββ templates/ # Mount point for generated templates
βββ reports/ # Mount point for logs and reports
Build PipelineΒΆ
Source Code βββΆ Cython Compile βββΆ Docker Build βββΆ Docker Image
(.py β .so) (multi-stage) (sec-provisioner:<tier>)
β
Tier Injection
(sed β app_config.yaml)
The Makefile:
Injects tier into
app_config.yamlviasedCompiles Python to
.sovia CythonBuilds Docker image with multi-stage build (uv dependency install β slim runtime)
Restores
app_config.yamlafter buildTags image as
sec-provisioner:<tier>(e.g.,startup-5,medium-10,enterprise-12)
CloudFormation DeploymentΒΆ
Startup Tier:
Config β Template Generation β TemplateBody β CloudFormation CreateStack
Medium/Enterprise Tiers:
Config β Template Generation β S3 Upload β TemplateURL β CloudFormation CreateStack
Post-deployment:
Stack Outputs β SSM Parameter Store (/security/{stem}/*)
Quality AttributesΒΆ
ReliabilityΒΆ
Schema validation: Config validated against tier-specific schema before any processing
Template validation: Local validation of YAML syntax, required keys, and reference integrity
Test deploy: Isolated test deployment with random suffix before production
Atomic deployment: CloudFormation ensures all-or-nothing resource creation
Automatic rollback: CloudFormation rolls back on any resource creation failure
MaintainabilityΒΆ
Single source of truth: YAML config drives all resource generation
Policy templates: New services added by dropping YAML files β no code changes
Shared common module: CLI, logging, AWS helpers shared across all 3 provisioners
Consistent patterns: All provisioners follow the same architecture (CLI β Manager β CloudFormation)
TestabilityΒΆ
Export actions: Review all generated resources as JSON before deployment
Test deploy: Full stack deployment with isolated resource names
Dry-run mode: Simulate operations without AWS calls
Template validation: Catch errors locally before deployment
SecurityΒΆ
Least privilege: Scoped policies per service and level
No hardcoded credentials: All credentials from host mount or instance role
Cython compilation: Source code protection
Non-root container: Runs as
secuser
PortabilityΒΆ
Docker-based: Runs on any system with Docker
No host dependencies: All dependencies bundled in image
Multi-platform: Python 3.13-slim base image
Integration ArchitectureΒΆ
Cross-Provisioner IntegrationΒΆ
The SEC Provisioner integrates with the S3 and VPC Provisioners via SSM Parameter Store:
S3 Provisioner βββΆ S3 Bucket βββΆ SEC Provisioner (template upload)
β
βΌ
SSM Parameters
β
βΌ
VPC Provisioner (reads role ARNs)
S3 β SEC: Medium and enterprise tiers upload templates to the S3 bucket created by the S3 Provisioner. The deployment.template_bucket config field references this bucket.
SEC β SSM: After deployment, all stack outputs (group ARNs, role ARNs, policy ARNs) are stored in SSM Parameter Store under /security/{stem}/.
SSM β Other Provisioners: Other provisioners can discover SEC resources by reading SSM parameters β for example, retrieving a SageMaker execution role ARN for use in a training pipeline.
AWS Service IntegrationΒΆ
AWS Service |
Usage |
|---|---|
CloudFormation |
Stack lifecycle (create, update, delete, drift, changeset) |
IAM |
Groups, roles, policies (managed by CloudFormation) |
S3 |
Template upload for medium/enterprise tiers |
SSM Parameter Store |
Stack output storage for cross-provisioner discovery |
STS |
Credential validation, caller identity |
AWS Marketplace |
License validation |
Operational ArchitectureΒΆ
Action Safety LevelsΒΆ
Level |
Actions |
AWS Impact |
|---|---|---|
Local |
validate-config, export-iam-policy, export-service-policies, export-groups, export-roles, create-prov-template, validate-prov-template |
None (local file operations only) |
Read-only |
show-changes, check-drift |
Read-only AWS calls (ChangeSet, drift detection) |
Mutating |
test-deploy, deploy, delete-stack |
Creates/modifies/deletes AWS resources |
LoggingΒΆ
All actions produce log files in
reports/Log format:
{stem}-{action}-{timestamp}.logLog levels: DEBUG, INFO, WARNING, ERROR, CRITICAL (configurable via
--verbose)HTML reports generated for template creation, deployment, and policy documentation
Error HandlingΒΆ
Config errors: Caught during schema validation (before any AWS calls)
Template errors: Caught during local validation (before deployment)
AWS errors: Caught and logged with error code and message
Stack failures: CloudFormation automatic rollback with event logging
Fatal errors: Caught by BaseCLI with exit code 1
MonitoringΒΆ
Drift detection:
check-driftidentifies resources modified outside CloudFormationChange preview:
show-changesshows pending modifications before applyingSSM parameters: Provide discoverable inventory of deployed resources
CloudFormation events: Full audit trail of stack operations