-
Notifications
You must be signed in to change notification settings - Fork 729
feat: security contacts worker [CM-1297] #4283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mbani01
wants to merge
19
commits into
main
Choose a base branch
from
feat/security_contacts_worker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,269
−64
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e955bdd
feat: scaffold security contacts worker (CM-1243)
mbani01 7bc5c4f
feat: security contacts worker scaffold, scoring and reconciliation (…
mbani01 55fee28
feat: add security-insights extractor (A1) for security contacts (CM-…
mbani01 9a851a6
feat: add SECURITY_CONTACTS extractor (A3) for security contacts
mbani01 351a6c9
feat: add security.txt extractor (A4) for security contacts
mbani01 6eb4137
feat: add SECURITY.md extractor (B1) for security contacts
mbani01 17ddd3d
feat: add npm registry contact extractor (B2/npm)
mbani01 2712873
feat: wire security contacts pipeline + DB write
mbani01 cd86897
chore: wire security-contacts-worker ops (CLI, compose, scripts, env)
mbani01 8cb71f6
chore: use unified github host
mbani01 efba8cd
fix: code review fixes
mbani01 f295c3a
chore: raise security contacts worker concurrency; hardcode tuning co…
mbani01 95dcf42
fix: code review fixes
mbani01 c50d5e9
fix: isolate per-repo failures in security contacts batch
mbani01 5f32ed1
fix: clear PVR reporting URL on disable; drain poison repos
mbani01 1cf1e69
Merge branch 'main' into feat/security_contacts_worker
mbani01 85cb09d
fix: incorrect SECURITY_CONTACTS_USER_AGENT value
mbani01 082f6a5
fix: skip PVR for archived repos; treat PVR 422 as unknown
mbani01 2ece757
fix: rate-limit-safe GitHub access for security contacts
mbani01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
backend/src/osspckgs/migrations/V1782950400__security_contacts.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| CREATE TABLE IF NOT EXISTS security_contacts ( | ||
| id BIGSERIAL PRIMARY KEY, | ||
| repo_id BIGINT NOT NULL REFERENCES repos(id) ON DELETE CASCADE, | ||
| channel TEXT NOT NULL, | ||
| value TEXT NOT NULL, | ||
| role TEXT NOT NULL, | ||
| name TEXT, | ||
| score NUMERIC(4,3) NOT NULL, | ||
| confidence TEXT NOT NULL, | ||
| provenance JSONB NOT NULL DEFAULT '[]', | ||
| last_refreshed TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
| created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
| updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | ||
| ); | ||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS security_contacts_repo_channel_value_uq | ||
| ON security_contacts (repo_id, channel, value); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS security_contacts_repo_confidence_idx | ||
| ON security_contacts (repo_id, confidence); | ||
|
|
||
| ALTER TABLE repos ADD COLUMN IF NOT EXISTS pvr_enabled BOOL; | ||
| ALTER TABLE repos ADD COLUMN IF NOT EXISTS security_policy_url TEXT; | ||
| ALTER TABLE repos ADD COLUMN IF NOT EXISTS vulnerability_reporting_url TEXT; | ||
| ALTER TABLE repos ADD COLUMN IF NOT EXISTS bug_bounty_url TEXT; | ||
| ALTER TABLE repos ADD COLUMN IF NOT EXISTS security_txt_url TEXT; | ||
| ALTER TABLE repos ADD COLUMN IF NOT EXISTS contacts_last_refreshed TIMESTAMPTZ; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| DOCKERFILE="./services/docker/Dockerfile.packages" | ||
| CONTEXT="../" | ||
| REPO="sjc.ocir.io/axbydjxa5zuh/packages" | ||
| SERVICES="github-repos-enricher bq-dataset-ingest npm-worker maven-worker osv-worker dockerhub-sync cargo-worker go-worker nuget-worker" | ||
| SERVICES="github-repos-enricher bq-dataset-ingest npm-worker maven-worker osv-worker dockerhub-sync cargo-worker go-worker nuget-worker security-contacts-worker" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| version: '3.1' | ||
|
|
||
| x-env-args: &env-args | ||
| DOCKER_BUILDKIT: 1 | ||
| NODE_ENV: docker | ||
| SERVICE: security-contacts-worker | ||
| SHELL: /bin/sh | ||
| SUPPRESS_NO_CONFIG_WARNING: 'true' | ||
| CROWD_TEMPORAL_TASKQUEUE: packages-worker | ||
|
|
||
| services: | ||
| security-contacts-worker: | ||
| build: | ||
| context: ../../ | ||
| dockerfile: ./scripts/services/docker/Dockerfile.packages | ||
| command: 'pnpm run start:security-contacts-worker' | ||
| working_dir: /usr/crowd/app/services/apps/packages_worker | ||
| env_file: | ||
| - ../../backend/.env.dist.local | ||
| - ../../backend/.env.dist.composed | ||
| - ../../backend/.env.override.local | ||
| - ../../backend/.env.override.composed | ||
| environment: | ||
| <<: *env-args | ||
| restart: always | ||
| networks: | ||
| - crowd-bridge | ||
|
|
||
| security-contacts-worker-dev: | ||
| build: | ||
| context: ../../ | ||
| dockerfile: ./scripts/services/docker/Dockerfile.packages | ||
| command: 'pnpm run dev:security-contacts-worker' | ||
| working_dir: /usr/crowd/app/services/apps/packages_worker | ||
| env_file: | ||
| - ../../backend/.env.dist.local | ||
| - ../../backend/.env.dist.composed | ||
| - ../../backend/.env.override.local | ||
| - ../../backend/.env.override.composed | ||
| environment: | ||
| <<: *env-args | ||
| hostname: security-contacts-worker | ||
| networks: | ||
| - crowd-bridge | ||
| volumes: | ||
| - ../../services/libs/audit-logs/src:/usr/crowd/app/services/libs/audit-logs/src | ||
| - ../../services/libs/common/src:/usr/crowd/app/services/libs/common/src | ||
| - ../../services/libs/common_services/src:/usr/crowd/app/services/libs/common_services/src | ||
| - ../../services/libs/data-access-layer/src:/usr/crowd/app/services/libs/data-access-layer/src | ||
| - ../../services/libs/database/src:/usr/crowd/app/services/libs/database/src | ||
| - ../../services/libs/integrations/src:/usr/crowd/app/services/libs/integrations/src | ||
| - ../../services/libs/logging/src:/usr/crowd/app/services/libs/logging/src | ||
| - ../../services/libs/nango/src:/usr/crowd/app/services/libs/nango/src | ||
| - ../../services/libs/opensearch/src:/usr/crowd/app/services/libs/opensearch/src | ||
| - ../../services/libs/queue/src:/usr/crowd/app/services/libs/queue/src | ||
| - ../../services/libs/redis/src:/usr/crowd/app/services/libs/redis/src | ||
| - ../../services/libs/snowflake/src:/usr/crowd/app/services/libs/snowflake/src | ||
| - ../../services/libs/telemetry/src:/usr/crowd/app/services/libs/telemetry/src | ||
| - ../../services/libs/temporal/src:/usr/crowd/app/services/libs/temporal/src | ||
| - ../../services/libs/types/src:/usr/crowd/app/services/libs/types/src | ||
| - ../../services/apps/packages_worker/src:/usr/crowd/app/services/apps/packages_worker/src | ||
|
|
||
| networks: | ||
| crowd-bridge: | ||
| external: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
services/apps/packages_worker/src/bin/security-contacts-worker.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { scheduleSecurityContactsIngestion } from '../security-contacts/schedule' | ||
| import { svc } from '../service' | ||
|
|
||
| setImmediate(async () => { | ||
| await svc.init() | ||
| await scheduleSecurityContactsIngestion() | ||
| await svc.start() | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
services/apps/packages_worker/src/enricher/installationPool.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { getServiceChildLogger } from '@crowd/logging' | ||
|
|
||
| const log = getServiceChildLogger('installation-pool') | ||
|
|
||
| // Park an installation before GitHub starts rejecting — avoids a failed request + requeue | ||
| const PROACTIVE_PARK_REMAINING = 50 | ||
|
|
||
| /** Round-robins over installations, skipping ones parked until their rate-limit reset. */ | ||
| export class InstallationPool { | ||
| private readonly parkedUntil = new Map<number, number>() | ||
| private roundRobinIdx = 0 | ||
|
|
||
| constructor(private readonly ids: number[]) {} | ||
|
|
||
| select(): { installationId: number; waitMs: number } { | ||
| const now = Date.now() | ||
| const n = this.ids.length | ||
|
|
||
| for (let i = 0; i < n; i++) { | ||
| const idx = (this.roundRobinIdx + i) % n | ||
| const id = this.ids[idx] | ||
| if ((this.parkedUntil.get(id) ?? 0) <= now) { | ||
| this.roundRobinIdx = (idx + 1) % n | ||
| return { installationId: id, waitMs: 0 } | ||
| } | ||
| } | ||
|
|
||
| let soonestReset = Infinity | ||
| let soonestId = this.ids[0] | ||
| for (const id of this.ids) { | ||
| const reset = this.parkedUntil.get(id) ?? 0 | ||
| if (reset < soonestReset) { | ||
| soonestReset = reset | ||
| soonestId = id | ||
| } | ||
| } | ||
| return { installationId: soonestId, waitMs: Math.max(1_000, soonestReset - now) } | ||
| } | ||
|
|
||
| park(installationId: number, untilMs: number): void { | ||
| this.parkedUntil.set(installationId, untilMs) | ||
| } | ||
|
|
||
| parkIfBudgetLow( | ||
| installationId: number, | ||
| remaining: number | null | undefined, | ||
| resetAt: string | null | undefined, | ||
| ): void { | ||
| if (remaining == null || resetAt == null || remaining >= PROACTIVE_PARK_REMAINING) return | ||
| this.park(installationId, new Date(resetAt).getTime() + 5_000) | ||
| log.info( | ||
| { installationId, remaining, resetAt }, | ||
| 'Budget low — proactively parking installation', | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
services/apps/packages_worker/src/security-contacts/activities.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { getServiceChildLogger } from '@crowd/logging' | ||
|
|
||
| import { getSecurityContactsConfig } from '../config' | ||
| import { getPackagesDb } from '../db' | ||
|
|
||
| import { BatchResult, processBatch } from './processBatch' | ||
|
|
||
| const log = getServiceChildLogger('security-contacts-activity') | ||
|
|
||
| export async function processSecurityContactsBatch(): Promise<BatchResult> { | ||
| const config = getSecurityContactsConfig() | ||
| const qx = await getPackagesDb() | ||
|
|
||
| const result = await processBatch(qx, config) | ||
| log.info({ ...result }, 'Security contacts batch activity complete') | ||
| return result | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.