mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5485] [Engine] serve: Cloudflare Access zero-trust JWT authentication (STRATA_CF_ACCESS_TEAM) #5463
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5463
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/5485
Author: @DamirLukina88
Created: 11/7/2026
Status: 🔄 Open
Base:
main← Head:feat/cloudflare-access-auth📝 Commits (2)
1b17f88feat(serve): opt-in Cloudflare Access JWT authentication (STRATA_CF_ACCESS_TEAM)58be0d3fix(serve): address review on CSRF origin checks, retry throttling, and non-dict JWT headers📊 Changes
4 files changed (+414 additions, -10 deletions)
View changed files
📝
docs/DETAILS.md(+2 -0)➕
serve/cf_access.py(+145 -0)📝
serve/server.py(+29 -10)➕
serve/test_cf_access.py(+238 -0)📄 Description
Problem and result
When exposing Strata remotely through a tunnel (such as cloudflared), clients connecting through a Cloudflare Access application must currently enter and store the server API key in browser storage, which presents credential leakage risks on shared machines.
This change adds opt-in support for verifying Cloudflare Access JWT assertions (
Cf-Access-Jwt-Assertionheader andCF_Authorizationcookie). When configured viaSTRATA_CF_ACCESS_TEAMandSTRATA_CF_ACCESS_AUD, requests arriving over loopback from the local tunnel connector are authorized without requiring an API key.Related discussion
Refs #4207 (remote host access and tunnel overrides).
Approach
serve/cf_access.py: A standard-library-only RSA PKCS#1 v1.5 SHA-256 JWT verifier (zero external dependencies). Verifies signatures against Cloudflare published JWKs (https://<team>.cloudflareaccess.com/cdn-cgi/access/certs, cached for 1 hour with a 60-second minimum refetch interval on both unknownkidlookups and failed network refreshes).exp,nbfwith 60-second clock skew tolerance).STRATA_CF_ACCESS_TEAMis set, the server operates in discovery mode: it logs the AUD tag of the first valid login seen without authorizing, allowing the audience tag to be copied easily from logs.serve/server.py: In_authorized()and_authorized_telemetry(), checks_access_claims()ifself.cf_accessis active and the client address is loopback (127.0.0.1/::1)._foreign_page(): browser POSTs authenticated via ambient Cloudflare Access credentials (rather than an explicit API key via_given_key()) still must passOriginandContent-Type: application/jsonchecks.self.cf_accessisNoneand the default authentication path remains byte-identical.serve/test_cf_access.py(covering JWT verification, non-dict header rejection, failed fetch retry throttling, CSRFOriginenforcement on Access cookies, and end-to-end HTTP mock server authorization).docs/DETAILS.md.Validation
Passed:
python3 serve/test_cf_access.py -v: All 11 unit tests passed in 1.80s (key caching, tamper rejection, non-dict header rejection, failed fetch retry throttling, expiry checks, discovery mode, token extraction, CSRFOrigincheck with Access cookies, and live HTTP mock server auth). Tested on revision58be0d3d.python3 -m unittest serve.test_security -v: All 30 security and auth tests passed in 10.3s.python3 tools/test_source_nul_bytes.py: Passed (0.16s).Failed:
Not run:
Limits
127.0.0.1,::1,::ffff:127.0.0.1) are eligible for Access claim authorization to prevent spoofing if the port is exposed directly.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.