Data Pipeline Entity Relationship Diagram
Visual representation of the core data model
Represents IT infrastructure components (hardware, software, network devices) that need to be audited.
Fields:
Security controls or compliance measures applied to assets to mitigate risks and meet standards.
Fields:
Documentation proving that controls are properly implemented (screenshots, logs, config files).
Fields:
Financial aspects associated with implementing and maintaining controls.
Fields:
Potential threats or vulnerabilities that controls aim to mitigate.
Fields:
One-to-many relationship where each asset can have multiple controls applied to it (e.g., a server might have access controls, patch management, and monitoring controls).
One-to-many relationship where each control requires multiple pieces of evidence to demonstrate its proper implementation (e.g., firewall rules, access logs).
One-to-many relationship tracking the financial investment in each control (e.g., license costs, implementation hours, maintenance expenses).
One-to-many relationship showing which risks each control mitigates, allowing for risk-based prioritization of control implementation.
Containerized data pipeline execution flow
Transformations for standards and tool integrations
Mappings from core tables to NIST SP 800-53 controls:
{
"mappings": {
"Control": {
"control_id → implemented-requirements/uuid",
"name → implemented-requirements/description",
"standard → implemented-requirements/control-id"
},
"Evidence": {
"file_path → implemented-requirements/links/href",
"collection_date → implemented-requirements/props/value"
}
},
"required_namespaces": [
"http://csrc.nist.gov/ns/oscal/1.0",
"http://csrc.nist.gov/ns/oscal/metaschema/1.0"
],
"example": {
"system-security-plan": {
"uuid": "a0e48328-...",
"implemented-requirements": [{
"uuid": "CTL-2024-001",
"control-id": "AC-2",
"description": "Server Access Control"
}]
}
}
}
mappings:
Control:
control_id: id
name: name
description: narrative
Evidence:
file_path: documentation
collected_by: referenced_by
collection_date: date
namespaces:
- opencontrol/schemas/1.0.0
example: |
standards:
- name: NIST-800-53
controls:
- id: CTL-2024-001
name: Patch Management
narrative: "Ensures timely..."
Vanta/Drata CSV Mappings:
Asset:
asset_id → Device ID
name → Asset Name
is_critical → Critical (true/false)
Control:
control_id → Control ID
implementation_status → Status
last_review_date → Last Tested
Example:
Device ID,Asset Name,Critical
ASSET-001,Web Server,true
Mappings:
CostItem:
amount → xbrli:monetaryItemType
currency → iso4217:currency
category → audit:costCategory
Namespaces:
- http://www.xbrl.org/2003/instance
- http://www.xbrl.org/dtr/type/numeric
Example:
<xbrl>
<cost:cybersecurityCost
contextRef="current"
unitRef="USD"
decimals="2">45000</cost:cybersecurityCost>
</xbrl>
Secure S3 bucket configuration with presigned URLs for auditor access
resource "aws_s3_bucket" "evidence_store" {
bucket = "audit-evidence-${var.account_id}"
object_lock_configuration {
object_lock_enabled = "Enabled"
}
lifecycle_rule {
id = "auto-expire"
enabled = true
expiration {
days = 90
}
}
}
resource "aws_s3_bucket_policy" "read_only" {
bucket = aws_s3_bucket.evidence_store.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = {"AWS": "arn:aws:iam::${var.auditor_account_id}:root"}
Action = ["s3:GetObject"]
Resource = "${aws_s3_bucket.evidence_store.arn}/*"
}]
})
}
import boto3
from datetime import datetime, timedelta
def upload_evidence(file_path, control_id):
s3 = boto3.client('s3')
bucket = 'audit-evidence-123456789012'
key = f"{control_id}/{datetime.now().isoformat()}_{file_path.split('/')[-1]}"
# Upload file with object lock retention
s3.upload_file(file_path, bucket, key, ExtraArgs={
'ObjectLockMode': 'GOVERNANCE',
'ObjectLockRetainUntilDate': datetime.now() + timedelta(days=90)
})
# Generate presigned URL
url = s3.generate_presigned_url(
'get_object',
Params={'Bucket': bucket, 'Key': key},
ExpiresIn=432000 # 5 days in seconds
)
return url
Auditors receive time-limited presigned URLs that:
Workflow:
Automated 90-day refresh cycle with observability
resource "aws_cloudwatch_event_rule" "quarterly_audit" {
name = "quarterly-audit-data-collection"
description = "Triggers audit data collection every 90 days"
schedule_expression = "rate(90 days)"
}
resource "aws_iam_role" "lambda_exec" {
name = "audit-data-collector-lambda"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "lambda.amazonaws.com"
}
}]
})
}
resource "aws_iam_role_policy" "lambda_policy" {
name = "least-privilege-audit-collector"
role = aws_iam_role.lambda_exec.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
Resource = "arn:aws:logs:*:*:*"
},
{
Effect = "Allow"
Action = [
"cloudwatch:PutMetricData"
]
Resource = "*"
}
]
})
}
resource "aws_lambda_function" "data_collector" {
filename = "data-collector.zip"
function_name = "audit-data-collector"
role = aws_iam_role.lambda_exec.arn
handler = "lambda_function.lambda_handler"
runtime = "python3.9"
timeout = 900 # 15 minutes
environment {
variables = {
DB_HOST = var.database_host
DB_PASSWORD = var.database_password
OPENAI_KEY = var.openai_key
}
}
}
resource "aws_cloudwatch_event_target" "trigger_lambda" {
rule = aws_cloudwatch_event_rule.quarterly_audit.name
target_id = "TriggerLambda"
arn = aws_lambda_function.data_collector.arn
}
resource "aws_lambda_permission" "allow_cloudwatch" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.data_collector.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.quarterly_audit.arn
}
import os
import boto3
from datetime import datetime
import psycopg2
import openai
cloudwatch = boto3.client('cloudwatch')
def lambda_handler(event, context):
# Connect to database using env vars
conn = psycopg2.connect(
host=os.environ['DB_HOST'],
database="audit",
user="collector",
password=os.environ['DB_PASSWORD']
)
try:
start_time = datetime.now()
# 1. Collect data from APIs
collect_assets()
collect_controls()
# 2. Process with OpenAI for risk analysis
analyze_risks()
# 3. Publish metrics
publish_metrics(
duration=(datetime.now() - start_time).total_seconds(),
assets_collected=100, # example value
controls_processed=50 # example value
)
return {"status": "success"}
except Exception as e:
publish_error_metric()
raise e
def publish_metrics(duration, assets_collected, controls_processed):
cloudwatch.put_metric_data(
Namespace='AuditDataCollection',
MetricData=[
{
'MetricName': 'ExecutionTime',
'Value': duration,
'Unit': 'Seconds'
},
{
'MetricName': 'AssetsCollected',
'Value': assets_collected,
'Unit': 'Count'
},
{
'MetricName': 'ControlsProcessed',
'Value': controls_processed,
'Unit': 'Count'
}
]
)
def publish_error_metric():
cloudwatch.put_metric_data(
Namespace='AuditDataCollection',
MetricData=[{
'MetricName': 'CollectionErrors',
'Value': 1,
'Unit': 'Count'
}]
)
Template for converting failed controls into actionable insights
Transform this failed control data into a concise risk narrative in JSON format:
1. Business Risk Summary: One sentence describing the business impact
2. Control Reference: Include the control_id
3. Actionable Fix: One practical recommendation (≤40 words)
4. Format: Strict JSON with keys summary, control_id, recommendation
Example Input:
{
"control_name": "Server Patch Management",
"control_id": "CTL-2024-001",
"failure_details": "30% of servers missing critical security patches"
}
Required Output Format:
{
"summary": "[business risk statement]",
"control_id": "[control identifier]",
"recommendation": "[concrete action item]"
}
{
"summary": "Unpatched servers create vulnerabilities for ransomware attacks and data breaches",
"control_id": "CTL-2024-001",
"recommendation": "Deploy automated patching system with 72-hour SLA for critical updates"
}