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

+12 -12
View File
@@ -83,7 +83,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;
```
The 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. At startup it verifies, through `information_schema.COLUMNS` of `DATABASE()`, that the table exists and has the six columns with compatible types; otherwise it exits with a clear error naming the missing table or column. It never creates or changes the table, its indexes or its collation.
@@ -149,7 +149,7 @@ Configuration comes from environment variables only. No configuration file is re
Validation happens before any other work. A missing required variable, an empty value, an invalid port, address, duration, boolean, CIDR, log level or TLS mode, or a table prefix not matching `^[A-Za-z0-9_]{0,32}$` produces a message naming the variable (never its value for `DB_PASSWORD`) and exit code `2`.
The connection is built with `mysql.Config` from `github.com/go-sql-driver/mysql`, never by string concatenation: `Net=tcp`, `ParseTime=true`, `Loc=UTC`, collation `utf8mb4_0900_ai_ci`, connect timeout 5 s, read and write timeouts 30 s, `MultiStatements=false`, `InterpolateParams=false`, TLS from `DB_TLS`. The pool uses the plugin's defaults: at most 10 open and 10 idle connections, connection lifetime 1 minute. The DSN and the password are never logged; logs carry host, port, user and database only.
The connection is built with `mysql.Config` from `github.com/go-sql-driver/mysql`, never by string concatenation: `Net=tcp`, `ParseTime=true`, `Loc=UTC`, charset `utf8mb4` via `SET NAMES`, connect timeout 5 s, read and write timeouts 30 s, `MultiStatements=false`, `InterpolateParams=false`, TLS from `DB_TLS`. The pool uses the plugin's defaults: at most 10 open and 10 idle connections, connection lifetime 1 minute. The DSN and the password are never logged; logs carry host, port, user and database only.
## 5. Process and command behavior
@@ -219,11 +219,11 @@ CREATE TABLE IF NOT EXISTS `coredns_webui_schema` (
`version` INT NOT NULL,
PRIMARY KEY (`id`),
CHECK (`id` = 1)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
CREATE TABLE `coredns_webui_users` (
`id` INT NOT NULL AUTO_INCREMENT,
`username` VARCHAR(64) NOT NULL,
`username` VARCHAR(64) COLLATE utf8mb4_bin NOT NULL,
`role` VARCHAR(8) NOT NULL,
`password_hash` VARCHAR(255) NOT NULL,
`created_at` DATETIME(6) NOT NULL,
@@ -233,7 +233,7 @@ CREATE TABLE `coredns_webui_users` (
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`),
CHECK (`role` IN ('admin', 'user'))
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
CREATE TABLE `coredns_webui_sessions` (
`token_hash` BINARY(32) NOT NULL,
@@ -247,10 +247,10 @@ CREATE TABLE `coredns_webui_sessions` (
KEY `user_id` (`user_id`),
KEY `expires_at` (`expires_at`),
FOREIGN KEY (`user_id`) REFERENCES `coredns_webui_users` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
CREATE TABLE `coredns_webui_zone_delegations` (
`zone` VARCHAR(255) NOT NULL,
`zone` VARCHAR(255) COLLATE utf8mb4_bin NOT NULL,
`user_id` INT NOT NULL,
`created_at` DATETIME(6) NOT NULL,
`created_by` INT NOT NULL,
@@ -258,7 +258,7 @@ CREATE TABLE `coredns_webui_zone_delegations` (
KEY `user_id` (`user_id`),
FOREIGN KEY (`user_id`) REFERENCES `coredns_webui_users` (`id`),
FOREIGN KEY (`created_by`) REFERENCES `coredns_webui_users` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
CREATE TABLE `coredns_webui_audit` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
@@ -272,8 +272,8 @@ CREATE TABLE `coredns_webui_audit` (
`zone` VARCHAR(255) NULL,
`record_id` BIGINT NULL,
`target_user_id` INT NULL,
`before_value` JSON NULL,
`after_value` JSON NULL,
`before_value` LONGTEXT NULL,
`after_value` LONGTEXT NULL,
PRIMARY KEY (`id`),
KEY `time` (`time`),
KEY `zone_time` (`zone`, `time`),
@@ -281,7 +281,7 @@ CREATE TABLE `coredns_webui_audit` (
KEY `operation_time` (`operation`, `time`),
FOREIGN KEY (`user_id`) REFERENCES `coredns_webui_users` (`id`),
FOREIGN KEY (`target_user_id`) REFERENCES `coredns_webui_users` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
```
All times are UTC. Rows of `<prefix>webui_users` are never deleted (section 8), so, as with the tokens referenced by the audit table of `dpsapi`, 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 holds the full ID range of an `INT UNSIGNED` records table.
@@ -351,7 +351,7 @@ Warnings:
### Concurrency
Every write runs on a dedicated connection: take the named lock `<prefix>webui:<first 16 hex chars of sha256(zone)>` with `GET_LOCK` (10 s timeout, HTTP 503 "zone busy" on timeout), begin the transaction, check again that the actor may operate on the zone (the user row and, for role `user`, the delegation row read with `FOR SHARE`, so a concurrent revocation, demotion or deletion waits for the write or wins before it), read the zone's rows, apply the rules, write records, SOA serial and audit row, commit, release the lock. The lock serializes writers of this application; other writers of the table are detected through ETags.
Every write runs on a dedicated connection: take the named lock `<prefix>webui:<first 16 hex chars of sha256(zone)>` with `GET_LOCK` (10 s timeout, HTTP 503 "zone busy" on timeout), begin the transaction, check again that the actor may operate on the zone (the user row and, for role `user`, the delegation row read with `LOCK IN SHARE MODE`, so a concurrent revocation, demotion or deletion waits for the write or wins before it), read the zone's rows, apply the rules, write records, SOA serial and audit row, commit, release the lock. The lock serializes writers of this application; other writers of the table are detected through ETags.
Every record carries an ETag: the hex SHA-256 of `id`, `zone`, `name`, `ttl`, `record_type` and the raw `content`, with explicit markers for `NULL`. Updates and deletes require `If-Match`; inside the transaction the row is read with `SELECT ... FOR UPDATE` and compared. A missing `If-Match` is HTTP 428, a mismatch or a missing row is HTTP 412 and the UI offers to reload.