ai-saas-guard 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -5
- package/README.zh-CN.md +7 -3
- package/dist/hosted/github-app.d.ts +69 -0
- package/dist/hosted/github-app.js +135 -0
- package/dist/hosted/service.d.ts +116 -0
- package/dist/hosted/service.js +250 -0
- package/docs/github-action.md +1 -1
- package/docs/github-app-deployment.md +79 -0
- package/docs/github-app-design.md +5 -1
- package/docs/hosted-service-runtime.md +86 -0
- package/docs/npm-publishing.md +3 -3
- package/docs/project-handoff.md +4 -2
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -73,8 +73,8 @@ The CLI is published on npm as `ai-saas-guard`, and the GitHub Action is availab
|
|
|
73
73
|
| JSON and SARIF output | Available |
|
|
74
74
|
| Composite GitHub Action | Available |
|
|
75
75
|
| Project config | `.ai-saas-guard.json` rule toggles, severity overrides, and fail thresholds |
|
|
76
|
-
| Versioned Action tags | `v0.
|
|
77
|
-
| npm package | `ai-saas-guard@0.
|
|
76
|
+
| Versioned Action tags | `v0.18.0`, `v0` |
|
|
77
|
+
| npm package | `ai-saas-guard@0.18.0` |
|
|
78
78
|
| npm publishing | Trusted Publisher/OIDC, no long-lived publish token |
|
|
79
79
|
|
|
80
80
|
## Quick Start
|
|
@@ -208,19 +208,23 @@ The first hosted service slice is defined in [docs/hosted-first-service-slice.md
|
|
|
208
208
|
|
|
209
209
|
The hosted deployment model is documented in [docs/hosted-deployment-model.md](docs/hosted-deployment-model.md). It chooses a containerized Node.js ingress and worker model with a managed durable queue, platform secret manager, structured redacted logs, installation/repository rate limits, and rollback/incident response paths.
|
|
210
210
|
|
|
211
|
+
The hosted service runtime is documented in [docs/hosted-service-runtime.md](docs/hosted-service-runtime.md). It exports `createHostedServiceRuntime` from `ai-saas-guard/hosted/service` and implements the provider-independent service core for signed webhook intake, idempotent queue upsert, read-only worker orchestration, compact report storage, Check Run publication adapters, and worker cleanup planning. It does not deploy a public hosted environment by itself.
|
|
212
|
+
|
|
213
|
+
The hosted GitHub App deployment planner is documented in [docs/github-app-deployment.md](docs/github-app-deployment.md). It exports `planHostedGitHubAppDeployment` from `ai-saas-guard/hosted/github-app`, generates the least-privilege manifest for the first hosted slice, and blocks creation when the release gate, HTTPS URLs, container digest, secret references, permissions, or events are incomplete or unsafe.
|
|
214
|
+
|
|
211
215
|
The hosted operational release gate is documented in [docs/hosted-operational-release-gate.md](docs/hosted-operational-release-gate.md). It defines the hosted-specific CI, replay, queue, worker cleanup, privacy, monitoring, rollback, and incident-response evidence required before any hosted environment is exposed to users. The pure gate evaluator exported from `ai-saas-guard/hosted/contracts` blocks hosted exposure unless every P0 evidence item is fresh, a container digest is recorded, and release notes avoid pentest, certification, and full-audit claims.
|
|
212
216
|
|
|
213
217
|
Hosted uninstall and data deletion behavior is documented in [docs/hosted-uninstall-data-deletion.md](docs/hosted-uninstall-data-deletion.md). It defines repository removal, full app uninstall, compact report deletion, queue cancellation, audit record retention, repeated cleanup, and user-facing deletion wording.
|
|
214
218
|
|
|
215
219
|
Hosted pricing and packaging boundaries are documented in [docs/hosted-pricing-packaging.md](docs/hosted-pricing-packaging.md). Core local scanning stays useful without an account; hosted plans may add workflow convenience, saved reports, team policy, and optional human review, but they do not gate local CLI scanning.
|
|
216
220
|
|
|
217
|
-
Hosted pre-implementation pure contracts are documented in [docs/hosted-preimplementation-contracts.md](docs/hosted-preimplementation-contracts.md). They now include a pull request webhook intake planner that verifies signatures before parsing or queueing, a durable scan queue planner that reuses queued, running, and completed jobs for the same trusted scan key, a worker read-only scan planner that fixes the CLI command and requires repository `contents: read`, and a Check Run publication planner that requires repository `checks: write` and builds bounded check-only payloads from compact reports. They also cover queue-safe webhook event parsing, bounded check-run summary rendering, idempotent queue cleanup planning, worker checkout cleanup planning, a retention/deletion cleanup planner, and an operational release gate evaluator that requires fresh CI, replay, static-check, dependency, container, cleanup, privacy, monitoring, rollback, incident-response, and release-cleanup evidence before hosted exposure. PR comments remain a later workflow or paid hosted feature, not part of the hosted MVP contract.
|
|
221
|
+
Hosted pre-implementation pure contracts are documented in [docs/hosted-preimplementation-contracts.md](docs/hosted-preimplementation-contracts.md). They now include a pull request webhook intake planner that verifies signatures before parsing or queueing, a durable scan queue planner that reuses queued, running, and completed jobs for the same trusted scan key, a worker read-only scan planner that fixes the CLI command and requires repository `contents: read`, and a Check Run publication planner that requires repository `checks: write` and builds bounded check-only payloads from compact reports. They also cover queue-safe webhook event parsing, bounded check-run summary rendering, idempotent queue cleanup planning, worker checkout cleanup planning, a retention/deletion cleanup planner, and an operational release gate evaluator that requires fresh CI, replay, static-check, dependency, container, cleanup, privacy, monitoring, rollback, incident-response, and release-cleanup evidence before hosted exposure. The service runtime composes these contracts behind replaceable adapters. PR comments remain a later workflow or paid hosted feature, not part of the hosted MVP contract.
|
|
218
222
|
|
|
219
223
|
A public hosted compact report schema fixture is available at [examples/hosted-compact-report.json](examples/hosted-compact-report.json). It is synthetic and public-safe: compact evidence only, no raw source, raw diffs, secrets, webhook payload bodies, customer payloads, private URLs, or worker checkout paths.
|
|
220
224
|
|
|
221
225
|
The proposed hosted app permission boundary is intentionally narrow: repository contents read, pull requests read, checks write, and metadata read for the first version. Optional PR comments require repository policy opt-in, and broad permissions such as administration, deployments, Actions write, and repository secrets are out of scope.
|
|
222
226
|
|
|
223
|
-
The repository also includes
|
|
227
|
+
The repository also includes hosted contract helpers and runtime tests for webhook intake order, webhook verification, installation token scoping, durable queue idempotency, compact reports, retention limits, uninstall cleanup, repeated cleanup idempotency, scoped deletion planning, operational release gate blocking, provider-independent hosted service orchestration, and GitHub App deployment planning. These helpers do not deploy a public hosted service.
|
|
224
228
|
|
|
225
229
|
Users should prefer the local CLI for private repositories, offline review, or no-account workflows where hosted code processing is not acceptable.
|
|
226
230
|
|
|
@@ -254,7 +258,7 @@ Use `suppressions` for narrower false-positive handling when one rule is noisy o
|
|
|
254
258
|
|
|
255
259
|
## GitHub Action
|
|
256
260
|
|
|
257
|
-
The repo includes a composite Action. Use `v0` for the latest compatible pre-1.0 Action, a specific release tag such as `v0.
|
|
261
|
+
The repo includes a composite Action. Use `v0` for the latest compatible pre-1.0 Action, a specific release tag such as `v0.18.0` for controlled upgrades, or pin a reviewed commit SHA for stricter supply-chain control:
|
|
258
262
|
|
|
259
263
|
```yaml
|
|
260
264
|
name: ai-saas-guard
|
package/README.zh-CN.md
CHANGED
|
@@ -55,7 +55,7 @@ AI 能很快把一个 SaaS 从想法做成可运行的产品。真正难的是
|
|
|
55
55
|
|
|
56
56
|
这个仓库是公开 GitHub 仓库。
|
|
57
57
|
|
|
58
|
-
CLI 已发布到 npm:`ai-saas-guard@0.
|
|
58
|
+
CLI 已发布到 npm:`ai-saas-guard@0.18.0`。GitHub Action 支持 `v0` 浮动标签,也支持固定版本标签,例如 `v0.18.0`。
|
|
59
59
|
|
|
60
60
|
| 模块 | 状态 |
|
|
61
61
|
| --- | --- |
|
|
@@ -66,8 +66,8 @@ CLI 已发布到 npm:`ai-saas-guard@0.16.0`。GitHub Action 支持 `v0` 浮动
|
|
|
66
66
|
| Markdown PR summary | 已可用 |
|
|
67
67
|
| GitHub Action | 已可用 |
|
|
68
68
|
| 项目配置 | `.ai-saas-guard.json` 支持规则开关、severity 覆盖和 fail threshold |
|
|
69
|
-
| 当前版本 | `0.
|
|
70
|
-
| Action 标签 | `v0.
|
|
69
|
+
| 当前版本 | `0.18.0` |
|
|
70
|
+
| Action 标签 | `v0.18.0`、`v0` |
|
|
71
71
|
| npm 发布 | GitHub Actions Trusted Publisher/OIDC,无需长期 npm token |
|
|
72
72
|
|
|
73
73
|
## 快速开始
|
|
@@ -243,8 +243,10 @@ jobs:
|
|
|
243
243
|
相关文档:
|
|
244
244
|
|
|
245
245
|
- [docs/github-app-design.md](docs/github-app-design.md)
|
|
246
|
+
- [docs/github-app-deployment.md](docs/github-app-deployment.md)
|
|
246
247
|
- [docs/hosted-first-service-slice.md](docs/hosted-first-service-slice.md)
|
|
247
248
|
- [docs/hosted-deployment-model.md](docs/hosted-deployment-model.md)
|
|
249
|
+
- [docs/hosted-service-runtime.md](docs/hosted-service-runtime.md)
|
|
248
250
|
- [docs/hosted-operational-release-gate.md](docs/hosted-operational-release-gate.md)
|
|
249
251
|
- [docs/hosted-uninstall-data-deletion.md](docs/hosted-uninstall-data-deletion.md)
|
|
250
252
|
- [docs/hosted-pricing-packaging.md](docs/hosted-pricing-packaging.md)
|
|
@@ -255,6 +257,8 @@ jobs:
|
|
|
255
257
|
- pull request webhook intake planner:先验签,再解析 payload、生成可信 identity、校验 selected-repository scope,并默认只走 check-run-only 输出
|
|
256
258
|
- durable scan queue planner:同一个 trusted scan key 的 queued/running/completed job 会复用,不重复排 worker,也不会把源码、diff、secret 或 PR 正文放进队列 payload
|
|
257
259
|
- worker read-only scan planner:只用 trusted identity 规划临时 worker checkout,要求 repository `contents: read`,固定运行 `ai-saas-guard pr-risk --json`,并忽略 PR 正文里的 repo 名、token scope 或命令
|
|
260
|
+
- hosted service runtime:`ai-saas-guard/hosted/service` 导出 `createHostedServiceRuntime`,把签名 webhook intake、幂等 queue upsert、read-only worker 编排、compact report 存储、Check Run 发布 adapter 和 worker cleanup 串成可测试的服务核心;它本身不部署公开 hosted 环境
|
|
261
|
+
- GitHub App deployment planner:`ai-saas-guard/hosted/github-app` 导出 `planHostedGitHubAppDeployment`,生成 first slice 最小权限 manifest,并在 release gate、HTTPS URL、container digest、secret 引用、permission 或 event 不安全时阻止创建
|
|
258
262
|
- webhook event parser
|
|
259
263
|
- check-run summary renderer
|
|
260
264
|
- Check Run publication planner:要求 repository `checks: write`,只从 compact report 生成有长度上限的 Check Run payload,包含 review categories、优先 review 文件、verification steps 和本地 CLI 复现命令;MVP 不发 PR comment
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export declare const HOSTED_GITHUB_APP_REQUIRED_PERMISSIONS: {
|
|
2
|
+
readonly contents: "read";
|
|
3
|
+
readonly pull_requests: "read";
|
|
4
|
+
readonly checks: "write";
|
|
5
|
+
readonly metadata: "read";
|
|
6
|
+
};
|
|
7
|
+
export declare const HOSTED_GITHUB_APP_EVENTS: readonly ["pull_request", "installation", "installation_repositories"];
|
|
8
|
+
export type HostedGitHubAppPermissionName = keyof typeof HOSTED_GITHUB_APP_REQUIRED_PERMISSIONS;
|
|
9
|
+
export type HostedGitHubAppPermissionValue = "read" | "write" | "none";
|
|
10
|
+
export type HostedGitHubAppEvent = (typeof HOSTED_GITHUB_APP_EVENTS)[number];
|
|
11
|
+
export interface HostedGitHubAppReleaseGateSummary {
|
|
12
|
+
shouldExposeHostedEnvironment: boolean;
|
|
13
|
+
blocked: boolean;
|
|
14
|
+
containerImageDigestRecorded: boolean;
|
|
15
|
+
missingEvidenceIds?: string[];
|
|
16
|
+
failedEvidenceIds?: string[];
|
|
17
|
+
staleEvidenceIds?: string[];
|
|
18
|
+
exceptionEvidenceIds?: string[];
|
|
19
|
+
releaseNotesCompliant?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface HostedGitHubAppSecretRefs {
|
|
22
|
+
appId: string;
|
|
23
|
+
privateKey: string;
|
|
24
|
+
webhookSecret: string;
|
|
25
|
+
}
|
|
26
|
+
export interface HostedGitHubAppDeploymentInput {
|
|
27
|
+
appName: string;
|
|
28
|
+
homepageUrl: string;
|
|
29
|
+
webhookUrl: string;
|
|
30
|
+
environment: string;
|
|
31
|
+
containerImageDigest: string;
|
|
32
|
+
secretRefs: HostedGitHubAppSecretRefs;
|
|
33
|
+
releaseGate: HostedGitHubAppReleaseGateSummary;
|
|
34
|
+
setupUrl?: string;
|
|
35
|
+
callbackUrl?: string;
|
|
36
|
+
requestedPermissions?: Record<string, HostedGitHubAppPermissionValue>;
|
|
37
|
+
requestedEvents?: string[];
|
|
38
|
+
rawPrivateKey?: string;
|
|
39
|
+
rawWebhookSecret?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface HostedGitHubAppManifest {
|
|
42
|
+
name: string;
|
|
43
|
+
url: string;
|
|
44
|
+
hook_attributes: {
|
|
45
|
+
url: string;
|
|
46
|
+
active: true;
|
|
47
|
+
};
|
|
48
|
+
redirect_url?: string;
|
|
49
|
+
setup_url?: string;
|
|
50
|
+
public: false;
|
|
51
|
+
default_permissions: typeof HOSTED_GITHUB_APP_REQUIRED_PERMISSIONS;
|
|
52
|
+
default_events: HostedGitHubAppEvent[];
|
|
53
|
+
}
|
|
54
|
+
export interface HostedGitHubAppDeploymentPlan {
|
|
55
|
+
readyToCreateGitHubApp: boolean;
|
|
56
|
+
blockedReasons: string[];
|
|
57
|
+
environment: string;
|
|
58
|
+
containerImageDigest: string;
|
|
59
|
+
manifest: HostedGitHubAppManifest;
|
|
60
|
+
requiredSecretRefs: string[];
|
|
61
|
+
deploymentSteps: string[];
|
|
62
|
+
privacy: {
|
|
63
|
+
includesPrivateKey: false;
|
|
64
|
+
includesWebhookSecret: false;
|
|
65
|
+
includesClientSecret: false;
|
|
66
|
+
includesCustomerPayloads: false;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export declare function planHostedGitHubAppDeployment(input: HostedGitHubAppDeploymentInput): HostedGitHubAppDeploymentPlan;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
export const HOSTED_GITHUB_APP_REQUIRED_PERMISSIONS = {
|
|
2
|
+
contents: "read",
|
|
3
|
+
pull_requests: "read",
|
|
4
|
+
checks: "write",
|
|
5
|
+
metadata: "read"
|
|
6
|
+
};
|
|
7
|
+
export const HOSTED_GITHUB_APP_EVENTS = [
|
|
8
|
+
"pull_request",
|
|
9
|
+
"installation",
|
|
10
|
+
"installation_repositories"
|
|
11
|
+
];
|
|
12
|
+
export function planHostedGitHubAppDeployment(input) {
|
|
13
|
+
const blockedReasons = [
|
|
14
|
+
...releaseGateBlockedReasons(input.releaseGate),
|
|
15
|
+
...containerDigestBlockedReasons(input.containerImageDigest),
|
|
16
|
+
...urlBlockedReasons("homepage_url", input.homepageUrl),
|
|
17
|
+
...urlBlockedReasons("webhook_url", input.webhookUrl),
|
|
18
|
+
...optionalUrlBlockedReasons("setup_url", input.setupUrl),
|
|
19
|
+
...optionalUrlBlockedReasons("callback_url", input.callbackUrl),
|
|
20
|
+
...secretRefBlockedReasons(input.secretRefs),
|
|
21
|
+
...permissionBlockedReasons(input.requestedPermissions),
|
|
22
|
+
...eventBlockedReasons(input.requestedEvents)
|
|
23
|
+
];
|
|
24
|
+
const manifest = {
|
|
25
|
+
name: input.appName.trim() || "AI SaaS Guard Hosted",
|
|
26
|
+
url: input.homepageUrl,
|
|
27
|
+
hook_attributes: {
|
|
28
|
+
url: input.webhookUrl,
|
|
29
|
+
active: true
|
|
30
|
+
},
|
|
31
|
+
...(input.callbackUrl ? { redirect_url: input.callbackUrl } : {}),
|
|
32
|
+
...(input.setupUrl ? { setup_url: input.setupUrl } : {}),
|
|
33
|
+
public: false,
|
|
34
|
+
default_permissions: HOSTED_GITHUB_APP_REQUIRED_PERMISSIONS,
|
|
35
|
+
default_events: [...HOSTED_GITHUB_APP_EVENTS]
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
readyToCreateGitHubApp: blockedReasons.length === 0,
|
|
39
|
+
blockedReasons,
|
|
40
|
+
environment: input.environment,
|
|
41
|
+
containerImageDigest: input.containerImageDigest,
|
|
42
|
+
manifest,
|
|
43
|
+
requiredSecretRefs: safeSecretRefs(input.secretRefs),
|
|
44
|
+
deploymentSteps: [
|
|
45
|
+
"Create the GitHub App from the generated least-privilege manifest.",
|
|
46
|
+
"Store the App ID, private key, and webhook secret in the platform secret manager.",
|
|
47
|
+
"Deploy webhook ingress and scan worker containers with the recorded image digest.",
|
|
48
|
+
"Run the hosted operational release gate against the deployed artifact before exposure."
|
|
49
|
+
],
|
|
50
|
+
privacy: {
|
|
51
|
+
includesPrivateKey: false,
|
|
52
|
+
includesWebhookSecret: false,
|
|
53
|
+
includesClientSecret: false,
|
|
54
|
+
includesCustomerPayloads: false
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function releaseGateBlockedReasons(gate) {
|
|
59
|
+
return gate.shouldExposeHostedEnvironment &&
|
|
60
|
+
!gate.blocked &&
|
|
61
|
+
gate.containerImageDigestRecorded &&
|
|
62
|
+
gate.releaseNotesCompliant !== false
|
|
63
|
+
? []
|
|
64
|
+
: ["release_gate_blocked"];
|
|
65
|
+
}
|
|
66
|
+
function containerDigestBlockedReasons(containerImageDigest) {
|
|
67
|
+
return /^sha256:[a-f0-9]{64}$/i.test(containerImageDigest)
|
|
68
|
+
? []
|
|
69
|
+
: ["invalid_container_image_digest"];
|
|
70
|
+
}
|
|
71
|
+
function urlBlockedReasons(name, value) {
|
|
72
|
+
return isSafeHttpsUrl(value) ? [] : [`invalid_${name}`];
|
|
73
|
+
}
|
|
74
|
+
function optionalUrlBlockedReasons(name, value) {
|
|
75
|
+
if (!value) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
return urlBlockedReasons(name, value);
|
|
79
|
+
}
|
|
80
|
+
function isSafeHttpsUrl(value) {
|
|
81
|
+
try {
|
|
82
|
+
const url = new URL(value);
|
|
83
|
+
return url.protocol === "https:" && url.hostname !== "localhost" && url.hostname !== "127.0.0.1";
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function secretRefBlockedReasons(secretRefs) {
|
|
90
|
+
const reasons = [];
|
|
91
|
+
for (const key of ["appId", "privateKey", "webhookSecret"]) {
|
|
92
|
+
const value = secretRefs[key];
|
|
93
|
+
if (!value.trim()) {
|
|
94
|
+
reasons.push(`missing_secret_ref:${key}`);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (looksLikeRawSecretMaterial(value)) {
|
|
98
|
+
reasons.push(`raw_secret_material:${key}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return reasons;
|
|
102
|
+
}
|
|
103
|
+
function looksLikeRawSecretMaterial(value) {
|
|
104
|
+
return /-----BEGIN [A-Z ]*PRIVATE KEY-----|whsec_|gh[opurs]_|github_pat_/i.test(value);
|
|
105
|
+
}
|
|
106
|
+
function permissionBlockedReasons(requestedPermissions) {
|
|
107
|
+
if (!requestedPermissions) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
const reasons = [];
|
|
111
|
+
for (const permission of Object.keys(requestedPermissions).sort()) {
|
|
112
|
+
if (!(permission in HOSTED_GITHUB_APP_REQUIRED_PERMISSIONS)) {
|
|
113
|
+
reasons.push(`permission_not_allowed:${permission}`);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const requiredValue = HOSTED_GITHUB_APP_REQUIRED_PERMISSIONS[permission];
|
|
117
|
+
if (requestedPermissions[permission] !== requiredValue) {
|
|
118
|
+
reasons.push(`permission_not_allowed:${permission}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return reasons;
|
|
122
|
+
}
|
|
123
|
+
function eventBlockedReasons(requestedEvents) {
|
|
124
|
+
if (!requestedEvents) {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
const allowedEvents = new Set(HOSTED_GITHUB_APP_EVENTS);
|
|
128
|
+
return [...new Set(requestedEvents)]
|
|
129
|
+
.filter((event) => !allowedEvents.has(event))
|
|
130
|
+
.sort()
|
|
131
|
+
.map((event) => `event_not_allowed:${event}`);
|
|
132
|
+
}
|
|
133
|
+
function safeSecretRefs(secretRefs) {
|
|
134
|
+
return [secretRefs.appId, secretRefs.privateKey, secretRefs.webhookSecret].filter((value) => value.trim() && !looksLikeRawSecretMaterial(value));
|
|
135
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type CompactHostedFinding, type CompactHostedReport, type HostedCheckRunPublicationPlan, type HostedScanQueueRecord, type HostedScanQueueUpsertDecision, type HostedWorkerCheckoutCleanupPlan, type HostedWorkerReadOnlyScanPlan } from "./contracts.js";
|
|
2
|
+
type RepositoryIdSource = Record<number, number[]> | Map<number, number[]>;
|
|
3
|
+
export interface HostedServiceWebhookRequest {
|
|
4
|
+
payload: string | Buffer;
|
|
5
|
+
signatureHeader?: string;
|
|
6
|
+
deliveryId?: string;
|
|
7
|
+
manualRerun?: boolean;
|
|
8
|
+
allowDraft?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type HostedServiceWebhookStage = "signature" | "payload" | "event" | "installation_scope" | "queue";
|
|
11
|
+
export interface HostedServiceWebhookResult {
|
|
12
|
+
accepted: boolean;
|
|
13
|
+
stage: HostedServiceWebhookStage;
|
|
14
|
+
reason?: string;
|
|
15
|
+
deliveryId?: string;
|
|
16
|
+
queueDecision?: HostedScanQueueUpsertDecision;
|
|
17
|
+
shouldFetchRepository: boolean;
|
|
18
|
+
shouldCreateCheckRun: boolean;
|
|
19
|
+
shouldCreatePrComment: false;
|
|
20
|
+
privacy: {
|
|
21
|
+
includesRawWebhookPayload: false;
|
|
22
|
+
includesUntrustedPrText: false;
|
|
23
|
+
includesRawSource: false;
|
|
24
|
+
includesRawDiffs: false;
|
|
25
|
+
includesSecrets: false;
|
|
26
|
+
includesCustomerPayloads: false;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface HostedServiceQueueAdapter {
|
|
30
|
+
records: Map<string, HostedScanQueueRecord>;
|
|
31
|
+
}
|
|
32
|
+
export interface HostedCompactReportStoreRecord {
|
|
33
|
+
id: string;
|
|
34
|
+
jobKey: string;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
report: CompactHostedReport;
|
|
37
|
+
}
|
|
38
|
+
export interface HostedCompactReportStore {
|
|
39
|
+
records?: HostedCompactReportStoreRecord[];
|
|
40
|
+
save(record: HostedCompactReportStoreRecord): Promise<void> | void;
|
|
41
|
+
}
|
|
42
|
+
export interface HostedCheckRunRequest {
|
|
43
|
+
method: "POST";
|
|
44
|
+
endpoint: string;
|
|
45
|
+
payload: NonNullable<HostedCheckRunPublicationPlan["request"]>["payload"];
|
|
46
|
+
}
|
|
47
|
+
export interface HostedCheckRunPublisher {
|
|
48
|
+
requests?: HostedCheckRunRequest[];
|
|
49
|
+
publish(request: HostedCheckRunRequest): Promise<void> | void;
|
|
50
|
+
}
|
|
51
|
+
export interface HostedServiceScanRunnerResult {
|
|
52
|
+
summaryCounts: Record<string, number>;
|
|
53
|
+
findings: CompactHostedFinding[];
|
|
54
|
+
retentionDays?: number;
|
|
55
|
+
rawSource?: string;
|
|
56
|
+
rawDiff?: string;
|
|
57
|
+
secretValues?: string[];
|
|
58
|
+
customerPayload?: unknown;
|
|
59
|
+
}
|
|
60
|
+
export interface HostedServiceScanRunnerInput {
|
|
61
|
+
plan: HostedWorkerReadOnlyScanPlan & {
|
|
62
|
+
accepted: true;
|
|
63
|
+
};
|
|
64
|
+
queueRecord: HostedScanQueueRecord;
|
|
65
|
+
}
|
|
66
|
+
export type HostedServiceScanRunner = (input: HostedServiceScanRunnerInput) => Promise<HostedServiceScanRunnerResult> | HostedServiceScanRunnerResult;
|
|
67
|
+
export interface HostedServiceRuntimeOptions {
|
|
68
|
+
signingKey: string | Buffer;
|
|
69
|
+
scannerVersion: string;
|
|
70
|
+
selectedRepositoryIdsByInstallation: RepositoryIdSource;
|
|
71
|
+
removedRepositoryIdsByInstallation?: RepositoryIdSource;
|
|
72
|
+
queue: HostedServiceQueueAdapter;
|
|
73
|
+
compactReportStore: HostedCompactReportStore;
|
|
74
|
+
checkRunPublisher: HostedCheckRunPublisher;
|
|
75
|
+
scanRunner: HostedServiceScanRunner;
|
|
76
|
+
now?: () => string;
|
|
77
|
+
}
|
|
78
|
+
export interface HostedServiceRuntime {
|
|
79
|
+
handlePullRequestWebhook(request: HostedServiceWebhookRequest): HostedServiceWebhookResult;
|
|
80
|
+
runNextQueuedScan(): Promise<HostedServiceWorkerResult>;
|
|
81
|
+
}
|
|
82
|
+
export type HostedServiceWorkerResult = {
|
|
83
|
+
processed: false;
|
|
84
|
+
reason: "empty_queue";
|
|
85
|
+
} | {
|
|
86
|
+
processed: true;
|
|
87
|
+
status: "completed";
|
|
88
|
+
queueRecord: HostedScanQueueRecord;
|
|
89
|
+
workerPlan: HostedWorkerReadOnlyScanPlan & {
|
|
90
|
+
accepted: true;
|
|
91
|
+
};
|
|
92
|
+
report: CompactHostedReport;
|
|
93
|
+
checkRunPublication: HostedCheckRunPublicationPlan;
|
|
94
|
+
cleanup: HostedWorkerCheckoutCleanupPlan;
|
|
95
|
+
} | {
|
|
96
|
+
processed: true;
|
|
97
|
+
status: "failed";
|
|
98
|
+
queueRecord: HostedScanQueueRecord;
|
|
99
|
+
reason?: string;
|
|
100
|
+
errorClass: "worker_plan_rejected" | "check_run_publication_rejected" | "scan_runner_failed";
|
|
101
|
+
workerPlan?: HostedWorkerReadOnlyScanPlan;
|
|
102
|
+
checkRunPublication?: HostedCheckRunPublicationPlan;
|
|
103
|
+
cleanup?: HostedWorkerCheckoutCleanupPlan;
|
|
104
|
+
};
|
|
105
|
+
export interface InMemoryHostedServiceAdapters {
|
|
106
|
+
queue: HostedServiceQueueAdapter;
|
|
107
|
+
compactReportStore: HostedCompactReportStore & {
|
|
108
|
+
records: HostedCompactReportStoreRecord[];
|
|
109
|
+
};
|
|
110
|
+
checkRunPublisher: HostedCheckRunPublisher & {
|
|
111
|
+
requests: HostedCheckRunRequest[];
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export declare function createInMemoryHostedServiceAdapters(): InMemoryHostedServiceAdapters;
|
|
115
|
+
export declare function createHostedServiceRuntime(options: HostedServiceRuntimeOptions): HostedServiceRuntime;
|
|
116
|
+
export {};
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { authorizeInstallationTokenScope, createCompactHostedReport, createHostedWorkerCheckoutCleanupPlan, parseHostedPullRequestEvent, planHostedCheckRunPublication, planHostedScanQueueUpsert, planHostedWorkerReadOnlyScan, verifyGitHubWebhook } from "./contracts.js";
|
|
2
|
+
export function createInMemoryHostedServiceAdapters() {
|
|
3
|
+
const compactReportRecords = [];
|
|
4
|
+
const checkRunRequests = [];
|
|
5
|
+
return {
|
|
6
|
+
queue: { records: new Map() },
|
|
7
|
+
compactReportStore: {
|
|
8
|
+
records: compactReportRecords,
|
|
9
|
+
save(record) {
|
|
10
|
+
compactReportRecords.push(record);
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
checkRunPublisher: {
|
|
14
|
+
requests: checkRunRequests,
|
|
15
|
+
publish(request) {
|
|
16
|
+
checkRunRequests.push(request);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function createHostedServiceRuntime(options) {
|
|
22
|
+
const seenDeliveryIds = new Set();
|
|
23
|
+
const now = options.now ?? (() => new Date().toISOString());
|
|
24
|
+
return {
|
|
25
|
+
handlePullRequestWebhook(request) {
|
|
26
|
+
const signatureDecision = verifyGitHubWebhook({
|
|
27
|
+
payload: request.payload,
|
|
28
|
+
signatureHeader: request.signatureHeader,
|
|
29
|
+
signingKey: options.signingKey,
|
|
30
|
+
deliveryId: request.deliveryId,
|
|
31
|
+
seenDeliveryIds
|
|
32
|
+
});
|
|
33
|
+
if (!signatureDecision.accepted) {
|
|
34
|
+
return rejectWebhookRequest("signature", signatureDecision.reason ?? "invalid_signature", request.deliveryId);
|
|
35
|
+
}
|
|
36
|
+
if (!request.deliveryId) {
|
|
37
|
+
return rejectWebhookRequest("event", "missing_delivery_id");
|
|
38
|
+
}
|
|
39
|
+
const parsedPayload = parseWebhookPayload(request.payload);
|
|
40
|
+
if (!parsedPayload) {
|
|
41
|
+
return rejectWebhookRequest("payload", "invalid_json", request.deliveryId);
|
|
42
|
+
}
|
|
43
|
+
const eventDecision = parseHostedPullRequestEvent({
|
|
44
|
+
payload: parsedPayload,
|
|
45
|
+
scannerVersion: options.scannerVersion,
|
|
46
|
+
allowDraft: request.allowDraft
|
|
47
|
+
});
|
|
48
|
+
if (!eventDecision.accepted || !eventDecision.identity) {
|
|
49
|
+
return rejectWebhookRequest("event", eventDecision.reason ?? "missing_required_field", request.deliveryId);
|
|
50
|
+
}
|
|
51
|
+
const selectedRepositoryIds = repositoryIdsFor(options.selectedRepositoryIdsByInstallation, eventDecision.identity.installationId);
|
|
52
|
+
const removedRepositoryIds = repositoryIdsFor(options.removedRepositoryIdsByInstallation, eventDecision.identity.installationId);
|
|
53
|
+
const scopeDecision = authorizeInstallationTokenScope({
|
|
54
|
+
identity: eventDecision.identity,
|
|
55
|
+
installationId: eventDecision.identity.installationId,
|
|
56
|
+
selectedRepositoryIds,
|
|
57
|
+
removedRepositoryIds
|
|
58
|
+
});
|
|
59
|
+
if (!scopeDecision.authorized) {
|
|
60
|
+
return rejectWebhookRequest("installation_scope", scopeDecision.reason ?? "repository_not_installed", request.deliveryId);
|
|
61
|
+
}
|
|
62
|
+
const queueDecision = planHostedScanQueueUpsert({
|
|
63
|
+
identity: eventDecision.identity,
|
|
64
|
+
deliveryId: request.deliveryId,
|
|
65
|
+
requestedAt: now(),
|
|
66
|
+
queue: options.queue.records,
|
|
67
|
+
manualRerun: request.manualRerun
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
accepted: true,
|
|
71
|
+
stage: "queue",
|
|
72
|
+
deliveryId: request.deliveryId,
|
|
73
|
+
queueDecision,
|
|
74
|
+
shouldFetchRepository: queueDecision.shouldEnqueueWorker,
|
|
75
|
+
shouldCreateCheckRun: queueDecision.shouldCreateCheckRun,
|
|
76
|
+
shouldCreatePrComment: false,
|
|
77
|
+
privacy: hostedServiceWebhookPrivacy()
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
async runNextQueuedScan() {
|
|
81
|
+
const queuedRecord = nextQueuedRecord(options.queue.records);
|
|
82
|
+
if (!queuedRecord) {
|
|
83
|
+
return { processed: false, reason: "empty_queue" };
|
|
84
|
+
}
|
|
85
|
+
const requestedAt = now();
|
|
86
|
+
queuedRecord.status = "running";
|
|
87
|
+
queuedRecord.updatedAt = requestedAt;
|
|
88
|
+
const selectedRepositoryIds = repositoryIdsFor(options.selectedRepositoryIdsByInstallation, queuedRecord.identity.installationId);
|
|
89
|
+
const removedRepositoryIds = repositoryIdsFor(options.removedRepositoryIdsByInstallation, queuedRecord.identity.installationId);
|
|
90
|
+
const workerPlan = planHostedWorkerReadOnlyScan({
|
|
91
|
+
identity: queuedRecord.identity,
|
|
92
|
+
jobKey: queuedRecord.key,
|
|
93
|
+
requestedAt,
|
|
94
|
+
installationId: queuedRecord.identity.installationId,
|
|
95
|
+
selectedRepositoryIds,
|
|
96
|
+
removedRepositoryIds,
|
|
97
|
+
installationTokenPermissions: { contents: "read" }
|
|
98
|
+
});
|
|
99
|
+
if (!workerPlan.accepted) {
|
|
100
|
+
queuedRecord.status = "failed";
|
|
101
|
+
queuedRecord.updatedAt = now();
|
|
102
|
+
return {
|
|
103
|
+
processed: true,
|
|
104
|
+
status: "failed",
|
|
105
|
+
queueRecord: cloneQueueRecord(queuedRecord),
|
|
106
|
+
reason: workerPlan.reason,
|
|
107
|
+
errorClass: "worker_plan_rejected",
|
|
108
|
+
workerPlan
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const acceptedWorkerPlan = workerPlan;
|
|
112
|
+
try {
|
|
113
|
+
const scanResult = await options.scanRunner({
|
|
114
|
+
plan: acceptedWorkerPlan,
|
|
115
|
+
queueRecord: cloneQueueRecord(queuedRecord)
|
|
116
|
+
});
|
|
117
|
+
const report = createCompactHostedReport({
|
|
118
|
+
identity: queuedRecord.identity,
|
|
119
|
+
summaryCounts: scanResult.summaryCounts,
|
|
120
|
+
findings: scanResult.findings,
|
|
121
|
+
retentionDays: scanResult.retentionDays,
|
|
122
|
+
rawDiff: scanResult.rawDiff,
|
|
123
|
+
secretValues: scanResult.secretValues,
|
|
124
|
+
customerPayload: scanResult.customerPayload
|
|
125
|
+
});
|
|
126
|
+
const reportId = `${queuedRecord.key}:${queuedRecord.attempt}`;
|
|
127
|
+
await options.compactReportStore.save({
|
|
128
|
+
id: reportId,
|
|
129
|
+
jobKey: queuedRecord.key,
|
|
130
|
+
createdAt: now(),
|
|
131
|
+
report
|
|
132
|
+
});
|
|
133
|
+
const checkRunPublication = planHostedCheckRunPublication({
|
|
134
|
+
identity: queuedRecord.identity,
|
|
135
|
+
report,
|
|
136
|
+
jobKey: queuedRecord.key,
|
|
137
|
+
requestedAt: now(),
|
|
138
|
+
installationId: queuedRecord.identity.installationId,
|
|
139
|
+
selectedRepositoryIds,
|
|
140
|
+
removedRepositoryIds,
|
|
141
|
+
installationTokenPermissions: { checks: "write" }
|
|
142
|
+
});
|
|
143
|
+
if (!checkRunPublication.accepted || !checkRunPublication.request) {
|
|
144
|
+
queuedRecord.status = "failed";
|
|
145
|
+
queuedRecord.updatedAt = now();
|
|
146
|
+
return {
|
|
147
|
+
processed: true,
|
|
148
|
+
status: "failed",
|
|
149
|
+
queueRecord: cloneQueueRecord(queuedRecord),
|
|
150
|
+
reason: checkRunPublication.reason,
|
|
151
|
+
errorClass: "check_run_publication_rejected",
|
|
152
|
+
workerPlan: acceptedWorkerPlan,
|
|
153
|
+
checkRunPublication
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
await options.checkRunPublisher.publish(checkRunPublication.request);
|
|
157
|
+
const cleanup = createHostedWorkerCheckoutCleanupPlan({
|
|
158
|
+
identity: queuedRecord.identity,
|
|
159
|
+
jobKey: queuedRecord.key,
|
|
160
|
+
terminalState: "success",
|
|
161
|
+
finishedAt: now()
|
|
162
|
+
});
|
|
163
|
+
queuedRecord.status = "completed";
|
|
164
|
+
queuedRecord.reportId = reportId;
|
|
165
|
+
queuedRecord.updatedAt = now();
|
|
166
|
+
return {
|
|
167
|
+
processed: true,
|
|
168
|
+
status: "completed",
|
|
169
|
+
queueRecord: cloneQueueRecord(queuedRecord),
|
|
170
|
+
workerPlan: acceptedWorkerPlan,
|
|
171
|
+
report,
|
|
172
|
+
checkRunPublication,
|
|
173
|
+
cleanup
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
const cleanup = createHostedWorkerCheckoutCleanupPlan({
|
|
178
|
+
identity: queuedRecord.identity,
|
|
179
|
+
jobKey: queuedRecord.key,
|
|
180
|
+
terminalState: "failure",
|
|
181
|
+
finishedAt: now()
|
|
182
|
+
});
|
|
183
|
+
queuedRecord.status = "failed";
|
|
184
|
+
queuedRecord.updatedAt = now();
|
|
185
|
+
return {
|
|
186
|
+
processed: true,
|
|
187
|
+
status: "failed",
|
|
188
|
+
queueRecord: cloneQueueRecord(queuedRecord),
|
|
189
|
+
errorClass: "scan_runner_failed",
|
|
190
|
+
workerPlan: acceptedWorkerPlan,
|
|
191
|
+
cleanup
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function rejectWebhookRequest(stage, reason, deliveryId) {
|
|
198
|
+
return {
|
|
199
|
+
accepted: false,
|
|
200
|
+
stage,
|
|
201
|
+
reason,
|
|
202
|
+
...(deliveryId === undefined ? {} : { deliveryId }),
|
|
203
|
+
shouldFetchRepository: false,
|
|
204
|
+
shouldCreateCheckRun: false,
|
|
205
|
+
shouldCreatePrComment: false,
|
|
206
|
+
privacy: hostedServiceWebhookPrivacy()
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function hostedServiceWebhookPrivacy() {
|
|
210
|
+
return {
|
|
211
|
+
includesRawWebhookPayload: false,
|
|
212
|
+
includesUntrustedPrText: false,
|
|
213
|
+
includesRawSource: false,
|
|
214
|
+
includesRawDiffs: false,
|
|
215
|
+
includesSecrets: false,
|
|
216
|
+
includesCustomerPayloads: false
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function parseWebhookPayload(payload) {
|
|
220
|
+
try {
|
|
221
|
+
return JSON.parse(Buffer.isBuffer(payload) ? payload.toString("utf8") : payload);
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function repositoryIdsFor(source, installationId) {
|
|
228
|
+
if (!source) {
|
|
229
|
+
return [];
|
|
230
|
+
}
|
|
231
|
+
if (source instanceof Map) {
|
|
232
|
+
return source.get(installationId) ?? [];
|
|
233
|
+
}
|
|
234
|
+
return source[installationId] ?? [];
|
|
235
|
+
}
|
|
236
|
+
function nextQueuedRecord(records) {
|
|
237
|
+
for (const record of records.values()) {
|
|
238
|
+
if (record.status === "queued") {
|
|
239
|
+
return record;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
function cloneQueueRecord(record) {
|
|
245
|
+
return {
|
|
246
|
+
...record,
|
|
247
|
+
identity: { ...record.identity },
|
|
248
|
+
deliveryIds: [...record.deliveryIds]
|
|
249
|
+
};
|
|
250
|
+
}
|
package/docs/github-action.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
`ai-saas-guard` ships as a composite GitHub Action for pull request and code scanning workflows.
|
|
4
4
|
|
|
5
|
-
Use `zr9959/ai-saas-guard@v0` for the latest compatible pre-1.0 Action. Use a specific tag such as `v0.
|
|
5
|
+
Use `zr9959/ai-saas-guard@v0` for the latest compatible pre-1.0 Action. Use a specific tag such as `v0.18.0` or a reviewed commit SHA when reproducibility is more important than automatic minor updates.
|
|
6
6
|
|
|
7
7
|
## PR Summary
|
|
8
8
|
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Hosted GitHub App Deployment
|
|
2
|
+
|
|
3
|
+
This document defines the GitHub App deployment planner now implemented in `src/hosted/github-app.ts`.
|
|
4
|
+
|
|
5
|
+
It does not create a GitHub App by itself. GitHub App creation still requires a real HTTPS webhook URL, a deployed hosted service artifact, platform secret storage, and a human owner or automation account with permission to create the app in GitHub. The planner makes those requirements explicit and blocks unsafe or incomplete deployment input.
|
|
6
|
+
|
|
7
|
+
## What Exists
|
|
8
|
+
|
|
9
|
+
The deployment planner exports `planHostedGitHubAppDeployment` from `ai-saas-guard/hosted/github-app`.
|
|
10
|
+
|
|
11
|
+
It creates a least-privilege GitHub App manifest for the first hosted slice:
|
|
12
|
+
|
|
13
|
+
- `contents: read`
|
|
14
|
+
- `pull_requests: read`
|
|
15
|
+
- `checks: write`
|
|
16
|
+
- `metadata: read`
|
|
17
|
+
|
|
18
|
+
Allowed events:
|
|
19
|
+
|
|
20
|
+
- `pull_request`
|
|
21
|
+
- `installation`
|
|
22
|
+
- `installation_repositories`
|
|
23
|
+
|
|
24
|
+
The manifest stays private by default and uses one active webhook URL.
|
|
25
|
+
|
|
26
|
+
## Required Inputs
|
|
27
|
+
|
|
28
|
+
A ready deployment plan requires:
|
|
29
|
+
|
|
30
|
+
- app name
|
|
31
|
+
- HTTPS homepage URL
|
|
32
|
+
- HTTPS webhook URL
|
|
33
|
+
- hosted environment name
|
|
34
|
+
- `sha256:<digest>` container image digest
|
|
35
|
+
- secret reference for GitHub App ID
|
|
36
|
+
- secret reference for GitHub App private key
|
|
37
|
+
- secret reference for webhook secret
|
|
38
|
+
- hosted operational release gate decision that allows hosted exposure
|
|
39
|
+
|
|
40
|
+
Secret references must be platform lookup names such as `platform-ref:github-app-key`, not raw secret values.
|
|
41
|
+
|
|
42
|
+
## Blockers
|
|
43
|
+
|
|
44
|
+
The planner blocks GitHub App creation when:
|
|
45
|
+
|
|
46
|
+
- the hosted release gate is blocked
|
|
47
|
+
- the container image digest is missing or malformed
|
|
48
|
+
- URLs are not HTTPS
|
|
49
|
+
- localhost URLs are used
|
|
50
|
+
- required secret references are missing
|
|
51
|
+
- raw private keys or webhook secrets are passed instead of secret references
|
|
52
|
+
- requested permissions exceed the first-slice permission contract
|
|
53
|
+
- requested events exceed the first-slice event contract
|
|
54
|
+
|
|
55
|
+
## Privacy
|
|
56
|
+
|
|
57
|
+
The deployment plan never returns:
|
|
58
|
+
|
|
59
|
+
- private key material
|
|
60
|
+
- webhook secret values
|
|
61
|
+
- client secret values
|
|
62
|
+
- customer payloads
|
|
63
|
+
|
|
64
|
+
It returns only safe manifest fields, blocker IDs, environment metadata, container digest, secret reference names, and deployment steps.
|
|
65
|
+
|
|
66
|
+
## Deployment Steps
|
|
67
|
+
|
|
68
|
+
When `readyToCreateGitHubApp` is true:
|
|
69
|
+
|
|
70
|
+
1. Create the GitHub App from the generated least-privilege manifest.
|
|
71
|
+
2. Store the App ID, private key, and webhook secret in the platform secret manager.
|
|
72
|
+
3. Deploy webhook ingress and scan worker containers with the recorded image digest.
|
|
73
|
+
4. Run the hosted operational release gate against the deployed artifact before exposure.
|
|
74
|
+
|
|
75
|
+
## Current Status
|
|
76
|
+
|
|
77
|
+
The repository can now produce and validate the deployment plan, but it cannot honestly create a live GitHub App until a public hosted webhook URL, container image digest, and secret manager references exist.
|
|
78
|
+
|
|
79
|
+
The next deployment stage should wire the hosted service runtime to a real platform queue, compact report store, GitHub installation authentication, and Checks API publisher.
|
|
@@ -50,13 +50,17 @@ The first hosted service slice is scoped in [docs/hosted-first-service-slice.md]
|
|
|
50
50
|
|
|
51
51
|
The hosted deployment model is scoped in [docs/hosted-deployment-model.md](hosted-deployment-model.md). It chooses containerized Node.js ingress and worker roles connected by a managed durable queue, with platform-managed secrets, structured redacted logs, installation/repository rate limits, rollback, and incident response paths.
|
|
52
52
|
|
|
53
|
+
The hosted service runtime is scoped in [docs/hosted-service-runtime.md](hosted-service-runtime.md). It implements the provider-independent core for signed webhook intake, idempotent queue upsert, read-only worker orchestration, compact report storage, Check Run publication adapters, and worker cleanup planning. It does not deploy a public hosted environment by itself.
|
|
54
|
+
|
|
55
|
+
The hosted GitHub App deployment planner is scoped in [docs/github-app-deployment.md](github-app-deployment.md). It generates the least-privilege first-slice manifest and blocks creation when release-gate evidence, HTTPS URLs, container digest, secret references, permissions, or events are incomplete or unsafe.
|
|
56
|
+
|
|
53
57
|
The hosted operational release gate is scoped in [docs/hosted-operational-release-gate.md](hosted-operational-release-gate.md). It blocks hosted exposure unless CI, webhook replay, signature verification, token scoping, idempotency, privacy and retention, worker cleanup, monitoring, alerting, rollback, and incident response evidence are fresh for the release candidate.
|
|
54
58
|
|
|
55
59
|
Hosted uninstall and data deletion behavior is scoped in [docs/hosted-uninstall-data-deletion.md](hosted-uninstall-data-deletion.md). It defines repository removal, full app uninstall, compact report deletion, queue cancellation, limited audit record retention, repeated cleanup idempotency, and user-facing deletion wording.
|
|
56
60
|
|
|
57
61
|
Hosted pricing and packaging boundaries are scoped in [docs/hosted-pricing-packaging.md](hosted-pricing-packaging.md). Core local scanning stays useful without an account; future hosted plans may charge for workflow convenience, saved reports, team policy, private repo hosted behavior, and optional human review, but not for access to useful local scanning.
|
|
58
62
|
|
|
59
|
-
Hosted pre-implementation pure contracts are scoped in [docs/hosted-preimplementation-contracts.md](hosted-preimplementation-contracts.md). They define service-free helpers such as queue-safe pull request event parsing, bounded check-run summary rendering, idempotent queue cleanup planning,
|
|
63
|
+
Hosted pre-implementation pure contracts are scoped in [docs/hosted-preimplementation-contracts.md](hosted-preimplementation-contracts.md). They define service-free helpers such as queue-safe pull request event parsing, bounded check-run summary rendering, idempotent queue cleanup planning, worker checkout cleanup planning, and operational release gate evaluation. The hosted service runtime composes those helpers behind replaceable adapters.
|
|
60
64
|
|
|
61
65
|
The hosted compact report schema fixture is published at [examples/hosted-compact-report.json](../examples/hosted-compact-report.json). It is synthetic and public-safe, and it documents the compact evidence shape without raw source, raw diffs, secrets, customer payloads, or worker checkout paths.
|
|
62
66
|
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Hosted Service Runtime
|
|
2
|
+
|
|
3
|
+
This document describes the first real hosted service runtime now implemented in `src/hosted/service.ts`.
|
|
4
|
+
|
|
5
|
+
It is not a public hosted deployment announcement. The runtime is a provider-independent service core that can be wired to a real queue, compact report store, GitHub Checks API client, and scanner worker in the next deployment stage. It does not deploy a public hosted environment.
|
|
6
|
+
|
|
7
|
+
## What Exists
|
|
8
|
+
|
|
9
|
+
The runtime exports `createHostedServiceRuntime` from `ai-saas-guard/hosted/service`.
|
|
10
|
+
|
|
11
|
+
It implements the first hosted service slice:
|
|
12
|
+
|
|
13
|
+
- signed GitHub App pull request webhook intake
|
|
14
|
+
- signature verification before JSON parsing, queue writes, repository lookup, token scope checks, or worker dispatch
|
|
15
|
+
- trusted scan identity from GitHub event fields only
|
|
16
|
+
- selected-repository installation authorization
|
|
17
|
+
- idempotent durable queue upsert through an adapter
|
|
18
|
+
- read-only worker planning
|
|
19
|
+
- scan runner adapter boundary
|
|
20
|
+
- compact report storage adapter boundary
|
|
21
|
+
- Check Run publication adapter boundary
|
|
22
|
+
- worker checkout cleanup planning after success or failure
|
|
23
|
+
|
|
24
|
+
## Runtime Roles
|
|
25
|
+
|
|
26
|
+
The service core keeps the two production roles from the deployment model:
|
|
27
|
+
|
|
28
|
+
- `webhook-ingress`: call `handlePullRequestWebhook`.
|
|
29
|
+
- `scan-worker`: call `runNextQueuedScan`.
|
|
30
|
+
|
|
31
|
+
The runtime does not start an HTTP server by itself. That keeps framework and cloud choices out of the package while preserving the exact trust-boundary order the hosted service needs.
|
|
32
|
+
|
|
33
|
+
## Adapter Boundaries
|
|
34
|
+
|
|
35
|
+
Production deployments must provide durable adapters:
|
|
36
|
+
|
|
37
|
+
- queue adapter backed by a managed durable queue or relational job table
|
|
38
|
+
- compact report store backed by managed storage
|
|
39
|
+
- Check Run publisher backed by GitHub App installation authentication
|
|
40
|
+
- scan runner backed by isolated worker checkout and the deterministic CLI
|
|
41
|
+
|
|
42
|
+
The exported `createInMemoryHostedServiceAdapters` is only for tests, local smoke runs, and examples. It is not a production queue or production data store.
|
|
43
|
+
|
|
44
|
+
## Privacy
|
|
45
|
+
|
|
46
|
+
The runtime intentionally returns safe planning and status objects only.
|
|
47
|
+
|
|
48
|
+
It does not return:
|
|
49
|
+
|
|
50
|
+
- raw webhook payloads
|
|
51
|
+
- untrusted PR text
|
|
52
|
+
- raw source
|
|
53
|
+
- raw diffs
|
|
54
|
+
- secrets
|
|
55
|
+
- customer payloads
|
|
56
|
+
- private checkout paths
|
|
57
|
+
- low-level worker exception messages
|
|
58
|
+
|
|
59
|
+
Compact reports continue to include only trusted identity, summary counts, rule IDs, compact evidence paths and line numbers, retention metadata, and model-training disabled status.
|
|
60
|
+
|
|
61
|
+
## Failure Behavior
|
|
62
|
+
|
|
63
|
+
Invalid webhooks stop at the signature stage and create no queue, worker, report, or Check Run side effects.
|
|
64
|
+
|
|
65
|
+
Worker failures are recorded with a cleanup-safe `scan_runner_failed` error class. The runtime still plans worker checkout deletion, but it does not expose raw exception text or private checkout paths.
|
|
66
|
+
|
|
67
|
+
## Tests
|
|
68
|
+
|
|
69
|
+
`tests/hosted-service.test.mjs` covers:
|
|
70
|
+
|
|
71
|
+
- a signed pull request webhook queues one idempotent job and the worker publishes one Check Run request
|
|
72
|
+
- duplicate deliveries reuse the logical queue record
|
|
73
|
+
- invalid signatures create no side effects
|
|
74
|
+
- worker failures preserve cleanup behavior without leaking private paths or low-level errors
|
|
75
|
+
|
|
76
|
+
## Deployment Status
|
|
77
|
+
|
|
78
|
+
This runtime makes the hosted service implementation-ready inside the repository. A public hosted environment still requires the next deployment stage:
|
|
79
|
+
|
|
80
|
+
- real GitHub App credentials
|
|
81
|
+
- platform secret manager
|
|
82
|
+
- managed queue
|
|
83
|
+
- compact report storage
|
|
84
|
+
- container image and digest
|
|
85
|
+
- live monitoring and rollback evidence
|
|
86
|
+
- hosted operational release gate evidence from the deployed artifact
|
package/docs/npm-publishing.md
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
## Current State
|
|
6
6
|
|
|
7
7
|
- Package name: `ai-saas-guard`
|
|
8
|
-
- Current version: `0.
|
|
8
|
+
- Current version: `0.18.0`
|
|
9
9
|
- npm registry state: published at <https://www.npmjs.com/package/ai-saas-guard>
|
|
10
10
|
- First npm-published version: `0.1.1`
|
|
11
|
-
- GitHub Release: `v0.
|
|
11
|
+
- GitHub Release: `v0.18.0`
|
|
12
12
|
- Publish workflow: `.github/workflows/npm-publish.yml`
|
|
13
13
|
- Trusted Publisher: GitHub Actions, `zr9959/ai-saas-guard`, workflow `npm-publish.yml`, allowed action `npm publish`
|
|
14
14
|
- Long-lived npm publish token: not required
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
Use GitHub Actions with npm Trusted Publisher/OIDC:
|
|
19
19
|
|
|
20
|
-
1. Create and review a release tag such as `v0.
|
|
20
|
+
1. Create and review a release tag such as `v0.18.0`.
|
|
21
21
|
2. Publish from the GitHub Release or run the `Publish npm` workflow manually with `ref` set to that tag.
|
|
22
22
|
3. Keep `permissions.id-token: write` in the workflow so npm can exchange the GitHub Actions OIDC identity for a short-lived publish credential.
|
|
23
23
|
4. Run `npm publish --access public` from the workflow. Trusted publishing automatically generates provenance for this public package from this public repository.
|
package/docs/project-handoff.md
CHANGED
|
@@ -57,9 +57,11 @@ Implemented surfaces:
|
|
|
57
57
|
- hosted operational release gate document requiring hosted CI, webhook replay, dependency and container scanning, privacy and retention verification, worker cleanup, monitoring and alerting, manual rollback, and incident response evidence before exposure
|
|
58
58
|
- hosted uninstall and data deletion document defining repository removal, full app uninstall, compact report deletion, queue cancellation, audit record retention, repeated cleanup idempotency, and user-facing deletion wording
|
|
59
59
|
- hosted pricing and packaging document defining open-source CLI boundaries, free/public repo hosted behavior, private repo hosted behavior, PR comments, saved reports, team policy, optional Launch Review, and no pentest/certification/full-audit claims
|
|
60
|
+
- hosted service runtime document and provider-independent runtime core for signed webhook intake, idempotent queue upsert, read-only worker orchestration, compact report storage, Check Run publication adapters, and worker cleanup planning
|
|
61
|
+
- hosted GitHub App deployment planner document and least-privilege manifest planner for required permissions, events, HTTPS URLs, container digest, secret references, and release-gate checks
|
|
60
62
|
- hosted pre-implementation contracts document, hosted compact report fixture, and pure helpers for pull request webhook intake planning, durable scan queue upsert planning, worker read-only scan planning, Check Run publication planning, queue-safe pull request event parsing from trusted GitHub event fields, bounded check-run summary rendering, idempotent queue cleanup planning, worker checkout cleanup planning, retention/deletion cleanup planning, and operational release gate evaluation
|
|
61
63
|
- implementation-ready hosted GitHub App permission contract for required permissions, optional PR comment permissions, selected repository installation, and out-of-scope broad permissions
|
|
62
|
-
-
|
|
64
|
+
- hosted GitHub App contract helpers and tests for webhook intake order, webhook verification, installation token scoping, durable scan queue idempotency, compact reports, retention limits, uninstall cleanup, repeated cleanup idempotency, scoped deletion planning, operational release gate blocking, provider-independent service runtime orchestration, and GitHub App deployment planning
|
|
63
65
|
- GitHub issue templates for bug reports, false positives, false negatives, rule requests, and public-safe security reports
|
|
64
66
|
- CODEOWNERS for source, tests, docs, workflows, Action, and package metadata
|
|
65
67
|
- JSON output
|
|
@@ -130,7 +132,7 @@ CI:
|
|
|
130
132
|
Publishing:
|
|
131
133
|
|
|
132
134
|
- npm package: `ai-saas-guard`
|
|
133
|
-
- Current release line: `v0.
|
|
135
|
+
- Current release line: `v0.18.0`
|
|
134
136
|
- Publish workflow: `.github/workflows/npm-publish.yml`
|
|
135
137
|
- Trusted Publisher: GitHub Actions for `zr9959/ai-saas-guard`, workflow `npm-publish.yml`
|
|
136
138
|
- Long-lived npm publish tokens should not be required.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-saas-guard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Repo-local launch-readiness scanner for AI-built SaaS apps.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://github.com/zr9959/ai-saas-guard#readme",
|
|
@@ -33,6 +33,14 @@
|
|
|
33
33
|
"./hosted/contracts": {
|
|
34
34
|
"types": "./dist/hosted/contracts.d.ts",
|
|
35
35
|
"default": "./dist/hosted/contracts.js"
|
|
36
|
+
},
|
|
37
|
+
"./hosted/service": {
|
|
38
|
+
"types": "./dist/hosted/service.d.ts",
|
|
39
|
+
"default": "./dist/hosted/service.js"
|
|
40
|
+
},
|
|
41
|
+
"./hosted/github-app": {
|
|
42
|
+
"types": "./dist/hosted/github-app.d.ts",
|
|
43
|
+
"default": "./dist/hosted/github-app.js"
|
|
36
44
|
}
|
|
37
45
|
},
|
|
38
46
|
"bin": {
|