Repository navigation
Conversation
… overtook traffic.maxmind_url must be https: every download sends the MaxMind account ID and license key there by HTTP Basic. An http:// URL is refused at startup unless its host is loopback (a mirror on the same machine, and the tests' mock), as credential forwarding does for its URL. A download stores its databases only while the state is still the one it claimed. claim() returns the claimed state, and update() swaps from it to the successful state in a transaction that stays open while the databases are put and loaded: credentials forgotten or set again during the download, on any instance, make the swap fail and the download is discarded, and forget() waits on the row for a download that is storing. A failure is recorded by the same swap, never over a state the download did not claim. Admin -> Traffic -> Settings says when Download now stored nothing because the account was removed or saved again meanwhile. Fixes #772 Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_012e6DJbVCXv53RS9Xaf8uxc
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #772
Clear-text license key: an
http://traffic.maxmind_urlis refusedOf the two options the issue allows, this refuses rather than warns: startup fails with an
http://traffic.maxmind_url, unless its host is loopback (localhost,127.0.0.1,[::1]).127.0.0.1). No documentation, compose file, chart or e2e setup names anhttp://mirror. The loopback exception keeps the tests as they are and allows a mirror on the same machine. It is the rule credential forwarding already has for its URL (validate_credential_forward_url).upgradefragment, only772.fixed.md.docs/deployment.md(Traffic statistics) andforge.toml.examplesay that the URL must behttps://, and why.Turn off races a download: the download is discarded
update()now stores its databases only while the state is still the one it claimed.claim()returns the claimed state (Claim) instead of abool, andupdate()takes it. The claimed state carries its ownlast_attempt, so it differs from every other state the row holds: credentials removed, credentials removed and stored again with the same account (set_credentialsclearslast_attempt), or a later claim.update()swaps the state from the claim to the successful one (replace_setting, a compare-and-swap on theforge_settingrow). Only if that swap succeeds does it put the databases. A download that lost the race puts nothing, writes nolast_success, and is logged as discarded.DELETE /admin/traffic/geoipthat arrives at that moment waits for it, then deletes the state and the databases. Nothing is put afterforget()has deleted them. The cost is one pooled connection held for the two puts.last_errorby the same swap, so it is never written over credentials removed or set since, nor over a state that cannot be read (the guarantee the earlier read-again had).Admin API and web UI
POST /admin/traffic/geoip/updatestill answers 200 with the status when its download was discarded; the status then shows the account removed, or no download yet. The settings screen (Admin → Traffic → Settings → Geolocation) showed "Downloaded: every instance uses the databases within ten minutes" for any successful answer without an error. It now shows that only when the answer carries a download's time, and otherwise says that nothing was downloaded because the account was removed or saved again while the download ran. No other screen changes: thehttp://refusal is a startup error, not something the UI sets.Tests
config::tests::a_plain_http_maxmind_url_is_refused_unless_loopback: https and loopback http are accepted, other http is refused with a message naming the key, other schemes are refused.turning_geoip_off_discards_a_download_in_flight(crates/server/tests/traffic.rs): the mock delays the second archive,DELETEruns while the download waits for it, and afterwards the bucket holds no database, the state is gone and the answer shows geolocation off.credentials_set_again_discard_the_download_started_before:DELETEthenPUTof the same account during the download; the old download stores nothing, and a new Download now works.a_failed_download_is_not_recorded_over_a_state_it_did_not_claimreplacesa_download_recorded_over_a_state_it_cannot_read_keeps_the_account_id, for the new signature.traffic.test.tsx: the screen says that a download overtaken by Turn off stored nothing.Against the code before the fix, the config test fails (
http://mirror.example.comis accepted) and both in-flight tests fail withtraffic/v1/geoip/asn.mmdbput back in the bucket.Checks run locally, all passing:
cargo test -p forge-server --test traffic(6 tests, ten runs in a row),cargo test -p forge-server --lib(296),cargo xtask check(fmt and clippy-D warnings),cargo xtask changelog --check,cargo xtask unused,cargo xtask doc-check, and inweb/:pnpm tsc,pnpm knip,vitest run src/routes/admin/traffic(8). The full workspace test suite, the e2e suites and the Playwright suite were not run locally.Generated by Claude Code