Skip to content

feat(auth): add EXTENDDB_DEV_IGNORE_CLOCK_SKEW for dev-mode builds - #1125

Open
jgaul3 wants to merge 3 commits into
ExtendDB:mainfrom
jgaul3:ignore-skew
Open

jgaul3 wants to merge 3 commits into
ExtendDB:mainfrom
jgaul3:ignore-skew

Conversation

@jgaul3

@jgaul3 jgaul3 commented Nov 18, 2026 •

Copy link
Copy Markdown

What

This PR adds the EXTENDDB_DEV_IGNORE_CLOCK_SKEW flag which dev-mode builds may use to disable the X-Amz-Date skew check for signatures. The signature is still verified aside from this.

  • Reads flag once at startup with values modeled after EXTENDDB_DEV_DISABLE_EXAMPLE_CREDENTIAL
  • Adds a startup banner if on and a warn trace log w/ risk

Why

Some existing DDB emulators do not check clock skew, meaning that tests which freeze or travel time fail using ExtendDB, preventing migration.

Closes #359

Testing done

Aside from local testing as described in the linked issue:

  • Unit tests in crates/auth cover the switch off, on, and on with a wrong signature, plus an unreadable date
    still refused with the switch on
  • Unit test in crates/app confirms banner
  • tests/test_dev_mode_clock_skew.py is run with and without the flag. With the flag a stale date is served, without it the date is rejected.

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace) (three existing failures in crates I didn't touch)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic) (again, warnings from other places in the code)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: n/a


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

@LeeroyHannigan LeeroyHannigan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the gate holds where it matters.

I built both kinds of server from this head and measured:

  • A production SQLite build with EXTENDDB_DEV_IGNORE_CLOCK_SKEW=1 still refuses a 2021 date before the key lookup, so the compile-time gate keeps the bypass out of production builds.
  • On a dev-mode build the check stays on by default: unset, empty and TRUE all refuse a 2021 date. With =1 the server answers a 2021 date, and it still refuses a wrong secret, an unknown key and a scope-date mismatch.
  • cargo test -p extenddb-auth --lib passes (515), and the branch merges cleanly with main. CI hasn't run at this head yet.

Before it merges:

  1. Nothing tells the operator the bypass is on. The banner and the DEVELOPER MODE warning are byte for byte the same with and without the variable, and they still say "SigV4 still enforced". With the bypass on, a captured signed request replays at any later time instead of within 15 minutes. Please read the variable once at startup in cmd_serve.rs, next to EXTENDDB_DEV_ALLOW_ANY_BIND, and add a banner line and a tracing::warn! when it's set.
  2. The gate has no unit test, and the crate's tests now depend on the developer's shell. With --features dev-mode and the variable exported, three auth tests fail (512 of 515 pass), because validate_timestamp reads the environment on each request. Please pass the switch in as a value (a field on BuiltinAuthProvider, or a parameter of validate_timestamp) that startup reads once. Then add unit tests for the switch off, on, and on with a wrong signature. In CI, please keep the existing dev-mode server as it was and start a second one with the variable set for test_dev_mode_clock_skew.py. Otherwise no CI run covers a dev-mode build with the check on.
  3. With the bypass on, the server answers a value that isn't a date. 20211301T000000Z (month 13), day 32 and hour 99 each get HTTP 200. parse_iso8601_basic checks the digits but not the ranges, and the skew comparison was the only thing that caught them. Please make it reject out-of-range fields, so the format error covers them in every build.
  4. The server ignores a value other than 1 or true without a word: TRUE and an empty value leave the check on. EXTENDDB_DEV_DISABLE_EXAMPLE_CREDENTIAL refuses to start on a value it doesn't know. Please do the same here.
  5. The docs section names UnrecognizedClientException, which #889 changes to the service's InvalidSignatureException. Please call it a signature error without the type. Please also add that with the check off, anyone who captures a signed request can replay it at any later time. So the switch belongs on a loopback-only server.

#889 edits the same if skew > MAX_CLOCK_SKEW_SECS block, so the two conflict. An early return Ok(timestamp) after the parse when the switch is on would keep the two changes apart.

@jgaul3

jgaul3 commented Dec 2, 2026

Copy link
Copy Markdown
Author

@LeeroyHannigan

Thank you for your feedback - I've made the changes as requested. I did edit parse_iso8601_basicto use time and reject dates with +, please let me know if that's alright.

@LeeroyHannigan LeeroyHannigan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. I read db4bb57 against main, and built a dev-mode and a production SQLite binary from it. The auth crate's 545 lib tests pass, with and without EXTENDDB_DEV_IGNORE_CLOCK_SKEW=1 exported, and so do the server's dev_credentials tests and the app's cmd_serve tests. The two pytest steps of the dev-mode CI job pass, each against a dev-mode server with the variable unset or set as that step expects. cargo fmt --check and clippy with -D warnings are clean.

Items 1, 2, 4 and 5 of the first review are done as asked:

  • With 1 or true, the banner and the WARN line say that the check is off and that a captured request can be replayed. A production build with the variable set still refuses a 2021 date.
  • cmd_serve.rs reads the switch once at startup, and the auth crate reads no environment. The unit tests cover the switch off, on, and on with a wrong secret. With the switch on, a wrong secret, an unknown key and a scope date that does not match are still refused. CI keeps the first dev-mode server as it was and starts a second one with the switch on.
  • TRUE, yes and an empty value stop the server before it binds, through the shared read_switch.
  • The docs no longer name the error type, and they say that the switch belongs on a loopback server.

You asked whether the parser change is alright. Part of it is not. That part came from item 3 of my first review, which asked for it without a measurement of the service. DynamoDB checks each field against a limit (month 12, day 31, hour 24, minute 60, second 60) and does no calendar check. These rows were measured in us-east-1 on 21 and 22 November, and #1356 records them:

  • 20261100T225657Z (day 00) is read as 31 October.
  • 2026-11-21T24:00:00Z is read as the next midnight, and 30 February as 2 March.
  • A request whose X-Amz-Date had second 60 answered 200, when its string to sign carried the next minute.
  • A field over its limit, such as month 13 or second 99, gets the format error.

At this head, day 00, 30 February, hour 24, minute 60 and second 60 get the format error in every build. Main and DynamoDB read them. The refusal of a field over its limit matches the service, but #1356 (opened 22 November) replaces parse_iso8601_basic with a parser that applies these limits. So this PR would add a second copy of that date check. Sorry for the extra round.

These two changes are needed before it merges:

  1. Please put parse_iso8601_basic back as it is on main, and drop parse_iso8601_basic_rejects_out_of_range_fields and parse_iso8601_basic_matches_known_epochs. In validate_timestamp_rejects_an_invalid_date_with_skew_ignored, a value such as 20210101T000000z keeps the check that the early return comes after the parse, because main's parser and #1356's parser both refuse it. "Valid date" then needs a new wording in docs/dev-image.md:113-114, verify.rs:163-164 and lib.rs:137, for example "a form the server reads". With these changes the PR changes no answer on a production build, so the "Breaking changes" paragraph can go. Until #1356 merges, a dev-mode server with the switch on serves a value such as month 13 again, as at your first commit. It still verifies the signature. #1356 also refuses the + sign.
  2. validate_timestamp now takes two arguments, but fuzz/fuzz_targets/sigv4_timestamp.rs:19 still calls it with one. fuzz/ is a workspace of its own, so a build or test of the root does not compile it. The Fuzz workflow runs cargo fuzz build for this target on every PR that changes crates/auth, so it would fail. validate_timestamp(&headers, false) there fixes it.

Smaller points:

  • docs/dev-image.md could say that the images through 1.1.0 ignore the variable and keep the check on. The section above it says this for its own switch.
  • The doc comment of the public read_switch (dev_credentials.rs:126 and :131) links to the private parse_switch, so the published docs would carry a dead link. Plain backticks, or the list of accepted values, would fix it.

Other PRs that change the same code: #1356 is named above. #1306, the base of #1356, changes the validate_timestamp call in lib.rs, so this PR conflicts with it there. #889 still conflicts in the skew block, and the early return keeps the two changes apart, as before. #635 also adds a parameter to dev_mode_banner_lines, so the second of the two to merge adds the other's argument.

CI has not run at this head yet: the workflow runs of a first-time contributor wait for a maintainer to approve them.

@jgaul3

jgaul3 commented Dec 4, 2026

Copy link
Copy Markdown
Author

@LeeroyHannigan Thank you for the feedback (and for tackling the fixes for parse_iso8601_basic 🙏 ). I've reverted those changes, fixed the timestamp validation caller, and called out the version difference explicitly as well as making my comments more concise in general. Please let me know if there's anything else I should address.

@navareamol navareamol self-assigned this Dec 4, 2026

@LeeroyHannigan LeeroyHannigan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. I read 8f3ae2c against main at a4e1731, and built it.

Both changes of my last review are in. parse_iso8601_basic is as on main, the two parser tests are gone, and the early return keeps its check with 20210101T000000z. The fuzz target calls validate_timestamp(&headers, false), and cargo fuzz build sigv4_timestamp succeeds on the pinned nightly. The two smaller points are done too, and the description no longer has the Breaking changes paragraph.

On this head, cargo fmt --check and clippy with -D warnings are clean for the auth, server and app crates. The auth crate's 543 lib tests pass, and so do the server's dev_credentials tests and the app's cmd_serve tests. I ran the two pytest steps of the dev-mode CI job against two dev-mode servers on loopback, and both pass. One server had the switch unset, and the other had it set to 1. With EXTENDDB_DEV_IGNORE_CLOCK_SKEW=yes, the server stops before it binds.

There's nothing else to change. I'll approve once CI has run on this head. The workflow runs of a first-time contributor wait for a maintainer to approve them.

@navareamol navareamol left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this on a dev-mode build with the variable unset and set to 1, signing ListTables with the example key at many dates. Unset, every date more than 15 minutes away gets 400. With 1, a 2021 date, a 2099 date, and the same stale request sent three times all get 200, a wrong secret, a wrong scope date and a wrong region are still refused, and the startup banner and the WARN line say the check is off. On a main build the variable does nothing. The values TRUE, yes and empty stop the server, 0 and false keep the check on. I also removed the early return in validate_timestamp on a clean tree and two auth tests fail, so they do guard it.

Three smaller points that Lee did not raise. First, the message for an empty EXTENDDB_DEV_DISABLE_EXAMPLE_CREDENTIAL changed with the shared parse_switch text. It used to say "to remove the example credential, 0 or false to keep it" and now says "to turn it on ... to turn it off". Could the name of the switch keep its explanation, for example by passing the meaning in as an argument? Second, serve_inner hands ignore_clock_skew to the auth provider without looking at dev_mode. Only the app crate sets it today, behind cfg!(feature = "dev-mode"), but another caller of ServeParams would get the bypass with no banner. Would you use ignore_clock_skew && dev_mode there? Third, the checklist says all tests pass with three existing failures. At this head I get 543 in the auth crate, 26 dev_credentials tests and 107 app tests passing, with and without the variable exported, so the note can go.

One test gap to know about. If cmd_serve::run stopped passing the value to ServeParams, no unit test would fail. The banner test calls dev_mode_banner_lines directly. Only the new Python test against the second CI server catches it, which I confirmed by making serve.rs pass false. That is fine if the CI job runs, and CI has not run at this head yet.

I will approve once CI has run at this head and the three points above are settled.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add dev-mode option to ignore or widen the 15 minute SigV4 clock skew window

3 participants