Repository navigation
feat(runtime): ingest API on secfoo serve with the user's API key (#66) - #98
Merged
Merged
Conversation
GET watchlist (ETag), POST events (gzip NDJSON through ingest_events, so replays never double-count), POST heartbeat and GET evidence under /api/runtime/v1, authenticated with Bearer keys issued by secfoo serve key create (stored hashed, project- and runtime-scopable, revocable). Unknown projects are rejected, bodies and line counts capped, requests rate-limited per key, and keys refused over plain HTTP on non-loopback binds unless --allow-insecure-runtime. load_sensor_config() reads SECFOO_API_KEY_FILE / SECFOO_SERVER / SECFOO_PROJECT with no fallback account. Closes #66 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment on lines
+187
to
+194
| return { | ||
| "sessions": report.sessions, | ||
| "loads": report.loads, | ||
| "hits": report.hits, | ||
| "skipped": [{"line": n, "reason": r} for n, r in report.skipped[:100]], | ||
| "skipped_count": len(report.skipped), | ||
| "unknown_fingerprints": sorted(report.unknown_fingerprints)[:100], | ||
| } |
| raise _error(403, "this API key has no access to that project") | ||
| yield _Caller(repo, key, project_id) | ||
| finally: | ||
| repo.close() |
Leaderboard update
karthickmk2001 now has 41 points (rank #1, Bronze). 9 more to reach Silver. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #66
What does this change, and why?
The runtime ingest API on
secfoo serve, so live sensors (#67) and the CLI/CI (#80) can send and read evidence with the same API key the user already has. Contract and setup are indocs/REFERENCE.md→ Runtime ingest API.Endpoints (
src/secfoo/runtime/api.py, versioned under/api/runtime/v1/,Authorization: Bearer <key>,projectrequired):GET watchlist: the Build a vulnerable-function watchlist from advisories #52 watchlist, with anETag(a hash of the entries, notgenerated_at).If-None-Matchreturns304.POST events: an NDJSON batch, gzip allowed. It runs through Runtime evidence format, storage andsecfoo runtime ingest#53'singest_events, so a retried batch never double-counts.app/envquery params (the sensor'sSECFOO_APP/SECFOO_ENV) fill session lines that don't set them.POST heartbeat:{sensor_id, version, app, env, instances, dropped}. It registers the sensor in a newruntime_sensorstable (for Runtime page: sensor health, live activity and alerts #72) and sums the drops.GET evidence: the runtime state of each open SCA finding (state, routes, coverage, conflict), reusing Runtime evidence in the SCA dashboard #57'ssca_runtime.Projects: matched on
projects.identifier, exactly as runs are. An unknown project gets404, with no auto-create, since evidence without a scan has nothing to attach to.Keys:
secfoo serve key create --name <label> [--project <p>] [--runtime-only], pluslistandrevoke.secfoo serveis now a command group, and plainsecfoo serve [--host --port]works as before.runtime_api_keys). The plaintext is printed once, to stdout, soKEY=$(...)captures it.401immediately.Hardening:
secfoo servebinds loopback by default. On any other--host, it refuses keys over plain HTTP unless--allow-insecure-runtimeis set. The docs say how to put TLS in front.Sensor side:
secfoo/runtime/client.pyload_sensor_config()reads:SECFOO_API_KEY_FILE(orSECFOO_API_KEY);SECFOO_SERVER, defaulting tosecfoo cloud login's portal URL;SECFOO_PROJECT,SECFOO_APPandSECFOO_ENV.There's no fallback account. It refuses non-HTTPS servers except loopback, and its
reprnever shows the key.Note: the route and dependency are
asyncon purpose. SQLite connections are bound to the thread that opened them, and FastAPI runs sync dependencies in a worker pool.Testing
pytest testspasses. 1183 passed locally. The only failures are the 4 existing Windows-only POSIX permission and symlink tests that fail onmaintoo; Linux CI is unaffected.ruff check .adds no new findings.tests/test_runtime/test_runtime_api.py(24 tests), covering the issue's Done when:ETaghit, and the heartbeatSECFOO_API_KEY_FILE/SECFOO_SERVERor the cloud-login default, and refusing incomplete configserve key create/list/revokecommands🤖 Generated with Claude Code