Skip to content
algo7Public

About

Serves pfsense aliases

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

23 Commits

Folders and files

Repository files navigation

Test aliasd

Table of Contents

Description

aliasd serves named lists of IP addresses and CIDR prefixes over HTTP, in the plain-text, one-entry-per-line format a pfSense URL Table alias consumes.

The lists live in a single YAML file, one top-level key per alias. Every entry is validated when the server starts, so a malformed prefix aborts startup with a message naming the alias and the offending value.

Supported Operating Systems and Architectures

OS Architecture
Linux x86_64
macOS x86_64
macOS arm64
Windows x86_64

User Guide

Configuration File

Each top-level key is an alias name and becomes the URL path it is served at. The example below is served at /office-vpn and /blocklist.

office-vpn:
  - "10.8.0.0/24"
  - "10.9.0.0/24"

blocklist:
  - "203.0.113.0/24"
  - "198.51.100.17"
  - "2001:db8::/32"

# Both forms below define an alias with no entries and will return 404 when requested.
staging-allow: []
retired-hosts:

Entries are served in the order they are written.

Note that the file is read once at startup, so editing it requires a restart.

An alias with no entries is ignored and requesting it returns 404.

Entry Validation

An entry is either a bare address or a CIDR prefix, IPv4 or IPv6. Two rules are enforced before the server will start:

  • A prefix must be the network address. 10.8.0.5/24 is rejected, because it is ambiguous about whether you meant the subnet or the single host.
  • IPv6 zone suffixes (fe80::1%eth0) are rejected — they are meaningless to a remote consumer.

A rejected prefix names the fix:

alias "office-vpn": "10.8.0.5/24" has host bits set: use 10.8.0.0/24 for the network or 10.8.0.5/32 for the single host

Environment Variables

Variable Default Description
ALIAS_FILE aliases.yaml Path to the YAML file holding the alias definitions.
ALIAS_USER pfsense HTTP Basic username.
ALIAS_PASS (unset) HTTP Basic password. Unset disables authentication entirely use for local development only.
LISTEN_ADDR :8080 Address the server listens on.

Running the Server

go build -o aliasd .
ALIAS_PASS=s3cret ALIAS_FILE=./aliases.yaml ./aliasd

Running with Docker

The image does not bundle a config file, so mount one. ALIAS_FILE defaults to aliases.yaml relative to the image's / working directory.

make docker-build

docker run --rm -p 8080:8080 \
  -v "$PWD/aliases.yaml:/aliases.yaml:ro" \
  -e ALIAS_PASS=s3cret \
  aliasd:latest

HTTP API

Request Response
GET /{name} with valid credentials, alias exists 200, text/plain, one entry per line
GET /{name} with valid credentials, no such alias 404
Any request with missing or wrong credentials 401 with a WWW-Authenticate challenge
curl -u pfsense:s3cret http://localhost:8080/office-vpn

pfSense Setup

Create a URL Table (IPs) alias under Firewall -> Aliases -> Add -> Type URL Table (IPs) then add the URL.

Credentials are supplied the usual way for a fetched URL:

https://user:password@aliasd.example.com/blocklist

Serve it over TLS or put it behind a reverse proxy; plain HTTP will shows the credentials in cleartext on the network.

Updating the URL Table Alias

pfSense only updates the URL Table alias based on the interval you set in the alias configuration. If you want to force an update, you can either:

Update a specific alias:

/etc/rc.update_urltables now forceupdate my_alias_name

Or update all URL Table aliases:

/etc/rc.update_urltables now forceupdate

Run the above commands in the pfSense via SSH or Diagnostics -> Command Prompt in the GU.

Maintainer Guide

Project Structure

.
├── aliases.yaml    // Local alias definitions used for development; not baked into the image
├── Dockerfile      // Two-stage build onto distroless, running as nonroot (65532)
├── main.go         // Reads the environment, loads the config, wires the mux, starts the server
├── Makefile        // Build, test and Docker targets
└── internal
    ├── auth        // HTTP Basic middleware, constant-time credential comparison
    └── config      // YAML loading, entry validation, and the alias HTTP handler

Config is both the parsed config and the handler that serves it — it implements http.Handler, which is what keeps the alias-serving logic testable rather than buried in a closure in main().

Building the Tool

go build -o aliasd .   # current platform
make build-all         # all four supported targets, into bin/
make docker-build      # container image, tagged aliasd:latest

Testing the Tool

make test              # go fmt, go vet, then tests with an HTML coverage report
go test ./internal/... # tests alone
go test -cover ./internal/...

About

Serves pfsense aliases

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages