Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
caeca80
feat(kin): live GitHub identity probe and hourly credential check
Surajsm60720 Nov 9, 2026
dd225bc
fix(kin): identity probe fails closed on every source it can't enumerate
Surajsm60720 Nov 9, 2026
51d70aa
fix(kin): identity probe checks an allowlist of host SSH and git config
Surajsm60720 Nov 9, 2026
294199e
Merge branch 'kin-appr-9-executor' into kin-appr-16-identity
Surajsm60720 Nov 9, 2026
fe59646
fix(kin): close the identity probe's round-3 review findings
Surajsm60720 Nov 9, 2026
c4b1134
test(kin): kill the probe's surviving PATH and owner-fill mutants
Surajsm60720 Nov 9, 2026
a4562be
fix(kin): a provider's PATH fails the check; projects may set their o…
Surajsm60720 Nov 9, 2026
3eb9bee
merge(kin): bring the APPR-9 executor and kin into APPR-16 identity
Surajsm60720 Nov 9, 2026
6eb0aca
merge(kin): bring the updated APPR-9 executor into APPR-16 identity
Surajsm60720 Nov 9, 2026
19b50fa
merge(kin): bring APPR-9's credentialCheck gate and executorLayer int…
Surajsm60720 Nov 9, 2026
bbd7402
merge(kin): bring current kin into APPR-16
Surajsm60720 Nov 9, 2026
06f4c26
Merge remote-tracking branch 'origin/kin' into t3/github-identity-sec…
Surajsm60720 Nov 9, 2026
5d21e63
fix(kin): close round-4 credential check gaps
Surajsm60720 Nov 9, 2026
c95fe87
chore(kin): merge kin into appr-16-identity
Surajsm60720 Nov 10, 2026
df17872
chore(kin): merge kin into appr-16-identity
Surajsm60720 Nov 10, 2026
cce2c48
chore(kin): merge kin into appr-16-identity
Surajsm60720 Nov 12, 2026
e3a68b0
chore(kin): merge kin into appr-16-identity
Surajsm60720 Nov 16, 2026
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
1 change: 1 addition & 0 deletions apps/server/src/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ describe("Kin chat file URLs", () => {
const layerRouteServices = Layer.mergeAll(
Layer.succeed(KinServer)({
taskCardUpdater: Layer.empty,
t3GitHubCredential: Layer.empty,
services: Option.some(kin as unknown as Context.Context<KinServices>),
subscribeForViewer: Option.none(),
}),
Expand Down
11 changes: 11 additions & 0 deletions apps/server/src/kin/KinServer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
import type * as Layer from "effect/Layer";
import type { ProjectStoreV2 } from "../orchestration-v2/ProjectStore.ts";
import type { OrchestratorV2 } from "../orchestration-v2/Orchestrator.ts";
import * as Context from "effect/Context";
import * as Option from "effect/Option";
Expand Down Expand Up @@ -65,6 +67,15 @@ export class KinServer extends Context.Service<
KinServer,
{
readonly taskCardUpdater: Layer.Layer<never, never, OrchestratorV2>;
/**
* Installs T3's own credential reader into the executor's slot. The slot stays out of
* `services`, so nothing holding them can install a reader that hides T3's tokens first.
*/
readonly t3GitHubCredential: Layer.Layer<
never,
never,
SourceControlHost.SourceControlHost | ProjectStoreV2
>;
readonly services: Option.Option<Context.Context<Services>>;
readonly subscribeForViewer: Option.Option<KinChatHub["Service"]["subscribeForViewer"]>;
}
Expand Down
149 changes: 129 additions & 20 deletions apps/server/src/kin/approvals/ActionExecutor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "@t3tools/contracts";
import { encodeGrantSigningInput } from "@t3tools/shared/kinGrant";
import * as Clock from "effect/Clock";
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Context from "effect/Context";
import * as ConfigProvider from "effect/ConfigProvider";
import * as Deferred from "effect/Deferred";
Expand All @@ -21,6 +22,7 @@ import * as Fiber from "effect/Fiber";
import * as Layer from "effect/Layer";
import * as Logger from "effect/Logger";
import * as Option from "effect/Option";
import * as Queue from "effect/Queue";
import * as Redacted from "effect/Redacted";
import * as Schema from "effect/Schema";
import * as SqlClient from "effect/sql/SqlClient";
Expand All @@ -32,6 +34,7 @@ import * as KinBotReads from "../github/KinBotReads.ts";
import * as KinGitHubApp from "../github/KinGitHubApp.ts";
import * as OwnerMergeClient from "../github/OwnerMergeClient.ts";
import {
BOT_ID,
fakeGitHub,
memoryKeychain,
scopeLayer,
Expand Down Expand Up @@ -246,6 +249,15 @@ function harness(
readonly outcome: string;
readonly note?: string;
}> = [];
// What the owner is told about the credential check; `posted` lets a test await each one.
const credentialNotices: {
readonly sent: Array<{
readonly orgId: string;
readonly failures: ReadonlyArray<string>;
readonly recoveredFrom?: number;
}>;
posted?: (failures: ReadonlyArray<string>) => Effect.Effect<unknown>;
} = { sent: [] };
const noticed = Deferred.makeUnsafe<void>();
// Each credential check runs `during` with its count; `failing` makes the identity unreadable.
const checks: {
Expand Down Expand Up @@ -306,25 +318,28 @@ function harness(
Layer.provide(Layer.mergeAll(app, github.layer, keychain.layer, scope)),
);
const identity = Layer.succeed(CredentialHygiene.T3GitHubIdentity, {
identities: Effect.suspend(() => {
checks.count += 1;
return checks.during?.(checks.count) ?? Effect.void;
}).pipe(
Effect.andThen(() =>
checks.failing
? Effect.fail(new CredentialHygiene.T3GitHubIdentityError({ cause: "probe failed" }))
: Effect.succeed({
t3: Option.some({ login: "kin-bot", source: "app" }),
ghAccounts: ["kin-bot"],
gitCredential: Option.none(),
ssh: ["git@github.com: Permission denied (publickey)."],
}),
identities: () =>
Effect.suspend(() => {
checks.count += 1;
return checks.during?.(checks.count) ?? Effect.void;
}).pipe(
Effect.andThen(() =>
checks.failing
? Effect.fail(new CredentialHygiene.T3GitHubIdentityError({ cause: "probe failed" }))
: Effect.succeed({
t3: [{ login: "kin-bot", id: BOT_ID, source: "app" }],
ghAccounts: ["kin-bot"],
gitCredential: Option.none(),
gitCredentialFor: [],
ssh: ["git@github.com: Permission denied (publickey)."],
providerEnvironments: [],
}),
),
),
),
});
const hygiene = CredentialHygiene.layer.pipe(
Layer.provide(identity),
Layer.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} }))),
Layer.provide(Layer.succeed(HostProcess.Environment, {})),
Layer.provide(scope),
);
const handlers = Layer.effect(
Expand All @@ -341,6 +356,14 @@ function harness(
const notifications = Layer.succeed(
KinExecutionNotices,
KinExecutionNotices.of({
credentialCheck: ({ orgId: org, report, recoveredFrom }) =>
Effect.sync(() =>
credentialNotices.sent.push({
orgId: org,
failures: report.failures,
...(recoveredFrom === undefined ? {} : { recoveredFrom }),
}),
).pipe(Effect.andThen(credentialNotices.posted?.(report.failures) ?? Effect.void)),
finished: ({ action, outcome, note }) =>
Effect.sync(
() =>
Expand Down Expand Up @@ -397,6 +420,7 @@ function harness(
world,
requests: github.requests,
notices,
credentialNotices,
noticed,
checks,
mints,
Expand Down Expand Up @@ -806,6 +830,8 @@ describe("KinActionExecutor", () => {
// Check 1 runs before the claim, check 2 right after it; each case changes state there.
const afterClaim = (source: string, change: Effect.Effect<unknown>) =>
Effect.gen(function* () {
// Past the shared probe's lifetime, so the pre-claim check probes again as check 1.
yield* TestClock.adjust("1 minute");
checks.count = 0;
checks.during = (count) => (count === 2 ? change : Effect.void);
const ref = yield* approvedMerge(source);
Expand Down Expand Up @@ -981,10 +1007,14 @@ describe("KinActionExecutor", () => {
);
assert.deepStrictEqual(
failed.map((entry) => entry.result),
["identity_unknown"],
// The probe's fixed reason rides along, so the owner can see which source failed.
["identity_unknown: probe failed"],
);
// Fixed before the grant lapses: it runs.
// Both holds within the minute shared one probe.
assert.strictEqual(checks.count, 1);
// Fixed before the grant lapses: the next tick's check sees it, and it runs.
checks.failing = false;
yield* TestClock.adjust("1 minute");
assert.deepInclude(yield* executor.execute(ref), { outcome: "succeeded" });
assert.deepStrictEqual(writes(requests), [`PUT ${PULL}/merge`]);
}).pipe(Effect.provide(layer));
Expand Down Expand Up @@ -1372,6 +1402,72 @@ describe("KinActionExecutor", () => {
}).pipe(Effect.provide(deps));
});

it.effect(
"the worker checks credentials at startup and hourly, telling the owner of changes",
() => {
const { checks, credentialNotices, deps } = harness();
return Effect.gen(function* () {
yield* seed;
const posted = yield* Queue.unbounded<ReadonlyArray<string>>();
credentialNotices.posted = (failures) => Queue.offer(posted, failures);
checks.failing = true;
yield* Effect.gen(function* () {
yield* ActionExecutor.KinActionExecutor;
assert.deepStrictEqual(yield* Queue.take(posted), ["identity_unknown"]);
// An unchanged hour stays quiet; the next one that passes says so.
yield* TestClock.adjust("1 hour");
assert.strictEqual(checks.count, 2);
checks.failing = false;
yield* TestClock.adjust("1 hour");
assert.deepStrictEqual(yield* Queue.take(posted), []);
}).pipe(Effect.provide(ActionExecutor.layer), Effect.scoped);
assert.strictEqual(checks.count, 3);
const failed = (yield* auditEntries).filter(
(entry) => entry.event === "credential_check_failed",
);
assert.deepStrictEqual(
failed.map((entry) => [entry.actionId, entry.result]),
[[undefined, "identity_unknown: probe failed"]],
);
assert.deepStrictEqual(credentialNotices.sent, [
{ orgId, failures: ["identity_unknown"] },
{ orgId, failures: [], recoveredFrom: failed[0]!.seq as number },
]);
}).pipe(Effect.provide(deps));
},
);

it.effect("tells only orgs with a merge token, and only of changes across restarts", () => {
const { checks, credentialNotices, deps } = harness();
return Effect.gen(function* () {
const { sql } = yield* seed;
// An org that never saved a merge token hasn't set GitHub up: no notice, no audit.
yield* sql`INSERT INTO kin_orgs (org_id, name, created_at)
VALUES ('org_02', 'Other', '2026-11-07T00:00:00.000Z')`;
checks.failing = true;
yield* (yield* ActionExecutor.make).checkCredentials;
assert.deepStrictEqual(credentialNotices.sent, [{ orgId, failures: ["identity_unknown"] }]);
const others = yield* sql`SELECT seq FROM kin_audit WHERE org_id = 'org_02'`;
assert.lengthOf(others, 0);
// Restarted while still failing: the owner already heard, so no second notice or entry.
for (const _ of [1, 2]) yield* (yield* ActionExecutor.make).checkCredentials;
assert.lengthOf(credentialNotices.sent, 1);
const [failure, ...again] = (yield* auditEntries).filter(
(entry) => entry.event === "credential_check_failed",
);
assert.lengthOf(again, 0);

// Restarted after the fix: each new executor says it passes again, under one notice id.
checks.failing = false;
yield* TestClock.adjust("1 minute");
for (const _ of [1, 2]) yield* (yield* ActionExecutor.make).checkCredentials;
assert.deepStrictEqual(credentialNotices.sent.slice(1), [
{ orgId, failures: [], recoveredFrom: failure!.seq as number },
{ orgId, failures: [], recoveredFrom: failure!.seq as number },
]);
}).pipe(Effect.provide(deps));
});

it.effect("the worker executes an approval as it lands", () => {
const { requests, deps } = harness();
return Effect.gen(function* () {
Expand Down Expand Up @@ -1416,6 +1512,8 @@ describe("KinActionExecutor", () => {
yield* Effect.gen(function* () {
yield* ActionExecutor.KinActionExecutor;
yield* TestClock.adjust("1 second");
// Past the startup check's shared probe, so the pre-claim check probes again as check 1.
yield* TestClock.adjust("1 minute");
// The first run's post-claim credential check never returns, so it holds the org's lock.
checks.count = 0;
checks.during = (count) => (count === 2 ? Effect.never : Effect.void);
Expand Down Expand Up @@ -1544,11 +1642,14 @@ describe("KinActionExecutor", () => {
KinExecutionNotices,
KinExecutionNotices.of({
finished: () => Effect.void,
credentialCheck: () => Effect.void,
lapsed: ({ holdReason }) => Effect.sync(() => void lapses.push(holdReason)),
}),
),
Layer.succeed(KinKeyNotices, KinKeyNotices.of({ changed: () => Effect.void })),
ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })),
// The hygiene check reads the server's environment; this one sets nothing.
Layer.succeed(HostProcess.Environment, {}),
KeySeal.layerTest(),
Sqlite.layerMemory,
),
Expand Down Expand Up @@ -1623,6 +1724,12 @@ describe("KinActionExecutor", () => {

it.effect("a configured host holds GitHub kinds on the missing identity probe", () => {
const lapses: Array<string> = [];
const identityUnavailable = Layer.succeed(CredentialHygiene.T3GitHubIdentity, {
identities: () =>
Effect.fail(
new CredentialHygiene.T3GitHubIdentityError({ cause: "the identity probe is missing" }),
),
});
const github = fakeGitHub(() => ({ status: 404, body: { message: "Not Found" } }));
const platform = Layer.mergeAll(
Layer.succeed(KinGitHubApp.KinGitHubAppConfig, { appId: "1" }),
Expand All @@ -1640,7 +1747,7 @@ describe("KinActionExecutor", () => {
return Effect.gen(function* () {
yield* TestClock.setTime(NOW);
const context = yield* Layer.build(
production(ApprovalsLayer.makeExecutorLayer(platform), lapses),
production(ApprovalsLayer.makeExecutorLayer(platform, identityUnavailable), lapses),
);
yield* Effect.gen(function* () {
yield* seed;
Expand All @@ -1651,11 +1758,13 @@ describe("KinActionExecutor", () => {
(yield* auditEntries)
.filter((entry) => entry.event === "credential_check_failed")
.map((entry) => entry.result),
["identity_unknown"],
["identity_unknown: the identity probe is missing"],
);
yield* TestClock.adjust("16 minutes");
assert.deepInclude(yield* stateOf(ref), { state: "voided", reason: "grant_expired" });
assert.deepStrictEqual(lapses, ["credential_check_failed: identity_unknown"]);
assert.deepStrictEqual(lapses, [
"credential_check_failed: identity_unknown: the identity probe is missing",
]);
}).pipe(Effect.provide(context));
assert.deepStrictEqual(github.requests, []);
}).pipe(Effect.scoped);
Expand Down
Loading