# S3 Signature Version 4, step by step

*HTML: https://book.ceph-s3.ir/en/lab-sigv4.html*
*Licence: CC BY-NC-SA 4.0. Author: Ramin Najarbashi.*

[Interactive lab](lab.html)S3 Signature Version 4, step by step
In the book: [Chapter 4](04-object-storage-rgw.html#sec-04-5-1)
LabS3 Signature Version 4, step by stepBuild an S3 request and watch the canonical request, the string to sign, the HMAC key chain and the final signature being made; then tamper with the request on the way and see why RGW answers 403.**c095b54110b5…**client signature**d5fa869cd9d7…**signature RGW computes**403**SignatureDoesNotMatchCanonical requestPUT /photos/2026/cat.jpg host:s3.example.com x-amz-content-sha256:d5e96cac390e4f85c6432c4511b4f2fbb9afa66bbc39285634235bae444538ab x-amz-date:20261122T090000Z host;x-amz-content-sha256;x-amz-date d5e96cac390e4f85c6432c4511b4f2fbb9afa66bbc39285634235bae444538abString to signAWS4-HMAC-SHA256 20261122T090000Z 20261122/default/s3/aws4_request fd548dd7f2d0efb2df8af523e1592b5a6dd035381778d3e3bb609f672ed0163aSigning key from the secretkDate = HMAC("AWS4" + secret, "20261122") = 0ca2545c1e4db2e3932d7d58bbb91087a61a62d01fc6fd54ec2fce561c1c5129 kRegion = HMAC(kDate, "default") = 9938f1b013b8084e0cdcb92bff4601ac8b964c9fc34c548ac0374cdb2d7601e7 kService = HMAC(kRegion, "s3") = cacf9b5259acd32f6f70071a14b04ddf16e2f8d48250786b098fdb5fd7dc742f kSigning = HMAC(kService, "aws4_request") = 887a8efa8413bdc44ab172532ee396498905b5ef91b72054488189b63a4eec3aSignature and the Authorization headerSignature = HMAC(kSigning, StringToSign) = c095b54110b5631e8b9fccdd22c070d95041b9b977eff72138ac618d91a0bc77 Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20261122/default/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=c095b54110b5631e8b9fccdd22c070d95041b9b977eff72138ac618d91a0bc77RGW recomputes it from the request that arrivedserver Signature = d5fa869cd9d7be230c799a4c05da281c6039efffea48466f05e88c43f841cd78 != client -> 403 SignatureDoesNotMatchIn practice SignatureDoesNotMatch usually comes from a clock difference of more than 15 minutes, a different path encoding, path-style versus virtual-host confusion or a proxy that rewrites the Host header (chapter 4). RGW computes the signature with the region in the request's own credential scope.Follows:`src/rgw/rgw_auth_s3.cc :: get_v4_canonical_qs, get_v4_canonical_headers, get_v4_string_to_sign` How RGW builds the canonical request and string to sign`src/rgw/rgw_auth_s3.cc :: get_v4_signing_key, get_v4_signature` The signing key and the signature`AWS documentation :: Signature Version 4 signing process, deriving the signing key` The protocol referenceA fixed snapshot of the simulator; the interactive version is in the web edition's lab. [Interactive lab: S3 Signature Version 4, step by step](lab-sigv4.html)The interactive version needs JavaScript; this is a fixed snapshot.
