Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
352c26e
docs(kin): a resubmitted accepted grant fails check 6 as replayed (AP…
Surajsm60720 Nov 8, 2026
bd49173
feat(kin): verify approval grants and serve challenge, submitGrant an…
Surajsm60720 Nov 8, 2026
af56c1c
Merge remote-tracking branch 'origin/kin-appr-5-approver-keys' into k…
Surajsm60720 Nov 8, 2026
ccf0dc3
fix(kin): close the grant verifier's security review findings (APPR-4)
Surajsm60720 Nov 8, 2026
ac851c3
Merge remote-tracking branch 'origin/kin-appr-5-approver-keys' into k…
Surajsm60720 Nov 8, 2026
51d029f
Merge remote-tracking branch 'origin/kin-appr-5-approver-keys' into k…
Surajsm60720 Nov 8, 2026
b725c9f
fix(kin): cap every kind of grant rejection in the audit; reject repo…
Surajsm60720 Nov 8, 2026
a5bb52a
Merge origin/kin-appr-5-approver-keys into kin-appr-4-grant-verifier
Surajsm60720 Nov 8, 2026
1ce521e
fix(kin): follow approval handlers through the makeKinHandlers aggreg…
Surajsm60720 Nov 8, 2026
18179e2
Merge branch 'kin-appr-5-approver-keys' into kin-appr-4-grant-verifier
Surajsm60720 Nov 8, 2026
088b453
Merge branch 'kin-appr-5-approver-keys' into kin-appr-4-grant-verifier
Surajsm60720 Nov 8, 2026
c95f250
fix(kin): check 10 re-reads key revocation through relay sessions
Surajsm60720 Nov 8, 2026
0f0befb
Merge branch 'kin-appr-5-approver-keys' into kin-appr-4-grant-verifier
Surajsm60720 Nov 8, 2026
67da33d
fix(kin): recheck the signing key when claiming a grant
Surajsm60720 Nov 8, 2026
1e79706
docs(kin): note that claim rechecks the signing key
Surajsm60720 Nov 8, 2026
209d066
chore: merge kin-appr-5-approver-keys into kin-appr-4-grant-verifier
Surajsm60720 Nov 8, 2026
1911840
chore: merge kin-appr-5-approver-keys into kin-appr-4-grant-verifier
Surajsm60720 Nov 8, 2026
1792446
fix(kin): pass GrantVerifier into approval handlers with the other Ki…
Surajsm60720 Nov 8, 2026
7d0833e
chore: merge kin-appr-5-approver-keys into kin-appr-4-grant-verifier
Surajsm60720 Nov 8, 2026
0ab9723
chore: merge kin-appr-5-approver-keys into kin-appr-4-grant-verifier
Surajsm60720 Nov 8, 2026
9d4623d
Merge branch 'kin-appr-5-approver-keys' into kin-appr-4-grant-verifier
Surajsm60720 Nov 8, 2026
7003bfd
test(server): cover grant RPCs refusing as disabled when Kin is off
Surajsm60720 Nov 8, 2026
5492da7
Merge branch 'kin-appr-5-approver-keys' into kin-appr-4-grant-verifier
Surajsm60720 Nov 8, 2026
f3407a2
Merge branch 'kin-appr-5-approver-keys' into kin-appr-4-grant-verifier
Surajsm60720 Nov 8, 2026
96f4eeb
test(kin): mirror APPR-6's full-hash grant vectors
Surajsm60720 Nov 8, 2026
b9dcc4e
Merge kin-appr-5-approver-keys and origin/kin into kin-appr-4-grant-v…
GLDRoger Nov 9, 2026
eb69a90
test(kin): the MCP reachability guard also forbids approver keys, the…
GLDRoger Nov 9, 2026
7a00a32
Merge remote-tracking branch 'origin/kin' into kin-appr-4-grant-verifier
GLDRoger Nov 9, 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
4 changes: 3 additions & 1 deletion apps/server/src/kin/KinServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { KinChatHub } from "./chat/KinChatHub.ts";
import { KinBudget } from "./lead/KinBudget.ts";
import { KinEventQueue } from "./lead/KinEventQueue.ts";
import { ApproverKeys } from "./approvals/ApproverKeys.ts";
import { GrantVerifier } from "./approvals/GrantVerifier.ts";
import { KinStop } from "./lead/KinStop.ts";
import type { KinGithubWebhookLock } from "./triggers/githubWebhooks.ts";

Expand All @@ -19,7 +20,8 @@ export type Services =
| KinChatHub
| KinStop
| KinGithubWebhookLock
| ApproverKeys;
| ApproverKeys
| GrantVerifier;

export class KinServer extends Context.Service<
KinServer,
Expand Down
14 changes: 6 additions & 8 deletions apps/server/src/kin/approvals/ApproverKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import {
KinEventId,
ThreadId,
type AuthSessionId,
type Hex64,
type KinActionKind,
type KinApprovalsConfirmKeyInput,
type KinApprovalsKeyChallengeResult,
type KinApprovalsKeyInput,
Expand Down Expand Up @@ -46,7 +44,11 @@ import {
verifyAppleAppAttest,
type AttestationResult,
} from "./attestation/verify.ts";
import { KIN_APPROVER_KEYS_REQUESTER, KinPendingActions } from "./PendingActions.ts";
import {
KIN_APPROVER_KEYS_REQUESTER,
KinPendingActions,
kinTargetDigest,
} from "./PendingActions.ts";

const CHALLENGE_TTL_MS = 5 * 60 * 1000;
const CONFIRM_TTL_MS = 10 * 60 * 1000;
Expand Down Expand Up @@ -120,10 +122,6 @@ export const kinKeyConfirmationCode = (thumbprint: string, challenge: Uint8Array
return String(digest.readUInt32BE(0) % 1_000_000).padStart(6, "0");
};

/** `sha256(stableStringify({kind, target, headSha?, base?}))`, approvals spec section 3. */
const kinTargetDigest = (kind: KinActionKind, target: KinActionTarget): Hex64 =>
NodeCrypto.createHash("sha256").update(stableStringify({ kind, target })).digest("hex");

const toKey = (row: KeyRow) =>
decodeKey({
orgId: row.org_id,
Expand Down Expand Up @@ -397,7 +395,7 @@ const make = Effect.gen(function* () {
kind: "register_approver_key",
target,
resolved: { _tag: "none" },
targetDigest: kinTargetDigest("register_approver_key", target),
targetDigest: kinTargetDigest("register_approver_key", target, { _tag: "none" }),
reason: `Add approver key for "${input.deviceLabel}".`,
requestedBy: SERVER_REQUESTER,
provenance: {
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/kin/approvals/Audit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const seed = Effect.gen(function* () {
yield* sql`INSERT INTO kin_orgs (org_id, name, created_at) VALUES
('org_01', 'Kin', '2026-11-07T00:00:00.000Z'),
('org_02', 'Other', '2026-11-07T00:00:00.000Z')`;
// Check 10 approves only while the signing key is active.
yield* sql`INSERT INTO kin_approver_keys (thumbprint, org_id, public_jwk_json, human_id,
device_label, platform, hardware, attested, state, created_at)
VALUES (${kid}, 'org_01', '{}', ${owner}, 'Pixel 9', 'android', 'tee', 1, 'active', 0)`;
return yield* KinAudit;
});

Expand Down
108 changes: 108 additions & 0 deletions apps/server/src/kin/approvals/GrantPorts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import {
KinApprovalError,
KinPersonId,
type KinActionKind,
type KinActionTarget,
type KinOrgId,
type KinResolvedTarget,
} from "@t3tools/contracts";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Schema from "effect/Schema";
import * as SqlClient from "effect/sql/SqlClient";

import { toPersistenceSqlError } from "../../persistence/Errors.ts";
import { KinAudit, type KinAuditAppendInput } from "./Audit.ts";

/** The verifier's rejection trace: the refusal is already decided, so a lost entry is only logged. */
export class KinGrantAudit extends Context.Service<
KinGrantAudit,
{ readonly append: (input: KinAuditAppendInput) => Effect.Effect<void> }
>()("t3/kin/approvals/GrantPorts/KinGrantAudit") {}

export const auditLayer = Layer.effect(
KinGrantAudit,
Effect.gen(function* () {
const audit = yield* KinAudit;
return KinGrantAudit.of({
append: Effect.fn("KinGrantAudit.append")(function* (entry) {
yield* audit
.append(entry)
.pipe(
Effect.catch((error) =>
Effect.logWarning(`Kin audit: ${entry.event} not written`, error),
),
);
}),
});
}),
);

/** Grant check 4's role lookup: never from the grant or the client, only stored identity. */
export class KinOrgRoles extends Context.Service<
KinOrgRoles,
{
readonly isOwner: (ref: {
readonly orgId: KinOrgId;
readonly personId: KinPersonId;
}) => Effect.Effect<boolean, KinApprovalError>;
}
>()("t3/kin/approvals/GrantPorts/KinOrgRoles") {}

// Phase 1 (chat spec, Identity): the org owner is the reserved person bootstrap creates.
// Phase 2 replaces this with org membership.
export const BOOTSTRAP_OWNER = Schema.decodeSync(KinPersonId)("kin-default-owner");

export const orgRolesLayer = Layer.effect(
KinOrgRoles,
Effect.gen(function* () {
const sql = yield* SqlClient.SqlClient;
return KinOrgRoles.of({
isOwner: Effect.fn("KinOrgRoles.isOwner")(
function* (ref) {
if (ref.personId !== BOOTSTRAP_OWNER) return false;
const rows = yield* sql`SELECT 1 FROM kin_people
WHERE org_id = ${ref.orgId} AND person_id = ${ref.personId}`;
return rows.length > 0;
},
Effect.catch((cause) =>
Effect.logWarning(
"KinOrgRoles.isOwner failed",
toPersistenceSqlError("KinOrgRoles.isOwner")(cause),
).pipe(
Effect.andThen(
Effect.fail(
new KinApprovalError({ reason: "unavailable", message: "Org roles unavailable." }),
),
),
),
),
),
});
}),
);

/** Grant check 9: the server's own read of the PR or branch, with the bot's credential. */
export class KinLiveTargets extends Context.Service<
KinLiveTargets,
{
readonly resolve: (input: {
readonly kind: KinActionKind;
readonly target: KinActionTarget;
}) => Effect.Effect<KinResolvedTarget, KinApprovalError>;
}
>()("t3/kin/approvals/GrantPorts/KinLiveTargets") {}

// Fails closed until APPR-8's installation tokens back it: no live read, no approval.
export const liveTargetsUnconfiguredLayer = Layer.succeed(
KinLiveTargets,
KinLiveTargets.of({
resolve: Effect.fn("KinLiveTargets.resolve")(function* () {
return yield* new KinApprovalError({
reason: "unavailable",
message: "Kin can't read GitHub yet, so it can't approve this.",
});
}),
}),
);
Loading