authcha learn

Learn / Integrations

The pfSense agent

Module 2 of 6 · 30 minutes

By the end you can

  • Explain why pfSense CE needs an agent
  • Install and run the agent in dry-run, then for real, with the right token and certificate
  • Choose between the Squid path and the address-based path
  • Run the agent as a service and verify it with --check

Two facts that shape everything

  • pfSense CE cannot enforce a per-user URL list by itself. Authcha decides which policy a person has, and an agent on the firewall turns that into Squid rules or firewall rules.
  • pfSense CE has no RFC 5176 listener. Authcha cannot send it a Disconnect-Request. The agent ends sessions through the portal's own disconnect instead.
 browser ── captive portal ──RADIUS──▶ Authcha ──▶ policy for "luser"
                  ▲                          │
                  │ disconnect               │ HTTPS, API token
                  │                          ▼
            the agent  ◀── /api/web-policy/active-sessions
                  │        /api/web-policy/pending-disconnects
                  ├─ Squid ACL files + squid -k reconfigure      (primary)
                  └─ pf aliases and floating rules via PHP       (second path)

The agent comes as a Python script (standard library only), a single static FreeBSD binary (Go, about 6 MB, no Python needed), or a static Linux binary (Rust) for a Squid host that is not pfSense. They take the same options and write the same files. It was written for pfSense 2.7 and verified in a lab on 2.9.0; the binaries have been tested on Linux against the agent suite, but the Go binary has not been run on a real pfSense yet.

Pick the path

Squid ACLs (primary)Aliases and floating rules (second)
EnforcesSource address and destination nameSource address and destination IPs
AccuracyGood for names the browser asks forApproximate: CDNs and shared hosting move
NeedsSquid in transparent mode, plus SSL filtering in splice mode for HTTPSNothing beyond pfSense
Choose it whenA person must be held to named sitesYou cannot run Squid and "mostly right" is acceptable

Use --mode squid (the default), pf or both.

Set it up

  1. A token. Settings → API tokens → New, kind Web policy agent. Copy it once. It can read the enforcement feed and nothing else. Save it on the firewall as /usr/local/authcha/token (mode 0600).
  2. The console certificate. The agent always verifies it. Copy the CA that signed it to /usr/local/authcha/ca.pem, or use a certificate your firewall already trusts. Installing your own console certificate avoids certificate-change surprises.
  3. Install. Copy the agent and its two PHP helpers to /usr/local/authcha/. (The binary needs no Python.)
  4. Squid (primary path). Install the Squid package, enable it as a transparent proxy on the captive-portal interface and, for HTTPS, turn on SSL filtering with Splice All, so Squid reads the TLS server name without decrypting. Under Custom Options (Before Auth) add include /usr/local/etc/squid/authcha/webpolicy.conf. It must come before the rule that allows your LAN.
  5. Captive-portal networks: add --require-session. A transparent Squid fetches HTTPS sites for any client redirected to it, and a client that has not signed in would get through, because it has no restricted session and so no policy. With the option, the agent also refuses every address with no live portal session.
  6. Try it without changing anything:

`` python3 /usr/local/authcha/authcha_webpolicy_agent.py \ --url https://authcha.example --token-file /usr/local/authcha/token \ --ca-file /usr/local/authcha/ca.pem --dry-run ``

  1. Run it continuously, with --interval 20, a cron job, or the service script below.

Check, then run as a service

--check tests the setup and changes nothing: the console answers and accepts the token (TLS included), the Squid and PHP programs exist, the portal zone can be found. It prints ok or FAIL per line and exits 0 when all is fine. Run it first and after every change.

integrations/pfsense/rc.d/authcha_webpolicy.sh runs the agent under FreeBSD's daemon(8), restarts it five seconds after it dies, and starts it at boot. It reads /usr/local/etc/authcha-webpolicy.conf for the URL, token file, CA file, AUTHCHA_REQUIRE_SESSION, the portal URL and AGENT_ARGS such as --disconnect --captive-zone guest. Commands: status, stop, restart and remove (which also runs --remove-all). The log is /var/log/authcha_webpolicy.log.

How fast is it

With --interval, the agent does not sleep: it asks the console to answer the moment a session starts or ends (or after 25 seconds with "unchanged"). A change is applied about 0.5 to 1 second after a sign-in, and a disconnect you queue wakes the agent at once. For delivery within about a second and failure alerts, the pfSense alias connector (the Enforcement connectors module later in this track) uses the pfSense REST API package.

Exit codes

0 done. 2 Authcha unreachable (nothing changed). 3 a change was refused by Squid or pfSense and rolled back. 4 configuration error.

LabHands-on

Needs a pfSense lab with the captive portal and Squid.

  1. Create a Web policy agent token and save it with mode 0600.
  2. Run --check. Fix each FAIL line.
  3. Run with --dry-run and read what it would create.
  4. Run it for real, sign a test user in at the portal and watch the Squid files appear in /usr/local/etc/squid/authcha/.
  5. Sign in as a user with a deny-list policy and try a blocked and an allowed site.
  6. Queue an End session in the console and time how long the agent takes to end it.
  7. Run authcha_webpolicy.sh remove and confirm the agent's files and rules go.

Check yourselfQuiz

1Why is an agent needed on pfSense CE?
2What does --check do?
3Why add --require-session on a captive-portal network?
4Which path holds a user to a named site?
5The agent exits with code 2. What does it mean?

Cheat sheetKeep this

  • pfSense CE: no per-user URL lists, no CoA. Agent decides nothing; it applies Authcha's policy and ends sessions.
  • Token kind Web policy agent. /usr/local/authcha/token mode 0600. CA at ca.pem.
  • Squid transparent + Splice All + include line before the allow-LAN rule.
  • Captive portal: --require-session.
  • Always --dry-run, then --check. Service: rc.d/authcha_webpolicy.sh.
  • Exit: 0 ok, 2 unreachable, 3 refused change, 4 config.
  • Read more: pfSense integration.