Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 36 ยท Projects and Practice

Project: Protect an Internal App with Tunnel and Access

Publish an internal dashboard safely: run it on a private host, connect it with Cloudflare Tunnel, add an Access policy with MFA, verify the JWT in the app and audit access.

Almost every company has an internal tool: an admin dashboard, a Grafana, a staging site. It often sits behind a VPN or, worse, is exposed on the internet with a weak password. In this project you publish such a tool safely using the Zero Trust pieces from earlier: Tunnel so the server needs no public exposure, Access so only the right people get in, and a JWT check so the app itself cannot be bypassed.

None of the Cloudflare services can run here, so the steps are exact but read-only. The runnable parts verify your plan, audit a configuration and test the JWT logic with stand-ins.

The goal

flowchart LR
  P["Staff member"] -->|"https://tools.example.com"| A["Access<br/>SSO + MFA + device check"]
  A --> T["Tunnel"]
  T --> S["Dashboard<br/>on private host, port 3000"]
  X["Attacker on the internet"] -.->|"no public IP, no open ports"| S

Requirements:

  • The dashboard server accepts no inbound connections from the internet.
  • Only members of the engineering group on a compliant device, using MFA, can open it.
  • Every access is logged, and the app verifies that requests really came through Access.
  • A health endpoint for monitoring stays reachable by a service token only.

Step 1: prepare the app

Run the dashboard on the private host, listening on localhost only (127.0.0.1:3000). Bind to localhost deliberately: even on the same network, nothing but cloudflared can reach it. Block inbound ports 80 and 443 in the firewall; allow only outbound connections.

Step 2: create the tunnel

Use a remotely managed tunnel (Networks, Tunnels, Create a tunnel, Cloudflared) and install the connector on the host with the single command the dashboard shows. Add a public hostname: tools.example.com pointing to the service http://localhost:3000. For a locally managed tunnel the equivalent is:

YAML
tunnel: <tunnel-id>
credentials-file: /etc/cloudflared/<tunnel-id>.json
ingress:
  - hostname: tools.example.com
    service: http://localhost:3000
  - service: http_status:404

Check that cloudflared tunnel info <name> shows a healthy connection, and run a second connector on another host if the tool is business-critical.

Step 3: create the Access application

Under Access controls, Applications, create a self-hosted application for tools.example.com, session duration 8 hours. Add two policies:

  1. Allow engineers: Action Allow; Include group engineering from your IdP; Require MFA (authentication method) and device posture: compliant.
  2. Allow monitoring: Action Service Auth; Include the service token monitor-bot; and, to keep it narrow, create a separate application for the path /healthz rather than putting the token on the whole app.

Copy the application's AUD tag; the app needs it in step 4.

Step 4: verify the token in the app

If someone reaches the dashboard some other way (a mistake in the firewall, another service on the host), the app must still refuse requests without a valid Access token. Add a middleware that follows the checklist from the Access lesson: verify the signature with the team's public keys, then check issuer, audience and expiry, then use the email claim as the user.

JS Middleware: allow only requests with valid Access claims

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Enforcing groups in the app is a second line of defense: Access already filtered, but defense in depth keeps a policy mistake from becoming a breach.

Step 5: audit the result

Before announcing the tool, test it like an attacker would. This checklist model scores a configuration against the requirements, so you can see what a review looks for.

JS Security review of the setup

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Do these real-world tests too:

  1. Open https://tools.example.com in a private window: you should reach a login screen, not the app.
  2. Sign in as a user outside the group: you should see a block page and the event in the Access logs.
  3. Try the origin's public IP directly: the connection should fail.
  4. Call the health path with and without the service token headers.
  5. Revoke a session in the dashboard and confirm the user is logged out.

Rollout and operations

  • Announce the change with the old and new address, and keep the old route disabled, not just hidden.
  • Put an alert on the tunnel health and on spikes of Access denials (see analytics and logs).
  • Manage the configuration as code with the Terraform provider (automation lesson) so changes go through review.
  • Review group membership regularly; access tracks the IdP, so offboarding someone in the IdP removes access here.
  • Document the break-glass procedure: who may change the Access policy if the IdP itself is down.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why bind the internal app to 127.0.0.1?

    Listening on localhost means nothing on the network can connect directly, so all traffic must go through the tunnel and Access.
  2. 2. Why does the app still verify the Access JWT?

    A direct request to the app could carry a forged header. Verifying the signed token proves the request passed Access.
  3. 3. A monitoring script must call /healthz. What is the cleanest way?

    Service tokens authenticate machines without weakening the human policy.
  4. 4. Which test proves the origin is not exposed?

    If the origin has no open inbound ports, direct connections fail, and only the tunnel path works.

Summary

  • Combine Tunnel (no inbound exposure), Access (SSO, MFA, device posture, groups) and an in-app JWT check for a layered design.
  • Bind the app to localhost, close inbound ports, run two connectors for availability.
  • Use service tokens for machines, short sessions for admin tools and no Bypass on protected paths.
  • Test like an attacker, export logs, alert on tunnel health and denials, and keep the configuration in code.

Next: Practice: Cloudflare Scenarios and Review