{"modulePath":"github.com/agentshield-dev/agentshield","version":"v0.0.1-rc.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package api\n\nPackage api serves the AgentShield HTTP API, the embedded web UI, and the optional OTLP log receiver.\n\nThe API is a read model over pkg/state: graph, catalog, and finding routes query the current materialized graph and stored findings and never modify the graph. The only routes that can change anything outside AgentShield are the remediation routes. They are always registered but act only on a server built with [NewServerWithRemediations](#NewServerWithRemediations); otherwise they return 503.\n\nThe rule review and regenerate routes change detection: approving a draft makes its rules active, and regenerating resets a Deployment's draft to shadow mode and calls the model again. They are always registered but act only on a server built with [WithRules](#WithRules) and writes enabled; otherwise they return 503. Enable writes only on a loopback listener or behind an authenticating proxy.\n\nThe manifest and overview routes do write: they call [state.Store.CreateManifest](/github.com/agentshield-dev/agentshield/pkg/state#Store.CreateManifest), which records the active contribution versions as a content-addressed manifest row, the same record analysis views pin. The row supplies the response's stable creation time and parent link, so computing the manifest without storing it would change what clients see. The write is idempotent: with no intervening publication, repeated requests return the existing row, so rows grow with the distinct graph states that were viewed, not with request count. Nothing deletes manifest rows today.\n\n### Routes {#hdr-Routes}\n\n\tGET  /healthz                         process liveness\n\tGET  /readyz                          database reachable and schema readable; never compiles the graph\n\tGET  /api/v1/graph                    current graph view, with ETag\n\tGET  /api/v1/manifest                 records (idempotently) and returns the current manifest\n\tGET  /api/v1/neighborhood             bounded neighborhood of one resource\n\tGET  /api/v1/overview                 counts, manifest (as above), and top active findings\n\tGET  /api/v1/resources[/{id}]         paginated, filterable resource catalog\n\tGET  /api/v1/relationships[/{id}]     paginated relationship catalog\n\tGET  /api/v1/exposures                exposure security semantics\n\tGET  /api/v1/events                   server-sent events on graph revision change\n\tGET  /api/v1/findings[/{id}]          stored findings, cursor-paginated\n\tGET  /api/v1/findings/{id}/remediations/{proposal}/candidates\n\tPOST /api/v1/findings/{id}/remediations/{proposal}/prepare\n\tPOST /api/v1/findings/{id}/remediations/{proposal}/approve\n\tGET  /api/v1/rules                    active ruleset and loaded resource rules (active or shadow)\n\tGET  /api/v1/rule-drafts[/{id}]       resource rule drafts; one draft includes its proposal\n\tPOST /api/v1/rule-drafts/{id}/review  approve selected rules or reject a completed draft\n\tPOST /api/v1/resources/{id}/rule-drafts  re-author a resource's current revision\n\tPOST /v1/logs                         OTLP logs, when a receiver is configured\n\tGET  /, /assets/                      embedded web UI\n\tPOST /v1/aws/firehose/vpc-flow-logs   AWS VPC flow logs; see below\n\nThe command mounts the AWS Firehose route in front of this server's handler when --aws-firehose-stream-arn is set; this package does not serve it. It authenticates with the Firehose access key and is not subject to the loopback Host check.\n\n### Graph events {#hdr-Graph_events}\n\nThe events route streams a \"graph\" event with the graph revision on connect and on every change, plus a keepalive comment every 25 seconds. It replaces the server's whole-response write timeout with a deadline on each write. Each open stream polls [StateStore.GraphRevision](#StateStore.GraphRevision) every 500ms and reads the shared revision-validated graph only when the revision changes.\n\n### Errors {#hdr-Errors}\n\nErrors are JSON objects of the form {\"error\": \"\\\u003caction\u003e: \\\u003creason\u003e\"}. A 4xx reason describes what is wrong with the request. A 5xx reason is generic, apart from a few fixed messages such as \"graph is not materialized\"; the detail is logged on the server.\n\n### Security model {#hdr-Security_model}\n\nThe API is unauthenticated and intended for a loopback listener during development. Every response carries a same-origin Content-Security-Policy.\n\nLive remediation is enabled only when the host builds the server with [NewServerWithRemediations](#NewServerWithRemediations), which the production command does only for a loopback listen address. A finding's remediation is driven entirely by server-owned proposals: the browser sends only a provider/source/action selection to prepare, and the exact plan ID to approve. Approval resolves the plan prepared by this process for the same finding and proposal; preparation state is in memory and is lost on restart. A finding that is no longer active cannot be remediated.\n\nMutating requests must have Content-Type application/json. A cross-site HTML form or simple fetch cannot send that type without a CORS preflight, which this server never approves, so another origin cannot drive approval through the user's browser. This is not a full CSRF policy.\n\nDNS rebinding can make a hostile page same-origin with a loopback listener, which defeats the content-type defense. [WithLoopbackHostCheck](#WithLoopbackHostCheck) rejects requests whose Host is not localhost or a loopback IP literal; it is on by default for servers with live remediation.\n\nExposing this server beyond loopback requires authenticated infrastructure in front of it. See [https://agent-shield.dev/docs/operations/security/](https://agent-shield.dev/docs/operations/security/) and [https://agent-shield.dev/docs/operations/configuration/](https://agent-shield.dev/docs/operations/configuration/).\n\n## Types\n\n```go\ntype Option func(*Server)\n```\nOption configures a [Server](#Server).\n\n```go\nfunc WithLoopbackHostCheck(enabled bool) Option\n```\nWithLoopbackHostCheck controls whether the server rejects requests whose Host header is not \"localhost\" or a loopback IP literal, on any port, with 403 Forbidden.\n\nEnable it whenever the server listens only on loopback. Binding to loopback keeps remote hosts out, but a page from another site can use DNS rebinding to resolve its own name to 127.0.0.1 and then call the API as a same-origin request. The browser still sends the attacker's name in Host, so checking Host closes that path. Do not enable it behind a proxy that forwards a non-loopback Host.\n\n```go\nfunc WithRules(store RuleStore, writable bool) Option\n```\nWithRules serves the detection rule routes from store. writable enables the review and regenerate routes; the API is unauthenticated, so enable it only on a loopback listener or behind an authenticating proxy.\n\n```go\ntype RemediationExecutor interface {\n\tCandidates(remediation.Proposal) ([]remediation.Candidate, error)\n\tPlan(context.Context, remediation.Proposal, string, ...string) (remediation.Plan, error)\n\tPrepare(context.Context, remediation.Proposal, remediation.Plan) (remediation.Preparation, error)\n\tExecute(context.Context, remediation.Proposal, remediation.Plan, remediation.Preparation, string) (remediation.ExecutionResult, error)\n\tVerify(context.Context, remediation.Proposal, remediation.Plan) (remediation.Verification, error)\n}\n```\nRemediationExecutor drives the remediation lifecycle. \\*remediation.Executor implements it.\n\n```go\ntype RuleStore interface {\n\tReadActiveDetectorRuleset(context.Context) (detector.Activation, error)\n\tReadResourceRulesForDetector(context.Context) ([]detector.ResourceRule, error)\n\tListResourceRuleJobs(context.Context, int, string) ([]state.ResourceRuleJobSummary, error)\n\tResourceRuleJobStatus(context.Context, int64) (state.ResourceRuleJobSummary, bool, error)\n\tResourceRuleProposal(context.Context, int64) (json.RawMessage, bool, error)\n\tReviewResourceRuleJobRules(context.Context, int64, string, string, []string) error\n\tRequestResourceRuleJob(context.Context, string, string) (state.ResourceRuleJobSummary, error)\n}\n```\nRuleStore is the detection rule model the rule routes serve. \\*state.Store implements it.\n\n```go\ntype Server struct {\n\t// contains filtered or unexported fields\n}\n```\nServer is the AgentShield HTTP API. Remediation preparation sessions are held in memory and are lost on restart.\n\n```go\nfunc NewServer(store StateStore, otlp http.Handler, options ...Option) (*Server, error)\n```\nNewServer returns a server without live remediation. otlp may be nil. The server does not know its listen address, so the loopback Host check is off unless enabled with [WithLoopbackHostCheck](#WithLoopbackHostCheck).\n\n```go\nfunc NewServerWithRemediations(store StateStore, otlp http.Handler, executor RemediationExecutor, options ...Option) (*Server, error)\n```\nNewServerWithRemediations returns a server whose remediation routes can plan, prepare, and execute actions through executor. Callers must serve it only on a loopback listener. The loopback Host check is therefore on by default; options are applied after that default.\n\n```go\nfunc (server *Server) CloseStreams()\n```\nCloseStreams ends every open and future graph event stream so [http.Server.Shutdown](/net/http#Server.Shutdown) does not wait for them. Register it with [http.Server.RegisterOnShutdown](/net/http#Server.RegisterOnShutdown). It is safe to call more than once.\n\n```go\nfunc (server *Server) Handler() http.Handler\n```\nHandler returns the routed handler with security headers and, when enabled, the loopback Host check applied to every route. See the package documentation for the route list.\n\n```go\ntype StateStore interface {\n\tPing(context.Context) error\n\tCurrentGraph(context.Context) (state.GraphView, error)\n\tGraphRevision(context.Context) (uint64, error)\n\tQueryResources(context.Context, state.ResourceQuery) (state.ResourcePage, error)\n\tGetResourceDetail(context.Context, string) (state.ResourceDetail, error)\n\tQueryRelationships(context.Context, state.RelationshipQuery) (state.RelationshipPage, error)\n\tGetRelationshipDetail(context.Context, string) (state.RelationshipDetail, error)\n\tCreateManifest(context.Context) (state.GraphManifest, error)\n\tNeighborhood(context.Context, string, int, string, int) (state.Neighborhood, error)\n\tGetFinding(context.Context, string) (state.Finding, error)\n\tQueryFindings(context.Context, state.FindingQuery) (state.FindingPage, error)\n}\n```\nStateStore is the read model the API serves. \\*state.Store implements it. CreateManifest is the only method that writes; it records an idempotent, content-addressed manifest row and never changes the graph.\n\n","path":"github.com/agentshield-dev/agentshield/pkg/api","name":"api","synopsis":"Package api serves the AgentShield HTTP API, the embedded web UI, and the optional OTLP log receiver.","isRedistributable":true}
