- test(e2e): set a user password and revoke a delegation from the web ui - test(e2e): switch a dynamic soa serial to a managed one through the ui - test(e2e): match audit ledger routes on the decoded api path - test(e2e): fuzz injection payloads in paths, filters and record data
coredns-web-ui
A web application, shipped as a container image, to manage the DNS zones and records that CoreDNS serves through the mysql plugin (github.com/cloud66-oss/coredns_mysql, built into git.bjphoster.com/docker/coredns-mysql). It reads and writes the plugin's records table in MySQL directly. CoreDNS reads the same table. The application never talks to CoreDNS, never edits the Corefile and never starts, stops or reloads CoreDNS.
The same binary starts the HTTP server when run without arguments and provides subcommands for user management, zone checks, audit inspection, health checks, version and help. Configuration comes from environment variables only.
What it does
- Login with local users, sessions and password change.
- Two roles:
adminsees and does everything,usersees and operates only on the zones delegated to them. - Zone creation (SOA and NS records in one transaction) and deletion, by admins.
- Creation, editing and deletion of records of every type the plugin serves:
A,AAAA,CNAME,NS,MX,TXT,SRV,CAAandSOA. Wildcard names are supported. Bulk deletion of records. - Automatic SOA serial management.
- A zone check that reports every row the plugin cannot serve correctly, with a repair path in the UI.
- Zone file export and import (RFC 1035 master file format).
- An audit table that records every operation performed through the web UI, the API and the CLI.
Out of scope: creating, altering or dropping the plugin's records table, Corefile management, record types the plugin does not serve, DNSSEC, zone transfers, API tokens, external identity providers, zone renaming.
Relationship with the CoreDNS mysql plugin
The records table belongs to the operator and is shared with CoreDNS and possibly with other writers. The application only runs SELECT, INSERT, UPDATE and DELETE on it. It never creates or changes the table, its indexes or its collation.
The plugin documents this table (<prefix>records, default prefix coredns_):
CREATE TABLE `coredns_records` (
`id` INT NOT NULL AUTO_INCREMENT,
`zone` VARCHAR(255) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`ttl` INT DEFAULT NULL,
`content` TEXT,
`record_type` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
At startup (and before every database CLI command) the application reads information_schema.COLUMNS of the configured database and exits with a message naming the table or column when the contract is not met. The contract accepts:
| Column | Accepted types |
|---|---|
id |
INT (signed or unsigned) |
zone |
VARCHAR(255) or longer, TEXT, MEDIUMTEXT, LONGTEXT |
name |
VARCHAR(255) or longer, TEXT, MEDIUMTEXT, LONGTEXT |
ttl |
INT, BIGINT |
content |
TEXT, MEDIUMTEXT, LONGTEXT, JSON |
record_type |
VARCHAR(9) or longer, TEXT, MEDIUMTEXT, LONGTEXT |
The application's own tables live in the same database, prefixed with <prefix>webui_, so the plugin never sees them.
What the application writes
zone: the zone apex, lowercase, with the trailing dot (example.org.). The plugin lists zones withSELECT DISTINCT zone, so a zone exists as soon as one row carries it.name: the owner name relative to the zone, lowercase, without trailing dot. The empty string is the apex.*as the complete leftmost label is a wildcard.ttl: an integer from 0 to 2147483647. NeverNULL, never negative.record_type: one of the nine uppercase type names.content: a JSON object in canonical form (keys in the order below, no other keys). Rows written by other writers are read tolerantly (any key order, extra keys ignored) and rewritten in canonical form only when edited.- Every host, target,
nsandMBoxis stored as a lowercase FQDN with the trailing dot, because the plugin does not makeNS,MX,SRVandSOAnames fully qualified and packing fails on names without it.
| Type | Content |
|---|---|
A |
{"ip": "192.0.2.10"} |
AAAA |
{"ip": "2001:db8::10"}, not IPv4-mapped |
CNAME |
{"host": "target.example.org."} |
NS |
{"host": "ns1.example.org."} |
MX |
{"host": "mail.example.org.", "preference": 10} (the plugin ignores a priority key) |
TXT |
{"text": "v=spf1 -all"}, 1 to 4096 bytes of printable ASCII without backslash |
SRV |
{"priority": 10, "weight": 5, "port": 443, "target": "host.example.org."}, the owner name starts with _service._proto |
CAA |
{"flag": 0, "tag": "issue", "value": "ca.example.net"}, flag 0 or 128 |
SOA |
{"ns": "ns1.example.org.", "MBox": "hostmaster.example.org.", "refresh": 3600, "retry": 600, "expire": 604800, "minttl": 300, "serial": 2026111700}, only at the apex |
After field validation every record is converted to the miekg/dns RR the plugin builds from it and packed into a message; a record that does not pack is refused.
Plugin behavior visible in the UI
- Zone reload interval. The plugin reloads its zone list at most every
zone_update_interval(default 10 minutes). A new zone is served only after the next reload, and a deleted zone is still matched until then. The UI states this after creating a zone. Record changes in an existing zone are read by the next query, apart from any caching configured in the Corefile. - SOA serial. The application manages explicit serials in the format
YYYYMMDDxx(UTC date and a two-digit counter). New zones getYYYYMMDD00of today. Every committed transaction that changes a zone whose SOA has a non-zero serial sets it tomax(serial + 1, YYYYMMDD00 of today), once per transaction whatever the number of changed records. After99the next change gets the following day's00, so the serial always increases. Editing the SOA never takes a serial from the user. A zone whose SOA has no serial (or0) keeps it that way: the plugin then serves the current Unix time, which changes on every query and differs between instances. The UI shows "dynamic (Unix time)" and offers "Use managed serial", which setsYYYYMMDD00of today. - TTL 0. The plugin serves a TTL of
0as 360 seconds. The UI displays it as "default (360 s)" and the zone file export writes it as 360. New records are prefilled with the TTL of the RRset they join, or 3600.
Zone rules and the zone check
Errors refuse a write with HTTP 422: a zone has exactly one SOA, at the apex, which cannot be created twice or deleted on its own; the last apex NS cannot be deleted; a name with a CNAME has no other record and only one CNAME; no two records share name, type and canonical content. Warnings let the write through and are returned with the response: records of one name and type with different TTLs, NS, MX or SRV targets that are CNAME owners or have no address record in the zone, names below a zone cut, TXT text longer than 255 bytes (served as several strings).
The zone page can repair an existing broken SOA set by editing a misplaced SOA or deleting an extra SOA. If a conflicting CNAME blocks the repair, delete that CNAME first. To restore a missing SOA, use a merge import containing an apex SOA.
The zone check (API, UI and check command) reports every row the plugin cannot serve correctly.
| Severity | Codes |
|---|---|
| error | zone_not_fqdn, zone_case, ttl_null, ttl_negative, content_null, content_json, type_unknown, field_invalid, name_not_fqdn, mx_priority_key, soa_missing, soa_multiple, soa_not_apex, cname_apex, cname_conflict, pack_failed |
| warning | ns_apex_missing, duplicate, rrset_ttl_mismatch, target_is_cname, target_no_address, below_zone_cut, txt_split, name_case, ttl_zero, soa_dynamic_serial, content_not_canonical |
Rows with errors are shown in the UI with their raw content and problems; editing one starts an empty typed form for its type and replaces the row.
Writes, locking and ETags
Every write takes a MySQL named lock per zone (<prefix>webui:<first 16 hex characters of sha256(zone)>, 10 s timeout, HTTP 503 "zone busy" on timeout), runs in one transaction and writes the records, the SOA serial and the audit row together. Every record carries an ETag (the SHA-256 of its columns). Updates and deletes require If-Match: a missing header is HTTP 428, a mismatch or a missing row is HTTP 412, so concurrent changes by other writers are detected instead of overwritten.
Zone files
Export writes $ORIGIN, the SOA first and the other records in UI order, each with an explicit TTL. Rows with check errors are not exported; each produces a ; skipped id=<id>: <code> line at the end. Import accepts a master file (at most 2 MiB and 10000 records, $INCLUDE disabled, class IN only, default TTL 3600), previews the diff and applies it in merge mode (adds missing records and updates the TTL of matching ones) or replace mode (also deletes records that are not in the file). Applying requires the fingerprint returned by the preview and answers 409 when the zone changed in between. The serial of an imported SOA is ignored and the managed serial is bumped.
MySQL grants
The application user needs SELECT, INSERT, UPDATE and DELETE on the records table, and table-level grants on its own tables, which MySQL allows before the tables exist when CREATE is included. This is least privilege (dev/mysql-init.sql applies exactly these grants):
CREATE USER 'coredns_webui'@'%' IDENTIFIED BY '<password>';
GRANT SELECT, INSERT, UPDATE, DELETE ON `coredns`.`coredns_records` TO 'coredns_webui'@'%';
GRANT SELECT, INSERT, UPDATE, CREATE, ALTER, INDEX, REFERENCES ON `coredns`.`coredns_webui_schema` TO 'coredns_webui'@'%';
GRANT SELECT, INSERT, UPDATE, CREATE, ALTER, INDEX, REFERENCES ON `coredns`.`coredns_webui_users` TO 'coredns_webui'@'%';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, REFERENCES ON `coredns`.`coredns_webui_sessions` TO 'coredns_webui'@'%';
GRANT SELECT, INSERT, DELETE, CREATE, ALTER, INDEX, REFERENCES ON `coredns`.`coredns_webui_zone_delegations` TO 'coredns_webui'@'%';
GRANT SELECT, INSERT, CREATE, ALTER, INDEX, REFERENCES ON `coredns`.`coredns_webui_audit` TO 'coredns_webui'@'%';
Replace coredns with the database and coredns_ with the table prefix. Without DELETE on the users table and without UPDATE and DELETE on the audit table, MySQL itself guarantees that users are never removed and audit rows are never changed or removed, even through a bug in the application.
The CoreDNS user keeps SELECT on coredns_records only, so it cannot read password hashes, sessions, delegations or the audit:
CREATE USER 'coredns'@'%' IDENTIFIED BY '<password>';
GRANT SELECT ON `coredns`.`coredns_records` TO 'coredns'@'%';
Application schema and migrations
Migrations are embedded SQL files (migrations/001_initial.sql, ...) applied in order. The current version is the single row of <prefix>webui_schema. The table prefix is substituted into the SQL after validation; it is the only value ever interpolated into SQL. Migrations run while holding the MySQL named lock <prefix>webui_migrate (GET_LOCK, 30 s timeout), so several instances starting together never race.
| Table | Content |
|---|---|
<prefix>webui_schema |
the schema version |
<prefix>webui_users |
id, username, role, password_hash, created_at, updated_at, last_login_at, deleted_at |
<prefix>webui_sessions |
SHA-256 of the session token, user, creation, last seen and expiry times, origin, user agent |
<prefix>webui_zone_delegations |
zone, user_id, created_at, created_by |
<prefix>webui_audit |
the audit rows (see Audit) |
All times are UTC. Rows of the users table are never deleted, so the foreign keys from sessions, delegations and audit rows always resolve. Audit rows have no foreign key to the records table, so deleted records keep their history. The audit record_id column is BIGINT to preserve IDs across the full range of an INT UNSIGNED records table.
Configuration
Configuration comes only from environment variables. No configuration file is read. A variable that is set but empty is an error, except DB_TABLE_PREFIX (an empty prefix is valid) and TRUSTED_PROXIES (empty means no trusted proxy).
| Variable | Required | Default | Accepted values |
|---|---|---|---|
DB_HOST |
yes | none | Host name or IP address of MySQL |
DB_PORT |
no | 3306 |
Integer from 1 to 65535, ASCII digits only |
DB_USER |
yes | none | At most 64 characters, no control characters |
DB_PASSWORD |
yes | none | Any non-empty value; never printed in messages |
DB_NAME |
yes | none | Database holding the records table; at most 64 characters, no control characters |
DB_TLS |
no | false |
false, true, skip-verify or preferred |
DB_TABLE_PREFIX |
no | coredns_ |
^[A-Za-z0-9_]{0,32}$; must equal the plugin's table_prefix |
HTTP_ADDR |
no | 0.0.0.0 |
A literal IPv4 or IPv6 address (no host names, ports or zones) |
HTTP_PORT |
no | 8080 |
Integer from 1 to 65535, ASCII digits only |
LOG_LEVEL |
no | INFO |
ERROR, WARN, INFO, DEBUG, TRACE, case-insensitive |
APP_NAME |
no | CoreDNS Web UI |
1 to 100 characters without control characters; shown in page titles and on /version |
COOKIE_SECURE |
no | true |
true or false; sets the Secure attribute of the session cookie |
SESSION_IDLE_TIMEOUT |
no | 1h |
Go duration, at least 1m |
SESSION_MAX_AGE |
no | 12h |
Go duration, at least SESSION_IDLE_TIMEOUT |
TRUSTED_PROXIES |
no | empty | Comma-separated CIDRs whose X-Forwarded-For is trusted |
Validation happens before any other work. The first problem is reported as coredns-web-ui: configuration error: <message> with a message that names the variable and never its value for DB_PASSWORD, and the process exits with code 2. Copy env.example for a ready-made set of development values.
The database connection is built with mysql.Config from github.com/go-sql-driver/mysql (ParseTime, UTC, collation utf8mb4_0900_ai_ci, connect timeout 5 s, read and write timeouts 30 s, no multi statements, no client-side interpolation). The pool holds at most 10 open and 10 idle connections with a connection lifetime of 1 minute. The DSN and the password are never logged.
TRUSTED_PROXIES controls the client origin stored in sessions and audit rows. By default it is the TCP peer address. When the peer is inside a trusted CIDR, it is the rightmost X-Forwarded-For entry that is not itself trusted; forwarding headers from other peers are ignored.
Server
/app with no arguments:
- Loads and validates the configuration and initializes the logger.
- Opens the pool and pings MySQL, retrying with backoff for up to 30 seconds.
- Verifies the records table contract.
- Applies the migrations under the named lock.
- Starts a background task that deletes expired sessions every 10 minutes.
- Listens on
${HTTP_ADDR}:${HTTP_PORT}withReadHeaderTimeout10 s,ReadTimeout30 s,WriteTimeout60 s,IdleTimeout120 s andMaxHeaderBytes64 KiB. - On
SIGINTorSIGTERM, stops accepting connections, waits up to 25 seconds for running requests, stops the background task and closes the pool.
The application keeps no local state and needs no volume: several instances can run against the same database. Login rate limits are kept per instance.
Endpoints without a session
| Method | Path | Behavior |
|---|---|---|
GET |
/health |
200 {"status":"ok"} when a MySQL ping succeeds within 2 s, 503 {"status":"unavailable"} otherwise |
GET |
/version |
HTML page with the application version and commit |
GET |
/static/<hash>/... |
embedded assets with long-lived immutable caching |
GET, POST |
/login |
the login page and the login form |
Everything else needs a session. The pages are / (zones), /zones/{zone}, /zones/{zone}/import, /audit, /account, /users and /users/{username} (the last two for admins). Pages carry no zone, record, user or audit data: all data is read through the JSON API under /api/v1, which needs a session (401 otherwise) and application/json bodies. Responses carry a restrictive Content-Security-Policy, X-Content-Type-Options: nosniff and Referrer-Policy: no-referrer; pages and API responses are Cache-Control: no-store. HSTS is left to the reverse proxy.
Authentication and sessions
- Passwords are hashed with argon2id (64 MiB, 3 iterations, parallelism 2) and stored as PHC strings. Unknown usernames are verified against a dummy hash, so timing and message (
invalid username or password) match a wrong password. - After 5 failed logins within 15 minutes for the same username or the same origin, login answers
429for 15 minutes. - The session token is 32 random bytes in the cookie
coredns_webui_session(HttpOnly,SameSite=Strict,Path=/,SecureperCOOKIE_SECURE). The database stores only its SHA-256. A new token is issued at every login. - Sessions end after
SESSION_IDLE_TIMEOUTwithout requests orSESSION_MAX_AGEafter login. Logout deletes the row. A password change deletes the user's other sessions; a password set by an admin, a CLI password change and a user deletion delete all of them. - Cross-site request forgery is refused for every non-safe method by
net/http'sCrossOriginProtection, together withSameSite=Strictand the JSON content type requirement.
Roles and zone delegation
| Capability | admin |
user |
|---|---|---|
| Zone list, zone page, records, SOA, check, export, import | every zone | delegated zones only |
| Create and delete zones | yes | no |
| Delegate and revoke zones | yes | no |
| Create users, change roles, set passwords, delete users | yes | no |
| Audit | every row | rows of their delegated zones and their own rows |
| Change their own password | yes | yes |
For a user, a zone that is not delegated to them does not exist: zone pages and zone API routes answer 404 exactly as for a missing zone, lists and the check of all zones contain only their delegated zones, and record ids of other zones are 404. Admin-only pages and routes answer 403.
Zone delegation gives a user access to a zone in this application. It never touches the records table or the Corefile and has nothing to do with DNS delegation through NS records.
- A delegation is a row of
<prefix>webui_zone_delegations. A user can have any number of zones and a zone any number of users. Admins need no delegation, and delegating to an admin is refused (422). A user promoted to admin keeps their delegation rows, which apply again if they are demoted. - Only admins grant and revoke delegations, from the zone page or the user page. Granting requires the zone to exist in the records table and is idempotent.
- Deleting a zone deletes its delegation rows in the same transaction (listed in the audit row). When the rows of a zone are removed outside the application, its delegation rows remain: creating a zone with that name deletes them, and until then the user page marks them "zone not found" and lets an admin revoke them.
- Sessions are bound to the user row: every request reads the role and
deleted_at, and every zone-scoped request reads the delegation, so deletions, role changes and delegation changes take effect on the next request without a new login.
Users
- Username:
^[a-z0-9][a-z0-9._-]{0,63}$, unique across every row of the users table, deleted users included. A deleted user's username can never be used again, so every audit row keeps pointing at one person.cliis reserved, because it is the actor of CLI audit rows. - Password: 12 to 256 bytes of valid UTF-8 without control characters.
- Role:
adminoruser. - Deletion only sets
deleted_at(andupdated_at) and deletes the user's sessions. The row, its password hash, its delegations and its audit history stay in the database. A deleted user cannot log in, cannot receive delegations and cannot be changed, is listed only when deleted users are asked for, and its username stays taken. Deleted users are never restored. - Once an active admin exists, at least one always remains: demoting or deleting the last active admin is refused (HTTP
409, CLI exit1). The check and the change run in one transaction that locks the active admin rows. - From the web UI an admin cannot change their own role or delete their own account (HTTP
403), and changes their own password only on the account page, which asks for the current one.
First admin bootstrap
The first admin is created with the CLI, through docker exec in the running container. Until an active admin exists, the login page shows this command:
printf '%s\n' "$PASSWORD" | docker exec -i <container> /app user add <username> admin
Every other user can then be managed from the Users page of the web UI.
CLI
usage:
coredns-web-ui start the HTTP server
coredns-web-ui help print this usage text
coredns-web-ui version print the version and commit
coredns-web-ui healthcheck query the local /health endpoint
coredns-web-ui user list [all] list the active users, or every user with all
coredns-web-ui user add <username> <role> create a user with role admin or user, reading the password from stdin
coredns-web-ui user passwd <username> set the password of a user, reading it from stdin
coredns-web-ui user role <username> <role> set the role of a user to admin or user
coredns-web-ui user delete <username> mark a user as deleted and end their sessions
coredns-web-ui check [zone] report the rows the plugin cannot serve correctly
coredns-web-ui audit [n] print the latest n audit rows (default 20)
Inside the image the binary is /app, so the commands run as docker exec <container> /app <command>; docker exec inherits the container's environment. Commands and arguments are case-sensitive.
| Command | Behavior |
|---|---|
help |
Prints the usage text to stdout and reads no configuration |
version |
Prints coredns-web-ui <APP_VERSION> <COMMIT_ID> and reads no configuration |
healthcheck |
Sends GET /health to 127.0.0.1:${HTTP_PORT} (or to HTTP_ADDR when it is a specific address) with a 3 s timeout and exits 0 on HTTP 200, 1 otherwise. It reads only HTTP_ADDR and HTTP_PORT. It is the image's HEALTHCHECK, since the scratch image has no shell or HTTP client |
user list [all] |
Prints the active users; with all (exact) also deleted ones, ordered by username |
user add <username> <role> |
Creates a user. Fails when the username is already used, also by a deleted user |
user passwd <username> |
Sets the password of an active user and ends their sessions |
user role <username> <role> |
Sets the role of an active user. Fails when it would leave no active admin |
user delete <username> |
Sets deleted_at and ends the user's sessions. Fails when it would leave no active admin |
check [zone] |
Runs the zone check on one zone or on all zones |
audit [n] |
Prints the latest n audit rows (default 20, n from 1, digits only), oldest first |
<role> is admin or user, exact and lowercase. user add and user passwd read the password: when stdin is a terminal they prompt Password: and Repeat password: on stderr with echo disabled and fail when the two differ; otherwise they read one line from stdin (at most 4096 bytes), so printf '%s\n' "$PASSWORD" | docker exec -i <container> /app user passwd alice works.
Every command except help, version and healthcheck loads and validates the full configuration, then validates its arguments before connecting to MySQL, so usage errors never touch the database. Commands that need the database run the contract check and the migrations like the server.
Output tables are padded with spaces (text/tabwriter, padding 2) and use - for empty values:
| Command | Columns |
|---|---|
user list |
USERNAME, ROLE, ZONES (delegated zones), CREATED_AT, LAST_LOGIN_AT, DELETED_AT |
check |
ZONE, NAME (@ for the apex), TYPE, ID, SEVERITY, PROBLEM (<code>: <message>) |
audit |
TIME, ACTOR, ORIGIN, OPERATION, STATUS, ZONE, RECORD, TARGET_USER |
Times are UTC in the form 2026-11-19T08:31:05Z.
Every successful CLI change (user add, user passwd, user role, user delete) writes one audit row in the same transaction. Failed commands and read-only commands (user list, check, audit) write nothing.
Exit codes
| Code | Meaning |
|---|---|
0 |
success, clean shutdown, check without problems |
1 |
runtime, database or I/O error (including check of a zone without rows and a refused change such as the last active admin) |
2 |
usage or configuration error |
3 |
check found at least one problem (error or warning) |
Errors are a single line on stderr prefixed with coredns-web-ui: . Usage errors are fixed messages prefixed by coredns-web-ui: usage error: that never echo the arguments, followed by the usage text on stderr, exit 2.
Audit
The audit table <prefix>webui_audit records every operation, who performed it and from where, and what changed. It is append-only: the application never updates or deletes audit rows, the grants do not allow it, and there is no retention.
What is an operation, with exactly one audit row each:
- Every request to
/api/v1made with a valid session, reads included, whatever the outcome: success, refused (403,404), invalid (400,413,415,422,428), conflict (409,412), busy or failed (500,503). - Every login attempt (success, wrong credentials, rate limited) and every logout.
- Every successful CLI change.
Requests without a valid session (401), requests refused by the cross-origin protection and requests to /health, /version, /static/ and the HTML pages are not operations and are only logged.
An authenticated API request with an unknown path or an unsupported method is recorded as an api_unknown read, with status 404 or 405 respectively.
Columns
| Column | Content |
|---|---|
id |
Auto-increment identifier |
time |
UTC, with microseconds |
user_id |
The acting user; NULL for CLI rows and for login attempts with an unknown username |
actor |
The acting user's username; for login attempts the submitted username with non-printable characters replaced by spaces and cropped to 64 characters; cli for CLI rows |
origin |
The client origin (see TRUSTED_PROXIES); local for CLI rows |
operation |
One of the names below |
status |
The HTTP status of the response; NULL for CLI rows |
error |
The error message of the response for statuses from 400; NULL otherwise |
zone, record_id, target_user_id |
The objects the operation addressed, when any |
before_value, after_value |
For successful changes, the affected objects as JSON before and after the change; NULL for reads and for requests that changed nothing |
before_value and after_value hold records as id, zone, name, ttl, record_type, content; users as id, username, role, created_at, deleted_at; delegations as zone, username. Changes of several objects store arrays of the changed objects only. Passwords, password hashes, session tokens, cookies, request bodies and import file contents are never stored.
Operations
| Kind | Operations |
|---|---|
| Reads | account_read, zone_list, zone_read, record_list, zone_check, check_all, zone_export, zone_import_preview, delegation_list, user_list, user_read, audit_read, api_unknown |
| Changes | login, logout, password_change, zone_create, zone_delete, record_create, record_update, record_delete, record_bulk_delete, soa_update, zone_import, delegation_grant, delegation_revoke, user_create, user_role, user_password, user_delete |
Each API route is exactly one operation. CLI rows use user_create, user_password, user_role and user_delete. Login attempts and logouts count as changes for the kind filter.
Writing and reading
- A successful change and its audit row are written in the same transaction. When the audit insert fails, the change is rolled back and the request answers
500. - For every other operation the audit row is inserted before the response is written. When the insert fails, the response is replaced by
500and no data is returned, so no read happens without its audit row. When the audit row of a500cannot be written either, the failure is only logged atERROR. - Admins see every row. Users see the rows whose zone is currently delegated to them and the rows they performed themselves. Reading the audit through the API is itself an operation (
audit_read). - The audit page (
/audit) lists rows newest first with filters by zone, actor, operation, kind (reads or changes) and outcome (success or error), and expands a row to a field-level diff.GET /api/v1/audittakes the same filters plusbefore_idandlimit(1 to 200, default 50). TheauditCLI command prints the latest rows, oldest first.
Logging
Logs go to stderr through log/slog (text handler) at the level of LOG_LEVEL: ERROR, WARN, INFO, DEBUG and TRACE below DEBUG.
INFO: startup with version and commit, one record per request (method, path, status, duration, user, role, origin;/healthand/static/log atDEBUG) and one record per committed change.WARN: failed and rate-limited logins,403refusals, zone routes answered404because the zone is not delegated, ETag and fingerprint conflicts, zone lock timeouts.ERROR: database errors, failed audit inserts, unexpected errors behind every500.DEBUG: configuration (without secrets), contract check, migrations, lock acquisition, CLI dispatch, session cleanup counts, shutdown.TRACE: function entry and exit and every SQL statement.
Passwords, password hashes, session tokens, cookies and the DSN never appear in logs at any level.
Container image
The image is built in stages: golang:1.27-alpine compiles a static binary with CGO_ENABLED=0, and the final stage is FROM scratch with /app, the CA bundle at /etc/ssl/cert.pem (for DB_TLS) and no shell, package manager or other runtime tool. It runs as 65532:65532, exposes 8080, carries the OCI labels source, revision, version and licenses, and defines HEALTHCHECK CMD ["/app", "healthcheck"] with ENTRYPOINT ["/app"].
The dockerfile also holds a test stage (see Build and test) and an integration stage used by scripts/integration.sh.
Development stack
compose.yaml runs the development stack bound to 127.0.0.1:
| Service | Image | Published |
|---|---|---|
mysql |
${MYSQL_IMAGE} (default mysql:8.4), initialized by dev/mysql-init.sql |
127.0.0.1:13306 |
coredns |
${COREDNS_IMAGE} (default git.bjphoster.com/docker/coredns-mysql:latest) with dev/Corefile |
127.0.0.1:10053 (UDP and TCP) |
app |
built from the working tree | 127.0.0.1:8080 |
dev/mysql-init.sql creates the coredns database, the records table as the plugin documents it, the read-only CoreDNS user (coredns) and the application user (coredns_webui) with the grants above. dev/Corefile enables the mysql plugin with the DSN from COREDNS_MYSQL_DSN, table_prefix coredns_ and zone_update_interval 10s.
./initialize.sh # copies vars.example to .vars and env.example to .env when missing
make run # docker compose --file compose.yaml up --build
Create the first admin, log in at http://127.0.0.1:8080, create a zone and, after the plugin's next zone reload (10 seconds in this stack), query it:
printf '%s\n' 'a-long-dev-password' | docker compose exec -T app /app user add admin admin
dig @127.0.0.1 -p 10053 example.org SOA
env.example lists every variable of Configuration with development values (DB_HOST=127.0.0.1 and DB_PORT=13306 address the stack's published MySQL port from the host, LOG_LEVEL=DEBUG, COOKIE_SECURE=false) plus MYSQL_ROOT_PASSWORD, which only compose uses. The compose file reads its variables from the same names with defaults, so it works without a .env file.
Build and test
The makefile reads its build variables from .vars (bootstrapped from vars.example on first use). Go and Node commands run only in containers; the host needs Docker and, for the compose-based targets, the Docker Compose plugin.
| Target | Action |
|---|---|
make / make version |
Runs ./version.sh: asks for a version, tags it in git, builds the image and optionally pushes it |
make build |
Static binary ./coredns-web-ui built in the builder image, with version and commit linked in |
make docker |
Builds the image ${CONTAINER_ORG}/${CONTAINER_IMAGE}:${APP_VERSION} with the build arguments and labels |
make dockerpush |
Pushes that image |
make test |
go test -count=1 ./... in the builder image |
make lint / make test-race |
docker build --target test: gofmt -l must be empty, go vet (also with -tags integration), staticcheck and go test -race -count=1 ./... |
make integration |
scripts/integration.sh: integration tests against a disposable MySQL container |
make test-image |
Builds the image and runs scripts/test-image.sh against it |
make test-e2e |
Builds the image and runs scripts/test-e2e.sh against it |
make run |
The development stack from compose.yaml |
make dockerrun |
Builds the image and runs it with --env-file .env on ${CONTAINER_IP}:${CONTAINER_PORT} |
make deploy |
Runs ./deploy.sh |
make clean |
Removes the local binary and this project's images |
APP_VERSION defaults to latest and can be set from the environment (APP_VERSION=1.0.0 make docker). COMMIT_ID is the short HEAD hash, or undefined outside a git repository. Both are linked into the binary, logged at startup, rendered on /version and set as image labels.
Without make, the same checks run as plain Docker commands, for example the unit tests:
docker run --rm -v "$PWD":/src -w /src -v coredns-web-ui-gomod:/go/pkg/mod -e GOFLAGS=-buildvcs=false golang:1.27-alpine go test -count=1 ./...
Integration tests
scripts/integration.sh builds the dockerfile's integration stage and runs the tests with the build tag integration against a disposable MySQL container (MYSQL_IMAGE, default mysql:8.4) on an internal Docker network with random credentials. Nothing is published on the host. It covers the records table contract, migrations (including two processes migrating at the same time), the least-privilege grants, the foreign keys, the stores and transactions, the zone lock and the races between role, delegation and user changes and writes. It needs only Docker. Containers, network, volume and image are named cdwu-it-<id> (IT_ID, default the shell's process id) and are removed at exit, also after failures.
Image tests
scripts/test-image.sh <image> <version> <commit> checks the OCI labels, the user 65532:65532, the entrypoint and healthcheck, that the image has no shell and holds only /app, the CA bundle and the files Docker itself adds, that version, help and usage errors behave as documented, that the container becomes healthy against a MySQL container initialized with dev/mysql-init.sql, that /health and /version answer, that the user CLI works through docker exec (user add with both roles, user passwd, user role, user delete leaving the row with deleted_at, user list all, the CLI audit rows), that no secret reaches the output or the logs, and that SIGTERM stops the container with exit 0 within the 25 second grace period. It needs Docker and the golang:1.27-alpine image (PROBE_IMAGE) for a probe with wget. Resources are named cdwu-img-<id> (IMG_ID) and are removed at exit.
End-to-end tests
scripts/test-e2e.sh <image> runs the Playwright suite in e2e/ inside a container built from the Playwright image pinned in vars.example (PLAYWRIGHT_IMAGE) with dnsutils and the Docker CLI added. It starts a compose stack from e2e/compose.yaml on an isolated internal network: MySQL (on tmpfs), CoreDNS from COREDNS_IMAGE with the mysql plugin, zone_update_interval 1s and no cache, and one instance of the application image under test per test group, each with its own database and users. Every change made through the UI is verified through the UI, through the rows in MySQL and through dig against CoreDNS. The suite has core, session, power user, stupid user, malicious user, fuzzer, long operator and accessibility (axe-core, both themes) groups.
Prerequisites: Docker with the Compose plugin, access to the Docker socket (the runner mounts E2E_DOCKER_SOCKET, default /var/run/docker.sock, to restart application containers), network access to pull the missing images and to build the runner (apt and npm ci), and about 2 GiB of memory for the MySQL tmpfs. The application image must already exist (make docker; make test-e2e builds it). Images the script had to pull are removed again at the end.
Optional environment variables: E2E_RUN_ID (lowercase letters, digits and hyphens; default random), E2E_SEED (reproduces a failing seed), E2E_WORKERS (default 4), E2E_FUZZ_CASES, E2E_FUZZ_RECORDS (fuzzed records per type, default 8), E2E_OPERATOR_ACTIONS and E2E_ARGS (extra playwright test arguments). Resources are named cdwu-e2e-<run id>, are removed at exit, and the script fails when a run leaves any behind. Reports, screenshots and failing seeds are copied to e2e/reports/cdwu-e2e-<run id>/.
Continuous integration
Gitea Actions:
.gitea/workflows/test.yamlruns on pushes tomain, every Monday and manually: theteststage, the integration tests, the image tests and the E2E suite..gitea/workflows/image.yamlruns on semantic version tags (1.2.3,v1.2.3, with an optional prerelease suffix): the same tests, then it builds the image with the tag as version and the commit as revision, publishesgit.bjphoster.com/source/coredns-web-ui:<version>and, for tags without a prerelease suffix,latest, and removes the local images. The repository needs the Actions variablesGIT_HOSTandREGISTRY_USERand the secretGIT_TOKENwith package write access.
Deployment
Production runs the published image git.bjphoster.com/source/coredns-web-ui:<version> from a compose project on the deployment host, behind an HTTPS reverse proxy, with COOKIE_SECURE=true (the default) and TRUSTED_PROXIES set to the proxy's network so that audit rows and the login rate limit see the real client origin. The application needs no volume. Database access is the grants above, and the container's HEALTHCHECK is /app healthcheck.
deploy.sh (make deploy) connects to DEPLOYMENT_HOST over SSH and, in the deployment path (DEPLOYMENT_PATHS, one or more space-separated paths; it asks which one when there are several), runs:
git pull && sed -i 's/VERSION=.*/VERSION=<version>/' .env && docker compose pull && docker compose up -d
The deployment directory therefore holds a compose.yaml that references the image through a VERSION variable and a .env with a VERSION= line. DEPLOYMENT_VERSION and DEPLOYMENT_PATH can be set in the environment to skip the prompts (the version defaults to latest).
License
GPL-2.0-or-later. See LICENSE.