a second token can read the operator's surfaces and change none of them
One admin secret meant one thing: whatever could read /admin-api/state could also delete every block and rewrite the policy. A Prometheus scrape therefore held a key that can lift a ban, a second operator checking why a visitor was refused held a key that can change what the edge enforces, and OPEN-61's export put a whole edge's config behind the same single GET. The operator's question was never "does this thing know the secret" but "what is it allowed to do", and the shipped answer could only be all or nothing. OpenWaf:Admin:ReadOnlyToken (env OPENWAF_READ_ONLY_TOKEN) is the second level. Unset is the default and the whole of the previous behaviour. The rulings: * A known token without the right is answered 403, not 401, and the body names the key that would grant the write. Collapsing the two sentences sends someone debugging a failing script to check the secret when what is wrong is the endpoint it was sent to. * The line is drawn by the request method, not by a flag per endpoint: GET/HEAD/OPTIONS read, everything else writes. A write endpoint added tomorrow is behind the rule the moment it is written; a per-endpoint flag would fail the other way, and one forgotten flag would open the write. * GET /admin-api/export is the one read held to the admin token. It is a read and it is still the whole config, so it is the surface where "can read" and "can take" are the same act - and the dashboard token is exactly the one that must not be able to lift a fleet's config. * A read-only token sees byte-identical answers to the admin token. Read-only is about what a token may do, not about 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 (compared after trimming, because env files add newlines) aborts startup naming both keys and never the secret. /admin-api/state answers readOnlyTokenConfigured, so the operator can check the key took effect instead of guessing from a 401. What the run caught, in order: (1) A real defect, and the interesting one. On the shipped image the startup refusal printed its reason and then the process sat at 100% CPU inside the runtime's crash path - the container stayed "Up (unhealthy)" forever, no exit code, nothing for a supervisor to react to. Refusing to start is only useful if the process leaves, so the refusal now writes the reason to stderr and returns 1; measured again on the image, it exits in 2 s with code 1 and the same sentence. (2) The gate's own assertion for that case had the same blind spot as the bug: waiting on a foreground docker compose run cannot tell "refused" from "hung", so the container is now started detached and polled for an exit within 30 s, and the assertion is that it left. (3) Two smoke asserts were wrong rather than the product: the blocks listing field is sourceKey, not ip, so the first version read an empty answer, and a two-code assertion compared a newline-separated pair against a space-separated literal. (4) An integration assert compared JsonElement.ToString() against "true" - a bool element prints True, so it now reads GetBoolean(). Gates on this tree: build 0 warnings / 0 errors, unit 307/307, integration 286/286 in 26s, smoke 105 passed / 0 failed (23 new), image 262 MB, compose-smoke 261 passed / 0 failed with 0 containers left behind (18 new, against the shipped image), console 90 assertions / 0 failed. Refs OPEN-62.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// <summary>What a presented token may do. <see cref="None"/> means the token is
|
||||
/// not one this edge knows — the answer to that is 401, and it must stay
|
||||
/// distinguishable from <see cref="ReadOnly"/>, which is a known token that
|
||||
/// simply lacks the right (403).</summary>
|
||||
public enum AdminTokenLevel { None, ReadOnly, Full }
|
||||
|
||||
public static class AdminTokenPolicy
|
||||
{
|
||||
/// <summary>The key that grants everything, as the operator has to type it.</summary>
|
||||
public const string FullKey = "OpenWaf__Admin__Token";
|
||||
|
||||
/// <summary>The key that grants reading only.</summary>
|
||||
public const string ReadOnlyKey = "OpenWaf__Admin__ReadOnlyToken";
|
||||
|
||||
/// <summary>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.</summary>
|
||||
public const string ReadOnlyRefusal =
|
||||
"this token is read-only: it can read the operator surfaces but not change them; " +
|
||||
$"the write surfaces need {FullKey}";
|
||||
|
||||
/// <summary>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".</summary>
|
||||
public static bool IsConfigured(string? token) => !string.IsNullOrWhiteSpace(token);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <returns>The problem, or null when the pair is usable.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>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.</summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>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.</summary>
|
||||
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));
|
||||
|
||||
/// <summary>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.</summary>
|
||||
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!));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using OpenWaf.Domain.Security;
|
||||
|
||||
namespace OpenWaf.Edge.Admin;
|
||||
|
||||
/// <summary>
|
||||
/// 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 <see cref="AdminTokenPolicy.IsRead"/> —
|
||||
/// so a write endpoint added tomorrow is behind this rule without anyone
|
||||
/// remembering to mark it. The secret comparison itself moved to
|
||||
/// <see cref="AdminTokenPolicy"/> 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.
|
||||
/// </summary>
|
||||
internal static class AdminAuth
|
||||
{
|
||||
@@ -22,16 +32,21 @@ internal static class AdminAuth
|
||||
/// tolerated, not recommended, and the warning says so.</summary>
|
||||
public const string Header = "X-Admin-Token";
|
||||
|
||||
/// <summary>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.</summary>
|
||||
private const string LevelItem = "openwaf:admin-token-level";
|
||||
|
||||
/// <summary>The shape <c>AddEndpointFilter</c> takes. Named as a Func rather
|
||||
/// than as <c>EndpointFilterDelegate</c> 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.</summary>
|
||||
public static Func<EndpointFilterInvocationContext, EndpointFilterDelegate, ValueTask<object?>> 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);
|
||||
};
|
||||
|
||||
/// <summary>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.</summary>
|
||||
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));
|
||||
}
|
||||
/// <summary>
|
||||
/// A surface that reads but is not for a read-only token.
|
||||
///
|
||||
/// There is exactly one: <c>GET /admin-api/export</c>. 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.
|
||||
/// </summary>
|
||||
public static Func<EndpointFilterInvocationContext, EndpointFilterDelegate, ValueTask<object?>> RequireFull(
|
||||
string refusal)
|
||||
=> (filterCtx, next) =>
|
||||
filterCtx.HttpContext.Items[LevelItem] is AdminTokenLevel.ReadOnly
|
||||
? new ValueTask<object?>(Results.Json(
|
||||
new { error = refusal, tokenLevel = "read-only" },
|
||||
statusCode: StatusCodes.Status403Forbidden))
|
||||
: next(filterCtx);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,14 @@ internal static partial class AdminEndpoints
|
||||
{
|
||||
private static void MapConfigTransfer(RouteGroupBuilder group)
|
||||
{
|
||||
group.MapGet("/export", async (OpenWafDbContext db, EdgePolicyProvider policy,
|
||||
// The one read on this surface that a read-only token may not do (OPEN-62),
|
||||
// and the exception is deliberate rather than an oversight: the document
|
||||
// is every block, exemption, rule and policy override the edge holds -
|
||||
// the capability OPEN-61 files under "not a backup". The token meant for
|
||||
// a dashboard and a second pair of eyes is exactly the one that must not
|
||||
// be able to lift the whole config, so this GET is held to the admin
|
||||
// token while every other GET is not.
|
||||
var export = group.MapGet("/export", async (OpenWafDbContext db, EdgePolicyProvider policy,
|
||||
HttpContext ctx, CancellationToken ct) =>
|
||||
{
|
||||
if (!TryKnownQuery(ctx, out var unknown)) return Results.BadRequest(new { error = unknown });
|
||||
@@ -105,6 +112,11 @@ internal static partial class AdminEndpoints
|
||||
countries = countryRows.Select(c => new ExportedCountry(c.Code, c.IsAllowed))
|
||||
});
|
||||
});
|
||||
export.AddEndpointFilter(AdminAuth.RequireFull(
|
||||
"the exported document is the whole operator config of this edge - every block, "
|
||||
+ "exemption, path rule, country rule and policy override - so it is a capability "
|
||||
+ "and not a view: it needs the admin token (OpenWaf__Admin__Token), not the "
|
||||
+ "read-only one"));
|
||||
|
||||
group.MapPost("/import", async (OpenWafDbContext db, EdgeStateStore state, EdgePolicyProvider policy,
|
||||
IStreakTracker streaks, RateTracker rates, BlockStore blocks, HttpContext ctx, CancellationToken ct) =>
|
||||
|
||||
@@ -19,14 +19,22 @@ namespace OpenWaf.Edge.Admin;
|
||||
/// </summary>
|
||||
internal static partial class AdminEndpoints
|
||||
{
|
||||
public static IEndpointRouteBuilder MapAdminApi(this IEndpointRouteBuilder app, string? adminToken)
|
||||
/// <param name="adminToken">The token that reads and writes. Nothing opens
|
||||
/// this surface without it.</param>
|
||||
/// <param name="readOnlyToken">The optional second token (OPEN-62): reads
|
||||
/// yes, writes no. Null or blank means the level does not exist and every
|
||||
/// request behaves exactly as it did before it was added.</param>
|
||||
public static IEndpointRouteBuilder MapAdminApi(this IEndpointRouteBuilder app, string? adminToken,
|
||||
string? readOnlyToken)
|
||||
{
|
||||
var group = app.MapGroup("/admin-api");
|
||||
|
||||
// The same check the metrics endpoint uses. One implementation, so the
|
||||
// query-string rule cannot drift between the two surfaces.
|
||||
// query-string rule cannot drift between the two surfaces - and since
|
||||
// OPEN-62, one implementation for the read-only level too, which is why
|
||||
// the level is decided here at the group rather than per endpoint.
|
||||
group.AddEndpointFilter(AdminAuth.Require(
|
||||
adminToken, "admin api disabled: set OpenWaf__Admin__Token"));
|
||||
adminToken, readOnlyToken, "admin api disabled: set OpenWaf__Admin__Token"));
|
||||
|
||||
group.MapGet("/blocks", async (string? source, bool? live, int? limit, int? offset, BlockStore store, HttpContext ctx, CancellationToken ct) =>
|
||||
{
|
||||
@@ -680,6 +688,10 @@ note = t.Note
|
||||
var allowExpired = state.Current.AllowEntries.Count - allowLive;
|
||||
return Results.Ok(new
|
||||
{
|
||||
// Whether this process has a second, read-only token at all
|
||||
// (OPEN-62). It is here because the alternative is an operator
|
||||
// guessing from a 401 whether the key they just wrote took effect.
|
||||
readOnlyTokenConfigured = AdminTokenPolicy.IsConfigured(readOnlyToken),
|
||||
snapshotAgeSeconds = Math.Round((DateTimeOffset.UtcNow - state.Current.GeneratedAt).TotalSeconds, 1),
|
||||
// The age without the TTL it is measured against is half a number. On
|
||||
// a single edge the TTL is invisible; behind a load balancer it *is*
|
||||
|
||||
@@ -44,7 +44,13 @@ namespace OpenWaf.Edge.Admin;
|
||||
/// </summary>
|
||||
internal static class MetricsEndpoint
|
||||
{
|
||||
public static IEndpointRouteBuilder MapMetrics(this IEndpointRouteBuilder app, string? adminToken)
|
||||
/// <param name="adminToken">The token that reads and writes.</param>
|
||||
/// <param name="readOnlyToken">The read-only token (OPEN-62). It is allowed
|
||||
/// here: /metrics is a read, and a scrape is the clearest case of a thing
|
||||
/// that has to be able to look and must not be able to change anything.
|
||||
/// It sits on an always-pass prefix for the same reason the numbers do.</param>
|
||||
public static IEndpointRouteBuilder MapMetrics(this IEndpointRouteBuilder app, string? adminToken,
|
||||
string? readOnlyToken)
|
||||
{
|
||||
var endpoint = app.MapGet("/metrics", (
|
||||
EdgeStateStore state,
|
||||
@@ -271,7 +277,7 @@ internal static class MetricsEndpoint
|
||||
});
|
||||
|
||||
endpoint.AddEndpointFilter(AdminAuth.Require(
|
||||
adminToken, "metrics disabled: set OpenWaf__Admin__Token"));
|
||||
adminToken, readOnlyToken, "metrics disabled: set OpenWaf__Admin__Token"));
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using OpenWaf.Domain.Engine;
|
||||
using OpenWaf.Domain.Security;
|
||||
using OpenWaf.Edge.Admin;
|
||||
using OpenWaf.Edge.Configuration;
|
||||
using OpenWaf.Edge.Health;
|
||||
@@ -240,11 +241,39 @@ app.MapGet("/readyz", async (OpenWafDbContext db, EdgeStateStore state, EdgePoli
|
||||
|
||||
var adminToken = builder.Configuration["OpenWaf:Admin:Token"];
|
||||
if (string.IsNullOrWhiteSpace(adminToken)) adminToken = Environment.GetEnvironmentVariable("OPENWAF_ADMIN_TOKEN");
|
||||
app.MapAdminApi(adminToken);
|
||||
|
||||
// The second token, for a thing that has to be able to look and must not be
|
||||
// able to change (OPEN-62): a Prometheus scrape, a dashboard, a second operator
|
||||
// checking why a visitor was refused. Unset is the default and the whole of
|
||||
// today's behaviour.
|
||||
var readOnlyToken = builder.Configuration["OpenWaf:Admin:ReadOnlyToken"];
|
||||
if (string.IsNullOrWhiteSpace(readOnlyToken))
|
||||
readOnlyToken = Environment.GetEnvironmentVariable("OPENWAF_READ_ONLY_TOKEN");
|
||||
|
||||
// Refused at startup rather than logged, for the same reason the TTL and the
|
||||
// retention windows are: a read-only token that is also the admin token is a
|
||||
// security promise that is false, and a process that serves traffic on a false
|
||||
// promise is worse than one that will not start. The message names the two keys
|
||||
// and never the secret, because this line is written into whatever the operator
|
||||
// pipes startup output to.
|
||||
if (AdminTokenPolicy.ExplainConfigurationProblem(adminToken, readOnlyToken) is { } tokenProblem)
|
||||
{
|
||||
// A clean exit, not a throw. Measured on the shipped image: an unhandled
|
||||
// exception here prints the reason and then the process sits at 100% CPU
|
||||
// inside the runtime's crash path instead of leaving - the container stays
|
||||
// "Up (unhealthy)" forever, so the supervisor sees no failure, restarts
|
||||
// nothing, and the operator has to notice a spinning process to learn the
|
||||
// edge never started. Refusing to start is only useful if the process
|
||||
// actually goes away and leaves a non-zero code behind.
|
||||
Console.Error.WriteLine(tokenProblem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
app.MapAdminApi(adminToken, readOnlyToken);
|
||||
// The operator's numbers, in the format their alerting reads (OPEN-58). Same
|
||||
// token as the admin API, and on an always-pass prefix like /healthz — an edge
|
||||
// tokens as the admin API, and on an always-pass prefix like /healthz — an edge
|
||||
// that has blocked the operator's own address still has to be watchable.
|
||||
app.MapMetrics(adminToken);
|
||||
app.MapMetrics(adminToken, readOnlyToken);
|
||||
app.MapAdminConsole();
|
||||
|
||||
if (!app.Environment.IsProduction())
|
||||
|
||||
@@ -26,6 +26,10 @@ internal sealed class EdgeFixture : IAsyncDisposable
|
||||
|
||||
public const string AdminToken = "test-admin-token";
|
||||
|
||||
/// <summary>The second token (OPEN-62): reads the operator surfaces, and
|
||||
/// is refused at every write. Passed only by the tests that are about it.</summary>
|
||||
public const string ReadOnlyToken = "test-read-only-token";
|
||||
|
||||
public EdgeFixture(
|
||||
string mode = "Enforce",
|
||||
int threshold = 3,
|
||||
@@ -36,6 +40,7 @@ internal sealed class EdgeFixture : IAsyncDisposable
|
||||
int? observationRetentionDays = null,
|
||||
int? banRetentionDays = null,
|
||||
string? adminToken = AdminToken,
|
||||
string? readOnlyToken = null,
|
||||
string? dbPath = null,
|
||||
bool sharedStreaks = false,
|
||||
string? alertWebhookPath = null,
|
||||
@@ -57,6 +62,9 @@ internal sealed class EdgeFixture : IAsyncDisposable
|
||||
// how the admin surface is switched off, and a test that asserts what
|
||||
// the page sees has to be able to ask for it.
|
||||
builder.UseSetting("OpenWaf:Admin:Token", adminToken ?? "");
|
||||
// The read-only token (OPEN-62). Empty means the level does not exist,
|
||||
// which is the shipped default and what every other fixture runs with.
|
||||
builder.UseSetting("OpenWaf:Admin:ReadOnlyToken", readOnlyToken ?? "");
|
||||
builder.UseSetting("OpenWaf:Policy:Mode", mode);
|
||||
builder.UseSetting("OpenWaf:Policy:StreakThreshold", threshold.ToString());
|
||||
builder.UseSetting("OpenWaf:Policy:StreakWindow", streakWindow);
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace OpenWaf.Tests.Integration;
|
||||
|
||||
/// <summary>
|
||||
/// A second token that can look but not change (OPEN-62).
|
||||
///
|
||||
/// One secret used to mean one thing: whatever could read the operator's
|
||||
/// surfaces could also clear the block list and rewrite the policy. The
|
||||
/// operator's actual question is not "does this thing know the secret" but
|
||||
/// "what is it allowed to do", and the shipped answer had to be all or nothing
|
||||
/// — so a Prometheus scrape held a key that can delete a ban, and OPEN-61's
|
||||
/// export document made that sharper by putting a whole edge's config behind the
|
||||
/// same single GET.
|
||||
///
|
||||
/// What these tests hold is the shape of the answer, not the 200s: a known
|
||||
/// token without the right is answered 403 and told which key would grant it,
|
||||
/// while an unknown token is answered 401. Collapse those two and an operator
|
||||
/// debugging a script is sent looking at the wrong thing. The read/write line is
|
||||
/// drawn by the request method, so the tests also ask whether a write is refused
|
||||
/// without anyone having marked it as one.
|
||||
/// </summary>
|
||||
public sealed class ReadOnlyTokenTests
|
||||
{
|
||||
/// <summary>The header the operator is asked to use. Spelled out rather
|
||||
/// than read from the edge's type: the surface is the contract, and a test
|
||||
/// that imports the implementation's name stops noticing when it moves.</summary>
|
||||
private const string Header = "X-Admin-Token";
|
||||
|
||||
private const string Written = "203.0.113.161";
|
||||
private const string Refused = "203.0.113.162";
|
||||
|
||||
private static async Task<HttpStatusCode> ReadAsync(EdgeFixture f, string path, string token)
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, path);
|
||||
request.Headers.TryAddWithoutValidation(Header, token);
|
||||
using var response = await f.Client.SendAsync(request);
|
||||
return response.StatusCode;
|
||||
}
|
||||
|
||||
private static async Task<string> ReadBodyAsync(EdgeFixture f, string path, string token)
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, path);
|
||||
request.Headers.TryAddWithoutValidation(Header, token);
|
||||
using var response = await f.Client.SendAsync(request);
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
private static async Task<(HttpStatusCode Status, string Body)> WriteAsync(
|
||||
EdgeFixture f, HttpMethod method, string path, string token, object? payload)
|
||||
{
|
||||
using var request = new HttpRequestMessage(method, path);
|
||||
request.Headers.TryAddWithoutValidation(Header, token);
|
||||
if (payload is not null)
|
||||
request.Content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json");
|
||||
using var response = await f.Client.SendAsync(request);
|
||||
return (response.StatusCode, await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
|
||||
/// <summary>The operator surfaces a read-only token is promised. Listed here
|
||||
/// rather than picked one by one so a surface added later is easy to add to
|
||||
/// the promise — and so a surface missing from it is visible.</summary>
|
||||
private static readonly string[] ReadSurfaces =
|
||||
{
|
||||
"/admin-api/state", "/admin-api/blocks", "/admin-api/allow", "/admin-api/rules",
|
||||
"/admin-api/policy", "/admin-api/rate", "/admin-api/observations", "/admin-api/streaks",
|
||||
"/admin-api/alerts", "/admin-api/countries", "/admin-api/countries/summary", "/admin-api/geo",
|
||||
"/admin-api/decide?ip=203.0.113.161"
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ReadSurfaceData))]
|
||||
public async Task The_read_only_token_reads_every_operator_surface(string path)
|
||||
{
|
||||
await using var f = new EdgeFixture(readOnlyToken: EdgeFixture.ReadOnlyToken);
|
||||
Assert.Equal(HttpStatusCode.OK, await ReadAsync(f, path, EdgeFixture.ReadOnlyToken));
|
||||
}
|
||||
|
||||
public static TheoryData<string> ReadSurfaceData()
|
||||
{
|
||||
var data = new TheoryData<string>();
|
||||
foreach (var surface in ReadSurfaces) data.Add(surface);
|
||||
return data;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task The_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. A dashboard and an operator have to be able to compare answers,
|
||||
// and a filtered read would make "what does the edge think" depend on
|
||||
// who asked.
|
||||
await using var f = new EdgeFixture(readOnlyToken: EdgeFixture.ReadOnlyToken);
|
||||
using (var write = await f.Client.PostAsJsonAsync(
|
||||
$"/admin-api/blocks?token={EdgeFixture.AdminToken}",
|
||||
new { ip = Written, reason = "written by the admin token" }))
|
||||
Assert.Equal(HttpStatusCode.NoContent, write.StatusCode);
|
||||
|
||||
var asAdmin = await ReadBodyAsync(f, "/admin-api/blocks", EdgeFixture.AdminToken);
|
||||
var asReadOnly = await ReadBodyAsync(f, "/admin-api/blocks", EdgeFixture.ReadOnlyToken);
|
||||
Assert.Contains(Written, asAdmin);
|
||||
Assert.Equal(asAdmin, asReadOnly);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("POST", "/admin-api/blocks")]
|
||||
[InlineData("POST", "/admin-api/allow")]
|
||||
[InlineData("POST", "/admin-api/rules")]
|
||||
[InlineData("PUT", "/admin-api/policy")]
|
||||
[InlineData("PUT", "/admin-api/countries/de?allowed=false")]
|
||||
[InlineData("DELETE", "/admin-api/blocks?source=operator")]
|
||||
[InlineData("POST", "/admin-api/import")]
|
||||
public async Task A_write_is_refused_for_the_read_only_token_whatever_the_verb(string method, string path)
|
||||
{
|
||||
await using var f = new EdgeFixture(readOnlyToken: EdgeFixture.ReadOnlyToken);
|
||||
var (status, body) = await WriteAsync(f, new HttpMethod(method), path, EdgeFixture.ReadOnlyToken,
|
||||
method == "POST" && path.EndsWith("import")
|
||||
? new { version = 1, blocks = Array.Empty<object>() }
|
||||
: new { ip = Refused, match = Refused, pattern = "/x*", mode = "Off" });
|
||||
|
||||
// 403, not 401: the token is known. The difference is the whole feature.
|
||||
Assert.Equal(HttpStatusCode.Forbidden, status);
|
||||
Assert.Contains("read-only", body);
|
||||
Assert.Contains("OpenWaf__Admin__Token", body);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_refused_write_leaves_nothing_behind()
|
||||
{
|
||||
await using var f = new EdgeFixture(readOnlyToken: EdgeFixture.ReadOnlyToken);
|
||||
var (status, _) = await WriteAsync(f, HttpMethod.Post, "/admin-api/blocks",
|
||||
EdgeFixture.ReadOnlyToken, new { ip = Refused, reason = "must not land" });
|
||||
Assert.Equal(HttpStatusCode.Forbidden, status);
|
||||
|
||||
using var list = await f.Client.GetAsync($"/admin-api/blocks?token={EdgeFixture.AdminToken}");
|
||||
using var all = await f.Client.GetAsync($"/admin-api/blocks?live=false&token={EdgeFixture.AdminToken}");
|
||||
Assert.Equal("[]", await list.Content.ReadAsStringAsync());
|
||||
Assert.Equal("[]", await all.Content.ReadAsStringAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task The_admin_token_still_writes_what_the_read_only_token_cannot()
|
||||
{
|
||||
// The regression this guards is the obvious wrong implementation: a
|
||||
// second token that quietly takes the first one's write power away.
|
||||
await using var f = new EdgeFixture(readOnlyToken: EdgeFixture.ReadOnlyToken);
|
||||
var (refused, _) = await WriteAsync(f, HttpMethod.Post, "/admin-api/blocks",
|
||||
EdgeFixture.ReadOnlyToken, new { ip = Refused });
|
||||
var (allowed, _) = await WriteAsync(f, HttpMethod.Post, "/admin-api/blocks",
|
||||
EdgeFixture.AdminToken, new { ip = Written, reason = "written by the admin token" });
|
||||
Assert.Equal(HttpStatusCode.Forbidden, refused);
|
||||
Assert.Equal(HttpStatusCode.NoContent, allowed);
|
||||
|
||||
using var list = await f.Client.GetAsync($"/admin-api/blocks?token={EdgeFixture.AdminToken}");
|
||||
using var body = JsonDocument.Parse(await list.Content.ReadAsStringAsync());
|
||||
Assert.Equal(1, body.RootElement.GetArrayLength());
|
||||
Assert.Equal(Written, body.RootElement[0].GetProperty("sourceKey").GetString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("/admin-api/state")]
|
||||
[InlineData("/admin-api/blocks")]
|
||||
public async Task An_unknown_token_is_answered_401_on_a_read_and_on_a_write(string path)
|
||||
{
|
||||
await using var f = new EdgeFixture(readOnlyToken: EdgeFixture.ReadOnlyToken);
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, await ReadAsync(f, path, "guessed-token"));
|
||||
var (status, body) = await WriteAsync(f, HttpMethod.Post, "/admin-api/blocks",
|
||||
"guessed-token", new { ip = Refused });
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, status);
|
||||
// The body must not explain a level to a token that has none: that would
|
||||
// be a way to probe which of the two secrets is configured.
|
||||
Assert.DoesNotContain("read-only", body);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task The_export_document_needs_the_admin_token_because_it_is_a_capability()
|
||||
{
|
||||
await using var f = new EdgeFixture(readOnlyToken: EdgeFixture.ReadOnlyToken);
|
||||
using (var write = await f.Client.PostAsJsonAsync(
|
||||
$"/admin-api/blocks?token={EdgeFixture.AdminToken}", new { ip = Written }))
|
||||
Assert.Equal(HttpStatusCode.NoContent, write.StatusCode);
|
||||
|
||||
var (refused, refusedBody) = await WriteAsync(f, HttpMethod.Get, "/admin-api/export",
|
||||
EdgeFixture.ReadOnlyToken, null);
|
||||
Assert.Equal(HttpStatusCode.Forbidden, refused);
|
||||
Assert.Contains("capability", refusedBody);
|
||||
|
||||
using var allowed = await f.Client.GetAsync($"/admin-api/export?token={EdgeFixture.AdminToken}");
|
||||
Assert.Equal(HttpStatusCode.OK, allowed.StatusCode);
|
||||
using var document = JsonDocument.Parse(await allowed.Content.ReadAsStringAsync());
|
||||
Assert.Equal(1, document.RootElement.GetProperty("counts").GetProperty("blocks").GetInt32());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task The_state_says_whether_a_second_token_exists()
|
||||
{
|
||||
await using var with = new EdgeFixture(readOnlyToken: EdgeFixture.ReadOnlyToken);
|
||||
await using var without = new EdgeFixture();
|
||||
foreach (var (fixture, expected) in new[] { (with, true), (without, false) })
|
||||
{
|
||||
using var response = await fixture.Client.GetAsync(
|
||||
$"/admin-api/state?token={EdgeFixture.AdminToken}");
|
||||
using var body = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
|
||||
Assert.Equal(expected, body.RootElement.GetProperty("readOnlyTokenConfigured").GetBoolean());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_read_only_token_that_was_never_configured_authenticates_as_nothing()
|
||||
{
|
||||
// The feature is off by default, and off has to mean off rather than
|
||||
// "a level that exists but is empty".
|
||||
await using var f = new EdgeFixture();
|
||||
Assert.Equal(HttpStatusCode.Unauthorized,
|
||||
await ReadAsync(f, "/admin-api/state", EdgeFixture.ReadOnlyToken));
|
||||
Assert.Equal(HttpStatusCode.Unauthorized,
|
||||
await ReadAsync(f, "/metrics", EdgeFixture.ReadOnlyToken));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task The_read_only_token_can_watch_the_numbers()
|
||||
{
|
||||
// A scrape is the clearest case of the whole feature: something that has
|
||||
// to be able to look and must not be able to change anything.
|
||||
await using var f = new EdgeFixture(readOnlyToken: EdgeFixture.ReadOnlyToken);
|
||||
Assert.Equal(HttpStatusCode.OK, await ReadAsync(f, "/metrics", EdgeFixture.ReadOnlyToken));
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, await ReadAsync(f, "/metrics", ""));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using OpenWaf.Domain.Security;
|
||||
|
||||
namespace OpenWaf.Tests.Unit;
|
||||
|
||||
/// <summary>
|
||||
/// Two tokens, two levels (OPEN-62).
|
||||
///
|
||||
/// The HTTP layer is covered by the integration tests; what lives here is the
|
||||
/// part that must be right whatever the transport is: which level a presented
|
||||
/// token has, which methods count as reads, and which configuration this build
|
||||
/// refuses to start with. The last one is the interesting pair — a read-only
|
||||
/// token that is also the admin token is a security promise that is false, and
|
||||
/// a false promise is worse than no promise, so it is a refusal rather than a
|
||||
/// warning.
|
||||
/// </summary>
|
||||
public sealed class AdminTokenPolicyTests
|
||||
{
|
||||
private const string Full = "full-token-value";
|
||||
private const string ReadOnly = "read-only-token-value";
|
||||
|
||||
[Fact]
|
||||
public void Each_configured_token_gets_its_own_level()
|
||||
{
|
||||
Assert.Equal(AdminTokenLevel.Full, AdminTokenPolicy.LevelOf(Full, Full, ReadOnly));
|
||||
Assert.Equal(AdminTokenLevel.ReadOnly, AdminTokenPolicy.LevelOf(ReadOnly, Full, ReadOnly));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_token_this_edge_does_not_know_has_no_level()
|
||||
{
|
||||
Assert.Equal(AdminTokenLevel.None, AdminTokenPolicy.LevelOf("guessed", Full, ReadOnly));
|
||||
Assert.Equal(AdminTokenLevel.None, AdminTokenPolicy.LevelOf("", Full, ReadOnly));
|
||||
Assert.Equal(AdminTokenLevel.None, AdminTokenPolicy.LevelOf(" ", Full, ReadOnly));
|
||||
Assert.Equal(AdminTokenLevel.None, AdminTokenPolicy.LevelOf(null, Full, ReadOnly));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_read_only_token_that_was_never_configured_authenticates_as_nothing()
|
||||
{
|
||||
// The feature is off by default, and off has to mean off: a value that
|
||||
// happens to be lying around is not a level.
|
||||
Assert.Equal(AdminTokenLevel.None, AdminTokenPolicy.LevelOf(ReadOnly, Full, null));
|
||||
Assert.Equal(AdminTokenLevel.None, AdminTokenPolicy.LevelOf(ReadOnly, Full, ""));
|
||||
Assert.Equal(AdminTokenLevel.None, AdminTokenPolicy.LevelOf(ReadOnly, Full, " "));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_blank_admin_token_grants_nothing_however_hard_it_is_presented()
|
||||
{
|
||||
// "No token configured" closes the surface rather than opening it
|
||||
// unauthenticated, and the level decision must not contradict that.
|
||||
Assert.Equal(AdminTokenLevel.None, AdminTokenPolicy.LevelOf("", null, ReadOnly));
|
||||
Assert.Equal(AdminTokenLevel.None, AdminTokenPolicy.LevelOf(ReadOnly, null, null));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("GET")]
|
||||
[InlineData("get")]
|
||||
[InlineData("HEAD")]
|
||||
[InlineData("OPTIONS")]
|
||||
public void A_read_is_a_read_whatever_the_casing(string method)
|
||||
=> Assert.True(AdminTokenPolicy.IsRead(method));
|
||||
|
||||
[Theory]
|
||||
[InlineData("POST")]
|
||||
[InlineData("PUT")]
|
||||
[InlineData("PATCH")]
|
||||
[InlineData("DELETE")]
|
||||
[InlineData("TRACE")]
|
||||
[InlineData("WHATEVER")]
|
||||
[InlineData("")]
|
||||
public void Anything_else_is_a_write(string method)
|
||||
=> Assert.False(AdminTokenPolicy.IsRead(method));
|
||||
|
||||
[Fact]
|
||||
public void An_unknown_method_is_a_write()
|
||||
=> Assert.False(AdminTokenPolicy.IsRead(null));
|
||||
|
||||
[Fact]
|
||||
public void No_read_only_token_configured_is_never_a_problem()
|
||||
{
|
||||
Assert.Null(AdminTokenPolicy.ExplainConfigurationProblem(Full, null));
|
||||
Assert.Null(AdminTokenPolicy.ExplainConfigurationProblem(Full, ""));
|
||||
Assert.Null(AdminTokenPolicy.ExplainConfigurationProblem(Full, " "));
|
||||
// Including when there is no admin token either: that is today's
|
||||
// "the surface is closed" configuration, and it stays startable.
|
||||
Assert.Null(AdminTokenPolicy.ExplainConfigurationProblem(null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_read_only_token_equal_to_the_admin_token_is_refused_by_name()
|
||||
{
|
||||
var problem = AdminTokenPolicy.ExplainConfigurationProblem(Full, Full);
|
||||
Assert.NotNull(problem);
|
||||
Assert.Contains(AdminTokenPolicy.ReadOnlyKey, problem!);
|
||||
Assert.Contains(AdminTokenPolicy.FullKey, problem!);
|
||||
// The message is written to startup output. It explains the mistake
|
||||
// without ever repeating the secret that made it.
|
||||
Assert.DoesNotContain(Full, problem!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_read_only_token_differing_only_by_a_trailing_newline_is_the_same_mistake()
|
||||
{
|
||||
// Tokens come out of env files with a newline on the end. "Different by
|
||||
// a newline" is not a difference a security check may rely on, so the
|
||||
// comparison trims before deciding the two keys were meant to differ.
|
||||
var problem = AdminTokenPolicy.ExplainConfigurationProblem(Full, Full + "\n");
|
||||
Assert.NotNull(problem);
|
||||
Assert.DoesNotContain(Full, problem!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_read_only_token_with_no_admin_token_is_refused_because_it_could_only_ever_be_answered_404()
|
||||
{
|
||||
var problem = AdminTokenPolicy.ExplainConfigurationProblem(null, ReadOnly);
|
||||
Assert.NotNull(problem);
|
||||
Assert.Contains(AdminTokenPolicy.ReadOnlyKey, problem!);
|
||||
Assert.Contains(AdminTokenPolicy.FullKey, problem!);
|
||||
Assert.DoesNotContain(ReadOnly, problem!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Two_different_secrets_are_a_usable_configuration()
|
||||
=> Assert.Null(AdminTokenPolicy.ExplainConfigurationProblem(Full, ReadOnly));
|
||||
|
||||
[Fact]
|
||||
public void The_refusal_a_read_only_token_gets_names_the_key_that_would_grant_the_write()
|
||||
{
|
||||
Assert.Contains(AdminTokenPolicy.FullKey, AdminTokenPolicy.ReadOnlyRefusal);
|
||||
Assert.Contains("read-only", AdminTokenPolicy.ReadOnlyRefusal);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,10 @@ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$ROOT" || exit 1
|
||||
: "${OPENWAF_ADMIN_TOKEN:?set OPENWAF_ADMIN_TOKEN before running, or run scripts/ci-gates.sh compose-smoke (it defaults a throwaway for the stack it starts itself)}"
|
||||
export OPENWAF_ADMIN_TOKEN
|
||||
# The second token (OPEN-62), for the section that is about it. A throwaway like
|
||||
# the admin one. Unset would be the shipped default and would make every
|
||||
# assertion below about a level that does not exist, so the gate asks for one.
|
||||
export OPENWAF_READ_ONLY_TOKEN="${OPENWAF_READ_ONLY_TOKEN:-ci-only-throwaway-readonly}"
|
||||
EDGE=${EDGE:-http://127.0.0.1:8080}
|
||||
SCANNER=203.0.113.66
|
||||
BYSTANDER=198.51.100.99
|
||||
@@ -1476,6 +1480,80 @@ check 'the transfer row is removable again, so the volume is left clean' '200' \
|
||||
"$(code -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \
|
||||
"$EDGE/admin-api/blocks?source=operator&key=$OPEN61_IP")"
|
||||
|
||||
echo '- a second token that can look but not change'
|
||||
# The read-only token (OPEN-62) against the shipped image. The 200s are the easy
|
||||
# half; what the gate is really for is the shape of the refusal — a known token
|
||||
# without the right answers 403 and names the key that would grant it, while an
|
||||
# unknown token answers 401 — and the fact that the shipped image refuses to
|
||||
# start when the two tokens are the same value.
|
||||
check 'the shipped state says a second token exists' 'true' \
|
||||
"$(admin "$EDGE/admin-api/state" | jval readOnlyTokenConfigured)"
|
||||
check 'the read-only token reads the shipped state' '200' \
|
||||
"$(code -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" "$EDGE/admin-api/state")"
|
||||
check 'the read-only token reads the shipped block list' '200' \
|
||||
"$(code -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" "$EDGE/admin-api/blocks")"
|
||||
check 'the read-only token can scrape the shipped numbers' '200' \
|
||||
"$(code -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" "$EDGE/metrics")"
|
||||
RO_WRITE=$(curl -s -m 10 -X POST -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" \
|
||||
-H 'Content-Type: application/json' -d '{"ip":"203.0.113.181","reason":"must not land"}' \
|
||||
"$EDGE/admin-api/blocks")
|
||||
check 'a read-only token cannot write a block on the shipped image' '403' \
|
||||
"$(code -X POST -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" -H 'Content-Type: application/json' \
|
||||
-d '{"ip":"203.0.113.181","reason":"must not land"}' "$EDGE/admin-api/blocks")"
|
||||
check 'the refusal says the token is read-only, not unknown' 'yes' \
|
||||
"$(printf '%s' "$RO_WRITE" | grep -q 'read-only' && echo yes || echo no)"
|
||||
check 'and it names the key that would grant the write' 'yes' \
|
||||
"$(printf '%s' "$RO_WRITE" | grep -q 'OpenWaf__Admin__Token' && echo yes || echo no)"
|
||||
check 'the refused write left no row behind' '0' \
|
||||
"$(admin "$EDGE/admin-api/blocks?live=false" | jcount 'b["sourceKey"]=="203.0.113.181"')"
|
||||
check 'a read-only token cannot change the shipped policy' '403' \
|
||||
"$(code -X PUT -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" -H 'Content-Type: application/json' \
|
||||
-d '{"mode":"Off"}' "$EDGE/admin-api/policy")"
|
||||
check 'a read-only token cannot read the shipped export' '403' \
|
||||
"$(code -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" "$EDGE/admin-api/export")"
|
||||
check 'and the refusal says the document is a capability' 'yes' \
|
||||
"$(curl -s -m 10 -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" "$EDGE/admin-api/export" \
|
||||
| grep -q 'capability' && echo yes || echo no)"
|
||||
check 'a read-only token cannot import a document' '403' \
|
||||
"$(code -X POST -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" -H 'Content-Type: application/json' \
|
||||
-d '{"version":1,"blocks":[]}' "$EDGE/admin-api/import")"
|
||||
check 'the admin token still writes on the shipped image' '204' \
|
||||
"$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
||||
-d '{"ip":"203.0.113.182","reason":"written by the admin token"}' "$EDGE/admin-api/blocks")"
|
||||
check 'and that row is removable again, so the volume stays clean' '200' \
|
||||
"$(code -X DELETE -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" \
|
||||
"$EDGE/admin-api/blocks?source=operator&key=203.0.113.182")"
|
||||
check 'an unknown token is still 401 on the shipped image' '401' \
|
||||
"$(code -H "X-Admin-Token: not-a-token" "$EDGE/admin-api/state")"
|
||||
|
||||
# The configuration the shipped image refuses to start with, run as a container:
|
||||
# a read-only token that is also the admin token. Asserted against the image
|
||||
# rather than only the source, because "refused at startup" is a claim about what
|
||||
# an operator who configures this actually gets.
|
||||
BAD_LOG=/tmp/openwaf-compose-bad-$$.log
|
||||
# Started detached and polled, not waited on: the assertion is that the process
|
||||
# LEAVES. A refusal that prints its reason and then keeps running is a container
|
||||
# that sits at full CPU forever with no exit code for the supervisor to react
|
||||
# to, and a gate that blocks on it cannot tell that apart from a slow run.
|
||||
BAD_NAME="openwaf-bad-token-$$"
|
||||
docker compose run -d --name "$BAD_NAME" -e OPENWAF_READ_ONLY_TOKEN="$OPENWAF_ADMIN_TOKEN" edge >/dev/null 2>&1
|
||||
BAD_RC=''
|
||||
for _ in $(seq 1 30); do
|
||||
if [ "$(docker inspect -f '{{.State.Status}}' "$BAD_NAME" 2>/dev/null)" = exited ]; then
|
||||
BAD_RC=$(docker inspect -f '{{.State.ExitCode}}' "$BAD_NAME" 2>/dev/null)
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
docker logs "$BAD_NAME" >"$BAD_LOG" 2>&1
|
||||
docker rm -f "$BAD_NAME" >/dev/null 2>&1
|
||||
check 'the shipped image leaves rather than sits there with a bad token pair' 'yes' \
|
||||
"$([ -n "$BAD_RC" ] && [ "$BAD_RC" -ne 0 ] && echo yes || echo no)"
|
||||
check 'it names both keys in the reason' 'yes' \
|
||||
"$(grep -q 'OpenWaf__Admin__ReadOnlyToken' "$BAD_LOG" && grep -q 'OpenWaf__Admin__Token' "$BAD_LOG" && echo yes || echo no)"
|
||||
check 'and it never prints the secret' 'yes' \
|
||||
"$(grep -q "$OPENWAF_ADMIN_TOKEN" "$BAD_LOG" && echo no || echo yes)"
|
||||
rm -f "$BAD_LOG"
|
||||
echo
|
||||
printf 'compose smoke: %d passed, %d failed\n' "$PASS" "$FAIL"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
|
||||
@@ -18,6 +18,7 @@ EDGE_PORT=${EDGE_PORT:-18088}
|
||||
UP_PORT=${UP_PORT:-18900}
|
||||
DB=/tmp/openwaf-smoke-$$.db
|
||||
TOKEN=smoketoken
|
||||
RO_TOKEN=smokereadonly
|
||||
BIN="$ROOT/dotnet/OpenWaf.Edge/bin/Release/net10.0/OpenWaf.Edge.dll"
|
||||
[ -f "$BIN" ] || BIN="$ROOT/dotnet/OpenWaf.Edge/bin/Debug/net10.0/OpenWaf.Edge.dll"
|
||||
|
||||
@@ -65,6 +66,7 @@ UP_PID=$!
|
||||
rm -f "$DB"
|
||||
ASPNETCORE_URLS="http://127.0.0.1:$EDGE_PORT" \
|
||||
OPENWAF_ADMIN_TOKEN="$TOKEN" \
|
||||
OPENWAF_READ_ONLY_TOKEN="$RO_TOKEN" \
|
||||
ConnectionStrings__OpenWaf="Data Source=$DB" \
|
||||
OpenWaf__Policy__StreakThreshold=3 \
|
||||
OpenWaf__Policy__Mode=Enforce \
|
||||
@@ -292,6 +294,92 @@ check 'the transfer row is removable again, so the run ends clean' 200 \
|
||||
"$(code -X DELETE -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks?source=operator&key=$TRANSFER_IP")"
|
||||
|
||||
echo '- a second token that can look but not change'
|
||||
# The read-only token (OPEN-62). The interesting assertions are not the 200s —
|
||||
# a read is a read — but the shape of the refusal: a known token that lacks the
|
||||
# right answers 403 and names the key that would grant it, while an unknown
|
||||
# token still answers 401. Those two sentences are the feature; collapsing them
|
||||
# is what would make an operator debug the wrong thing.
|
||||
check 'the state says a second token exists on this edge' True \
|
||||
"$(curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/state" \
|
||||
| python3 -c 'import sys,json;print(json.load(sys.stdin)["readOnlyTokenConfigured"])')"
|
||||
check 'the read-only token reads the state' 200 \
|
||||
"$(code -H "X-Admin-Token: $RO_TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/state")"
|
||||
check 'the read-only token reads the block list' 200 \
|
||||
"$(code -H "X-Admin-Token: $RO_TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/blocks")"
|
||||
check 'the read-only token reads the path rules' 200 \
|
||||
"$(code -H "X-Admin-Token: $RO_TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/rules")"
|
||||
check 'the read-only token reads the policy' 200 \
|
||||
"$(code -H "X-Admin-Token: $RO_TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/policy")"
|
||||
check 'the read-only token can watch /metrics' 200 \
|
||||
"$(code -H "X-Admin-Token: $RO_TOKEN" "http://127.0.0.1:$EDGE_PORT/metrics")"
|
||||
check 'a read-only token presented in the query string is served' 200 \
|
||||
"$(code "http://127.0.0.1:$EDGE_PORT/admin-api/observations?token=$RO_TOKEN")"
|
||||
RO_WRITE="$(curl -s -X POST -H "X-Admin-Token: $RO_TOKEN" -H 'Content-Type: application/json' \
|
||||
-d '{"ip":"203.0.113.155","reason":"must not land"}' \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks")"
|
||||
check 'a read-only token cannot write a block' 403 \
|
||||
"$(code -X POST -H "X-Admin-Token: $RO_TOKEN" -H 'Content-Type: application/json' \
|
||||
-d '{"ip":"203.0.113.155","reason":"must not land"}' \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks")"
|
||||
check 'the refusal says the token is read-only, not unknown' yes \
|
||||
"$(printf '%s' "$RO_WRITE" | python3 -c 'import sys,json;print("yes" if "read-only" in json.load(sys.stdin)["error"] else "no")')"
|
||||
check 'and it names the key that would grant the write' yes \
|
||||
"$(printf '%s' "$RO_WRITE" | grep -q 'OpenWaf__Admin__Token' && echo yes || echo no)"
|
||||
check 'the write really did not land' 0 \
|
||||
"$(curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/blocks?live=false" \
|
||||
| python3 -c 'import sys,json;print(len([b for b in json.load(sys.stdin) if b["sourceKey"]=="203.0.113.155"]))')"
|
||||
check 'a read-only token cannot change the policy' 403 \
|
||||
"$(code -X PUT -H "X-Admin-Token: $RO_TOKEN" -H 'Content-Type: application/json' --data-binary "$POLICY_OFF_JSON" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/policy")"
|
||||
check 'a read-only token cannot delete a block' 403 \
|
||||
"$(code -X DELETE -H "X-Admin-Token: $RO_TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks?source=operator")"
|
||||
check 'a read-only token cannot import a document' 403 \
|
||||
"$(code -X POST -H "X-Admin-Token: $RO_TOKEN" -H 'Content-Type: application/json' \
|
||||
-d '{"version":1,"blocks":[]}' "http://127.0.0.1:$EDGE_PORT/admin-api/import")"
|
||||
check 'the export is not readable by the read-only token' 403 \
|
||||
"$(code -H "X-Admin-Token: $RO_TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/export")"
|
||||
check 'and the refusal says the document is a capability' yes \
|
||||
"$(curl -s -H "X-Admin-Token: $RO_TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/export" \
|
||||
| grep -q 'capability' && echo yes || echo no)"
|
||||
check 'the admin token still writes what the other one cannot' 204 \
|
||||
"$(code -X POST -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' \
|
||||
-d '{"ip":"203.0.113.156","reason":"written by the admin token"}' \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks")"
|
||||
# Cleaned up straight away: the later sections count operator rows, and a row
|
||||
# left behind by this scene would be read as one of theirs.
|
||||
check 'and the admin-token row is removable again' 200 \
|
||||
"$(code -X DELETE -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks?source=operator&key=203.0.113.156")"
|
||||
check 'an unknown token is still 401, not 403' 401 \
|
||||
"$(code -H "X-Admin-Token: not-a-token" "http://127.0.0.1:$EDGE_PORT/admin-api/state")"
|
||||
check 'and an unknown token cannot write either' 401 \
|
||||
"$(code -X POST -H "X-Admin-Token: not-a-token" -H 'Content-Type: application/json' \
|
||||
-d '{"ip":"203.0.113.157"}' "http://127.0.0.1:$EDGE_PORT/admin-api/blocks")"
|
||||
|
||||
# The configuration this build refuses to start with: a read-only token that is
|
||||
# also the admin token. Started for real, on its own port and its own database,
|
||||
# because "refused at startup" is only worth claiming if a process that is
|
||||
# actually configured that way fails to come up. The message has to name both
|
||||
# keys and must not repeat the secret — startup output is where secrets leak.
|
||||
BAD_DB=/tmp/openwaf-smoke-bad-$$.db
|
||||
BAD_LOG=/tmp/openwaf-smoke-bad-$$.log
|
||||
rm -f "$BAD_DB"
|
||||
ASPNETCORE_URLS="http://127.0.0.1:$((EDGE_PORT+7))" \
|
||||
OPENWAF_ADMIN_TOKEN="$TOKEN" \
|
||||
OPENWAF_READ_ONLY_TOKEN="$TOKEN" \
|
||||
ConnectionStrings__OpenWaf="Data Source=$BAD_DB" \
|
||||
dotnet "$BIN" --contentRoot "$BIN_DIR" >"$BAD_LOG" 2>&1
|
||||
BAD_RC=$?
|
||||
check 'an edge whose read-only token is also its admin token does not start' yes \
|
||||
"$([ "$BAD_RC" -ne 0 ] && echo yes || echo no)"
|
||||
check 'it names both keys in the reason' yes \
|
||||
"$(grep -q 'OpenWaf__Admin__ReadOnlyToken' "$BAD_LOG" && grep -q 'OpenWaf__Admin__Token' "$BAD_LOG" && echo yes || echo no)"
|
||||
check 'and it never prints the secret' yes \
|
||||
"$(grep -q "$TOKEN" "$BAD_LOG" && echo no || echo yes)"
|
||||
rm -f "$BAD_DB" "$BAD_DB-shm" "$BAD_DB-wal" "$BAD_LOG"
|
||||
|
||||
echo '- volume budget'
|
||||
STATE0_JSON="$(curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/state")"
|
||||
check 'the budget is off until an operator writes one' Off \
|
||||
|
||||
Reference in New Issue
Block a user