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
10 changes: 10 additions & 0 deletions docs/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2528,3 +2528,13 @@ lives in `docs/`, the locked decisions in `docs/DECISIONS.md`, and claims no tes
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.

- **Destructive actions ask first (2026-11-16, Part of #391).** The first production install found that the trash
icons on the People tab acted at once. An audit of every destructive action in the dashboard found five that did
not ask: removing a sign-in application, unlinking an operator's SCM account, removing a person from an account's
allowed people or a repository's /fix overrides, removing an allowed person from a work source, and Reset to
default on a prompt. Each now opens `ConfirmDialog`, which names what goes and what that means; a refused request
stays in the dialog. The drift banner's "Take the new default" stays one click, as it already shows both texts.
`ScmOAuthAppForm` and `OperatorLinksTable` moved out of their screens to keep the files small. docs/TLS.md now gives
nginx proxy manager's advanced settings from that install: without the header buffers the sign-in callback
answered 502 "upstream sent too big header".
29 changes: 27 additions & 2 deletions docs/TLS.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,33 @@ Configured through its UI rather than a file, so as a settings list:
| SSL certificate | Let's Encrypt, or your own |
| Force SSL | on |
| HTTP/2 Support | optional |
| Advanced → Custom Nginx Configuration | **required** — the six lines below |

```nginx
proxy_buffer_size 16k;
proxy_buffers 8 16k;
large_client_header_buffers 4 32k;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
client_max_body_size 25m;
```

These match the dashboard's own proxy (`spire-ui/nginx/default.conf.template`), and proxy manager
needs them for the same reasons, because it is a second nginx in front of that one:

- **The buffers.** The sign-in callback answers with the operator session as several large
`Set-Cookie` headers, and the browser sends them back as one large `Cookie` header. At nginx's
4k/8k defaults the callback fails with a bare 502 and `upstream sent too big header` in proxy
manager's log, while every Code Spire service logs nothing, because each one answered correctly.
Proven on the first production install (2026-11-15): sign-in returned 502 until these three lines
were added.
- **The timeouts.** The WebSockets are idle between events; at the 60-second default they reconnect
every minute (see [Long-lived connections](#long-lived-connections)).
- **The body size.** An SCM webhook for a large pull request exceeds proxy manager's 1 MB default,
and the SCM records a failed delivery.
Comment thread
artyomsv marked this conversation as resolved.
Resolved

Proxy manager sends `X-Forwarded-Proto` and preserves `Host` by default, satisfying requirements 1
and 2 with no custom configuration. Give the identity provider its own proxy host under requirement 5.
Proxy manager sends `X-Forwarded-Proto` and preserves `Host` by default, so requirements 1 and 2
need no custom configuration; the Advanced lines above are for the buffers, timeouts and body size. Give the identity provider its own proxy host under requirement 5.

**Websockets Support is not optional.** With it off, the dashboard loads and REST works, so the
deployment looks healthy — but the timeline, the review detail, the attention panel and the gateway's
Expand Down Expand Up @@ -348,6 +372,7 @@ Each of these is silent in at least one component, which is why the symptom is t
| Login completes, then bounces back to the login screen | The browser is discarding a `Secure` cookie over a non-trustworthy origin. You are on plain HTTP somewhere other than a loopback address. |
| Identity provider rejects the redirect | Either `redirect_uri` is `http://` (requirement 1 or 4), or it is correct and simply not registered for the client (requirement 5). Check which before changing proxy settings — with the bundled realm, an unregistered callback is the likelier cause. |
| Login redirects to an address the browser cannot resolve | The IdP is advertising a hostname only the containers can reach — requirement 5, point 1. |
| Sign-in callback answers 502, the terminator logs `upstream sent too big header` | The terminator's header buffers are at nginx's defaults and the session cookies do not fit. Raise them as in [nginx proxy manager](#nginx-proxy-manager). |
| Login round-trip lands on a backend port | `Host` was rewritten — requirement 2. |
| Services refuse to start | `SPIRE_TRUSTED_PROXIES` is unset — requirement 4. This one is loud, by design. |
| Everything starts, but `redirect_uri` is `http://` anyway | `SPIRE_TRUSTED_PROXIES` is *set but wrong* — it does not cover the dashboard's actual address, so the headers are distrusted. A Docker range carried into Kubernetes does this. |
Expand Down
39 changes: 38 additions & 1 deletion spire-ui/src/components/ActorPicker.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, fireEvent, screen, within } from '@testing-library/react';
import { act, fireEvent, screen, waitFor, within } from '@testing-library/react';

import { beforeEach, expect, test, vi } from 'vitest';
import ActorPicker from './ActorPicker';
Expand Down Expand Up @@ -116,3 +116,40 @@ test('edits a repository deny with the stored version', async () => {
handle: '@TEST-person', providerUserId: '900123', effect: 'DENY', revision: 2,
});
});

// Removing a person changes who may command the bot, so the row's Remove only asks.
async function askToRemove(repositoryId?: string) {
vi.mocked(api.fetchActors).mockResolvedValue({ revision: 1, actors: [stored] });
vi.mocked(api.deleteActor).mockResolvedValue(undefined as never);
renderWithQuery(<ActorPicker accountId="TEST-account" accountType="github" repositoryId={repositoryId} />);
const row = await screen.findByRole('button', { name: 'Remove @TEST-person' });
await waitFor(() => expect(row).toBeEnabled());
await user.click(row);
return screen.getByRole('dialog');
}

test('asks before removing an allowed person, naming what it means', async () => {
const dialog = await askToRemove();
expect(dialog).toHaveTextContent('Remove @TEST-person from the allowed people? Their review commands and conversations are no longer accepted until they are added again.');
expect(api.deleteActor).not.toHaveBeenCalled();
});

test('asks before removing a fix override, naming what it means', async () => {
const dialog = await askToRemove('TEST-repo');
expect(dialog).toHaveTextContent('Remove the override for @TEST-person? Whether they may use /fix on this repository is decided by their push access again.');
expect(api.deleteActor).not.toHaveBeenCalled();
});

test('removes the person once the dialog is confirmed', async () => {
const dialog = await askToRemove();
await user.click(within(dialog).getByRole('button', { name: 'Remove' }));
expect(api.deleteActor).toHaveBeenCalledWith('/api/providers/TEST-account/actors', stored, 1);
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
});

test('keeps the person when the dialog is cancelled', async () => {
const dialog = await askToRemove();
await user.click(within(dialog).getByRole('button', { name: 'Cancel' }));
expect(screen.queryByRole('dialog')).toBeNull();
expect(api.deleteActor).not.toHaveBeenCalled();
});
24 changes: 18 additions & 6 deletions spire-ui/src/components/ActorPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useEffect, useMemo, useState } from 'react';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { invalidateLive, writeLive } from '../liveCache';
import { actorLabel, actorPath, actorsKey, deleteActor, fetchActors, resolveActor, saveActor, type Actor, type ActorPolicy } from './actorsApi';
import { actorLabel, actorPath, actorsKey, deleteActor, fetchActors, resolveActor, saveActor, type Actor, type ActorDisplay, type ActorPolicy } from './actorsApi';
import { fetchRepositories, repositoriesKey } from './repositories/repositoriesApi';
import ConfirmDialog from './ConfirmDialog';

interface Props {
accountId: string;
Expand Down Expand Up @@ -36,6 +37,8 @@ export default function ActorPicker({ accountId, accountType, repositoryId }: Pr
?? (read.error ? String(read.error) : null)
?? (scopeAsked && repositoriesRead.error ? String(repositoriesRead.error) : null);
const [busy, setBusy] = useState(false);
// Removing a person changes who may command the bot, so it waits for a yes.
const [removing, setRemoving] = useState<ActorDisplay | null>(null);

async function load(refresh = false) {
if (!refresh) { await invalidateLive(client, actorsKey(path)); return; }
Expand Down Expand Up @@ -65,6 +68,13 @@ export default function ActorPicker({ accountId, accountType, repositoryId }: Pr
} catch (failure) { setError(String(failure)); }
finally { setBusy(false); }
}
// A failed remove stays in the dialog, so it can be tried again or cancelled.
async function remove(actor: ActorDisplay) {
if (!policy) return;
setError(null);
await deleteActor(path, actor, repositoryId ? actor.revision : policy.revision);
await load();
}
function chooseScope() {
// Each click asks again, as it always did; the cached list fills the select meanwhile.
if (scopeAsked) void invalidateLive(client, repositoriesKey);
Expand Down Expand Up @@ -95,12 +105,14 @@ export default function ActorPicker({ accountId, accountType, repositoryId }: Pr
{error && <p className="prov-error" role="alert">{error}</p>}
{policy ? <ul>{policy.actors.map(actor => <li key={actor.providerUserId}>
<span>{actorLabel(actor)}</span> — {actor.effect === 'DENY' ? 'Denied' : 'Allowed'}{actor.stale && <span> · stale display; refresh by ID</span>}
<button className="btn-ghost" type="button" disabled={busy || !current} onClick={async () => {
setBusy(true); setError(null);
try { await deleteActor(path, actor, repositoryId ? actor.revision : policy.revision); await load(); }
catch (failure) { setError(String(failure)); } finally { setBusy(false); }
}}>Remove {actorLabel(actor)}</button>
<button className="btn-ghost" type="button" disabled={busy || !current} onClick={() => setRemoving(actor)}>Remove {actorLabel(actor)}</button>
</li>)}</ul> : <p>People have not loaded.</p>}
<button className="btn-ghost" type="button" disabled={busy} onClick={() => { setError(null); void load(true); }}>Reload people and refresh names</button>
{removing && <ConfirmDialog title={repositoryId ? 'Remove fix override' : 'Remove allowed person'}
message={repositoryId
? `Remove the override for ${actorLabel(removing)}? Whether they may use /fix on this repository is decided by their push access again.`
: `Remove ${actorLabel(removing)} from the allowed people? Their review commands and conversations are no longer accepted until they are added again.`}
confirmLabel="Remove" busyLabel="Removing…" danger
onConfirm={() => remove(removing)} onClose={() => setRemoving(null)} />}
</section>;
}
51 changes: 51 additions & 0 deletions spire-ui/src/components/OperatorLinksTable.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { describe, it, expect, vi } from 'vitest';
import { render, screen, waitFor, fireEvent, within } from '@testing-library/react';
import { OperatorLinksTable } from './OperatorLinksTable';
import * as api from '../api';

/**
* Unlinking stops an operator seeing their own numbers for that account, so the trash icon only
* asks; nothing is unlinked until the dialog's Unlink is pressed.
*/

const LINKS: api.OperatorIdentityLink[] = [
{ oidcSubject: 'TEST-SUBJECT-1', providerType: 'github', authorId: '3218389', authorHandle: 'TEST-handle' },
];
const OPERATORS: api.SeenOperator[] = [
{ subject: 'TEST-SUBJECT-1', username: 'test-user-one', displayName: 'TEST Operator One' },
];

function renderTable(onUnlinked = vi.fn()) {
render(<OperatorLinksTable links={LINKS} operators={OPERATORS} candidates={[]} onUnlinked={onUnlinked} />);
fireEvent.click(screen.getByRole('button', { name: 'Unlink TEST-SUBJECT-1 on github' }));
return screen.getByRole('dialog');
}

describe('OperatorLinksTable unlinking', () => {
it('asks first, naming the operator and the account', () => {
const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined);

expect(renderTable()).toHaveTextContent('Unlink TEST Operator One · test-user-one from github · TEST-handle?');
expect(unlink).not.toHaveBeenCalled();
});

it('unlinks once the dialog is confirmed', async () => {
const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined);
const onUnlinked = vi.fn();

fireEvent.click(within(renderTable(onUnlinked)).getByRole('button', { name: 'Unlink' }));

await waitFor(() => expect(unlink).toHaveBeenCalledWith('TEST-SUBJECT-1', 'github'));
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
expect(onUnlinked).toHaveBeenCalled();
});

it('keeps the link when the dialog is cancelled', () => {
const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined);

fireEvent.click(within(renderTable()).getByRole('button', { name: 'Cancel' }));

expect(screen.queryByRole('dialog')).toBeNull();
expect(unlink).not.toHaveBeenCalled();
});
});
105 changes: 105 additions & 0 deletions spire-ui/src/components/OperatorLinksTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { useState } from 'react';
import { Trash2 } from 'lucide-react';
import { ObservedAuthor, OperatorIdentityLink, SeenOperator, unlinkOperatorIdentity } from '../api';
import ConfirmDialog from './ConfirmDialog';
import { NameWithId } from './NameWithId';

interface Props {
links: OperatorIdentityLink[];
operators: SeenOperator[];
candidates: ObservedAuthor[];
onUnlinked: () => void;
}

/**
* The operator-to-account links, each with an Unlink that waits for a yes: an unlinked operator stops seeing their own
* numbers for that account until somebody links it again.
*/
export function OperatorLinksTable({ links, operators, candidates, onUnlinked }: Props) {
const [unlinking, setUnlinking] = useState<OperatorIdentityLink | null>(null);

// A failed unlink stays in the dialog, so it can be tried again or cancelled.
const unlink = async (link: OperatorIdentityLink) => {
await unlinkOperatorIdentity(link.oidcSubject, link.providerType);
onUnlinked();
};

return (
<>
<table className="prov-table">
<thead>
<tr>
<th>Operator</th>
<th>Platform</th>
<th>SCM account</th>
<th className="cell-r" />
</tr>
</thead>
<tbody>
{links.map((link) => (
<tr key={`${link.oidcSubject}-${link.providerType}`}>
<td>
<NameWithId name={operatorName(operators, link.oidcSubject)} id={link.oidcSubject} />
</td>
<td>{link.providerType}</td>
<td>
<NameWithId name={nameFor(candidates, link)} id={link.authorId} />
</td>
<td className="cell-r">
<button
className="iconbtn"
aria-label={`Unlink ${link.oidcSubject} on ${link.providerType}`}
onClick={() => setUnlinking(link)}
>
<Trash2 size={15} />
</button>
</td>
</tr>
))}
</tbody>
</table>

{unlinking && (
<ConfirmDialog
title="Unlink operator account"
message={`Unlink ${operatorName(operators, unlinking.oidcSubject)} from ${unlinking.providerType} · ${nameFor(candidates, unlinking)}? They no longer see their own activity for that account until it is linked again.`}
confirmLabel="Unlink"
busyLabel="Unlinking…"
danger
onConfirm={() => unlink(unlinking)}
onClose={() => setUnlinking(null)}
/>
)}
</>
);
}

/**
* Name first, username second, and the opaque subject only when there is nothing else to show.
*
* The username is empty when the identity provider's login is an email address (it is never stored),
* so the name stands alone then.
*/
export function labelFor(operator: SeenOperator): string {
if (operator.displayName && operator.username && operator.displayName !== operator.username) {
return `${operator.displayName} · ${operator.username}`;
}
return operator.displayName || operator.username || operator.subject;
}

function operatorName(operators: SeenOperator[], subject: string): string {
const match = operators.find((o) => o.subject === subject);
return match ? labelFor(match) : subject;
}

/**
* The login the operator proved by signing in, else the name the reviews recorded, else the id
* (a link made by hand for an author no review has seen).
*/
function nameFor(candidates: ObservedAuthor[], link: OperatorIdentityLink): string {
if (link.authorHandle) return link.authorHandle;
const match = candidates.find(
(c) => c.providerType === link.providerType && c.authorId === link.authorId,
);
return match ? match.displayName : link.authorId;
}
79 changes: 79 additions & 0 deletions spire-ui/src/components/PromptDetail.reset.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { describe, it, expect, vi } from 'vitest';
import { fireEvent, screen, waitFor, within } from '@testing-library/react';
import { MemoryRouter, Route, Routes } from 'react-router';
import PromptDetail from './PromptDetail';
import * as api from '../api';
import { renderWithQuery } from '../test/queryWrapper';

/**
* Reset to default deletes the custom text saved for the scope, and nothing keeps a copy, so the
* button only asks; the prompt is reset when the dialog's Reset is pressed.
*/

function customizedView(): api.PromptView {
return {
kind: 'review',
scope: '*',
inheritedFrom: 'global',
customized: true,
system: 'TEST persona',
body: 'Diff:\n{{diff}}',
updatedAt: '2026-08-20T10:00:00Z',
palette: [],
lockedSuffixPreview: 'TEST suffix',
baseKnown: true,
defaultDrifted: false,
currentDefaultSystem: 'TEST default persona',
currentDefaultBody: 'Diff:\n{{diff}}',
baseSystem: 'TEST default persona',
baseBody: 'Diff:\n{{diff}}',
};
}

function renderPrompt() {
vi.spyOn(api, 'fetchPrompt').mockResolvedValue(customizedView());
renderWithQuery(
<MemoryRouter initialEntries={['/settings/prompts/review']}>
<Routes>
<Route path="/settings/prompts/:kind" element={<PromptDetail />} />
</Routes>
</MemoryRouter>,
);
}

describe('reset to default', () => {
it('asks first, naming the prompt and what is lost', async () => {
const reset = vi.spyOn(api, 'resetPrompt').mockResolvedValue();
renderPrompt();

fireEvent.click(await screen.findByRole('button', { name: /reset to default/i }));

expect(screen.getByRole('dialog')).toHaveTextContent(
'Reset Review to its default? The custom text saved for this scope is deleted and cannot be restored.',
);
expect(reset).not.toHaveBeenCalled();
});

it('resets once the dialog is confirmed', async () => {
const reset = vi.spyOn(api, 'resetPrompt').mockResolvedValue();
renderPrompt();

fireEvent.click(await screen.findByRole('button', { name: /reset to default/i }));
fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Reset' }));

await waitFor(() => expect(reset).toHaveBeenCalledWith('review', '*'));
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
});

it('keeps the custom text when the dialog is cancelled', async () => {
const reset = vi.spyOn(api, 'resetPrompt').mockResolvedValue();
renderPrompt();

fireEvent.click(await screen.findByRole('button', { name: /reset to default/i }));
fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Cancel' }));

expect(screen.queryByRole('dialog')).toBeNull();
expect(reset).not.toHaveBeenCalled();
expect(screen.getByDisplayValue('TEST persona')).toBeInTheDocument();
});
});
Loading
Loading