Add Cloudflare Access authentication#176
Conversation
Merge pull request remnawave#155 from remnawave/dev
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
PR Summary
These improvements aim to enhance user experience, system security, and general product efficiency. |
Greptile SummaryThis PR adds Cloudflare Access as an optional authentication method, validating
Confidence Score: 3/5The new Cloudflare Access auth flow itself is well-structured, but two defects in the changed files can cause runtime crashes or a complete auth outage before any fixes are applied. The
Important Files Changed
Reviews (1): Last reviewed commit: "Add Cloudflare Access authentication" | Re-trigger Greptile |
| private async getCertByKeyId(teamDomain: string, keyId: string): Promise<string | null> { | ||
| const cacheKey = `cloudflare-access:${teamDomain}:certs`; | ||
| const cachedCerts = await this.rawCacheService.get<ICloudflareAccessCert[]>(cacheKey); | ||
| const certs = cachedCerts ?? (await this.fetchCerts(teamDomain)); | ||
|
|
||
| if (!cachedCerts && certs.length > 0) { | ||
| await this.rawCacheService.set(cacheKey, certs, 3600); | ||
| } | ||
|
|
||
| return certs.find((cert) => cert.kid === keyId)?.cert ?? null; | ||
| } |
There was a problem hiding this comment.
Stale cache on Cloudflare key rotation
When Cloudflare rotates its signing keys (which it does periodically), new JWTs carry a new kid. If the cert list is already cached, cachedCerts ?? (await this.fetchCerts(...)) returns the stale cached list and certs.find((cert) => cert.kid === keyId) returns undefined — so the method returns null without ever re-fetching. Every Cloudflare Access login attempt then fails with 403 for up to 1 hour (the cache TTL), effectively locking out all CF Access users until the cache naturally expires.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
Frontend PR: remnawave/frontend#348 |
Summary
Adds Cloudflare Access as an optional authentication method for the panel.
The implementation validates the
Cf-Access-Jwt-AssertionJWT instead of trusting forwarded identity headers. It verifies the token signature against the Cloudflare Access cert endpoint, checks issuer and audience, extracts the authenticated email from the JWT payload, and then issues the regular Remnawave admin JWT.Changes
POST /api/auth/cloudflare-accessSecurity Notes
Cf-Access-Authenticated-User-EmailValidation
git diff --check