Files
skills/public/infrastructure-infrastructure-security.html
zeekayandHanzo Dev 9e10c1c10e Each llms index points at the other two
hanzoskills.com/llms.txt now opens with the install line, the API
reference index and the company index, so an agent that lands on any
one of the three can find the rest.

robots.txt claimed 537 documents while llms.txt counts 920. The number
is gone from robots.txt; llms.txt derives it.

public/ is regenerated from scripts/site.py, which it had fallen
behind: the copy-prompt menu and agent bar were in the generator and
not in the committed pages. tests/site.mjs passes against the result.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-11 00:27:59 -07:00

905 lines
35 KiB
HTML

<!doctype html>
<html lang="en"><head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>infrastructure-infrastructure-security</title>
<meta name="color-scheme" content="dark">
<style>
/* Committed to one visual world: a dark instrument panel. No light variant —
the dot field and the hairline rules only read on black, and a naive
inversion would wash both out. Every colour is painted explicitly so the page
never borrows a host background. */
@font-face{font-family:'Zen';src:url('/fonts/Zen-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
@font-face{font-family:'Zen';src:url('/fonts/Zen-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
@font-face{font-family:'Zen Pixel Square';src:url('/fonts/ZenPixel-Square.woff2') format('woff2');font-style:normal;font-display:swap}
:root{
--ink:#f4f4f2; --soft:#9c9c98; --faint:#6a6a66; --ground:#000; --panel:#0a0a0a;
--line:#232323; --line-hi:#3a3a3a; --accent:#f4f4f2;
--font-zen-sans:'Zen',-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
--font-zen-mono:'Zen Mono',ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
--font-zen-pixel-square:'Zen Pixel Square',monospace;
--mono:var(--font-zen-mono);
--sans:var(--font-zen-sans);
/* Controls are pills and surfaces are soft, as on hanzo.ai. */
--r:999px; --r-soft:14px;
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0;background:var(--ground);color:var(--ink);font-family:var(--sans);
font-size:16px;line-height:1.65;-webkit-font-smoothing:antialiased}
.wrap{max-width:60rem;margin:0 auto;padding:0 1.75rem}
/* The dot field. A halftone made of one repeating radial-gradient, faded out
along the diagonal by a mask so it reads as a wave rather than wallpaper. */
/* No overflow clip here: the dot field is inset to the box already, and a clip
would cut off the copy-prompt menu. */
.hero{position:relative;border-bottom:1px solid var(--line)}
.hero::before{content:"";position:absolute;inset:0;
background-image:radial-gradient(var(--line-hi) 1px, transparent 1px);
background-size:7px 7px;
-webkit-mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
pointer-events:none}
.hero .wrap{position:relative;padding-top:5.5rem;padding-bottom:4rem}
nav{border-bottom:1px solid var(--line)}
nav .in{max-width:60rem;margin:0 auto;padding:1.1rem 1.75rem;display:flex;
justify-content:space-between;align-items:center;gap:1rem}
.brand{font-family:var(--mono);font-size:.85rem;letter-spacing:.14em;
text-transform:uppercase;color:var(--ink);text-decoration:none;
display:inline-flex;align-items:center;gap:.6rem}
.brand i{font-style:normal;color:var(--faint)}
.mark{width:1.15em;height:1.15em;display:block;flex:0 0 auto}
nav a.up{font-family:var(--mono);font-size:.72rem;letter-spacing:.14em;
text-transform:uppercase;color:var(--soft);text-decoration:none}
nav a.up:hover{color:var(--ink)}
h1{font-family:var(--mono);font-size:clamp(2rem,5.4vw,3.4rem);line-height:1.12;
letter-spacing:-.02em;margin:0 0 1.1rem;font-weight:500;text-wrap:balance}
h1 em{font-style:normal;color:var(--faint)}
.lede{color:var(--soft);font-size:1.05rem;max-width:52ch;margin:0 0 2.25rem}
.btns{display:flex;flex-wrap:wrap;gap:.7rem;margin:0 0 .5rem;align-items:center}
.btn{display:inline-flex;align-items:center;gap:.5rem;font-family:var(--mono);
font-size:.72rem;letter-spacing:.14em;text-transform:uppercase;
padding:.8rem 1.4rem;border:1px solid var(--line-hi);border-radius:var(--r);
color:var(--ink);text-decoration:none;background:transparent;cursor:pointer;
line-height:1.2;font-weight:400}
.btn:hover{background:#141414;text-decoration:none;border-color:var(--soft)}
.btn.solid{background:var(--ink);color:#000;border-color:var(--ink)}
.btn.solid:hover{background:#d8d8d4}
.btn .chev{width:.7em;height:.7em;flex:0 0 auto;transition:transform .15s ease}
.btn[aria-expanded="true"] .chev{transform:rotate(180deg)}
/* Copy-prompt selector. Each row copies the prompt for its own target. */
.copy{position:relative;display:inline-flex}
.menu{position:absolute;top:calc(100% + .5rem);left:0;z-index:20;min-width:21rem;
background:var(--panel);border:1px solid var(--line-hi);border-radius:var(--r-soft);
padding:.4rem;display:flex;flex-direction:column;
box-shadow:0 12px 32px rgba(0,0,0,.75)}
.menu[hidden]{display:none}
.mi{display:flex;align-items:center;gap:.7rem;width:100%;text-align:left;
padding:.62rem .8rem;border:0;border-radius:calc(var(--r-soft) - .35rem);
background:transparent;color:var(--ink);font-family:var(--mono);font-size:.76rem;
letter-spacing:.04em;text-decoration:none;cursor:pointer;line-height:1.3;
white-space:nowrap}
.mi:hover,.mi:focus-visible{background:#181818;outline:none}
.mi .mark{width:1.05rem;height:1.05rem;color:var(--soft)}
.mi:hover .mark{color:var(--ink)}
.mi u{margin-left:auto;color:var(--faint);text-decoration:none;font-size:.68rem;
letter-spacing:.1em;text-transform:uppercase}
/* Works-with bar: one scrolling row, name and mark per agent. */
.strip{border-bottom:1px solid var(--line);background:var(--panel)}
.strip .in{max-width:60rem;margin:0 auto;padding:.9rem 1.75rem;display:flex;
align-items:center;gap:1.25rem;font-family:var(--mono);font-size:.72rem;
letter-spacing:.1em;text-transform:uppercase;color:var(--faint)}
.strip b{color:var(--soft);font-weight:400;flex:0 0 auto;
border-right:1px solid var(--line);padding-right:1.25rem;align-self:stretch;
display:flex;align-items:center}
.bar{display:flex;align-items:center;gap:.5rem;flex:1 1 auto;min-width:0;
overflow-x:auto;scrollbar-width:none;scroll-snap-type:x proximity;
-webkit-overflow-scrolling:touch;
-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent);
mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent)}
.bar::-webkit-scrollbar{display:none}
.agent{display:inline-flex;align-items:center;gap:.45rem;flex:0 0 auto;
padding:.4rem .85rem;border:1px solid var(--line);border-radius:var(--r);
color:var(--soft);white-space:nowrap;scroll-snap-align:start;
text-decoration:none;background:var(--ground)}
.agent:hover{color:var(--ink);border-color:var(--line-hi);text-decoration:none}
.agent .mark{width:.95rem;height:.95rem}
h2{font-family:var(--mono);font-size:1.1rem;letter-spacing:-.01em;margin:2.75rem 0 .75rem;font-weight:500}
h3{font-size:1rem;margin:2rem 0 .5rem;font-weight:600}
h4,h5,h6{font-size:.94rem;margin:1.5rem 0 .5rem;font-weight:600}
p{margin:0 0 1rem;max-width:70ch}
ul,ol{margin:0 0 1rem;padding-left:1.35rem;max-width:70ch}
li{margin:.22rem 0}
a{color:var(--ink);text-decoration:underline;text-underline-offset:3px;
text-decoration-color:var(--line-hi)}
a:hover{text-decoration-color:var(--ink)}
a:focus-visible{outline:1px solid var(--ink);outline-offset:3px}
code{font-family:var(--mono);font-size:.85em;background:var(--panel);
border:1px solid var(--line);border-radius:5px;padding:.1em .36em}
pre{background:var(--panel);border:1px solid var(--line);padding:1rem 1.1rem;
border-radius:var(--r-soft);overflow-x:auto;margin:0 0 1.25rem}
pre code{background:none;border:0;padding:0;font-size:.82rem;line-height:1.7}
blockquote{margin:0 0 1rem;padding-left:1rem;border-left:1px solid var(--line-hi);color:var(--soft)}
hr{border:0;border-top:1px solid var(--line);margin:2.5rem 0}
table{border-collapse:collapse;width:100%;margin:0 0 1.25rem;font-size:.92rem;
display:block;overflow-x:auto}
th,td{border:1px solid var(--line);padding:.5rem .7rem;text-align:left}
.curl{display:block;background:var(--panel);border:1px solid var(--line);
border-radius:var(--r-soft);padding:.95rem 1.1rem;font-family:var(--mono);
font-size:.8rem;color:var(--soft);overflow-x:auto;margin:0 0 2.5rem;
white-space:pre;line-height:1.9}
.curl b{color:var(--ink);font-weight:400}
.curl i{font-style:normal;color:var(--faint)}
/* index */
#q{width:100%;padding:.85rem 1.2rem;font-family:var(--mono);font-size:.85rem;color:var(--ink);
background:var(--panel);border:1px solid var(--line);border-radius:var(--r);margin:0 0 .6rem}
#q::placeholder{color:var(--faint);text-transform:uppercase;letter-spacing:.1em;font-size:.72rem}
#q:focus{outline:none;border-color:var(--soft)}
#count{color:var(--faint);font-family:var(--mono);font-size:.72rem;letter-spacing:.1em;
text-transform:uppercase;margin:0 0 2rem}
.cat{margin:2.5rem 0 .5rem;font-family:var(--mono);font-size:.7rem;letter-spacing:.16em;
text-transform:uppercase;color:var(--faint);border-bottom:1px solid var(--line);
padding-bottom:.45rem}
.row{display:block;padding:.6rem .9rem;margin:0 -.9rem;border-bottom:1px solid var(--line);
border-radius:var(--r-soft);text-decoration:none}
.row:hover{background:#0a0a0a}
.nm{font-family:var(--mono);font-size:.84rem;color:var(--ink);display:block}
.ds{color:var(--soft);font-size:.9rem;display:block;margin-top:.12rem}
footer{margin-top:4rem;padding:2rem 0 4rem;border-top:1px solid var(--line);
color:var(--faint);font-size:.85rem}
footer a{color:var(--soft)}
.fmap{display:grid;gap:1.75rem;grid-template-columns:repeat(auto-fit,minmax(11rem,1fr));
margin:0 0 2rem;font-size:.85rem}
.fmap b{display:block;font-family:var(--mono);font-size:.68rem;letter-spacing:.16em;
text-transform:uppercase;color:var(--faint);font-weight:400;margin:0 0 .6rem;
border-bottom:1px solid var(--line);padding-bottom:.4rem}
.fmap a{display:inline-block;color:var(--ink);text-decoration:none;margin:.3rem .35rem 0 0}
.fmap a:hover{text-decoration:underline}
.fmap div{color:var(--faint);line-height:1.5}
.fend{border-top:1px solid var(--line);padding-top:1.25rem;font-size:.82rem}
@media (max-width:640px){
.hero .wrap{padding-top:3.25rem;padding-bottom:2.75rem}
.btns{gap:.5rem}
.btn{padding:.75rem 1.15rem;font-size:.68rem}
.copy,.copy .btn{width:100%;justify-content:center}
.menu{left:0;right:0;min-width:0}
.strip .in{flex-direction:column;align-items:flex-start;gap:.6rem;padding:.9rem 1.75rem}
.strip b{border-right:0;padding-right:0}
.bar{width:100%}
}
</style>
<link rel="alternate" type="text/markdown" href="/infrastructure-infrastructure-security.md">
<link rel="icon" href="/favicon.svg">
<link rel="canonical" href="https://hanzoskills.com/infrastructure-infrastructure-security">
</head>
<!-- Reading this with a machine? Every page here is also plain markdown.
This one: https://hanzoskills.com/infrastructure-infrastructure-security.md
Index: https://hanzoskills.com/llms.txt
Corpus: https://hanzoskills.com/all.md
Append .md to any path for the markdown twin. -->
<body>
<nav><div class="in">
<a class="brand" href="/"><svg class="mark" viewBox="0 0 67 67" fill="currentColor" aria-hidden="true"><path d="M22.21 67V44.6369H0V67H22.21Z"/><path d="M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z"/><path d="M22.21 0H0V22.3184H22.21V0Z"/><path d="M66.7198 0H44.5098V22.3184H66.7198V0Z"/><path d="M66.7198 67V44.6369H44.5098V67H66.7198Z"/></svg> HANZO<i>SKILLS</i></a>
<a class="up" href="/">All skills</a>
</div></nav>
<div class="wrap">
<h1>infrastructure-infrastructure-security</h1><p class="lede">Setting up IAM roles and policies</p><h1>Infrastructure Security</h1>
<p><strong>Scope</strong>: Security best practices - IAM, security groups, secrets management, encryption <strong>Lines</strong>: 381 <strong>Last Updated</strong>: 2025-10-18 <strong>Format Version</strong>: 1.0 (Atomic)</p>
<hr>
<h2>When to Use This Skill</h2>
<p><strong>Activate when</strong>:</p>
<ul><li>Setting up IAM roles and policies</li><li>Configuring network security (security groups, NACLs)</li><li>Managing secrets and credentials</li><li>Implementing encryption at rest and in transit</li><li>Establishing least privilege access</li><li>Securing API endpoints and services</li></ul>
<p><strong>Prerequisites</strong>:</p>
<ul><li>Understanding of cloud provider (AWS, GCP, Azure)</li><li>Basic networking knowledge (CIDR, ports, protocols)</li><li>Familiarity with cryptography concepts</li><li>Access to cloud provider console/CLI</li><li>Understanding of compliance requirements (if applicable)</li></ul>
<p><strong>Common scenarios</strong>:</p>
<ul><li>Securing serverless applications</li><li>Multi-tier application security</li><li>Database encryption and access control</li><li>API authentication and authorization</li><li>Secrets rotation and management</li><li>Compliance with SOC2, HIPAA, PCI-DSS</li></ul>
<hr>
<h2>Core Concepts</h2>
<h3>1. IAM Policies (AWS)</h3>
<pre><code class="lang-json">{
&quot;Version&quot;: &quot;2012-10-17&quot;,
&quot;Statement&quot;: [
{
&quot;Sid&quot;: &quot;LambdaDynamoDBAccess&quot;,
&quot;Effect&quot;: &quot;Allow&quot;,
&quot;Action&quot;: [
&quot;dynamodb:GetItem&quot;,
&quot;dynamodb:PutItem&quot;,
&quot;dynamodb:UpdateItem&quot;,
&quot;dynamodb:Query&quot;
],
&quot;Resource&quot;: [
&quot;arn:aws:dynamodb:us-east-1:123456789012:table/Users&quot;,
&quot;arn:aws:dynamodb:us-east-1:123456789012:table/Users/index/*&quot;
]
},
{
&quot;Sid&quot;: &quot;S3ReadAccess&quot;,
&quot;Effect&quot;: &quot;Allow&quot;,
&quot;Action&quot;: [
&quot;s3:GetObject&quot;,
&quot;s3:ListBucket&quot;
],
&quot;Resource&quot;: [
&quot;arn:aws:s3:::my-bucket&quot;,
&quot;arn:aws:s3:::my-bucket/*&quot;
],
&quot;Condition&quot;: {
&quot;StringLike&quot;: {
&quot;s3:prefix&quot;: [&quot;public/*&quot;]
}
}
},
{
&quot;Sid&quot;: &quot;SecretsManagerAccess&quot;,
&quot;Effect&quot;: &quot;Allow&quot;,
&quot;Action&quot;: [
&quot;secretsmanager:GetSecretValue&quot;
],
&quot;Resource&quot;: &quot;arn:aws:secretsmanager:us-east-1:123456789012:secret:db-credentials-*&quot;
},
{
&quot;Sid&quot;: &quot;CloudWatchLogs&quot;,
&quot;Effect&quot;: &quot;Allow&quot;,
&quot;Action&quot;: [
&quot;logs:CreateLogGroup&quot;,
&quot;logs:CreateLogStream&quot;,
&quot;logs:PutLogEvents&quot;
],
&quot;Resource&quot;: &quot;arn:aws:logs:*:*:*&quot;
}
]
}</code></pre>
<h3>2. IAM Roles and Trust Policies</h3>
<pre><code class="lang-json">// Trust policy - who can assume this role
{
&quot;Version&quot;: &quot;2012-10-17&quot;,
&quot;Statement&quot;: [
{
&quot;Effect&quot;: &quot;Allow&quot;,
&quot;Principal&quot;: {
&quot;Service&quot;: &quot;lambda.amazonaws.com&quot;
},
&quot;Action&quot;: &quot;sts:AssumeRole&quot;
}
]
}
// Cross-account access trust policy
{
&quot;Version&quot;: &quot;2012-10-17&quot;,
&quot;Statement&quot;: [
{
&quot;Effect&quot;: &quot;Allow&quot;,
&quot;Principal&quot;: {
&quot;AWS&quot;: &quot;arn:aws:iam::987654321098:root&quot;
},
&quot;Action&quot;: &quot;sts:AssumeRole&quot;,
&quot;Condition&quot;: {
&quot;StringEquals&quot;: {
&quot;sts:ExternalId&quot;: &quot;unique-external-id-12345&quot;
}
}
}
]
}</code></pre>
<h3>3. Security Groups</h3>
<pre><code class="lang-hcl"># Terraform - Web tier security group
resource &quot;aws_security_group&quot; &quot;web&quot; {
name = &quot;web-tier-sg&quot;
description = &quot;Security group for web tier&quot;
vpc_id = var.vpc_id
# Inbound rules
ingress {
description = &quot;HTTPS from internet&quot;
from_port = 443
to_port = 443
protocol = &quot;tcp&quot;
cidr_blocks = [&quot;0.0.0.0/0&quot;]
}
ingress {
description = &quot;HTTP from internet&quot;
from_port = 80
to_port = 80
protocol = &quot;tcp&quot;
cidr_blocks = [&quot;0.0.0.0/0&quot;]
}
# Outbound rules
egress {
description = &quot;To app tier&quot;
from_port = 8080
to_port = 8080
protocol = &quot;tcp&quot;
security_groups = [aws_security_group.app.id]
}
egress {
description = &quot;HTTPS to internet&quot;
from_port = 443
to_port = 443
protocol = &quot;tcp&quot;
cidr_blocks = [&quot;0.0.0.0/0&quot;]
}
tags = {
Name = &quot;web-tier-sg&quot;
Tier = &quot;web&quot;
}
}
# Application tier security group
resource &quot;aws_security_group&quot; &quot;app&quot; {
name = &quot;app-tier-sg&quot;
description = &quot;Security group for app tier&quot;
vpc_id = var.vpc_id
ingress {
description = &quot;From web tier&quot;
from_port = 8080
to_port = 8080
protocol = &quot;tcp&quot;
security_groups = [aws_security_group.web.id]
}
egress {
description = &quot;To database&quot;
from_port = 5432
to_port = 5432
protocol = &quot;tcp&quot;
security_groups = [aws_security_group.database.id]
}
tags = {
Name = &quot;app-tier-sg&quot;
Tier = &quot;app&quot;
}
}
# Database tier security group
resource &quot;aws_security_group&quot; &quot;database&quot; {
name = &quot;database-tier-sg&quot;
description = &quot;Security group for database tier&quot;
vpc_id = var.vpc_id
ingress {
description = &quot;PostgreSQL from app tier&quot;
from_port = 5432
to_port = 5432
protocol = &quot;tcp&quot;
security_groups = [aws_security_group.app.id]
}
# No outbound rules - database doesn&#x27;t initiate connections
tags = {
Name = &quot;database-tier-sg&quot;
Tier = &quot;database&quot;
}
}</code></pre>
<h3>4. Secrets Management</h3>
<pre><code class="lang-python"># AWS Secrets Manager
import boto3
import json
from botocore.exceptions import ClientError
def get_secret(secret_name, region_name=&quot;us-east-1&quot;):
&quot;&quot;&quot;Retrieve secret from AWS Secrets Manager&quot;&quot;&quot;
session = boto3.session.Session()
client = session.client(
service_name=&#x27;secretsmanager&#x27;,
region_name=region_name
)
try:
response = client.get_secret_value(SecretId=secret_name)
if &#x27;SecretString&#x27; in response:
return json.loads(response[&#x27;SecretString&#x27;])
else:
# Binary secret
return response[&#x27;SecretBinary&#x27;]
except ClientError as e:
if e.response[&#x27;Error&#x27;][&#x27;Code&#x27;] == &#x27;ResourceNotFoundException&#x27;:
print(f&quot;Secret {secret_name} not found&quot;)
elif e.response[&#x27;Error&#x27;][&#x27;Code&#x27;] == &#x27;InvalidRequestException&#x27;:
print(f&quot;Invalid request for secret {secret_name}&quot;)
elif e.response[&#x27;Error&#x27;][&#x27;Code&#x27;] == &#x27;InvalidParameterException&#x27;:
print(f&quot;Invalid parameter for secret {secret_name}&quot;)
raise e
# Lambda function using secrets
import os
def lambda_handler(event, context):
# Get database credentials
db_secret = get_secret(os.environ[&#x27;DB_SECRET_NAME&#x27;])
# Use credentials
db_host = db_secret[&#x27;host&#x27;]
db_user = db_secret[&#x27;username&#x27;]
db_password = db_secret[&#x27;password&#x27;]
# Connect to database
# ...
# Create/update secret
def create_secret(secret_name, secret_value, region_name=&quot;us-east-1&quot;):
&quot;&quot;&quot;Create or update a secret&quot;&quot;&quot;
client = boto3.client(&#x27;secretsmanager&#x27;, region_name=region_name)
try:
response = client.create_secret(
Name=secret_name,
SecretString=json.dumps(secret_value),
Tags=[
{&#x27;Key&#x27;: &#x27;Environment&#x27;, &#x27;Value&#x27;: &#x27;production&#x27;},
{&#x27;Key&#x27;: &#x27;ManagedBy&#x27;, &#x27;Value&#x27;: &#x27;terraform&#x27;}
]
)
return response[&#x27;ARN&#x27;]
except client.exceptions.ResourceExistsException:
# Update existing secret
response = client.update_secret(
SecretId=secret_name,
SecretString=json.dumps(secret_value)
)
return response[&#x27;ARN&#x27;]
# Rotate secret
def rotate_secret(secret_name):
&quot;&quot;&quot;Rotate secret (requires Lambda rotation function)&quot;&quot;&quot;
client = boto3.client(&#x27;secretsmanager&#x27;)
response = client.rotate_secret(
SecretId=secret_name,
RotationLambdaARN=&#x27;arn:aws:lambda:us-east-1:123456789012:function:rotate-secret&#x27;,
RotationRules={
&#x27;AutomaticallyAfterDays&#x27;: 30
}
)
return response</code></pre>
<h3>5. Encryption</h3>
<pre><code class="lang-python"># S3 encryption at rest
import boto3
s3 = boto3.client(&#x27;s3&#x27;)
# Server-side encryption with S3-managed keys (SSE-S3)
s3.put_object(
Bucket=&#x27;my-bucket&#x27;,
Key=&#x27;file.txt&#x27;,
Body=b&#x27;data&#x27;,
ServerSideEncryption=&#x27;AES256&#x27;
)
# Server-side encryption with KMS (SSE-KMS)
s3.put_object(
Bucket=&#x27;my-bucket&#x27;,
Key=&#x27;file.txt&#x27;,
Body=b&#x27;data&#x27;,
ServerSideEncryption=&#x27;aws:kms&#x27;,
SSEKMSKeyId=&#x27;arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012&#x27;
)
# Client-side encryption
from cryptography.fernet import Fernet
# Generate key (store in Secrets Manager)
key = Fernet.generate_key()
cipher = Fernet(key)
# Encrypt data
plaintext = b&quot;sensitive data&quot;
ciphertext = cipher.encrypt(plaintext)
# Upload encrypted data
s3.put_object(
Bucket=&#x27;my-bucket&#x27;,
Key=&#x27;encrypted-file.txt&#x27;,
Body=ciphertext
)
# Decrypt data
encrypted_data = s3.get_object(Bucket=&#x27;my-bucket&#x27;, Key=&#x27;encrypted-file.txt&#x27;)[&#x27;Body&#x27;].read()
decrypted_data = cipher.decrypt(encrypted_data)</code></pre>
<h3>6. Network ACLs</h3>
<pre><code class="lang-hcl"># Terraform - Network ACL for public subnet
resource &quot;aws_network_acl&quot; &quot;public&quot; {
vpc_id = var.vpc_id
subnet_ids = var.public_subnet_ids
# Inbound rules
ingress {
rule_no = 100
protocol = &quot;tcp&quot;
action = &quot;allow&quot;
cidr_block = &quot;0.0.0.0/0&quot;
from_port = 443
to_port = 443
}
ingress {
rule_no = 110
protocol = &quot;tcp&quot;
action = &quot;allow&quot;
cidr_block = &quot;0.0.0.0/0&quot;
from_port = 80
to_port = 80
}
ingress {
rule_no = 120
protocol = &quot;tcp&quot;
action = &quot;allow&quot;
cidr_block = &quot;0.0.0.0/0&quot;
from_port = 1024
to_port = 65535 # Ephemeral ports for return traffic
}
# Deny all other inbound
ingress {
rule_no = 32767
protocol = &quot;-1&quot;
action = &quot;deny&quot;
cidr_block = &quot;0.0.0.0/0&quot;
from_port = 0
to_port = 0
}
# Outbound rules
egress {
rule_no = 100
protocol = &quot;-1&quot;
action = &quot;allow&quot;
cidr_block = &quot;0.0.0.0/0&quot;
from_port = 0
to_port = 0
}
tags = {
Name = &quot;public-nacl&quot;
}
}</code></pre>
<hr>
<h2>Patterns</h2>
<h3>Least Privilege IAM Policy</h3>
<pre><code class="lang-json">{
&quot;Version&quot;: &quot;2012-10-17&quot;,
&quot;Statement&quot;: [
{
&quot;Sid&quot;: &quot;SpecificResourceAccess&quot;,
&quot;Effect&quot;: &quot;Allow&quot;,
&quot;Action&quot;: [
&quot;dynamodb:GetItem&quot;,
&quot;dynamodb:PutItem&quot;
],
&quot;Resource&quot;: &quot;arn:aws:dynamodb:us-east-1:123456789012:table/Users&quot;,
&quot;Condition&quot;: {
&quot;ForAllValues:StringEquals&quot;: {
&quot;dynamodb:LeadingKeys&quot;: [&quot;${aws:username}&quot;]
}
}
},
{
&quot;Sid&quot;: &quot;DenyUnencryptedUploads&quot;,
&quot;Effect&quot;: &quot;Deny&quot;,
&quot;Action&quot;: &quot;s3:PutObject&quot;,
&quot;Resource&quot;: &quot;arn:aws:s3:::my-bucket/*&quot;,
&quot;Condition&quot;: {
&quot;StringNotEquals&quot;: {
&quot;s3:x-amz-server-side-encryption&quot;: &quot;aws:kms&quot;
}
}
}
]
}</code></pre>
<h3>Multi-Factor Authentication</h3>
<pre><code class="lang-json">// Require MFA for sensitive operations
{
&quot;Version&quot;: &quot;2012-10-17&quot;,
&quot;Statement&quot;: [
{
&quot;Sid&quot;: &quot;AllowViewAccountInfo&quot;,
&quot;Effect&quot;: &quot;Allow&quot;,
&quot;Action&quot;: [
&quot;iam:GetAccountPasswordPolicy&quot;,
&quot;iam:ListVirtualMFADevices&quot;
],
&quot;Resource&quot;: &quot;*&quot;
},
{
&quot;Sid&quot;: &quot;RequireMFAForSensitiveOperations&quot;,
&quot;Effect&quot;: &quot;Allow&quot;,
&quot;Action&quot;: [
&quot;ec2:TerminateInstances&quot;,
&quot;rds:DeleteDBInstance&quot;,
&quot;s3:DeleteBucket&quot;
],
&quot;Resource&quot;: &quot;*&quot;,
&quot;Condition&quot;: {
&quot;Bool&quot;: {
&quot;aws:MultiFactorAuthPresent&quot;: &quot;true&quot;
},
&quot;NumericLessThan&quot;: {
&quot;aws:MultiFactorAuthAge&quot;: &quot;3600&quot;
}
}
}
]
}</code></pre>
<h3>VPC Endpoints for Private Access</h3>
<pre><code class="lang-hcl"># Private access to AWS services without internet gateway
resource &quot;aws_vpc_endpoint&quot; &quot;s3&quot; {
vpc_id = var.vpc_id
service_name = &quot;com.amazonaws.us-east-1.s3&quot;
route_table_ids = var.private_route_table_ids
policy = jsonencode({
Version = &quot;2012-10-17&quot;
Statement = [
{
Sid = &quot;AllowS3Access&quot;
Effect = &quot;Allow&quot;
Principal = &quot;*&quot;
Action = [
&quot;s3:GetObject&quot;,
&quot;s3:PutObject&quot;
]
Resource = &quot;arn:aws:s3:::my-private-bucket/*&quot;
}
]
})
tags = {
Name = &quot;s3-vpc-endpoint&quot;
}
}
# Interface endpoint for other services
resource &quot;aws_vpc_endpoint&quot; &quot;secretsmanager&quot; {
vpc_id = var.vpc_id
service_name = &quot;com.amazonaws.us-east-1.secretsmanager&quot;
vpc_endpoint_type = &quot;Interface&quot;
subnet_ids = var.private_subnet_ids
security_group_ids = [aws_security_group.vpc_endpoint.id]
private_dns_enabled = true
tags = {
Name = &quot;secretsmanager-vpc-endpoint&quot;
}
}</code></pre>
<h3>Certificate Management</h3>
<pre><code class="lang-python"># AWS Certificate Manager
import boto3
acm = boto3.client(&#x27;acm&#x27;)
# Request certificate
response = acm.request_certificate(
DomainName=&#x27;example.com&#x27;,
SubjectAlternativeNames=[
&#x27;*.example.com&#x27;,
&#x27;www.example.com&#x27;
],
ValidationMethod=&#x27;DNS&#x27;,
Tags=[
{&#x27;Key&#x27;: &#x27;Environment&#x27;, &#x27;Value&#x27;: &#x27;production&#x27;}
]
)
certificate_arn = response[&#x27;CertificateArn&#x27;]
# Get certificate validation records
response = acm.describe_certificate(CertificateArn=certificate_arn)
validation_options = response[&#x27;Certificate&#x27;][&#x27;DomainValidationOptions&#x27;]
# Create Route53 validation records automatically
route53 = boto3.client(&#x27;route53&#x27;)
for option in validation_options:
route53.change_resource_record_sets(
HostedZoneId=&#x27;Z1234567890ABC&#x27;,
ChangeBatch={
&#x27;Changes&#x27;: [{
&#x27;Action&#x27;: &#x27;CREATE&#x27;,
&#x27;ResourceRecordSet&#x27;: {
&#x27;Name&#x27;: option[&#x27;ResourceRecord&#x27;][&#x27;Name&#x27;],
&#x27;Type&#x27;: option[&#x27;ResourceRecord&#x27;][&#x27;Type&#x27;],
&#x27;TTL&#x27;: 300,
&#x27;ResourceRecords&#x27;: [{&#x27;Value&#x27;: option[&#x27;ResourceRecord&#x27;][&#x27;Value&#x27;]}]
}
}]
}
)</code></pre>
<h3>API Authentication</h3>
<pre><code class="lang-python"># Lambda authorizer for API Gateway
import json
def lambda_handler(event, context):
&quot;&quot;&quot;
Custom authorizer for API Gateway
Validates JWT or API key
&quot;&quot;&quot;
token = event[&#x27;authorizationToken&#x27;] # Bearer token
method_arn = event[&#x27;methodArn&#x27;]
# Validate token (check signature, expiration, etc.)
if validate_token(token):
principal_id = extract_user_id(token)
policy = generate_policy(principal_id, &#x27;Allow&#x27;, method_arn)
# Add context to pass to Lambda function
policy[&#x27;context&#x27;] = {
&#x27;userId&#x27;: principal_id,
&#x27;role&#x27;: extract_role(token)
}
return policy
else:
raise Exception(&#x27;Unauthorized&#x27;)
def generate_policy(principal_id, effect, resource):
&quot;&quot;&quot;Generate IAM policy&quot;&quot;&quot;
policy = {
&#x27;principalId&#x27;: principal_id,
&#x27;policyDocument&#x27;: {
&#x27;Version&#x27;: &#x27;2012-10-17&#x27;,
&#x27;Statement&#x27;: [{
&#x27;Action&#x27;: &#x27;execute-api:Invoke&#x27;,
&#x27;Effect&#x27;: effect,
&#x27;Resource&#x27;: resource
}]
}
}
return policy
def validate_token(token):
&quot;&quot;&quot;Validate JWT token&quot;&quot;&quot;
# Implementation depends on your token type
# For JWT: decode, verify signature, check expiration
return True # Simplified
def extract_user_id(token):
&quot;&quot;&quot;Extract user ID from token&quot;&quot;&quot;
return &quot;user123&quot; # Simplified
def extract_role(token):
&quot;&quot;&quot;Extract role from token&quot;&quot;&quot;
return &quot;admin&quot; # Simplified</code></pre>
<hr>
<h2>Quick Reference</h2>
<h3>AWS IAM Best Practices</h3>
<pre><code class="lang-bash"># Enable MFA for root account
# Create IAM users instead of using root
# Use groups to assign permissions
# Grant least privilege
# Use roles for applications
# Rotate credentials regularly
# Enable CloudTrail for auditing
# AWS CLI
aws iam create-user --user-name developer
aws iam create-group --group-name developers
aws iam add-user-to-group --user-name developer --group-name developers
aws iam attach-group-policy --group-name developers --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess
# Create access key
aws iam create-access-key --user-name developer
# Rotate access key
aws iam update-access-key --access-key-id AKIAIOSFODNN7EXAMPLE --status Inactive --user-name developer
aws iam delete-access-key --access-key-id AKIAIOSFODNN7EXAMPLE --user-name developer</code></pre>
<h3>Security Checklist</h3>
<pre><code>[ ] IAM users have MFA enabled
[ ] Root account not used for daily tasks
[ ] Least privilege policies applied
[ ] Security groups follow principle of least access
[ ] Encryption at rest enabled (S3, EBS, RDS)
[ ] Encryption in transit enforced (HTTPS, TLS)
[ ] Secrets stored in Secrets Manager/Parameter Store
[ ] CloudTrail enabled for audit logging
[ ] VPC Flow Logs enabled
[ ] Regular security scans (AWS Inspector, GuardDuty)
[ ] Backup and disaster recovery plan
[ ] Network segmentation (public/private subnets)
[ ] WAF configured for web applications
[ ] Regular security patches applied</code></pre>
<hr>
<h2>Anti-Patterns</h2>
<h3>Critical Violations</h3>
<pre><code class="lang-json">// ❌ NEVER: Use wildcard permissions in production
{
&quot;Effect&quot;: &quot;Allow&quot;,
&quot;Action&quot;: &quot;*&quot;,
&quot;Resource&quot;: &quot;*&quot;
}
// ✅ CORRECT: Specific permissions
{
&quot;Effect&quot;: &quot;Allow&quot;,
&quot;Action&quot;: [
&quot;s3:GetObject&quot;,
&quot;s3:PutObject&quot;
],
&quot;Resource&quot;: &quot;arn:aws:s3:::my-bucket/path/*&quot;
}</code></pre>
<pre><code class="lang-python"># ❌ NEVER: Hardcode credentials
AWS_ACCESS_KEY = &quot;AKIAIOSFODNN7EXAMPLE&quot;
AWS_SECRET_KEY = &quot;wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY&quot;
# ✅ CORRECT: Use IAM roles or environment variables
import boto3
# Uses IAM role credentials automatically
s3 = boto3.client(&#x27;s3&#x27;)
# Or environment variables
import os
access_key = os.environ[&#x27;AWS_ACCESS_KEY_ID&#x27;]</code></pre>
<pre><code class="lang-hcl"># ❌ NEVER: Open security groups to 0.0.0.0/0 for SSH
resource &quot;aws_security_group_rule&quot; &quot;ssh&quot; {
type = &quot;ingress&quot;
from_port = 22
to_port = 22
protocol = &quot;tcp&quot;
cidr_blocks = [&quot;0.0.0.0/0&quot;] # Dangerous!
security_group_id = aws_security_group.example.id
}
# ✅ CORRECT: Restrict to specific IPs or use bastion
resource &quot;aws_security_group_rule&quot; &quot;ssh&quot; {
type = &quot;ingress&quot;
from_port = 22
to_port = 22
protocol = &quot;tcp&quot;
cidr_blocks = [&quot;10.0.0.0/16&quot;] # Internal only
security_group_id = aws_security_group.example.id
}</code></pre>
<hr>
<h2>Related Skills</h2>
<p><strong>Infrastructure</strong>:</p>
<ul><li><code>aws-serverless.md</code> - IAM roles for Lambda, API Gateway authorizers</li><li><code>terraform-patterns.md</code> - Infrastructure as Code for security resources</li><li><code>kubernetes-basics.md</code> - RBAC, network policies, secrets</li></ul>
<p><strong>Networking</strong>:</p>
<ul><li><code>mtls-implementation.md</code> - Mutual TLS for service-to-service auth</li><li><code>tailscale-vpn.md</code> - Zero-trust networking</li></ul>
<p><strong>Standards from CLAUDE.md</strong>:</p>
<ul><li>Never hardcode credentials</li><li>Use IAM roles for services</li><li>Principle of least privilege</li><li>Encryption at rest and in transit</li><li>Secrets in Secrets Manager</li><li>MFA for sensitive operations</li></ul>
<hr>
<p><strong>Last Updated</strong>: 2025-10-18 <strong>Format Version</strong>: 1.0 (Atomic)</p>
<footer>
<div class="fmap">
<div><b>Build</b>
<a href="https://hanzo.app">hanzo.app</a> app builder
<a href="https://hanzo.codes">hanzo.codes</a> code with an agent
<a href="https://hanzoskills.com">hanzoskills.com</a> what an agent reads</div>
<div><b>Run</b>
<a href="https://console.hanzo.ai">console.hanzo.ai</a> cloud console
<a href="https://api.hanzo.ai">api.hanzo.ai</a> the API</div>
<div><b>Account</b>
<a href="https://hanzo.id">hanzo.id</a> sign in
<a href="https://pay.hanzo.ai">pay.hanzo.ai</a> top up
<a href="https://billing.hanzo.ai">billing.hanzo.ai</a> invoices and usage</div>
<div><b>Company</b>
<a href="https://hanzo.ai">hanzo.ai</a> canonical
<a href="https://hanzo.ventures">hanzo.ventures</a> ventures</div>
</div>
<div class="fend"><a href="/infrastructure-infrastructure-security.md">This page as plain text</a> · <a href="/llms.txt">Index for agents</a></div>
</footer>
</div></body></html>