Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
9e46fdf
Gateway, awsJson codec, IAM and STS services, AWS-managed policy catalog
rotmanjanez Nov 22, 2026
d89e910
Generator: constraints, defaults, error members, actions; DynamoDB, S…
rotmanjanez Nov 23, 2026
2b70580
IAM policy evaluator, replayed against IAM's policy simulator
rotmanjanez Nov 23, 2026
05d99c8
Tapes: AWS's answers recorded once, replayed against the Gateway
rotmanjanez Nov 23, 2026
94d6b9d
Tapes: drop the markers of differences the generated validation closed
rotmanjanez Nov 23, 2026
1ecdba8
Caller: regional state, and the caller a service is when it calls ano…
rotmanjanez Nov 23, 2026
8f4023a
Caller: the endpoint a request came to
rotmanjanez Nov 23, 2026
d9bb15f
IAM enforced: every request is allowed by the policies that apply to …
rotmanjanez Nov 23, 2026
bebf093
SQS: queues, messages, batches, dead-letter queues and FIFO
rotmanjanez Nov 23, 2026
59f1273
DynamoDB: tables, items, Query and Scan, batches and transactions
rotmanjanez Nov 23, 2026
f7e4f0b
SNS: topics, subscriptions, filter policies, publishing to SQS
rotmanjanez Nov 23, 2026
84e27e1
EventBridge: buses, rules, targets, and PutEvents delivered within th…
rotmanjanez Nov 23, 2026
8a5d040
All six services behind one gateway; a resource policy's Sid is free
rotmanjanez Nov 23, 2026
561ec41
IAM and STS answer as their tapes recorded; permissions boundaries; w…
rotmanjanez Nov 23, 2026
c149b77
Blobs in mapped temporary files, descending scans, and S3's request f…
rotmanjanez Nov 23, 2026
6626312
The stack under IAM: deliveries decided by resource policies, users p…
rotmanjanez Nov 23, 2026
35f6e39
S3's API over a restXml codec; SQS, awsJson and DynamoDB fixes
rotmanjanez Nov 23, 2026
b176fb6
Secrets Manager and SSM Parameter Store: secrets, versions and labels…
rotmanjanez Nov 23, 2026
e04c5bc
IAM's groups, recorded permissions boundaries and dependent actions; …
rotmanjanez Nov 23, 2026
5d6c12f
DynamoDB's legacy parameters, reserved words, descending pages and Pa…
rotmanjanez Nov 23, 2026
f4c73d6
S3 tapes: the tape tool records and replays S3's REST requests
rotmanjanez Nov 23, 2026
de0464b
CloudWatch Logs: log groups, streams, events and their filter pattern…
rotmanjanez Nov 23, 2026
af8ed6c
KMS: keys, aliases, real encryption under key policies and grants
rotmanjanez Nov 23, 2026
92580aa
S3: buckets, objects and their versions, multipart uploads, bucket po…
rotmanjanez Nov 23, 2026
fa0515f
Every service of the round behind one gateway; a Logs marker the enum…
rotmanjanez Nov 23, 2026
d58cabd
Generator: what AWS answers beyond its models, in facts tables
rotmanjanez Nov 23, 2026
af2fd74
S3 answers as the tapes recorded it; SigV2 presigned URLs, a body lim…
rotmanjanez Nov 23, 2026
d3a60b5
S3: bucket configurations, CORS at work, notifications to queues and …
rotmanjanez Nov 23, 2026
d4579d0
KMS key policies decide; AWS managed keys; Secrets Manager and SSM en…
rotmanjanez Nov 23, 2026
43a686f
IAM: instance profiles, OIDC and SAML providers, the account's summar…
rotmanjanez Nov 23, 2026
6d5f7bc
Kinesis: streams, records, resharding, consumers and resource policies
rotmanjanez Nov 23, 2026
3f0be56
DynamoDB Streams behind DynamoDB's signing name; time to live that ne…
rotmanjanez Nov 23, 2026
1376dd8
Enums of a single value are checked as such
rotmanjanez Nov 23, 2026
9c340e0
restJson1 beside restXml over one HTTP binding; Lambda's API, unimple…
rotmanjanez Nov 23, 2026
d8c6a29
Health, reset and in-memory snapshots under /_localstack/ and /_bober…
rotmanjanez Nov 23, 2026
174a279
Health does not list Lambda while it implements nothing
rotmanjanez Nov 23, 2026
a81b6e4
Step Functions: state machines and executions that run to their end w…
rotmanjanez Nov 23, 2026
4eefab9
Route 53: hosted zones, record sets as atomic batches, VPCs and tags
rotmanjanez Nov 23, 2026
f27cfe3
CloudWatch: metrics, statistics, metric math and metric alarms, in aw…
rotmanjanez Nov 23, 2026
82cca39
Server-side encryption under KMS: S3 objects, SQS queues, SNS topics,…
rotmanjanez Nov 23, 2026
ff638cc
Deliveries between services, inside the request
rotmanjanez Nov 23, 2026
e25dd0e
IAM: access key state and last use, login profiles, service-linked ro…
rotmanjanez Nov 23, 2026
f2d1f30
Firehose: delivery streams to S3, each put one object; Logs, EventBri…
rotmanjanez Nov 23, 2026
3b77df2
ACM: requested and imported certificates, tags, options and the accou…
rotmanjanez Nov 23, 2026
1dba4f5
CloudWatch: dashboards, validation in AWS's words, tapes from eu-north-1
rotmanjanez Nov 23, 2026
fe2fc36
SES: the classic API and v2 over one state; messages stored, listed a…
rotmanjanez Nov 23, 2026
001c59d
IAM and CloudWatch Logs: fault namespaces, statement positions, conte…
rotmanjanez Nov 23, 2026
8d10d23
Step Functions: callbacks, activities, nested executions, SDK error n…
rotmanjanez Nov 23, 2026
001814f
CloudWatch's not-found answers carry no Message, as the tape says
rotmanjanez Nov 23, 2026
61bdfb8
S3: SignatureDoesNotMatch in S3's words, configuration values refused…
rotmanjanez Nov 23, 2026
1d8e24d
Route 53: health checks, access denied, a change PENDING to its first…
rotmanjanez Nov 23, 2026
8e0029a
The STS test names no particular SDK
rotmanjanez Nov 23, 2026
de196af
Firehose: other destinations and sources stored and described, prefix…
rotmanjanez Nov 23, 2026
eb95b3c
ACM: imported certificates read from their DER, key algorithms as AWS…
rotmanjanez Nov 23, 2026
f7999cb
SES: configuration sets and event destinations of both APIs, tags, pa…
rotmanjanez Nov 23, 2026
e1951cf
CloudWatch: composite alarms, anomaly detectors stored; awsQuery erro…
rotmanjanez Nov 23, 2026
08d6c9b
SES's quota in doubles as the codec now writes them
rotmanjanez Nov 23, 2026
44f5404
Step Functions: activity events, secret task tokens, versions and ali…
rotmanjanez Nov 23, 2026
6cd06b6
SES's quota after a second message, in doubles too
rotmanjanez Nov 23, 2026
c107f25
Roles that services act as: trusted by the service, passed only as ia…
rotmanjanez Nov 23, 2026
c4c3313
KMS: Ed25519 signing keys with Sign, Verify and GetPublicKey; ACM: Se…
rotmanjanez Nov 23, 2026
bba08f3
ACM: a certificate's serial in the fewest bytes, as DER demands
rotmanjanez Nov 23, 2026
8127804
CloudFormation: stacks of JSON templates made inside their request, b…
rotmanjanez Nov 23, 2026
95d233c
S3: flags read as S3 reads them, stored configurations, replication, …
rotmanjanez Nov 23, 2026
8b38899
SES: identity attributes and sending authorization policies, the supp…
rotmanjanez Nov 23, 2026
f0580a9
EventBridge: state machine targets, dead-letter attributes, archives …
rotmanjanez Nov 23, 2026
8582f75
Route 53: validation names members as AWS does, limits, TestDNSAnswer…
rotmanjanez Nov 23, 2026
59ed3eb
Lambda: the control plane, without execution
rotmanjanez Nov 23, 2026
aa98b2b
CloudWatch Logs Insights: queries Complete at once in the Insights la…
rotmanjanez Nov 23, 2026
da83d33
CloudWatch: metric filters publish to it, alarms on metric math, AT_L…
rotmanjanez Nov 23, 2026
acf8789
EventBridge Scheduler: schedules and schedule groups, stored and vali…
rotmanjanez Nov 23, 2026
2b6cc61
Firehose refuses a role it cannot assume when a stream is made or upd…
rotmanjanez Nov 23, 2026
4a7d305
CloudFormation: change sets, a stack's role acted as and passed, and …
rotmanjanez Nov 23, 2026
3a0809b
S3: conditions and ranges taped, Object Lock on writes, XML names AWS…
rotmanjanez Nov 23, 2026
bfeebb9
SES: notifications under a topic's default policy, v2 faults in restJ…
rotmanjanez Nov 23, 2026
66f3e6a
Step Functions: version and alias ARNs described and listed, deletion…
rotmanjanez Nov 23, 2026
2ddef24
Lambda: PassRole and the role's trust, mapping sources checked, layer…
rotmanjanez Nov 23, 2026
3e40d21
Resource policies parsed when set by SQS, SNS, EventBridge, Logs and …
rotmanjanez Nov 23, 2026
ed69b97
Step Functions: Lambda tasks through Lambda's handler as the executio…
rotmanjanez Nov 23, 2026
a930c40
SES: contact lists and contacts, receipt rule sets, rules and filters…
rotmanjanez Nov 23, 2026
2b271fe
CloudFormation: Lambda's functions of inline code zipped as AWS names…
rotmanjanez Nov 23, 2026
73d3642
Step Functions: Distributed Map processed inline, its map run kept, i…
rotmanjanez Nov 23, 2026
d145e76
Step Functions: a map run's child executions kept, listed by its ARN,…
rotmanjanez Nov 23, 2026
8ef8fe5
CloudFormation: a TemplateURL read from S3 as the caller, the stack's…
rotmanjanez Nov 23, 2026
d1acf77
CloudFormation: IAM groups and instance profiles, the aws:cloudformat…
rotmanjanez Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions core/auth/chunked.bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//! The aws-chunked encoding that S3's clients stream a body in: chunks of hex sizes, each signed in a chain from the
//! request's signature or none, then trailing headers, as a checksum, signed or not.

import { Fault } from "../fault"
import { Authorization, key, scope, stampOf } from "./sigv4"
import { endsWith, indexOf, startsWith } from "std/algo"
import { CryptoError } from "std/crypto/error"
import { equal, hmacSha256, sha256 } from "std/crypto/hash"
import * as hex from "std/encoding/hex"
import { Request } from "std/http"
import { ParseError, lower, parseInt, split, trim } from "std/string"

/// Whether req's body is aws-chunked, as its X-Amz-Content-Sha256 says.
export function chunked(req: Request): bool {
return startsWith(req.headers.get("x-amz-content-sha256") ?? "", "STREAMING-")
}

/// The bytes body, req's aws-chunked one, stands for, its trailing headers set on req as headers and aws-chunked taken
/// from its Content-Encoding; the chunks' and trailer's signatures checked by secret in auth's scope unless it is null.
/// Throws as S3 answers a body that is cut short or does not match X-Amz-Decoded-Content-Length, or a signature that
/// does not match.
export function decode(req: Request, body: string, auth: Authorization,
secret: string | null): string throws Fault | CryptoError {
const mode = req.headers.get("x-amz-content-sha256") ?? ""
const signed = startsWith(mode, "STREAMING-AWS4-HMAC-SHA256-PAYLOAD")
const k = if (signed && secret != null) key(auth, secret!) else null
const head = `${stampOf(req, auth)}\n${scope(auth)}\n`
const empty = hex.encode(sha256(""))
const cut = new Fault(400, "IncompleteBody", "The request body terminated unexpectedly")
let previous = auth.signature
const check = (kind: string, hash: string, given: string) => {
if (k != null) {
const sig = hex.encode(hmacSha256(k!, `AWS4-HMAC-SHA256-${kind}\n${head}${previous}\n${hash}`))
if (!equal(sig, given)) {
throw new Fault(403, "SignatureDoesNotMatch",
"The request signature we calculated does not match the "
+ "signature you provided. Check your key and signing method.")
}
previous = sig
}
}
const pieces: string[] = []
let at = 0
while (true) {
const end = indexOf(body, "\r\n", at)
if (end < 0) {
throw cut
}
const line = split(body.slice(at, end), ";")
let size = 0
try {
size = parseInt(line[0], 16)
} catch (e: ParseError) {
throw cut
}
const given = if (line.length > 1 && startsWith(line[1], "chunk-signature=")) line[1].slice(16, line[1].length)
else ""
at = end + 2
if (size < 0 || at + size > body.length || size > 0 && body.slice(at + size, at + size + 2) != "\r\n") {
throw cut
}
const data = body.slice(at, at + size)
check("PAYLOAD", `${empty}\n${hex.encode(sha256(data))}`, given)
if (size == 0) {
break
}
pieces.push(data)
at += size + 2
}
let trailers = ""
let trailerSignature = ""
while (true) {
const end = indexOf(body, "\r\n", at)
if (end < 0) {
throw cut
}
const line = body.slice(at, end)
at = end + 2
if (line == "") {
break
}
const colon = indexOf(line, ":")
const name = lower(trim(line.slice(0, if (colon < 0) 0 else colon)))
const v = trim(line.slice(colon + 1, line.length))
if (name == "x-amz-trailer-signature") {
trailerSignature = v
} else {
trailers += `${name}:${v}\n`
req.headers.set(name, v)
}
}
if (endsWith(mode, "-TRAILER") && signed) {
check("TRAILER", hex.encode(sha256(trailers)), trailerSignature)
}
const decoded = pieces.join("")
const declared = req.headers.get("x-amz-decoded-content-length")
if (declared != null && declared != `${decoded.length}`) {
throw new Fault(400, "IncompleteBody",
"You did not provide the number of bytes specified by the X-Amz-Decoded-Content-Length HTTP header")
}
const encodings = split(req.headers.get("content-encoding") ?? "",
",").map(trim).filter(e => e != "" && e != "aws-chunked")
if (encodings.length == 0) {
req.headers.delete("content-encoding")
} else {
req.headers.set("content-encoding", encodings.join(", "))
}
return decoded
}
90 changes: 90 additions & 0 deletions core/auth/chunked.test.bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Fault } from "../fault"
import { chunked, decode } from "./chunked"
import { authorization, verify } from "./sigv4"
import { Request } from "std/http"
import { parseIso8601Basic } from "std/time"

// AWS's worked examples of S3's chunked uploads, of signed chunks, and of signed chunks with a signed trailer.
const secret = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
const at = "20130524T000000Z"

/// n bytes of a.
function as(n: i32): string {
const b: u8[] = []
for (const i of 1 ... n) {
b.push(0x61)
}
return fromBytes(b)
}

/// The examples' PUT of chunkObject.txt in the mode given, with headers and signed as given.
function put(mode: string, signed: string, seed: string, headers: [string, string][]): Request {
const req = new Request("PUT", "http://s3.amazonaws.com/examplebucket/chunkObject.txt")
const all: [string, string][] = [["host", "s3.amazonaws.com"], ["x-amz-date", at],
["x-amz-storage-class", "REDUCED_REDUNDANCY"], ["content-encoding", "aws-chunked"],
["x-amz-content-sha256", mode], ["x-amz-decoded-content-length", "66560"]]
for (const [k, v] of [...all, ...headers]) {
req.headers.set(k, v)
}
req.headers.set("authorization",
"AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/s3/"
+ `aws4_request, SignedHeaders=${signed}, Signature=${seed}`)
return req
}

/// The code of what decode throws for req with body, "" if nothing.
function fails(req: Request, body: string, key: string | null = secret): string {
try {
decode(req, body, authorization(req)!, key)
} catch (f: Fault) {
return f.code
}
return ""
}

test "signed chunks" {
const body = "10000;chunk-signature=ad80c730a21e5b8d04586a2213dd63b9a0e99e0e2307b0ade35a65485a288648\r\n"
+ as(65536) + "\r\n400;chunk-signature=0055627c9e194cb4542bae2aa5492e3c1575bbb81b612b7d234b86a503ef5497\r\n"
+ as(1024) + "\r\n0;chunk-signature=b6c6ea8a5354eaf15b3cb7646744f4275b71ea724fed81ceb9323e279d449df9\r\n\r\n"
const signed = "content-encoding;content-length;host;x-amz-content-sha256;x-amz-date;x-amz-decoded-content-length;"
+ "x-amz-storage-class"
const req = () => put("STREAMING-AWS4-HMAC-SHA256-PAYLOAD", signed,
"4f232c4386841ef735655705268965c44a0e4690baa4adea153f7db9fa80a0a9", [["content-length", "66824"]])
const r = req()
assert body.length == 66824 && chunked(r) && !chunked(new Request("GET", "http://localhost/"))
assert verify(r, body, authorization(r)!, secret, parseIso8601Basic(at)) == null
assert decode(r, body, authorization(r)!, secret) == as(66560) && !r.headers.has("content-encoding")
const forged = body.slice(0, 22) + "bd" + body.slice(24, body.length)
assert fails(req(), forged) == "SignatureDoesNotMatch" && fails(req(), forged, null) == ""
assert fails(req(), body.slice(0, 66000)) == "IncompleteBody"
&& fails(req(), body.slice(0, 66822)) == "IncompleteBody"
const short = req()
short.headers.set("x-amz-decoded-content-length", "66561")
assert fails(short, body) == "IncompleteBody"
}

test "signed chunks with a signed trailer, and unsigned ones" {
const body = "10000;chunk-signature=b474d8862b1487a5145d686f57f013e54db672cee1c953b3010fb58501ef5aa2\r\n"
+ as(65536) + "\r\n400;chunk-signature=1c1344b170168f8e65b41376b44b20fe354e373826ccbbe2c1d40a8cae51e5c7\r\n"
+ as(1024) + "\r\n0;chunk-signature=2ca2aba2005185cf7159c6277faf83795951dd77a3a99e6e65d5c9f85863f992\r\n"
+ "x-amz-checksum-crc32c:sOO8/Q==\r\n"
+ "x-amz-trailer-signature:d81f82fc3505edab99d459891051a732e8730629a2e4a59689829ca17fe2e435\r\n\r\n"
const signed = "content-encoding;host;x-amz-content-sha256;x-amz-date;x-amz-decoded-content-length;"
+ "x-amz-storage-class;x-amz-trailer"
const req = () => put("STREAMING-AWS4-HMAC-SHA256-PAYLOAD-TRAILER", signed,
"106e2a8a18243abcf37539882f36619c00e2dfc72633413f02d3b74544bfeb8e",
[["x-amz-trailer", "x-amz-checksum-crc32c"]])
const r = req()
assert verify(r, body, authorization(r)!, secret, parseIso8601Basic(at)) == null
assert decode(r, body, authorization(r)!, secret) == as(66560)
&& r.headers.get("x-amz-checksum-crc32c") == "sOO8/Q=="
const forged = body.slice(0, body.length - 10) + "x" + body.slice(body.length - 9, body.length)
assert fails(req(), forged) == "SignatureDoesNotMatch"
const unsigned = put("STREAMING-UNSIGNED-PAYLOAD-TRAILER", signed, "00",
[["x-amz-trailer", "x-amz-checksum-crc32"], ["x-amz-decoded-content-length", "5"],
["content-encoding", "gzip, aws-chunked"]])
const plain = "5\r\nhello\r\n0\r\nx-amz-checksum-crc32:NhCmhg==\r\n\r\n"
assert decode(unsigned, plain, authorization(unsigned)!, secret) == "hello"
assert unsigned.headers.get("x-amz-checksum-crc32") == "NhCmhg=="
&& unsigned.headers.get("content-encoding") == "gzip"
}
42 changes: 38 additions & 4 deletions core/auth/credentials.bob
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import { Fault } from "../fault"
import { Store, Table } from "../state/store"
import * as sigv2 from "./sigv2"
import { Authorization, verify } from "./sigv4"
import { isDigit } from "std/ascii"
import { CryptoError } from "std/crypto/error"
import { bytes } from "std/crypto/random"
import { EncodeError } from "std/encoding/json"
import { Request } from "std/http"
import { minute } from "std/time"

/// An access key issued: a user's, or a temporary one, which a session token goes with until it expires.
export class Credential {
Expand All @@ -20,6 +23,19 @@ export class Credential {
/// A temporary one's; "" and 0 for a user's.
token = ""
expiry: i64 = 0
/// A temporary one's: the kind of session, "role" of AssumeRole, "federated-user" of GetFederationToken, "user" of
/// GetSessionToken; the ARN of the user a federated user's was issued to; its session policies, the document given,
/// "" if none, and the managed policies' ARNs; and its session tags.
session = ""
issuer = ""
policy = ""
policyArns: string[] = []
tags: [string, string][] = []
/// When it last signed a request that was let in, to the minute, 0 if never, and the signing name and region of
/// that request.
used: i64 = 0
usedService = ""
usedRegion = ""
}

/// The credentials issued, by access key id, in the global state.
Expand All @@ -31,18 +47,36 @@ export function accountOf(accessKey: string): string {
return if (accessKey.length == 12 && accessKey.every(isDigit)) accessKey else "000000000000"
}

/// Records in global that c, the credential of the access key id, signed a request to service in region at now.
export function use(global: Store, id: string, c: Credential, service: string, region: string, now: i64) throws Fault {
c.used = now - now % minute
c.usedService = service
c.usedRegion = region
try {
credentials(global).put(id, c)
} catch (e: EncodeError) {
throw new Fault(500, "InternalFailure", `A credential of ${e.value} cannot be stored`)
}
}

/// Why c may not sign req, whose body is body, under auth at the instant now, as AWS answers it; null if it may: it is
/// active, of the session token the request bears, not yet expired, and the signature is its.
/// active, of the session token the request bears, in a header or a presigned URL, not yet expired, and the signature
/// is its.
export function authenticate(c: Credential, req: Request, body: string, auth: Authorization,
now: i64): Fault | null throws CryptoError {
if (c.status != "Active" || c.token != (req.headers.get("x-amz-security-token") ?? "")) {
const token = req.headers.get("x-amz-security-token") ?? req.url.query.get("X-Amz-Security-Token") ?? ""
if (c.status != "Active" || c.token != token) {
return new Fault(403, "InvalidClientTokenId", "The security token included in the request is invalid.")
}
if (c.expiry != 0 && now >= c.expiry) {
return new Fault(403, "ExpiredToken", "The security token included in the request is expired")
}
const why = verify(req, body, auth, c.secret, now)
return if (why == null) null else new Fault(403, "SignatureDoesNotMatch", why)
const why = if (auth.version == 2) sigv2.verify(req, auth, c.secret, now)
else verify(req, body, auth, c.secret, now)
if (why instanceof string) {
return new Fault(403, "SignatureDoesNotMatch", why)
}
return why
}

/// A unique id as AWS makes them: prefix and n random characters of A-Z and 2-7, as AIDA… for a user or AKIA… for
Expand Down
Loading
Loading