Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/DATA-MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ there was no history to recover — the same honest shape as the symbol index.
with the platform because a bare `providerUserId` is not a person: the same id on two SCMs belongs
to two unrelated humans. Admin-managed; inferring the link by matching usernames is refused, since
a coincidental match shows one person another person's performance data with nothing on screen
looking wrong.
looking wrong. **V116** adds `author_handle` TEXT NULL: the login the forge reported when the operator
proved the account by signing in (never an email address), null for a link made by hand. Display
data only; `author_id` stays the key.

`review_event` (flattened timeline for the dashboard): `id` BIGINT PK, `review_id`, `type`,
`at`, `summary` — non-sensitive projection of the log for the UI (no payloads).
Expand Down
13 changes: 13 additions & 0 deletions docs/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2515,3 +2515,16 @@ lives in `docs/`, the locked decisions in `docs/DECISIONS.md`, and claims no tes
`fsGroup`, so on a root-owned volume (Longhorn, EBS, Ceph; kind's local-path volumes are world-writable) neither
could write its data: both pods now set `fsGroup` with `fsGroupChangePolicy: OnRootMismatch`. render.sh
`check_first_install` asserts both and its self-test breaks both.

- **Operator names on the first install (2026-11-15, Part of #391).** Two People-tab defects from the first
production install. Nothing called `OperatorDirectory.seen`, so `operator_seen` stayed empty: Settings → Operators
said "Nobody has signed in yet" and a linked operator rendered as the raw OIDC subject twice. `/api/me` now records
the signed-in operator; the live socket's close handler asks it before every reconnect, so an identical sighting
within 60 s is skipped in memory and a changed name is written at once (a failure is logged and the probe still
answers). Email is never stored: on that realm `preferred_username` is the email address, so `OperatorNames` drops
any value with an `@` and the username is stored empty, the display name is the `name` claim, and a subject that is
itself an email is not recorded. Second, a linked SCM account showed its numeric id twice, because the only handle
came from authors observed in reviews. V116 adds `operator_identity.author_handle`: the connect callback stores the
login the forge reported (`Author.username`, never the email, dropped if it looks like one), the identity list
returns it, and the People table and the My activity chips show it with the id as fallback; a link made by hand
keeps null, and a hand relink of the same account keeps the observed login. A name equal to its id is shown once.
1 change: 1 addition & 0 deletions docs/UNVERIFIED.md
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,7 @@ Each has a runbook mode. None has been run by an operator.
| **GitHub review fallbacks and the dismissal** (ADR-047, 2026-10-15) | none yet | WireMock and fakes prove the self-authored refusal (422 "own pull request" → posted again as Comment), the rejected anchor (body only, then inline one by one, then a body update), the dismissal of the bot's own standing Request changes when the setting is off, the crash window between a review post and its idempotency mark (the review is found again by head and header), and the reviewer request refused for a non-collaborator. The dismissal met GitHub on 2026-10-18: on `spire-test` PR 55 a re-run with the setting off posted Comment review 5563717456 and dismissed the bot's own Request changes 5554693017 with a message naming the new review (`factory/GITHUB-REVIEWS-ACCEPTANCE.md`); the look-first on a redelivery is proven by the same re-runs. The rest has not. Evidence needed: a PR opened by the reviewer account; a finding whose anchor GitHub rejects; a worker killed between the post and the mark; a reviewer login that is not a collaborator. Whether a dismissal needs write access is API knowledge, not measured. GitLab and Bitbucket native reviews are absent by design. A legacy summary issue comment posted before this slice stays on the PR unchanged beside the new review; nothing edits it (M-10) |
| **The factory land gate at Block approval at Major or Minor** (PR #420, 2026-11-14) | none yet | `WorkReview` tests prove a MAJOR-only review holds land at Major and completes at Blocker. The verdict at both levels is live on `spire-test` #106; no factory item has landed, or been held, at a level other than Blocker. |
| **OIDC sessions actually renew instead of re-authenticating** | **Mode J check 11** (2026-09-10) | The bug it fixes needs a real browser, a real Keycloak and **fifteen elapsed minutes**. No suite here has any of the three: there are zero WebSocket client tests, and nothing observes a token reaching its `exp`. `OidcSessionsAreRenewedTest` asserts the four `application.yml` files *say* renewal is on — it cannot assert Quarkus *does* it |
| **Operator names on a live realm** (2026-11-15) | none yet | `/api/me` recording the operator and dropping an email `preferred_username` is proven by a unit test with a hand-built JWT and a `@TestSecurity` test that has no JWT; no real Keycloak token has been through it. The connect callback storing the forge login is proven against a fake `OperatorOAuth`, not a real GitHub sign-in |

**Evidence needed.** An operator pass per mode. These are cheap and the runbooks are written.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ public class OperatorIdentities {
* <p>{@code providerType} is not decoration: a bare {@code providerUserId} is not a person. The
* same numeric id on GitHub and GitLab belongs to two unrelated humans, and this project has
* already been bitten twice by treating a workspace name as unique across platforms.
*
* <p>{@code authorHandle} is the login the forge reported when the operator proved the account by
* signing in (V116), or null for a link an admin made by hand. Display data only: nothing keys on
* it, and it is never an email address.
*/
public record Link(String oidcSubject, String providerType, String authorId) {
public record Link(String oidcSubject, String providerType, String authorId, String authorHandle) {
}

@Inject
Expand All @@ -50,11 +54,11 @@ public List<Link> all() {
List<Link> links = new ArrayList<>();
try (Connection c = dataSource.getConnection();
PreparedStatement ps = c.prepareStatement(
"SELECT oidc_subject, provider_type, author_id FROM operator_identity"
"SELECT oidc_subject, provider_type, author_id, author_handle FROM operator_identity"
+ " ORDER BY oidc_subject, provider_type");
ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
links.add(new Link(rs.getString(1), rs.getString(2), rs.getString(3)));
links.add(new Link(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4)));
}
} catch (SQLException e) {
throw new IllegalStateException("could not read operator identities", e);
Expand All @@ -70,12 +74,12 @@ public List<Link> forSubject(String oidcSubject) {
List<Link> links = new ArrayList<>();
try (Connection c = dataSource.getConnection();
PreparedStatement ps = c.prepareStatement(
"SELECT oidc_subject, provider_type, author_id FROM operator_identity"
"SELECT oidc_subject, provider_type, author_id, author_handle FROM operator_identity"
+ " WHERE oidc_subject = ? ORDER BY provider_type")) {
ps.setString(1, oidcSubject);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
links.add(new Link(rs.getString(1), rs.getString(2), rs.getString(3)));
links.add(new Link(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4)));
}
}
} catch (SQLException e) {
Expand Down Expand Up @@ -122,17 +126,28 @@ public Optional<Link> firstFor(String oidcSubject) {
return forSubject(oidcSubject).stream().findFirst();
}

/**
* Writes the link.
*
* <p>A relink to the SAME account with no handle (an admin repairing it by hand) keeps the handle a
* sign-in observed; a link to a different account takes the new handle, null included, because the
* old login names somebody else's account.
*/
public void link(Link link) {
String sql = """
INSERT INTO operator_identity (oidc_subject, provider_type, author_id)
VALUES (?, ?, ?)
INSERT INTO operator_identity (oidc_subject, provider_type, author_id, author_handle)
VALUES (?, ?, ?, ?)
ON CONFLICT (oidc_subject, provider_type)
DO UPDATE SET author_id = EXCLUDED.author_id
DO UPDATE SET author_id = EXCLUDED.author_id,
author_handle = CASE WHEN operator_identity.author_id = EXCLUDED.author_id
THEN COALESCE(EXCLUDED.author_handle, operator_identity.author_handle)
ELSE EXCLUDED.author_handle END
""";
try (Connection c = dataSource.getConnection(); PreparedStatement ps = c.prepareStatement(sql)) {
ps.setString(1, link.oidcSubject());
ps.setString(2, link.providerType());
ps.setString(3, link.authorId());
ps.setString(4, link.authorHandle());
ps.executeUpdate();
} catch (SQLException e) {
throw new IllegalStateException("could not link the operator identity", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Response link(LinkRequest request) {
return Response.status(Response.Status.BAD_REQUEST).entity(rejection).build();
}
identities.link(new OperatorIdentities.Link(request.oidcSubject().trim(),
request.providerType().trim(), request.authorId().trim()));
request.providerType().trim(), request.authorId().trim(), null));
return Response.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.codespire.contract.scm.OAuthApp;
import dev.codespire.orchestrator.analytics.OperatorIdentities;
import dev.codespire.orchestrator.security.OidcSubjects;
import dev.codespire.orchestrator.security.OperatorNames;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
Expand Down Expand Up @@ -191,10 +192,22 @@ public Response callback(@PathParam("type") String type,
return back("noaccount");
}

identities.link(new OperatorIdentities.Link(attempt.oidcSubject(), type, author.providerUserId()));
identities.link(linkOf(attempt, type, author));
return back("connected");
}

/**
* The proved link, with the login the forge just reported kept beside the id so the dashboard can
* show {@code artyomsv} rather than {@code 3218389}. The login is display data only, never a key.
* Only {@code username}: the author's email is never stored, and a login that looks like an email
* is dropped too (null, as for a link made by hand).
*/
static OperatorIdentities.Link linkOf(ConnectStates.Pending attempt, String type, Author author) {
String handle = OperatorNames.withoutEmail(author.username());
return new OperatorIdentities.Link(attempt.oidcSubject(), type, author.providerUserId(),
handle.isEmpty() ? null : handle);
}

/**
* This deployment's own callback address, as the browser reached it.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@
@Produces(MediaType.APPLICATION_JSON)
public class AuthResource {

private static final org.jboss.logging.Logger LOG = org.jboss.logging.Logger.getLogger(AuthResource.class);

@Inject
SecurityIdentity identity;

@Inject
OperatorDirectory directory;

@Inject
RecentOperatorSightings sightings;

@ConfigProperty(name = "spire.security.auth-enabled", defaultValue = "true")
boolean authEnabled;

Expand All @@ -57,6 +65,9 @@ public record Me(boolean authEnabled, boolean authenticated, String user, List<S
@Path("/me")
public Me me() {
boolean signedIn = !identity.isAnonymous();
if (signedIn) {
recordSignedIn();
}
return new Me(
authEnabled,
signedIn,
Expand All @@ -65,22 +76,36 @@ public Me me() {
signedIn ? OidcSubjects.of(identity) : "");
}


/**
Comment thread
artyomsv marked this conversation as resolved.
Resolved
* The operator's human name when the token carries one.
* Records the caller in the operator directory, so an admin can pick them by name.
*
* <p>On the session probe because every dashboard load asks it, which is exactly "who has been
* here". The live socket's close handler ({@code useLiveSocket}) asks it too, before every
* reconnect, so {@link RecentOperatorSightings} skips an identical sighting within 60 s: a
* flapping socket must not become a write stream, while a changed name is written at once. Names
* go through {@link OperatorNames}, which drops every email address: on a realm whose login is
* the email, the username is stored empty and the {@code name} claim is shown. A subject that is
* itself an email (no JWT, a principal named by email) is not recorded at all.
*
* <p>Falls back to the principal name rather than to blank: the picker exists so a person can be
* recognised, and a row showing only an opaque subject would send an admin back to the database
* this whole change removes.
* <p>{@link OperatorDirectory#seen} never throws by design; the catch keeps that promise here too,
* because a dashboard that cannot load its session over a display table is the worse outcome.
*/
private static String displayName(SecurityIdentity identity) {
if (identity.getPrincipal() instanceof org.eclipse.microprofile.jwt.JsonWebToken jwt) {
Object name = jwt.getClaim("name");
if (name instanceof String text && !text.isBlank()) {
return text;
}
private void recordSignedIn() {
String subject = OidcSubjects.of(identity);
if (OperatorNames.withoutEmail(subject).isEmpty()) {
return;
}
String username = OperatorNames.username(identity);
String displayName = OperatorNames.displayName(identity);
if (!sightings.isNew(subject, username, displayName)) {
return;
}
try {
directory.seen(subject, username, displayName);
sightings.remember(subject, username, displayName);
} catch (RuntimeException e) {
LOG.warn("could not record the signed-in operator", e);
}
return identity.getPrincipal().getName();
}

/** Only this application's own roles; an operator's other realm roles are not our business. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package dev.codespire.orchestrator.security;

import io.quarkus.security.identity.SecurityIdentity;
import org.eclipse.microprofile.jwt.JsonWebToken;

/**
* The names a signed-in operator is shown by, with every email address taken out.
*
* <p>Email is never persisted (CLAUDE.md), and an identity provider does not promise that its name
* claims are not emails: on the first production realm {@code preferred_username} IS the email
* address, and the principal name follows it. So any value with an {@code @} is dropped, and the
* caller gets an empty string instead. The dashboard then shows the display name, or the subject.
*/
public final class OperatorNames {

private static final String NAME_CLAIM = "name";
private static final String USERNAME_CLAIM = "preferred_username";

private OperatorNames() {
}

/** The login, or empty when the provider's login is an email address or there is none. */
public static String username(SecurityIdentity identity) {
if (identity == null || identity.isAnonymous()) {
return "";
}
String claimed = claim(identity, USERNAME_CLAIM);
return withoutEmail(claimed.isEmpty() ? identity.getPrincipal().getName() : claimed);
}

/** The {@code name} claim, else the login, else empty. Never an email address. */
public static String displayName(SecurityIdentity identity) {
if (identity == null || identity.isAnonymous()) {
return "";
}
String name = withoutEmail(claim(identity, NAME_CLAIM));
return name.isEmpty() ? username(identity) : name;
}

/** {@code value} trimmed, or empty when it is blank or looks like an email address. */
public static String withoutEmail(String value) {
if (value == null || value.isBlank() || value.contains("@")) {
return "";
}
return value.trim();
}

private static String claim(SecurityIdentity identity, String claimName) {
if (identity.getPrincipal() instanceof JsonWebToken jwt
&& jwt.getClaim(claimName) instanceof String text) {
return text.trim();
}
return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package dev.codespire.orchestrator.security;

import jakarta.enterprise.context.ApplicationScoped;

import java.time.Duration;
import java.time.Instant;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

/**
* Which operators this process recorded a moment ago, so {@code /api/me} does not write the same row
* again.
*
* <p>The session probe is not only asked once per dashboard load: the live socket's close handler
* ({@code useLiveSocket}) asks it on every close before it reconnects, so a flapping socket would turn
* {@code operator_seen} into a write stream. An identical sighting within {@link #WINDOW} is skipped;
* a changed username or display name is written at once. Per process and in memory: a second
* instance or a restart writes once more, which is harmless.
*/
@ApplicationScoped
public class RecentOperatorSightings {

static final Duration WINDOW = Duration.ofSeconds(60);

private record Sighting(String username, String displayName, Instant at) {
}

private final Map<String, Sighting> recent = new ConcurrentHashMap<>();

Supplier<Instant> clock = Instant::now;

/** Whether this sighting differs from the last one recorded, or that one is older than the window. */
public boolean isNew(String subject, String username, String displayName) {
Sighting last = recent.get(subject);
return last == null
|| !last.username().equals(username)
|| !last.displayName().equals(displayName)
|| last.at().plus(WINDOW).isBefore(clock.get());
}

public void remember(String subject, String username, String displayName) {
recent.put(subject, new Sighting(username, displayName, clock.get()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- The SCM login an operator proved by signing in, shown beside the stable id (FR-11).
--
-- A fresh install showed a linked account as its numeric id twice ("3218389 / 3218389"): the only
-- handle the dashboard knew came from authors observed in reviews, and there were none yet. The connect
-- callback has just been told the login by the forge itself, so it is kept with the link.
--
-- Display data only, never a key: author_id stays the identity. NULL for a link an admin made by hand
-- (no login was observed); the dashboard then falls back to the observed authors, then to the id.
-- Never an email address: the callback refuses to store one.
ALTER TABLE operator_identity ADD COLUMN author_handle TEXT;
Loading
Loading