openapi.yaml 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788
  1. openapi: '3.0.3'
  2. info:
  3. title: IRDB — IP Reputation Database
  4. version: '1.0.0'
  5. description: |
  6. Self-hosted IP reputation service: ingest abuse reports, distribute tailored block lists.
  7. ## Versioning
  8. Single major version `v1`. Changes within `v1` are additive only — new endpoints, new optional fields, new optional query params. Breaking changes ship as `v2`.
  9. ## Endpoint groups
  10. - **Public**: machine clients (reporters, consumers).
  11. - **Admin**: UI BFF + admin-kind tokens. RBAC enforced server-side.
  12. - **Auth**: UI BFF only — bridges browser auth to user records. Marked `x-internal: true`.
  13. - **Internal jobs**: not in this spec. Scheduler-only, network-restricted.
  14. ## Authentication
  15. Bearer token in the `Authorization` header. Four token kinds: `reporter`, `consumer`, `admin`, `service`. See `doc/auth-flows.md`.
  16. ## Errors
  17. Uniform envelope: `{"error":"<code>","details":{...}}`. Validation errors include `details`. Authentication failures return `401` `unauthorized`. Authorization failures return `403`.
  18. ## Rate limiting
  19. Public endpoints: 60 req/s/token (configurable). On exhaustion: `429` with `Retry-After: 1`.
  20. license:
  21. name: TBD
  22. servers:
  23. - url: http://localhost:8081
  24. description: Default compose deployment
  25. - url: https://reputation-api.example.com
  26. description: Production (replace hostname)
  27. tags:
  28. - name: Public
  29. description: 'Machine clients: reporters and blocklist consumers.'
  30. - name: Admin
  31. description: UI BFF + admin-kind tokens.
  32. - name: Auth
  33. description: UI BFF only. Service token required, no impersonation.
  34. security:
  35. - BearerAuth: []
  36. paths:
  37. '/api/v1/report':
  38. post:
  39. tags:
  40. - Public
  41. summary: Submit an abuse report
  42. description: |
  43. Token kind: `reporter`. Rate limit: 60 req/s per token (configurable).
  44. Returns `202 Accepted` on success.
  45. security:
  46. - BearerAuth: []
  47. requestBody:
  48. required: true
  49. content:
  50. 'application/json':
  51. schema:
  52. '$ref': '#/components/schemas/ReportRequest'
  53. responses:
  54. '202':
  55. description: Report accepted
  56. content:
  57. 'application/json':
  58. schema:
  59. '$ref': '#/components/schemas/ReportResponse'
  60. '400':
  61. description: Validation failed
  62. content:
  63. 'application/json':
  64. schema:
  65. '$ref': '#/components/schemas/Error'
  66. '401':
  67. description: Bad / wrong-kind token
  68. content:
  69. 'application/json':
  70. schema:
  71. '$ref': '#/components/schemas/Error'
  72. '429':
  73. description: Rate limited
  74. headers:
  75. Retry-After:
  76. schema:
  77. type: integer
  78. description: Seconds to wait before retrying.
  79. content:
  80. 'application/json':
  81. schema:
  82. '$ref': '#/components/schemas/Error'
  83. '/api/v1/blocklist':
  84. get:
  85. tags:
  86. - Public
  87. summary: Pull a tailored blocklist
  88. description: |
  89. Token kind: `consumer`. The consumer's bound policy decides which IPs/CIDRs land in the output.
  90. Cached internally for 30 s per consumer. Honour `If-None-Match` to skip retransfer.
  91. `?format=json` returns structured rows; default is `text/plain`, one entry per line.
  92. security:
  93. - BearerAuth: []
  94. parameters:
  95. - name: format
  96. in: query
  97. schema:
  98. type: string
  99. enum:
  100. - text
  101. - json
  102. default: text
  103. - name: If-None-Match
  104. in: header
  105. schema:
  106. type: string
  107. responses:
  108. '200':
  109. description: Current blocklist
  110. headers:
  111. ETag:
  112. schema:
  113. type: string
  114. X-Blocklist-Generated-At:
  115. schema:
  116. type: string
  117. format: date-time
  118. X-Blocklist-Entries:
  119. schema:
  120. type: integer
  121. X-Blocklist-Policy:
  122. schema:
  123. type: string
  124. content:
  125. 'text/plain':
  126. schema:
  127. type: string
  128. example: |
  129. 203.0.113.42
  130. 198.51.100.0/24
  131. 'application/json':
  132. schema:
  133. '$ref': '#/components/schemas/BlocklistJson'
  134. '304':
  135. description: Not modified — body matches `If-None-Match`
  136. '401':
  137. description: Bad / wrong-kind token
  138. '/api/v1/admin/me':
  139. get:
  140. tags:
  141. - Admin
  142. summary: Current acting identity
  143. security:
  144. - BearerAuth: []
  145. parameters:
  146. - '$ref': '#/components/parameters/ActingUserId'
  147. responses:
  148. '200':
  149. description: Identity info
  150. content:
  151. 'application/json':
  152. schema:
  153. '$ref': '#/components/schemas/User'
  154. '/api/v1/admin/ips':
  155. get:
  156. tags:
  157. - Admin
  158. summary: Search IPs
  159. security:
  160. - BearerAuth: []
  161. parameters:
  162. - '$ref': '#/components/parameters/ActingUserId'
  163. - name: q
  164. in: query
  165. schema:
  166. type: string
  167. - name: category
  168. in: query
  169. schema:
  170. type: string
  171. - name: min_score
  172. in: query
  173. schema:
  174. type: number
  175. format: float
  176. - name: max_score
  177. in: query
  178. schema:
  179. type: number
  180. format: float
  181. - name: country
  182. in: query
  183. schema:
  184. type: string
  185. - name: asn
  186. in: query
  187. schema:
  188. type: integer
  189. - name: status
  190. in: query
  191. schema:
  192. type: string
  193. enum:
  194. - scored
  195. - manual
  196. - allowlisted
  197. - clean
  198. - '$ref': '#/components/parameters/Page'
  199. - '$ref': '#/components/parameters/PageSize'
  200. responses:
  201. '200':
  202. description: Page of IPs
  203. content:
  204. 'application/json':
  205. schema:
  206. type: object
  207. properties:
  208. page:
  209. type: integer
  210. minimum: 1
  211. example: 1
  212. page_size:
  213. type: integer
  214. minimum: 1
  215. maximum: 200
  216. example: 50
  217. total:
  218. type: integer
  219. minimum: 0
  220. example: 1284
  221. items:
  222. type: array
  223. items:
  224. type: object
  225. '/api/v1/admin/ips/countries':
  226. get:
  227. tags:
  228. - Admin
  229. summary: Country code dropdown source
  230. security:
  231. - BearerAuth: []
  232. parameters:
  233. - '$ref': '#/components/parameters/ActingUserId'
  234. responses:
  235. '200':
  236. description: '`[{code, count}]`'
  237. content:
  238. 'application/json':
  239. schema:
  240. type: object
  241. properties:
  242. items:
  243. type: array
  244. items:
  245. type: object
  246. properties:
  247. code:
  248. type: string
  249. count:
  250. type: integer
  251. '/api/v1/admin/ips/{ip}':
  252. get:
  253. tags:
  254. - Admin
  255. summary: IP detail
  256. security:
  257. - BearerAuth: []
  258. parameters:
  259. - '$ref': '#/components/parameters/ActingUserId'
  260. - name: ip
  261. in: path
  262. required: true
  263. schema:
  264. type: string
  265. responses:
  266. '200':
  267. description: IP detail
  268. content:
  269. 'application/json':
  270. schema:
  271. '$ref': '#/components/schemas/IpDetail'
  272. '404':
  273. description: Invalid IP / not found
  274. '/api/v1/admin/stats/dashboard':
  275. get:
  276. tags:
  277. - Admin
  278. summary: Dashboard stats (30s cached)
  279. security:
  280. - BearerAuth: []
  281. parameters:
  282. - '$ref': '#/components/parameters/ActingUserId'
  283. responses:
  284. '200':
  285. description: Dashboard payload
  286. content:
  287. 'application/json':
  288. schema:
  289. type: object
  290. '/api/v1/admin/manual-blocks':
  291. get:
  292. tags:
  293. - Admin
  294. summary: List manual blocks
  295. security:
  296. - BearerAuth: []
  297. parameters:
  298. - '$ref': '#/components/parameters/ActingUserId'
  299. responses:
  300. '200':
  301. description: list
  302. post:
  303. tags:
  304. - Admin
  305. summary: Create manual block
  306. description: Operator+ role required. `kind=ip` requires `ip`; `kind=subnet` requires `cidr`.
  307. security:
  308. - BearerAuth: []
  309. parameters:
  310. - '$ref': '#/components/parameters/ActingUserId'
  311. requestBody:
  312. required: true
  313. content:
  314. 'application/json':
  315. schema:
  316. type: object
  317. properties:
  318. kind:
  319. type: string
  320. enum:
  321. - ip
  322. - subnet
  323. ip:
  324. type: string
  325. cidr:
  326. type: string
  327. reason:
  328. type: string
  329. expires_at:
  330. type: string
  331. format: date-time
  332. responses:
  333. '201':
  334. description: Created
  335. content:
  336. 'application/json':
  337. schema:
  338. '$ref': '#/components/schemas/ManualBlock'
  339. '/api/v1/admin/manual-blocks/{id}':
  340. get:
  341. tags:
  342. - Admin
  343. summary: Show manual block
  344. security:
  345. - BearerAuth: []
  346. parameters:
  347. - '$ref': '#/components/parameters/ActingUserId'
  348. - name: id
  349. in: path
  350. required: true
  351. schema:
  352. type: integer
  353. responses:
  354. '200':
  355. description: manual block
  356. content:
  357. 'application/json':
  358. schema:
  359. '$ref': '#/components/schemas/ManualBlock'
  360. delete:
  361. tags:
  362. - Admin
  363. summary: Delete manual block
  364. security:
  365. - BearerAuth: []
  366. parameters:
  367. - '$ref': '#/components/parameters/ActingUserId'
  368. - name: id
  369. in: path
  370. required: true
  371. schema:
  372. type: integer
  373. responses:
  374. '204':
  375. description: Deleted
  376. '/api/v1/admin/allowlist':
  377. get:
  378. tags:
  379. - Admin
  380. summary: List allowlist
  381. security:
  382. - BearerAuth: []
  383. parameters:
  384. - '$ref': '#/components/parameters/ActingUserId'
  385. responses:
  386. '200':
  387. description: list
  388. post:
  389. tags:
  390. - Admin
  391. summary: Create allowlist entry
  392. security:
  393. - BearerAuth: []
  394. parameters:
  395. - '$ref': '#/components/parameters/ActingUserId'
  396. requestBody:
  397. required: true
  398. content:
  399. 'application/json':
  400. schema:
  401. type: object
  402. properties:
  403. kind:
  404. type: string
  405. enum:
  406. - ip
  407. - subnet
  408. ip:
  409. type: string
  410. cidr:
  411. type: string
  412. reason:
  413. type: string
  414. responses:
  415. '201':
  416. description: Created
  417. content:
  418. 'application/json':
  419. schema:
  420. '$ref': '#/components/schemas/AllowlistEntry'
  421. '/api/v1/admin/allowlist/{id}':
  422. get:
  423. tags:
  424. - Admin
  425. summary: Show allowlist entry
  426. security:
  427. - BearerAuth: []
  428. parameters:
  429. - '$ref': '#/components/parameters/ActingUserId'
  430. - name: id
  431. in: path
  432. required: true
  433. schema:
  434. type: integer
  435. responses:
  436. '200':
  437. description: allowlist entry
  438. content:
  439. 'application/json':
  440. schema:
  441. '$ref': '#/components/schemas/AllowlistEntry'
  442. delete:
  443. tags:
  444. - Admin
  445. summary: Delete allowlist entry
  446. security:
  447. - BearerAuth: []
  448. parameters:
  449. - '$ref': '#/components/parameters/ActingUserId'
  450. - name: id
  451. in: path
  452. required: true
  453. schema:
  454. type: integer
  455. responses:
  456. '204':
  457. description: Deleted
  458. '/api/v1/admin/reporters':
  459. get:
  460. tags:
  461. - Admin
  462. summary: List reporters
  463. security:
  464. - BearerAuth: []
  465. parameters:
  466. - '$ref': '#/components/parameters/ActingUserId'
  467. responses:
  468. '200':
  469. description: list
  470. post:
  471. tags:
  472. - Admin
  473. summary: Create reporter
  474. security:
  475. - BearerAuth: []
  476. parameters:
  477. - '$ref': '#/components/parameters/ActingUserId'
  478. requestBody:
  479. required: true
  480. content:
  481. 'application/json':
  482. schema:
  483. '$ref': '#/components/schemas/Reporter'
  484. responses:
  485. '201':
  486. description: Created
  487. content:
  488. 'application/json':
  489. schema:
  490. '$ref': '#/components/schemas/Reporter'
  491. '/api/v1/admin/reporters/{id}':
  492. get:
  493. tags:
  494. - Admin
  495. summary: Show reporter
  496. security:
  497. - BearerAuth: []
  498. parameters:
  499. - '$ref': '#/components/parameters/ActingUserId'
  500. - name: id
  501. in: path
  502. required: true
  503. schema:
  504. type: integer
  505. responses:
  506. '200':
  507. description: reporter
  508. content:
  509. 'application/json':
  510. schema:
  511. '$ref': '#/components/schemas/Reporter'
  512. patch:
  513. tags:
  514. - Admin
  515. summary: Update reporter
  516. security:
  517. - BearerAuth: []
  518. parameters:
  519. - '$ref': '#/components/parameters/ActingUserId'
  520. - name: id
  521. in: path
  522. required: true
  523. schema:
  524. type: integer
  525. requestBody:
  526. content:
  527. 'application/json':
  528. schema:
  529. '$ref': '#/components/schemas/Reporter'
  530. responses:
  531. '200':
  532. description: Updated
  533. content:
  534. 'application/json':
  535. schema:
  536. '$ref': '#/components/schemas/Reporter'
  537. delete:
  538. tags:
  539. - Admin
  540. summary: Soft-delete reporter
  541. security:
  542. - BearerAuth: []
  543. parameters:
  544. - '$ref': '#/components/parameters/ActingUserId'
  545. - name: id
  546. in: path
  547. required: true
  548. schema:
  549. type: integer
  550. responses:
  551. '204':
  552. description: Deleted
  553. '409':
  554. description: Has reports — flagged inactive instead.
  555. '/api/v1/admin/consumers':
  556. get:
  557. tags:
  558. - Admin
  559. summary: List consumers
  560. security:
  561. - BearerAuth: []
  562. parameters:
  563. - '$ref': '#/components/parameters/ActingUserId'
  564. responses:
  565. '200':
  566. description: list
  567. post:
  568. tags:
  569. - Admin
  570. summary: Create consumer
  571. security:
  572. - BearerAuth: []
  573. parameters:
  574. - '$ref': '#/components/parameters/ActingUserId'
  575. requestBody:
  576. required: true
  577. content:
  578. 'application/json':
  579. schema:
  580. '$ref': '#/components/schemas/Consumer'
  581. responses:
  582. '201':
  583. description: Created
  584. content:
  585. 'application/json':
  586. schema:
  587. '$ref': '#/components/schemas/Consumer'
  588. '/api/v1/admin/consumers/{id}':
  589. get:
  590. tags:
  591. - Admin
  592. summary: Show consumer
  593. security:
  594. - BearerAuth: []
  595. parameters:
  596. - '$ref': '#/components/parameters/ActingUserId'
  597. - name: id
  598. in: path
  599. required: true
  600. schema:
  601. type: integer
  602. responses:
  603. '200':
  604. description: consumer
  605. content:
  606. 'application/json':
  607. schema:
  608. '$ref': '#/components/schemas/Consumer'
  609. patch:
  610. tags:
  611. - Admin
  612. summary: Update consumer
  613. security:
  614. - BearerAuth: []
  615. parameters:
  616. - '$ref': '#/components/parameters/ActingUserId'
  617. - name: id
  618. in: path
  619. required: true
  620. schema:
  621. type: integer
  622. requestBody:
  623. content:
  624. 'application/json':
  625. schema:
  626. '$ref': '#/components/schemas/Consumer'
  627. responses:
  628. '200':
  629. description: Updated
  630. delete:
  631. tags:
  632. - Admin
  633. summary: Soft-delete consumer
  634. security:
  635. - BearerAuth: []
  636. parameters:
  637. - '$ref': '#/components/parameters/ActingUserId'
  638. - name: id
  639. in: path
  640. required: true
  641. schema:
  642. type: integer
  643. responses:
  644. '204':
  645. description: Deleted
  646. '/api/v1/admin/tokens':
  647. get:
  648. tags:
  649. - Admin
  650. summary: List tokens
  651. description: Service tokens are filtered out unconditionally.
  652. security:
  653. - BearerAuth: []
  654. parameters:
  655. - '$ref': '#/components/parameters/ActingUserId'
  656. responses:
  657. '200':
  658. description: list
  659. post:
  660. tags:
  661. - Admin
  662. summary: Create token
  663. description: Returns the raw token ONCE in `raw_token`. Service tokens are not creatable here.
  664. security:
  665. - BearerAuth: []
  666. parameters:
  667. - '$ref': '#/components/parameters/ActingUserId'
  668. requestBody:
  669. required: true
  670. content:
  671. 'application/json':
  672. schema:
  673. type: object
  674. properties:
  675. kind:
  676. type: string
  677. enum:
  678. - reporter
  679. - consumer
  680. - admin
  681. reporter_id:
  682. type: integer
  683. consumer_id:
  684. type: integer
  685. role:
  686. type: string
  687. enum:
  688. - viewer
  689. - operator
  690. - admin
  691. expires_at:
  692. type: string
  693. format: date-time
  694. responses:
  695. '201':
  696. description: Created
  697. content:
  698. 'application/json':
  699. schema:
  700. '$ref': '#/components/schemas/TokenCreated'
  701. '/api/v1/admin/tokens/{id}':
  702. delete:
  703. tags:
  704. - Admin
  705. summary: Revoke token
  706. security:
  707. - BearerAuth: []
  708. parameters:
  709. - '$ref': '#/components/parameters/ActingUserId'
  710. - name: id
  711. in: path
  712. required: true
  713. schema:
  714. type: integer
  715. responses:
  716. '204':
  717. description: Revoked
  718. '/api/v1/admin/categories':
  719. get:
  720. tags:
  721. - Admin
  722. summary: List categories
  723. security:
  724. - BearerAuth: []
  725. parameters:
  726. - '$ref': '#/components/parameters/ActingUserId'
  727. responses:
  728. '200':
  729. description: list
  730. post:
  731. tags:
  732. - Admin
  733. summary: Create category
  734. security:
  735. - BearerAuth: []
  736. parameters:
  737. - '$ref': '#/components/parameters/ActingUserId'
  738. requestBody:
  739. required: true
  740. content:
  741. 'application/json':
  742. schema:
  743. '$ref': '#/components/schemas/Category'
  744. responses:
  745. '201':
  746. description: Created
  747. content:
  748. 'application/json':
  749. schema:
  750. '$ref': '#/components/schemas/Category'
  751. '/api/v1/admin/categories/{id}':
  752. get:
  753. tags:
  754. - Admin
  755. summary: Show category
  756. security:
  757. - BearerAuth: []
  758. parameters:
  759. - '$ref': '#/components/parameters/ActingUserId'
  760. - name: id
  761. in: path
  762. required: true
  763. schema:
  764. type: integer
  765. responses:
  766. '200':
  767. description: category
  768. content:
  769. 'application/json':
  770. schema:
  771. '$ref': '#/components/schemas/Category'
  772. patch:
  773. tags:
  774. - Admin
  775. summary: Update category
  776. security:
  777. - BearerAuth: []
  778. parameters:
  779. - '$ref': '#/components/parameters/ActingUserId'
  780. - name: id
  781. in: path
  782. required: true
  783. schema:
  784. type: integer
  785. requestBody:
  786. content:
  787. 'application/json':
  788. schema:
  789. '$ref': '#/components/schemas/Category'
  790. responses:
  791. '200':
  792. description: Updated
  793. delete:
  794. tags:
  795. - Admin
  796. summary: Hard-delete category (refused if in use)
  797. security:
  798. - BearerAuth: []
  799. parameters:
  800. - '$ref': '#/components/parameters/ActingUserId'
  801. - name: id
  802. in: path
  803. required: true
  804. schema:
  805. type: integer
  806. responses:
  807. '204':
  808. description: Deleted
  809. '409':
  810. description: Category in use; soft-delete via PATCH `is_active=false`.
  811. '/api/v1/admin/policies':
  812. get:
  813. tags:
  814. - Admin
  815. summary: List policies
  816. security:
  817. - BearerAuth: []
  818. parameters:
  819. - '$ref': '#/components/parameters/ActingUserId'
  820. responses:
  821. '200':
  822. description: list
  823. post:
  824. tags:
  825. - Admin
  826. summary: Create policy
  827. security:
  828. - BearerAuth: []
  829. parameters:
  830. - '$ref': '#/components/parameters/ActingUserId'
  831. requestBody:
  832. required: true
  833. content:
  834. 'application/json':
  835. schema:
  836. '$ref': '#/components/schemas/Policy'
  837. responses:
  838. '201':
  839. description: Created
  840. content:
  841. 'application/json':
  842. schema:
  843. '$ref': '#/components/schemas/Policy'
  844. '/api/v1/admin/policies/{id}':
  845. get:
  846. tags:
  847. - Admin
  848. summary: Show policy
  849. security:
  850. - BearerAuth: []
  851. parameters:
  852. - '$ref': '#/components/parameters/ActingUserId'
  853. - name: id
  854. in: path
  855. required: true
  856. schema:
  857. type: integer
  858. responses:
  859. '200':
  860. description: policy
  861. content:
  862. 'application/json':
  863. schema:
  864. '$ref': '#/components/schemas/Policy'
  865. patch:
  866. tags:
  867. - Admin
  868. summary: Update policy (replaces thresholds wholesale when present)
  869. security:
  870. - BearerAuth: []
  871. parameters:
  872. - '$ref': '#/components/parameters/ActingUserId'
  873. - name: id
  874. in: path
  875. required: true
  876. schema:
  877. type: integer
  878. requestBody:
  879. content:
  880. 'application/json':
  881. schema:
  882. '$ref': '#/components/schemas/Policy'
  883. responses:
  884. '200':
  885. description: Updated
  886. delete:
  887. tags:
  888. - Admin
  889. summary: Delete policy (refused if used by consumers)
  890. security:
  891. - BearerAuth: []
  892. parameters:
  893. - '$ref': '#/components/parameters/ActingUserId'
  894. - name: id
  895. in: path
  896. required: true
  897. schema:
  898. type: integer
  899. responses:
  900. '204':
  901. description: Deleted
  902. '409':
  903. description: Policy in use
  904. '/api/v1/admin/policies/{id}/preview':
  905. get:
  906. tags:
  907. - Admin
  908. summary: Preview policy (count + sample)
  909. security:
  910. - BearerAuth: []
  911. parameters:
  912. - '$ref': '#/components/parameters/ActingUserId'
  913. - name: id
  914. in: path
  915. required: true
  916. schema:
  917. type: integer
  918. responses:
  919. '200':
  920. description: Preview
  921. '/api/v1/admin/audit-log':
  922. get:
  923. tags:
  924. - Admin
  925. summary: Filtered audit log
  926. security:
  927. - BearerAuth: []
  928. parameters:
  929. - '$ref': '#/components/parameters/ActingUserId'
  930. - name: actor_kind
  931. in: query
  932. schema:
  933. type: string
  934. enum:
  935. - user
  936. - admin-token
  937. - reporter
  938. - consumer
  939. - system
  940. - name: actor_id
  941. in: query
  942. schema:
  943. type: integer
  944. - name: action
  945. in: query
  946. schema:
  947. type: string
  948. - name: entity_type
  949. in: query
  950. schema:
  951. type: string
  952. - name: entity_id
  953. in: query
  954. schema:
  955. type: string
  956. - name: from
  957. in: query
  958. schema:
  959. type: string
  960. format: date-time
  961. - name: to
  962. in: query
  963. schema:
  964. type: string
  965. format: date-time
  966. - '$ref': '#/components/parameters/Page'
  967. - '$ref': '#/components/parameters/PageSize'
  968. responses:
  969. '200':
  970. description: Audit page
  971. content:
  972. 'application/json':
  973. schema:
  974. type: object
  975. properties:
  976. page:
  977. type: integer
  978. minimum: 1
  979. example: 1
  980. page_size:
  981. type: integer
  982. minimum: 1
  983. maximum: 200
  984. example: 50
  985. total:
  986. type: integer
  987. minimum: 0
  988. example: 1284
  989. items:
  990. type: array
  991. items:
  992. '$ref': '#/components/schemas/AuditEntry'
  993. '/api/v1/admin/jobs/status':
  994. get:
  995. tags:
  996. - Admin
  997. summary: Jobs status (Viewer)
  998. security:
  999. - BearerAuth: []
  1000. parameters:
  1001. - '$ref': '#/components/parameters/ActingUserId'
  1002. responses:
  1003. '200':
  1004. description: Jobs status
  1005. content:
  1006. 'application/json':
  1007. schema:
  1008. type: object
  1009. properties:
  1010. now:
  1011. type: string
  1012. format: date-time
  1013. jobs:
  1014. type: object
  1015. additionalProperties:
  1016. '$ref': '#/components/schemas/JobStatus'
  1017. '/api/v1/admin/jobs/trigger/{name}':
  1018. post:
  1019. tags:
  1020. - Admin
  1021. summary: Manually trigger a job (Admin)
  1022. description: 'Whitelisted params: `full`, `max_rows`, `reenrich`. Other body fields are dropped.'
  1023. security:
  1024. - BearerAuth: []
  1025. parameters:
  1026. - '$ref': '#/components/parameters/ActingUserId'
  1027. - name: name
  1028. in: path
  1029. required: true
  1030. schema:
  1031. type: string
  1032. requestBody:
  1033. content:
  1034. 'application/json':
  1035. schema:
  1036. type: object
  1037. properties:
  1038. full:
  1039. type: boolean
  1040. max_rows:
  1041. type: integer
  1042. reenrich:
  1043. type: boolean
  1044. responses:
  1045. '200':
  1046. description: Job ran
  1047. content:
  1048. 'application/json':
  1049. schema:
  1050. '$ref': '#/components/schemas/JobOutcome'
  1051. '404':
  1052. description: Unknown job
  1053. '409':
  1054. description: Lock held; status=`skipped_locked`
  1055. '412':
  1056. description: refresh-geoip without credential
  1057. '/api/v1/admin/config':
  1058. get:
  1059. tags:
  1060. - Admin
  1061. summary: Effective config (secrets masked)
  1062. description: Admin only.
  1063. security:
  1064. - BearerAuth: []
  1065. parameters:
  1066. - '$ref': '#/components/parameters/ActingUserId'
  1067. responses:
  1068. '200':
  1069. description: Config sections
  1070. content:
  1071. 'application/json':
  1072. schema:
  1073. type: object
  1074. properties:
  1075. sections:
  1076. type: object
  1077. additionalProperties:
  1078. type: object
  1079. '/api/v1/admin/app-settings':
  1080. get:
  1081. tags:
  1082. - Admin
  1083. summary: Runtime feature flags (Admin)
  1084. description: |
  1085. Returns the runtime-mutable feature flags. Currently exposes the
  1086. audit-emission toggles for high-volume public endpoints
  1087. (`audit_report_received_enabled`, `audit_blocklist_request_enabled`).
  1088. security:
  1089. - BearerAuth: []
  1090. parameters:
  1091. - '$ref': '#/components/parameters/ActingUserId'
  1092. responses:
  1093. '200':
  1094. description: Current toggle state
  1095. content:
  1096. 'application/json':
  1097. schema:
  1098. type: object
  1099. additionalProperties:
  1100. type: boolean
  1101. patch:
  1102. tags:
  1103. - Admin
  1104. summary: Update runtime feature flags (Admin)
  1105. description: |
  1106. Updates one or more runtime feature flags. Body keys not listed are left
  1107. untouched. Returns the post-update snapshot.
  1108. security:
  1109. - BearerAuth: []
  1110. parameters:
  1111. - '$ref': '#/components/parameters/ActingUserId'
  1112. requestBody:
  1113. required: true
  1114. content:
  1115. 'application/json':
  1116. schema:
  1117. type: object
  1118. properties:
  1119. audit_report_received_enabled:
  1120. type: boolean
  1121. audit_blocklist_request_enabled:
  1122. type: boolean
  1123. responses:
  1124. '200':
  1125. description: Updated snapshot
  1126. content:
  1127. 'application/json':
  1128. schema:
  1129. type: object
  1130. additionalProperties:
  1131. type: boolean
  1132. '400':
  1133. description: Validation error
  1134. '/api/v1/admin/maintenance/purge':
  1135. post:
  1136. tags:
  1137. - Admin
  1138. summary: Wipe operational data (Admin)
  1139. description: |
  1140. Deletes reports, scores, enrichment, manual blocks, allowlist, audit log, job history, reporters, consumers, policies, and non-service tokens. Preserves users, OIDC role mappings, abuse categories, and the `service`-kind token.
  1141. Requires `confirm: "PURGE"` in the body — any other value returns 400.
  1142. security:
  1143. - BearerAuth: []
  1144. parameters:
  1145. - '$ref': '#/components/parameters/ActingUserId'
  1146. requestBody:
  1147. required: true
  1148. content:
  1149. 'application/json':
  1150. schema:
  1151. type: object
  1152. required:
  1153. - confirm
  1154. properties:
  1155. confirm:
  1156. type: string
  1157. enum:
  1158. - PURGE
  1159. responses:
  1160. '200':
  1161. description: Purge succeeded
  1162. content:
  1163. 'application/json':
  1164. schema:
  1165. type: object
  1166. properties:
  1167. status:
  1168. type: string
  1169. example: purged
  1170. deleted:
  1171. type: object
  1172. additionalProperties:
  1173. type: integer
  1174. '400':
  1175. description: Missing or wrong `confirm` value
  1176. '/api/v1/admin/maintenance/seed-demo':
  1177. post:
  1178. tags:
  1179. - Admin
  1180. summary: Load demo dataset (Admin)
  1181. description: 'Populates reporters, consumers, IPs, reports, manual blocks, allowlist, and synthetic GeoIP for demos and screenshots. Triggers a full score recompute on completion. Idempotent: returns 409 if demo data is already present.'
  1182. security:
  1183. - BearerAuth: []
  1184. parameters:
  1185. - '$ref': '#/components/parameters/ActingUserId'
  1186. responses:
  1187. '200':
  1188. description: Demo data inserted
  1189. content:
  1190. 'application/json':
  1191. schema:
  1192. type: object
  1193. properties:
  1194. status:
  1195. type: string
  1196. example: seeded
  1197. summary:
  1198. type: object
  1199. additionalProperties:
  1200. type: integer
  1201. recompute:
  1202. '$ref': '#/components/schemas/JobOutcome'
  1203. '409':
  1204. description: Demo data already present
  1205. '412':
  1206. description: No categories configured
  1207. '/api/v1/auth/users/upsert-oidc':
  1208. post:
  1209. tags:
  1210. - Auth
  1211. summary: Upsert an OIDC-authenticated user
  1212. description: |
  1213. **UI BFF only.** Service-token-required, no impersonation header.
  1214. Resolves the user record + role (via `oidc_role_mappings`) for a freshly-validated ID token.
  1215. x-internal: true
  1216. security:
  1217. - BearerAuth: []
  1218. requestBody:
  1219. required: true
  1220. content:
  1221. 'application/json':
  1222. schema:
  1223. type: object
  1224. properties:
  1225. subject:
  1226. type: string
  1227. email:
  1228. type: string
  1229. display_name:
  1230. type: string
  1231. groups:
  1232. type: array
  1233. items:
  1234. type: string
  1235. responses:
  1236. '200':
  1237. description: User record
  1238. content:
  1239. 'application/json':
  1240. schema:
  1241. '$ref': '#/components/schemas/User'
  1242. '/api/v1/auth/users/upsert-local':
  1243. post:
  1244. tags:
  1245. - Auth
  1246. summary: Upsert the local-admin user
  1247. description: '**UI BFF only.** Called after the UI validates the local-admin password.'
  1248. x-internal: true
  1249. security:
  1250. - BearerAuth: []
  1251. requestBody:
  1252. required: true
  1253. content:
  1254. 'application/json':
  1255. schema:
  1256. type: object
  1257. properties:
  1258. username:
  1259. type: string
  1260. responses:
  1261. '200':
  1262. description: User record
  1263. content:
  1264. 'application/json':
  1265. schema:
  1266. '$ref': '#/components/schemas/User'
  1267. '/api/v1/auth/users/{id}':
  1268. get:
  1269. tags:
  1270. - Auth
  1271. summary: Refetch a user record
  1272. description: '**UI BFF only.** Used to refresh role / display_name during a session.'
  1273. x-internal: true
  1274. security:
  1275. - BearerAuth: []
  1276. parameters:
  1277. - name: id
  1278. in: path
  1279. required: true
  1280. schema:
  1281. type: integer
  1282. responses:
  1283. '200':
  1284. description: User record
  1285. content:
  1286. 'application/json':
  1287. schema:
  1288. '$ref': '#/components/schemas/User'
  1289. components:
  1290. securitySchemes:
  1291. BearerAuth:
  1292. type: http
  1293. scheme: bearer
  1294. description: |
  1295. Token in the form `irdb_<kind>_<32 base32 chars>`.
  1296. See `doc/auth-flows.md` for the four token kinds.
  1297. parameters:
  1298. Page:
  1299. name: page
  1300. in: query
  1301. schema:
  1302. type: integer
  1303. minimum: 1
  1304. default: 1
  1305. PageSize:
  1306. name: page_size
  1307. in: query
  1308. schema:
  1309. type: integer
  1310. minimum: 1
  1311. maximum: 200
  1312. default: 50
  1313. ActingUserId:
  1314. name: X-Acting-User-Id
  1315. in: header
  1316. description: |
  1317. Required when authenticating with a `service` token.
  1318. The api applies RBAC for the named user. Ignored on other token kinds.
  1319. schema:
  1320. type: integer
  1321. schemas:
  1322. Error:
  1323. type: object
  1324. required:
  1325. - error
  1326. properties:
  1327. error:
  1328. type: string
  1329. example: unauthorized
  1330. details:
  1331. type: object
  1332. description: Field-level errors for `validation_failed`.
  1333. additionalProperties:
  1334. type: string
  1335. ReportRequest:
  1336. type: object
  1337. required:
  1338. - ip
  1339. - category
  1340. properties:
  1341. ip:
  1342. type: string
  1343. example: '203.0.113.42'
  1344. category:
  1345. type: string
  1346. example: brute_force
  1347. metadata:
  1348. type: object
  1349. description: Free-form per-report data, max 4 KB after json_encode.
  1350. additionalProperties: true
  1351. ReportResponse:
  1352. type: object
  1353. properties:
  1354. report_id:
  1355. type: integer
  1356. example: 12345
  1357. ip:
  1358. type: string
  1359. example: '203.0.113.42'
  1360. received_at:
  1361. type: string
  1362. format: date-time
  1363. BlocklistEntry:
  1364. type: object
  1365. properties:
  1366. ip_or_cidr:
  1367. type: string
  1368. example: '203.0.113.42'
  1369. categories:
  1370. type: array
  1371. items:
  1372. type: string
  1373. score:
  1374. type: number
  1375. format: float
  1376. example: 1.42
  1377. reason:
  1378. type: string
  1379. enum:
  1380. - scored
  1381. - manual
  1382. example: scored
  1383. BlocklistJson:
  1384. type: object
  1385. properties:
  1386. count:
  1387. type: integer
  1388. example: 42
  1389. generated_at:
  1390. type: string
  1391. format: date-time
  1392. policy:
  1393. type: string
  1394. example: moderate
  1395. entries:
  1396. type: array
  1397. items:
  1398. '$ref': '#/components/schemas/BlocklistEntry'
  1399. Token:
  1400. type: object
  1401. properties:
  1402. id:
  1403. type: integer
  1404. kind:
  1405. type: string
  1406. enum:
  1407. - reporter
  1408. - consumer
  1409. - admin
  1410. prefix:
  1411. type: string
  1412. example: irdb_adm
  1413. reporter_id:
  1414. type: integer
  1415. nullable: true
  1416. consumer_id:
  1417. type: integer
  1418. nullable: true
  1419. role:
  1420. type: string
  1421. nullable: true
  1422. enum:
  1423. - viewer
  1424. - operator
  1425. - admin
  1426. - null
  1427. expires_at:
  1428. type: string
  1429. format: date-time
  1430. nullable: true
  1431. revoked_at:
  1432. type: string
  1433. format: date-time
  1434. nullable: true
  1435. last_used_at:
  1436. type: string
  1437. format: date-time
  1438. nullable: true
  1439. TokenCreated:
  1440. allOf:
  1441. - '$ref': '#/components/schemas/Token'
  1442. - type: object
  1443. properties:
  1444. raw_token:
  1445. type: string
  1446. description: Returned ONCE on creation — copy it now, never displayed again.
  1447. example: irdb_adm_AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD
  1448. Reporter:
  1449. type: object
  1450. properties:
  1451. id:
  1452. type: integer
  1453. name:
  1454. type: string
  1455. example: web-prod-01
  1456. description:
  1457. type: string
  1458. nullable: true
  1459. trust_weight:
  1460. type: number
  1461. format: float
  1462. minimum: 0
  1463. maximum: 2
  1464. is_active:
  1465. type: boolean
  1466. Consumer:
  1467. type: object
  1468. properties:
  1469. id:
  1470. type: integer
  1471. name:
  1472. type: string
  1473. example: edge-fw-01
  1474. description:
  1475. type: string
  1476. nullable: true
  1477. policy_id:
  1478. type: integer
  1479. is_active:
  1480. type: boolean
  1481. last_pulled_at:
  1482. type: string
  1483. format: date-time
  1484. nullable: true
  1485. Category:
  1486. type: object
  1487. properties:
  1488. id:
  1489. type: integer
  1490. slug:
  1491. type: string
  1492. example: brute_force
  1493. name:
  1494. type: string
  1495. description:
  1496. type: string
  1497. nullable: true
  1498. decay_function:
  1499. type: string
  1500. enum:
  1501. - linear
  1502. - exponential
  1503. decay_param:
  1504. type: number
  1505. format: float
  1506. is_active:
  1507. type: boolean
  1508. Policy:
  1509. type: object
  1510. properties:
  1511. id:
  1512. type: integer
  1513. name:
  1514. type: string
  1515. example: moderate
  1516. description:
  1517. type: string
  1518. nullable: true
  1519. include_manual_blocks:
  1520. type: boolean
  1521. thresholds:
  1522. type: object
  1523. description: '`{category_slug: threshold}`'
  1524. additionalProperties:
  1525. type: number
  1526. format: float
  1527. ManualBlock:
  1528. type: object
  1529. properties:
  1530. id:
  1531. type: integer
  1532. kind:
  1533. type: string
  1534. enum:
  1535. - ip
  1536. - subnet
  1537. ip:
  1538. type: string
  1539. nullable: true
  1540. cidr:
  1541. type: string
  1542. nullable: true
  1543. reason:
  1544. type: string
  1545. nullable: true
  1546. expires_at:
  1547. type: string
  1548. format: date-time
  1549. nullable: true
  1550. created_at:
  1551. type: string
  1552. format: date-time
  1553. AllowlistEntry:
  1554. type: object
  1555. properties:
  1556. id:
  1557. type: integer
  1558. kind:
  1559. type: string
  1560. enum:
  1561. - ip
  1562. - subnet
  1563. ip:
  1564. type: string
  1565. nullable: true
  1566. cidr:
  1567. type: string
  1568. nullable: true
  1569. reason:
  1570. type: string
  1571. nullable: true
  1572. created_at:
  1573. type: string
  1574. format: date-time
  1575. IpDetail:
  1576. type: object
  1577. properties:
  1578. ip:
  1579. type: string
  1580. is_ipv4:
  1581. type: boolean
  1582. scores:
  1583. type: array
  1584. items:
  1585. type: object
  1586. properties:
  1587. category:
  1588. type: string
  1589. score:
  1590. type: number
  1591. format: float
  1592. last_report_at:
  1593. type: string
  1594. format: date-time
  1595. nullable: true
  1596. report_count_30d:
  1597. type: integer
  1598. enrichment:
  1599. type: object
  1600. properties:
  1601. country_code:
  1602. type: string
  1603. nullable: true
  1604. asn:
  1605. type: integer
  1606. nullable: true
  1607. as_org:
  1608. type: string
  1609. nullable: true
  1610. enriched_at:
  1611. type: string
  1612. format: date-time
  1613. nullable: true
  1614. status:
  1615. type: string
  1616. enum:
  1617. - scored
  1618. - manually_blocked
  1619. - allowlisted
  1620. - clean
  1621. manual_block:
  1622. type: object
  1623. nullable: true
  1624. allowlist:
  1625. type: object
  1626. nullable: true
  1627. history:
  1628. type: array
  1629. items:
  1630. type: object
  1631. has_more:
  1632. type: boolean
  1633. AuditEntry:
  1634. type: object
  1635. properties:
  1636. id:
  1637. type: integer
  1638. occurred_at:
  1639. type: string
  1640. format: date-time
  1641. actor_kind:
  1642. type: string
  1643. enum:
  1644. - user
  1645. - admin-token
  1646. - reporter
  1647. - consumer
  1648. - system
  1649. actor_id:
  1650. type: string
  1651. nullable: true
  1652. action:
  1653. type: string
  1654. example: manual_block.created
  1655. entity_type:
  1656. type: string
  1657. nullable: true
  1658. entity_id:
  1659. type: string
  1660. nullable: true
  1661. entity_label:
  1662. type: string
  1663. nullable: true
  1664. description: Human-readable identifier for the target (name, slug, IP, CIDR, prefix). Frozen at write time.
  1665. details:
  1666. type: object
  1667. nullable: true
  1668. additionalProperties: true
  1669. description: 'For update events, contains a `changes` map of `{field: {from, to}}` for every modified field.'
  1670. source_ip:
  1671. type: string
  1672. nullable: true
  1673. JobStatus:
  1674. type: object
  1675. properties:
  1676. name:
  1677. type: string
  1678. default_interval_seconds:
  1679. type: integer
  1680. max_runtime_seconds:
  1681. type: integer
  1682. overdue:
  1683. type: boolean
  1684. last_run:
  1685. type: object
  1686. nullable: true
  1687. properties:
  1688. id:
  1689. type: integer
  1690. status:
  1691. type: string
  1692. enum:
  1693. - success
  1694. - failure
  1695. - skipped_locked
  1696. - running
  1697. items_processed:
  1698. type: integer
  1699. triggered_by:
  1700. type: string
  1701. enum:
  1702. - schedule
  1703. - manual
  1704. - api
  1705. started_at:
  1706. type: string
  1707. format: date-time
  1708. nullable: true
  1709. finished_at:
  1710. type: string
  1711. format: date-time
  1712. nullable: true
  1713. error_message:
  1714. type: string
  1715. nullable: true
  1716. JobOutcome:
  1717. type: object
  1718. properties:
  1719. job:
  1720. type: string
  1721. status:
  1722. type: string
  1723. enum:
  1724. - success
  1725. - failure
  1726. - skipped_locked
  1727. - running
  1728. items_processed:
  1729. type: integer
  1730. duration_ms:
  1731. type: integer
  1732. run_id:
  1733. type: integer
  1734. nullable: true
  1735. error:
  1736. type: string
  1737. nullable: true
  1738. User:
  1739. type: object
  1740. properties:
  1741. id:
  1742. type: integer
  1743. email:
  1744. type: string
  1745. nullable: true
  1746. display_name:
  1747. type: string
  1748. role:
  1749. type: string
  1750. enum:
  1751. - viewer
  1752. - operator
  1753. - admin
  1754. source:
  1755. type: string
  1756. enum:
  1757. - oidc
  1758. - local
  1759. - admin-token
  1760. is_local:
  1761. type: boolean
  1762. Pagination:
  1763. type: object
  1764. properties:
  1765. page:
  1766. type: integer
  1767. minimum: 1
  1768. example: 1
  1769. page_size:
  1770. type: integer
  1771. minimum: 1
  1772. maximum: 200
  1773. example: 50
  1774. total:
  1775. type: integer
  1776. minimum: 0
  1777. example: 1284