fix: support utf8mb4 across MySQL and MariaDB
Test / test (push) Canceled after 6m35s
Build and publish image / image (push) Successful in 13m42s

This commit is contained in:
bryanpedini committed 2026-11-20 15:14:28 +01:00
1 parent cce17c5fa4
commit d34894c9cd
28 files changed
+224 -121

No files matched your search

+8 -6
View File
@@ -1,6 +1,6 @@
# 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.
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 or MariaDB 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.
@@ -32,7 +32,7 @@ CREATE TABLE `coredns_records` (
`content` TEXT,
`record_type` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4;
```
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:
@@ -100,7 +100,7 @@ Every write takes a MySQL named lock per zone (`<prefix>webui:<first 16 hex char
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
## Database 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):
@@ -143,7 +143,7 @@ Configuration comes only from environment variables. No configuration file is re
| Variable | Required | Default | Accepted values |
|---|---|---|---|
| `DB_HOST` | yes | none | Host name or IP address of MySQL |
| `DB_HOST` | yes | none | Host name or IP address of the database server |
| `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 |
@@ -161,7 +161,9 @@ Configuration comes only from environment variables. No configuration file is re
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.
The database connection is built with `mysql.Config` from `github.com/go-sql-driver/mysql` (`ParseTime`, UTC, charset `utf8mb4` via `SET NAMES`, 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.
Use a database with the `utf8mb4` character set and InnoDB. The database may use any `utf8mb4` collation. Usernames and delegation keys use exact matching, and zone names are normalized before DNS comparisons. Existing application tables keep their collations and data. On new databases the audit tables store JSON payloads as text; existing native JSON columns still work. CI tests MySQL 5.7, MySQL 8.4 and MariaDB 10.11.
`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.
@@ -417,7 +419,7 @@ docker run --rm -v "$PWD":/src -w /src -v coredns-web-ui-gomod:/go/pkg/mod -e GO
### 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.
`scripts/integration.sh` builds the dockerfile's `integration` stage and runs the tests with the build tag `integration` against a disposable MySQL or MariaDB 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. Run with `MYSQL_IMAGE=mysql:5.7` or `MYSQL_IMAGE=mariadb:10.11` to use the other databases in CI. 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