ADR-0131: Keycloak grant broker and schema v39 account identities
Foundation / checks (checks) (push) Successful in 42m13s
Foundation / checks (deploy) (push) Successful in 4m5s
Foundation / checks (ecs) (push) Successful in 2m25s
Foundation / checks (network) (push) Successful in 19m18s
Foundation / checks (postgres) (push) Successful in 44m19s
Foundation / checks (tsan) (push) Successful in 9m48s
Foundation / checks (client) (push) Failing after 12m6s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

evo-grant-broker verifies realm aeternalis access tokens offline (RS256 against
the pinned JWKS; audience aevolution-grants, client aevolution-game, verified
email) and issues 10-minute session grants:
- POST /grant routes to the region holding the account's life, or the default.
- POST /logout makes every issued grant stale and expires current control.
- GET /healthz.

Schema v39 maps (issuer, subject) to stable accounts with strictly increasing
serials. The binary ships in the server image. The DEV manifests are in
deploy/kubernetes/grant-broker-dev and are not yet enabled in region/dev; that
waits for the image promotion and the out-of-band Secrets and Ingress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-15 10:20:27 -04:00
co-authored by Claude Opus 5.5
parent 817a830a8a
commit 68880ba3b4
29 changed files with 1967 additions and 18 deletions
+67 -3
View File
@@ -15,8 +15,12 @@ const char* reason(int status) {
return "OK";
case 400:
return "Bad Request";
case 401:
return "Unauthorized";
case 404:
return "Not Found";
case 429:
return "Too Many Requests";
case 405:
return "Method Not Allowed";
case 431:
@@ -33,7 +37,9 @@ std::string encode(const OpsResponse& r) {
"\r\nContent-Length: " + std::to_string(r.body.size()) +
"\r\nCache-Control: no-store\r\nConnection: close\r\n";
if (r.status == 405)
out += "Allow: GET\r\n";
out += "Allow: GET, POST\r\n";
if (r.status == 401)
out += "WWW-Authenticate: Bearer\r\n";
return out + "\r\n" + r.body;
}
bool printable(std::string_view s) {
@@ -122,7 +128,65 @@ void OpsServer::respond(Connection& c, const OpsHandler& handler) {
c.out = encode(response);
}
void OpsServer::respond_api(Connection& c, const ApiHandler& handler) {
OpsResponse response;
const std::string_view request = c.in;
const auto line_end = request.find("\r\n");
const auto line = request.substr(0, line_end);
const auto first = line.find(' ');
const auto second = first == std::string_view::npos ? first : line.find(' ', first + 1);
if (second == std::string_view::npos || line.substr(second + 1).rfind("HTTP/1.", 0) != 0) {
c.out = encode({400, "bad request\n"});
return;
}
const auto method = line.substr(0, first);
const auto path = line.substr(first + 1, second - first - 1);
std::string_view authorization;
bool has_body = false;
// Header lines up to the blank line; names are case-insensitive.
auto at = line_end + 2;
while (at < request.size()) {
const auto end = request.find("\r\n", at);
if (end == std::string_view::npos || end == at)
break;
const auto header = request.substr(at, end - at);
const auto colon = header.find(':');
if (colon != std::string_view::npos) {
std::string name(header.substr(0, colon));
for (auto& ch : name)
ch = static_cast<char>(ch >= 'A' && ch <= 'Z' ? ch - 'A' + 'a' : ch);
auto value = header.substr(colon + 1);
while (!value.empty() && value.front() == ' ')
value.remove_prefix(1);
if (name == "authorization")
authorization = value;
else if ((name == "content-length" && value != "0") || name == "transfer-encoding")
has_body = true;
}
at = end + 2;
}
if (method != "GET" && method != "POST")
response = {405, "method not allowed\n"};
else if (path.empty() || path.front() != '/' || path.size() > 256 || !printable(path) ||
has_body)
response = {400, "bad request\n"};
else
response = handler({method, path, authorization});
if (response.body.size() > max_response_bytes)
response = {500, "response too large\n"};
c.out = encode(response);
}
void OpsServer::serve(const OpsHandler& handler) {
serve_with(max_request_bytes, [&](Connection& c) { respond(c, handler); });
}
void OpsServer::serve_api(const ApiHandler& handler) {
serve_with(max_api_request_bytes, [&](Connection& c) { respond_api(c, handler); });
}
template <typename Answer>
void OpsServer::serve_with(std::size_t request_limit, const Answer& answer) {
const auto accepted_at = Clock::now();
for (std::size_t attempt = 0; attempt < max_accepts_per_serve; ++attempt) {
const int fd = ::accept4(fd_, nullptr, nullptr, SOCK_NONBLOCK | SOCK_CLOEXEC);
@@ -148,10 +212,10 @@ void OpsServer::serve(const OpsHandler& handler) {
done = true;
} else if (n > 0) {
c.in.append(chunk, static_cast<std::size_t>(n));
if (c.in.size() > max_request_bytes)
if (c.in.size() > request_limit)
c.out = encode({431, "request too large\n"});
else if (c.in.find("\r\n\r\n") != std::string::npos)
respond(c, handler);
answer(c);
}
}
if (!done && !c.out.empty()) {