mirror of
https://github.com/hanzoai/skills.git
synced 2026-11-19 00:47:36 +00:00
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]>
905 lines
35 KiB
HTML
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">{
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{
|
|
"Sid": "LambdaDynamoDBAccess",
|
|
"Effect": "Allow",
|
|
"Action": [
|
|
"dynamodb:GetItem",
|
|
"dynamodb:PutItem",
|
|
"dynamodb:UpdateItem",
|
|
"dynamodb:Query"
|
|
],
|
|
"Resource": [
|
|
"arn:aws:dynamodb:us-east-1:123456789012:table/Users",
|
|
"arn:aws:dynamodb:us-east-1:123456789012:table/Users/index/*"
|
|
]
|
|
},
|
|
{
|
|
"Sid": "S3ReadAccess",
|
|
"Effect": "Allow",
|
|
"Action": [
|
|
"s3:GetObject",
|
|
"s3:ListBucket"
|
|
],
|
|
"Resource": [
|
|
"arn:aws:s3:::my-bucket",
|
|
"arn:aws:s3:::my-bucket/*"
|
|
],
|
|
"Condition": {
|
|
"StringLike": {
|
|
"s3:prefix": ["public/*"]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"Sid": "SecretsManagerAccess",
|
|
"Effect": "Allow",
|
|
"Action": [
|
|
"secretsmanager:GetSecretValue"
|
|
],
|
|
"Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:db-credentials-*"
|
|
},
|
|
{
|
|
"Sid": "CloudWatchLogs",
|
|
"Effect": "Allow",
|
|
"Action": [
|
|
"logs:CreateLogGroup",
|
|
"logs:CreateLogStream",
|
|
"logs:PutLogEvents"
|
|
],
|
|
"Resource": "arn:aws:logs:*:*:*"
|
|
}
|
|
]
|
|
}</code></pre>
|
|
<h3>2. IAM Roles and Trust Policies</h3>
|
|
<pre><code class="lang-json">// Trust policy - who can assume this role
|
|
{
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{
|
|
"Effect": "Allow",
|
|
"Principal": {
|
|
"Service": "lambda.amazonaws.com"
|
|
},
|
|
"Action": "sts:AssumeRole"
|
|
}
|
|
]
|
|
}
|
|
|
|
// Cross-account access trust policy
|
|
{
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{
|
|
"Effect": "Allow",
|
|
"Principal": {
|
|
"AWS": "arn:aws:iam::987654321098:root"
|
|
},
|
|
"Action": "sts:AssumeRole",
|
|
"Condition": {
|
|
"StringEquals": {
|
|
"sts:ExternalId": "unique-external-id-12345"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}</code></pre>
|
|
<h3>3. Security Groups</h3>
|
|
<pre><code class="lang-hcl"># Terraform - Web tier security group
|
|
resource "aws_security_group" "web" {
|
|
name = "web-tier-sg"
|
|
description = "Security group for web tier"
|
|
vpc_id = var.vpc_id
|
|
|
|
# Inbound rules
|
|
ingress {
|
|
description = "HTTPS from internet"
|
|
from_port = 443
|
|
to_port = 443
|
|
protocol = "tcp"
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
}
|
|
|
|
ingress {
|
|
description = "HTTP from internet"
|
|
from_port = 80
|
|
to_port = 80
|
|
protocol = "tcp"
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
}
|
|
|
|
# Outbound rules
|
|
egress {
|
|
description = "To app tier"
|
|
from_port = 8080
|
|
to_port = 8080
|
|
protocol = "tcp"
|
|
security_groups = [aws_security_group.app.id]
|
|
}
|
|
|
|
egress {
|
|
description = "HTTPS to internet"
|
|
from_port = 443
|
|
to_port = 443
|
|
protocol = "tcp"
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
}
|
|
|
|
tags = {
|
|
Name = "web-tier-sg"
|
|
Tier = "web"
|
|
}
|
|
}
|
|
|
|
# Application tier security group
|
|
resource "aws_security_group" "app" {
|
|
name = "app-tier-sg"
|
|
description = "Security group for app tier"
|
|
vpc_id = var.vpc_id
|
|
|
|
ingress {
|
|
description = "From web tier"
|
|
from_port = 8080
|
|
to_port = 8080
|
|
protocol = "tcp"
|
|
security_groups = [aws_security_group.web.id]
|
|
}
|
|
|
|
egress {
|
|
description = "To database"
|
|
from_port = 5432
|
|
to_port = 5432
|
|
protocol = "tcp"
|
|
security_groups = [aws_security_group.database.id]
|
|
}
|
|
|
|
tags = {
|
|
Name = "app-tier-sg"
|
|
Tier = "app"
|
|
}
|
|
}
|
|
|
|
# Database tier security group
|
|
resource "aws_security_group" "database" {
|
|
name = "database-tier-sg"
|
|
description = "Security group for database tier"
|
|
vpc_id = var.vpc_id
|
|
|
|
ingress {
|
|
description = "PostgreSQL from app tier"
|
|
from_port = 5432
|
|
to_port = 5432
|
|
protocol = "tcp"
|
|
security_groups = [aws_security_group.app.id]
|
|
}
|
|
|
|
# No outbound rules - database doesn't initiate connections
|
|
|
|
tags = {
|
|
Name = "database-tier-sg"
|
|
Tier = "database"
|
|
}
|
|
}</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="us-east-1"):
|
|
"""Retrieve secret from AWS Secrets Manager"""
|
|
session = boto3.session.Session()
|
|
client = session.client(
|
|
service_name='secretsmanager',
|
|
region_name=region_name
|
|
)
|
|
|
|
try:
|
|
response = client.get_secret_value(SecretId=secret_name)
|
|
|
|
if 'SecretString' in response:
|
|
return json.loads(response['SecretString'])
|
|
else:
|
|
# Binary secret
|
|
return response['SecretBinary']
|
|
|
|
except ClientError as e:
|
|
if e.response['Error']['Code'] == 'ResourceNotFoundException':
|
|
print(f"Secret {secret_name} not found")
|
|
elif e.response['Error']['Code'] == 'InvalidRequestException':
|
|
print(f"Invalid request for secret {secret_name}")
|
|
elif e.response['Error']['Code'] == 'InvalidParameterException':
|
|
print(f"Invalid parameter for secret {secret_name}")
|
|
raise e
|
|
|
|
# Lambda function using secrets
|
|
import os
|
|
|
|
def lambda_handler(event, context):
|
|
# Get database credentials
|
|
db_secret = get_secret(os.environ['DB_SECRET_NAME'])
|
|
|
|
# Use credentials
|
|
db_host = db_secret['host']
|
|
db_user = db_secret['username']
|
|
db_password = db_secret['password']
|
|
|
|
# Connect to database
|
|
# ...
|
|
|
|
# Create/update secret
|
|
def create_secret(secret_name, secret_value, region_name="us-east-1"):
|
|
"""Create or update a secret"""
|
|
client = boto3.client('secretsmanager', region_name=region_name)
|
|
|
|
try:
|
|
response = client.create_secret(
|
|
Name=secret_name,
|
|
SecretString=json.dumps(secret_value),
|
|
Tags=[
|
|
{'Key': 'Environment', 'Value': 'production'},
|
|
{'Key': 'ManagedBy', 'Value': 'terraform'}
|
|
]
|
|
)
|
|
return response['ARN']
|
|
except client.exceptions.ResourceExistsException:
|
|
# Update existing secret
|
|
response = client.update_secret(
|
|
SecretId=secret_name,
|
|
SecretString=json.dumps(secret_value)
|
|
)
|
|
return response['ARN']
|
|
|
|
# Rotate secret
|
|
def rotate_secret(secret_name):
|
|
"""Rotate secret (requires Lambda rotation function)"""
|
|
client = boto3.client('secretsmanager')
|
|
|
|
response = client.rotate_secret(
|
|
SecretId=secret_name,
|
|
RotationLambdaARN='arn:aws:lambda:us-east-1:123456789012:function:rotate-secret',
|
|
RotationRules={
|
|
'AutomaticallyAfterDays': 30
|
|
}
|
|
)
|
|
return response</code></pre>
|
|
<h3>5. Encryption</h3>
|
|
<pre><code class="lang-python"># S3 encryption at rest
|
|
import boto3
|
|
|
|
s3 = boto3.client('s3')
|
|
|
|
# Server-side encryption with S3-managed keys (SSE-S3)
|
|
s3.put_object(
|
|
Bucket='my-bucket',
|
|
Key='file.txt',
|
|
Body=b'data',
|
|
ServerSideEncryption='AES256'
|
|
)
|
|
|
|
# Server-side encryption with KMS (SSE-KMS)
|
|
s3.put_object(
|
|
Bucket='my-bucket',
|
|
Key='file.txt',
|
|
Body=b'data',
|
|
ServerSideEncryption='aws:kms',
|
|
SSEKMSKeyId='arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012'
|
|
)
|
|
|
|
# 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"sensitive data"
|
|
ciphertext = cipher.encrypt(plaintext)
|
|
|
|
# Upload encrypted data
|
|
s3.put_object(
|
|
Bucket='my-bucket',
|
|
Key='encrypted-file.txt',
|
|
Body=ciphertext
|
|
)
|
|
|
|
# Decrypt data
|
|
encrypted_data = s3.get_object(Bucket='my-bucket', Key='encrypted-file.txt')['Body'].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 "aws_network_acl" "public" {
|
|
vpc_id = var.vpc_id
|
|
subnet_ids = var.public_subnet_ids
|
|
|
|
# Inbound rules
|
|
ingress {
|
|
rule_no = 100
|
|
protocol = "tcp"
|
|
action = "allow"
|
|
cidr_block = "0.0.0.0/0"
|
|
from_port = 443
|
|
to_port = 443
|
|
}
|
|
|
|
ingress {
|
|
rule_no = 110
|
|
protocol = "tcp"
|
|
action = "allow"
|
|
cidr_block = "0.0.0.0/0"
|
|
from_port = 80
|
|
to_port = 80
|
|
}
|
|
|
|
ingress {
|
|
rule_no = 120
|
|
protocol = "tcp"
|
|
action = "allow"
|
|
cidr_block = "0.0.0.0/0"
|
|
from_port = 1024
|
|
to_port = 65535 # Ephemeral ports for return traffic
|
|
}
|
|
|
|
# Deny all other inbound
|
|
ingress {
|
|
rule_no = 32767
|
|
protocol = "-1"
|
|
action = "deny"
|
|
cidr_block = "0.0.0.0/0"
|
|
from_port = 0
|
|
to_port = 0
|
|
}
|
|
|
|
# Outbound rules
|
|
egress {
|
|
rule_no = 100
|
|
protocol = "-1"
|
|
action = "allow"
|
|
cidr_block = "0.0.0.0/0"
|
|
from_port = 0
|
|
to_port = 0
|
|
}
|
|
|
|
tags = {
|
|
Name = "public-nacl"
|
|
}
|
|
}</code></pre>
|
|
<hr>
|
|
<h2>Patterns</h2>
|
|
<h3>Least Privilege IAM Policy</h3>
|
|
<pre><code class="lang-json">{
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{
|
|
"Sid": "SpecificResourceAccess",
|
|
"Effect": "Allow",
|
|
"Action": [
|
|
"dynamodb:GetItem",
|
|
"dynamodb:PutItem"
|
|
],
|
|
"Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/Users",
|
|
"Condition": {
|
|
"ForAllValues:StringEquals": {
|
|
"dynamodb:LeadingKeys": ["${aws:username}"]
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"Sid": "DenyUnencryptedUploads",
|
|
"Effect": "Deny",
|
|
"Action": "s3:PutObject",
|
|
"Resource": "arn:aws:s3:::my-bucket/*",
|
|
"Condition": {
|
|
"StringNotEquals": {
|
|
"s3:x-amz-server-side-encryption": "aws:kms"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}</code></pre>
|
|
<h3>Multi-Factor Authentication</h3>
|
|
<pre><code class="lang-json">// Require MFA for sensitive operations
|
|
{
|
|
"Version": "2012-10-17",
|
|
"Statement": [
|
|
{
|
|
"Sid": "AllowViewAccountInfo",
|
|
"Effect": "Allow",
|
|
"Action": [
|
|
"iam:GetAccountPasswordPolicy",
|
|
"iam:ListVirtualMFADevices"
|
|
],
|
|
"Resource": "*"
|
|
},
|
|
{
|
|
"Sid": "RequireMFAForSensitiveOperations",
|
|
"Effect": "Allow",
|
|
"Action": [
|
|
"ec2:TerminateInstances",
|
|
"rds:DeleteDBInstance",
|
|
"s3:DeleteBucket"
|
|
],
|
|
"Resource": "*",
|
|
"Condition": {
|
|
"Bool": {
|
|
"aws:MultiFactorAuthPresent": "true"
|
|
},
|
|
"NumericLessThan": {
|
|
"aws:MultiFactorAuthAge": "3600"
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}</code></pre>
|
|
<h3>VPC Endpoints for Private Access</h3>
|
|
<pre><code class="lang-hcl"># Private access to AWS services without internet gateway
|
|
resource "aws_vpc_endpoint" "s3" {
|
|
vpc_id = var.vpc_id
|
|
service_name = "com.amazonaws.us-east-1.s3"
|
|
|
|
route_table_ids = var.private_route_table_ids
|
|
|
|
policy = jsonencode({
|
|
Version = "2012-10-17"
|
|
Statement = [
|
|
{
|
|
Sid = "AllowS3Access"
|
|
Effect = "Allow"
|
|
Principal = "*"
|
|
Action = [
|
|
"s3:GetObject",
|
|
"s3:PutObject"
|
|
]
|
|
Resource = "arn:aws:s3:::my-private-bucket/*"
|
|
}
|
|
]
|
|
})
|
|
|
|
tags = {
|
|
Name = "s3-vpc-endpoint"
|
|
}
|
|
}
|
|
|
|
# Interface endpoint for other services
|
|
resource "aws_vpc_endpoint" "secretsmanager" {
|
|
vpc_id = var.vpc_id
|
|
service_name = "com.amazonaws.us-east-1.secretsmanager"
|
|
vpc_endpoint_type = "Interface"
|
|
|
|
subnet_ids = var.private_subnet_ids
|
|
security_group_ids = [aws_security_group.vpc_endpoint.id]
|
|
|
|
private_dns_enabled = true
|
|
|
|
tags = {
|
|
Name = "secretsmanager-vpc-endpoint"
|
|
}
|
|
}</code></pre>
|
|
<h3>Certificate Management</h3>
|
|
<pre><code class="lang-python"># AWS Certificate Manager
|
|
import boto3
|
|
|
|
acm = boto3.client('acm')
|
|
|
|
# Request certificate
|
|
response = acm.request_certificate(
|
|
DomainName='example.com',
|
|
SubjectAlternativeNames=[
|
|
'*.example.com',
|
|
'www.example.com'
|
|
],
|
|
ValidationMethod='DNS',
|
|
Tags=[
|
|
{'Key': 'Environment', 'Value': 'production'}
|
|
]
|
|
)
|
|
|
|
certificate_arn = response['CertificateArn']
|
|
|
|
# Get certificate validation records
|
|
response = acm.describe_certificate(CertificateArn=certificate_arn)
|
|
validation_options = response['Certificate']['DomainValidationOptions']
|
|
|
|
# Create Route53 validation records automatically
|
|
route53 = boto3.client('route53')
|
|
for option in validation_options:
|
|
route53.change_resource_record_sets(
|
|
HostedZoneId='Z1234567890ABC',
|
|
ChangeBatch={
|
|
'Changes': [{
|
|
'Action': 'CREATE',
|
|
'ResourceRecordSet': {
|
|
'Name': option['ResourceRecord']['Name'],
|
|
'Type': option['ResourceRecord']['Type'],
|
|
'TTL': 300,
|
|
'ResourceRecords': [{'Value': option['ResourceRecord']['Value']}]
|
|
}
|
|
}]
|
|
}
|
|
)</code></pre>
|
|
<h3>API Authentication</h3>
|
|
<pre><code class="lang-python"># Lambda authorizer for API Gateway
|
|
import json
|
|
|
|
def lambda_handler(event, context):
|
|
"""
|
|
Custom authorizer for API Gateway
|
|
Validates JWT or API key
|
|
"""
|
|
token = event['authorizationToken'] # Bearer token
|
|
method_arn = event['methodArn']
|
|
|
|
# Validate token (check signature, expiration, etc.)
|
|
if validate_token(token):
|
|
principal_id = extract_user_id(token)
|
|
policy = generate_policy(principal_id, 'Allow', method_arn)
|
|
|
|
# Add context to pass to Lambda function
|
|
policy['context'] = {
|
|
'userId': principal_id,
|
|
'role': extract_role(token)
|
|
}
|
|
|
|
return policy
|
|
else:
|
|
raise Exception('Unauthorized')
|
|
|
|
def generate_policy(principal_id, effect, resource):
|
|
"""Generate IAM policy"""
|
|
policy = {
|
|
'principalId': principal_id,
|
|
'policyDocument': {
|
|
'Version': '2012-10-17',
|
|
'Statement': [{
|
|
'Action': 'execute-api:Invoke',
|
|
'Effect': effect,
|
|
'Resource': resource
|
|
}]
|
|
}
|
|
}
|
|
return policy
|
|
|
|
def validate_token(token):
|
|
"""Validate JWT token"""
|
|
# Implementation depends on your token type
|
|
# For JWT: decode, verify signature, check expiration
|
|
return True # Simplified
|
|
|
|
def extract_user_id(token):
|
|
"""Extract user ID from token"""
|
|
return "user123" # Simplified
|
|
|
|
def extract_role(token):
|
|
"""Extract role from token"""
|
|
return "admin" # 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
|
|
{
|
|
"Effect": "Allow",
|
|
"Action": "*",
|
|
"Resource": "*"
|
|
}
|
|
|
|
// ✅ CORRECT: Specific permissions
|
|
{
|
|
"Effect": "Allow",
|
|
"Action": [
|
|
"s3:GetObject",
|
|
"s3:PutObject"
|
|
],
|
|
"Resource": "arn:aws:s3:::my-bucket/path/*"
|
|
}</code></pre>
|
|
<pre><code class="lang-python"># ❌ NEVER: Hardcode credentials
|
|
AWS_ACCESS_KEY = "AKIAIOSFODNN7EXAMPLE"
|
|
AWS_SECRET_KEY = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
|
|
|
|
# ✅ CORRECT: Use IAM roles or environment variables
|
|
import boto3
|
|
# Uses IAM role credentials automatically
|
|
s3 = boto3.client('s3')
|
|
|
|
# Or environment variables
|
|
import os
|
|
access_key = os.environ['AWS_ACCESS_KEY_ID']</code></pre>
|
|
<pre><code class="lang-hcl"># ❌ NEVER: Open security groups to 0.0.0.0/0 for SSH
|
|
resource "aws_security_group_rule" "ssh" {
|
|
type = "ingress"
|
|
from_port = 22
|
|
to_port = 22
|
|
protocol = "tcp"
|
|
cidr_blocks = ["0.0.0.0/0"] # Dangerous!
|
|
security_group_id = aws_security_group.example.id
|
|
}
|
|
|
|
# ✅ CORRECT: Restrict to specific IPs or use bastion
|
|
resource "aws_security_group_rule" "ssh" {
|
|
type = "ingress"
|
|
from_port = 22
|
|
to_port = 22
|
|
protocol = "tcp"
|
|
cidr_blocks = ["10.0.0.0/16"] # 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> |