diff --git a/README.md b/README.md
index 19dc906..fbc0179 100644
--- a/README.md
+++ b/README.md
@@ -267,6 +267,7 @@ process registers:
| `OpenWaf:Alerts:WebhookTimeoutSeconds` | `5` | how long one push may take. 1–60 whole seconds; anything else aborts startup naming the key, as the other startup-parsed bounds do — a 0-second timeout drops every push and a 600-second one parks a queue worker on an endpoint that is not answering, and neither is what the operator typed. |
| `OpenWaf:Alerts:MaxPushAttempts` (OPEN-60) | `6` | how many attempts one delivery gets before the edge stops asking. 1–20 whole attempts; anything else aborts startup naming the key. Against an endpoint that refuses, the default spends its last attempt a little over three minutes in (30 s, 60 s, 120 s, 240 s, 480 s — each step capped at 30 min) and then records the row as given up: `alertPushGivenUp` counts those rows and `alertPushLastError` says why in the sentence the row carries (`gave up after 6 attempts: the endpoint answered 500`). A row that has given up is never retried, and the alert row behind it is untouched — what is lost is the telling, not the record. |
| `OpenWaf:Alerts:PushRetrySeconds` | `30` | the base of the backoff between attempts: attempt *n* waits `base × 2^(n−1)`, capped at 30 minutes per step, because exponential growth from a 30-second base reaches a day in eight steps and a day is not a retry interval for a page meant to fire at 03:00. 1–3600 whole seconds, same startup refusal — a 0-second interval against a dead endpoint is a busy loop. |
+| `OpenWaf:Admin:ReadOnlyToken` (OPEN-62) | empty | a second token that can read every operator surface and change none of it. Unset means the level does not exist and the admin token is the only one there is. The level is decided by the request method — GET, HEAD and OPTIONS read, everything else writes — so a write endpoint added later is behind the rule without anyone remembering to mark it, and forgetting fails closed. `GET /admin-api/export` is the one read deliberately held to the admin token, because the document is a capability. A value equal to the admin token (compared after trimming, because env files add newlines) aborts startup naming both keys and never the secret, and it exits 1 rather than throwing: measured on the shipped image, an unhandled exception there printed the reason and then spun at 100% CPU with the container "Up (unhealthy)" forever, which is a failure no supervisor can see. |
Database: `Database:Provider` = `sqlite` (default) or `postgres`,
`ConnectionStrings__OpenWaf`. GeoIP: `GEOIP_MAXMIND_DB_PATH`.
@@ -907,6 +908,47 @@ What the transfer does **not** do is the part worth reading:
After an import the guard enforces it on the next request — the snapshot is
invalidated, as it is for every other mutation.
+### A second token that can look but not change
+
+There is one admin secret, and until now it meant one thing: whatever could read
+`/admin-api/state` could also delete every block and rewrite the policy. So a
+Prometheus scrape held a key that can lift a ban, a second operator checking
+"why was this visitor refused" held a key that can change what the edge enforces,
+and `GET /admin-api/export` put a whole edge's config behind the same single
+request.
+
+```bash
+OPENWAF_READ_ONLY_TOKEN=dashboard-key docker compose up -d
+curl -H "X-Admin-Token: $DASHBOARD_KEY" http://edge:8080/admin-api/state # 200
+curl -X POST -H "X-Admin-Token: $DASHBOARD_KEY" \
+ -H 'Content-Type: application/json' -d '{"ip":"203.0.113.9"}' \
+ http://edge:8080/admin-api/blocks # 403
+```
+
+The rulings, in the order they matter:
+
+* **403, not 401.** A known token without the right is a different sentence from
+ an unknown one, and collapsing them sends an operator debugging a failing script
+ to check the secret when what is wrong is the endpoint it was sent to. The body
+ names the key that would grant the write.
+* **The line is drawn by the method, not by a flag per endpoint.** GET, HEAD and
+ OPTIONS are reads; everything else is a write. A write endpoint added tomorrow
+ is behind the rule the moment it is written. A per-endpoint flag would fail the
+ other way — one forgotten flag and the write is open.
+* **`GET /admin-api/export` needs the admin token.** It is a read, and it is still
+ the whole config: every block, exemption, path rule, country decision and the
+ policy that bounds them. The token meant for a dashboard and a second pair of
+ eyes is exactly the one that must not be able to lift it, so this one read is
+ held to the admin token while every other read is not.
+* **A read-only token sees exactly what the admin token sees.** Read-only is about
+ what a token may do, not about showing a weaker view; two people comparing
+ answers must not get different answers because of who asked.
+* **A read-only token equal to the admin token aborts startup.** A security
+ promise that is false is worse than no promise, and the refusal names both keys
+ without ever printing the secret. `/admin-api/state` answers
+ `readOnlyTokenConfigured`, so an operator can check from outside that the key
+ they wrote took effect instead of guessing from a 401.
+
## Console
`GET /admin` serves a single page over those endpoints — mode and snapshot age,
@@ -1090,9 +1132,9 @@ Rehearsed 2026-10-02, most recently at `dc88f36`, each stage run on its own.
On the head of this file the host suite has been re-run and the container stages
have not, so the two sets of numbers are labelled separately rather than merged
into one green line. macOS host, this tree, re-measured 2026-10-05 with the durable
-alert-push queue and the config transfer on it: build 0 warnings / 0 errors, unit **285/285**,
-integration **257/257 in 20 s**, console **90 assertions, 0 failed**, smoke **passed 82,
-failed 0**, and compose **243 passed, 0 failed** against the built image at
+alert-push queue, the config transfer and the second token on it: build 0 warnings / 0 errors,
+unit **307/307**, integration **286/286 in 26 s**, console **90 assertions, 0 failed**, smoke
+**passed 105, failed 0**, and compose **261 passed, 0 failed** against the built image at
262 MB, 0 containers left behind. The smoke count moved by more than its new scene: the edge was being
started from the repository root, where there is no `appsettings.json`, so it
loaded no `ReverseProxy` section, logged "Request reached the end of the
@@ -1287,7 +1329,9 @@ Stated, because a defence that hides its failure modes is not a defence.
it does not restore what an edge knows, and it is only as secret as the admin
token that reads it. Import is additive for the same reason: a document that
could delete rows the operator never wrote would make a leak of the file worse
- than a leak of the file already is.
+ than a leak of the file already is. It is also why the read-only token (OPEN-62)
+ is refused on `/export` with a 403: the one surface where "can read" and "can
+ take" are the same act is held to the admin token.
* **The push queue is durable; the delivery is still not guaranteed.** What is owed
is a row in `alert_pushes`, so a restart picks it up and two edges over one
database claim a row before sending it — but the bound is attempts, not time.
diff --git a/docker-compose.yml b/docker-compose.yml
index d293f80..b18fcb1 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -23,6 +23,10 @@ services:
- "${EDGE_PORT:-8080}:8080"
environment:
OPENWAF_ADMIN_TOKEN: ${OPENWAF_ADMIN_TOKEN:?set OPENWAF_ADMIN_TOKEN before starting}
+ # The second token (OPEN-62): it can read every operator surface and
+ # change none of them. Empty means unset, which is the shipped default —
+ # the level only exists when an operator gives it its own value.
+ OPENWAF_READ_ONLY_TOKEN: ${OPENWAF_READ_ONLY_TOKEN:-}
OpenWaf__Policy__Mode: Enforce
OpenWaf__Policy__StreakThreshold: "10"
OpenWaf__Policy__StreakWindow: "00:05:00"
diff --git a/dotnet/OpenWaf.Domain/Security/AdminTokenPolicy.cs b/dotnet/OpenWaf.Domain/Security/AdminTokenPolicy.cs
new file mode 100644
index 0000000..e4aa3d3
--- /dev/null
+++ b/dotnet/OpenWaf.Domain/Security/AdminTokenPolicy.cs
@@ -0,0 +1,125 @@
+namespace OpenWaf.Domain.Security;
+
+// ---------------------------------------------------------------------------
+// Two tokens, two levels of power (OPEN-62).
+//
+// There used to be one admin secret, and it was all-or-nothing: whatever could
+// read /admin-api/state could also delete every block and rewrite the policy.
+// The operator's real question is never "does this thing know the secret" but
+// "what is this thing allowed to do" — a Prometheus scrape and a human
+// checking why a customer was refused should not hold a key that can clear the
+// block list.
+//
+// The level is decided by the request method, not by a flag on each endpoint,
+// and that is a ruling rather than a shortcut: a new write endpoint is
+// protected the moment it is written, while a per-endpoint flag would fail the
+// other way — forget it once and the write is open to a read-only token.
+//
+// The functions here are pure and the comparison is constant-time, so the one
+// place a secret is compared stays in one place. AdminAuth used to own that
+// comparison; it now asks this type, because a second copy of a secret check is
+// how one of the two ends up stale.
+// ---------------------------------------------------------------------------
+
+/// What a presented token may do. means the token is
+/// not one this edge knows — the answer to that is 401, and it must stay
+/// distinguishable from , which is a known token that
+/// simply lacks the right (403).
+public enum AdminTokenLevel { None, ReadOnly, Full }
+
+public static class AdminTokenPolicy
+{
+ /// The key that grants everything, as the operator has to type it.
+ public const string FullKey = "OpenWaf__Admin__Token";
+
+ /// The key that grants reading only.
+ public const string ReadOnlyKey = "OpenWaf__Admin__ReadOnlyToken";
+
+ /// What a read-only token is told when it reaches a write surface.
+ /// It names the key that would grant the write, because the operator
+ /// debugging a failing script is the audience for this sentence.
+ public const string ReadOnlyRefusal =
+ "this token is read-only: it can read the operator surfaces but not change them; " +
+ $"the write surfaces need {FullKey}";
+
+ /// A blank or whitespace token is not a configured token. The
+ /// configuration system distinguishes "" from unset and the edge has
+ /// learned the hard way that treating them differently here would be a
+ /// surprise, so both mean "this level does not exist".
+ public static bool IsConfigured(string? token) => !string.IsNullOrWhiteSpace(token);
+
+ ///
+ /// A configuration that cannot mean what it says, named before the edge
+ /// starts serving. Two cases, and both are refusals rather than warnings:
+ ///
+ /// * a read-only token equal to the admin token makes the read-only claim
+ /// false — every "look but do not change" promise would be a promise
+ /// about a token that can change everything, which is worse than having
+ /// no such promise at all;
+ /// * a read-only token with no admin token configures a level on a surface
+ /// that is closed: the admin token is what opens the surface, so the
+ /// operator would be handed a 404 and no explanation.
+ ///
+ /// The equality test trims. A token read out of a file or an env pair often
+ /// carries a trailing newline, and "different by a newline" is exactly the
+ /// difference a security check must not be relying on. Authentication
+ /// itself compares the bytes as configured — this trim is only for deciding
+ /// that the two keys were meant to be different secrets.
+ ///
+ /// The problem, or null when the pair is usable.
+ public static string? ExplainConfigurationProblem(string? fullToken, string? readOnlyToken)
+ {
+ if (!IsConfigured(readOnlyToken)) return null;
+
+ if (!IsConfigured(fullToken))
+ return $"{ReadOnlyKey} is set while {FullKey} is not: the admin token is what opens " +
+ "the operator surfaces, so a read-only token on its own would only ever be answered 404. " +
+ "Set an admin token, or remove the read-only one.";
+
+ if (string.Equals(fullToken!.Trim(), readOnlyToken!.Trim(), StringComparison.Ordinal))
+ return $"{ReadOnlyKey} is the same value as {FullKey}: a read-only token that is also the " +
+ "admin token can change everything, so the read-only claim would be false. " +
+ "Give the read-only token its own value.";
+
+ return null;
+ }
+
+ /// Which level a presented token has. Compared against at most the
+ /// two configured tokens — there is no token list and no lookup table, so
+ /// the number of comparisons a request costs is fixed at two.
+ public static AdminTokenLevel LevelOf(string? provided, string? fullToken, string? readOnlyToken)
+ {
+ if (string.IsNullOrWhiteSpace(provided)) return AdminTokenLevel.None;
+
+ // Full is checked first on purpose. The startup refusal above makes
+ // "both tokens are the same value" unstartable; if a process is still
+ // configured that way by some path this build did not predict, the
+ // honest answer is the level the value actually has, not a downgrade of
+ // a token that can in fact write.
+ if (Matches(provided, fullToken)) return AdminTokenLevel.Full;
+ if (Matches(provided, readOnlyToken)) return AdminTokenLevel.ReadOnly;
+ return AdminTokenLevel.None;
+ }
+
+ /// Is this method a read? GET, HEAD and OPTIONS ask for a
+ /// representation and change nothing, so both tokens may do them. Everything
+ /// else — POST, PUT, PATCH, DELETE — is a write and needs the admin token.
+ /// Unknown methods count as writes: failing closed is the whole point of
+ /// deciding by method.
+ public static bool IsRead(string? httpMethod)
+ => httpMethod is not null
+ && (string.Equals(httpMethod, "GET", StringComparison.OrdinalIgnoreCase)
+ || string.Equals(httpMethod, "HEAD", StringComparison.OrdinalIgnoreCase)
+ || string.Equals(httpMethod, "OPTIONS", StringComparison.OrdinalIgnoreCase));
+
+ /// Constant-time on purpose: the comparison is against a secret,
+ /// and a comparison that returns early on the first wrong byte tells an
+ /// attacker how far their guess got.
+ private static bool Matches(string provided, string? configured)
+ {
+ if (!IsConfigured(configured)) return false;
+ return System.Security.Cryptography.CryptographicOperations.FixedTimeEquals(
+ System.Text.Encoding.UTF8.GetBytes(provided),
+ System.Text.Encoding.UTF8.GetBytes(configured!));
+ }
+}
diff --git a/dotnet/OpenWaf.Edge/Admin/AdminAuth.cs b/dotnet/OpenWaf.Edge/Admin/AdminAuth.cs
index 46d3d10..068e570 100644
--- a/dotnet/OpenWaf.Edge/Admin/AdminAuth.cs
+++ b/dotnet/OpenWaf.Edge/Admin/AdminAuth.cs
@@ -1,9 +1,11 @@
using Microsoft.AspNetCore.Http;
+using OpenWaf.Domain.Security;
namespace OpenWaf.Edge.Admin;
///
-/// The one token check the operator's surfaces share (OPEN-58).
+/// The one token check the operator's surfaces share (OPEN-58), now with two
+/// levels of power (OPEN-62).
///
/// It used to live inline on the admin API group. It is a type now because the
/// metrics endpoint needs the same rule and a second copy of an auth check is
@@ -11,10 +13,18 @@ namespace OpenWaf.Edge.Admin;
/// admin surface was already carrying a decision about the query string that a
/// second implementation would not have known about.
///
-/// The rule itself is unchanged and the reasoning is unchanged — no token
-/// configured means the surface is closed rather than open without auth, and
-/// the query string is accepted but named out loud, because a URL is the part
-/// of a request that access logs, proxies and browser histories keep.
+/// What is new is that knowing a token is no longer one answer. The admin token
+/// reads and writes; the read-only token reads. Which of the two a request
+/// needs is decided by the method — see —
+/// so a write endpoint added tomorrow is behind this rule without anyone
+/// remembering to mark it. The secret comparison itself moved to
+/// so there is exactly one place in the build
+/// where a token is compared to a configured token.
+///
+/// Unchanged: no token configured means the surface is closed rather than open
+/// without auth, and the query string is accepted but named out loud, because a
+/// URL is the part of a request that access logs, proxies and browser histories
+/// keep.
///
internal static class AdminAuth
{
@@ -22,16 +32,21 @@ internal static class AdminAuth
/// tolerated, not recommended, and the warning says so.
public const string Header = "X-Admin-Token";
+ /// Where the level decided for this request is parked, so an
+ /// endpoint-level filter can ask what the group filter already settled
+ /// without comparing the secret a second time.
+ private const string LevelItem = "openwaf:admin-token-level";
+
/// The shape AddEndpointFilter takes. Named as a Func rather
/// than as EndpointFilterDelegate because that delegate type is the
/// inner link of the chain, not the thing the registration accepts — the
/// two have different arities, and the compiler only figures that out for a
/// lambda written inline at the call site.
public static Func> Require(
- string? adminToken, string disabledMessage)
+ string? adminToken, string? readOnlyToken, string disabledMessage)
=> async (filterCtx, next) =>
{
- if (string.IsNullOrWhiteSpace(adminToken))
+ if (!AdminTokenPolicy.IsConfigured(adminToken))
return Results.NotFound(new { error = disabledMessage });
var req = filterCtx.HttpContext.Request;
@@ -43,7 +58,8 @@ internal static class AdminAuth
viaQuery = !string.IsNullOrWhiteSpace(provided);
}
- if (!FixedTimeEquals(provided, adminToken)) return Results.Unauthorized();
+ var level = AdminTokenPolicy.LevelOf(provided, adminToken, readOnlyToken);
+ if (level == AdminTokenLevel.None) return Results.Unauthorized();
// The query string is accepted for one reason: an operator typing
// curl at a keyboard does it without thinking, and refusing them is
@@ -58,7 +74,9 @@ internal static class AdminAuth
// the token at the shipped level and 2 at Information ("Request
// starting" and "Request finished"), and a header request leaves 0
// at either. So the request is served and the moment it happens is
- // named, without ever repeating the secret.
+ // named, without ever repeating the secret. It applies to the
+ // read-only token exactly as it applies to the admin one: a weaker
+ // token is still a token.
if (viaQuery)
{
filterCtx.HttpContext.RequestServices
@@ -71,16 +89,36 @@ internal static class AdminAuth
req.Path.Value);
}
+ filterCtx.HttpContext.Items[LevelItem] = level;
+
+ // A known token that lacks the right is a different answer from an
+ // unknown one, and the difference is the whole point of the feature:
+ // 401 would tell an operator debugging a script that the token is
+ // wrong, when what is wrong is the endpoint it was sent to.
+ if (level == AdminTokenLevel.ReadOnly && !AdminTokenPolicy.IsRead(req.Method))
+ return Results.Json(
+ new { error = AdminTokenPolicy.ReadOnlyRefusal, tokenLevel = "read-only" },
+ statusCode: StatusCodes.Status403Forbidden);
+
return await next(filterCtx);
};
- /// Constant-time on purpose: the comparison is against a secret,
- /// and a comparison that returns early on the first wrong byte tells an
- /// attacker how far their guess got.
- private static bool FixedTimeEquals(string a, string b)
- {
- if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(b)) return false;
- return System.Security.Cryptography.CryptographicOperations.FixedTimeEquals(
- System.Text.Encoding.UTF8.GetBytes(a), System.Text.Encoding.UTF8.GetBytes(b));
- }
+ ///
+ /// A surface that reads but is not for a read-only token.
+ ///
+ /// There is exactly one: GET /admin-api/export. The exported document
+ /// is the edge's whole operator config — every block, exemption, rule and
+ /// policy override — and OPEN-61 itself files it under "a capability, not a
+ /// backup". The token meant for a dashboard and for a second pair of eyes is
+ /// precisely the one that must not be able to lift it, so this read is
+ /// deliberately held to the admin token while every other read is not.
+ ///
+ public static Func> RequireFull(
+ string refusal)
+ => (filterCtx, next) =>
+ filterCtx.HttpContext.Items[LevelItem] is AdminTokenLevel.ReadOnly
+ ? new ValueTask