openapi.yaml 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  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/auth/users/upsert-oidc':
  1080. post:
  1081. tags:
  1082. - Auth
  1083. summary: Upsert an OIDC-authenticated user
  1084. description: |
  1085. **UI BFF only.** Service-token-required, no impersonation header.
  1086. Resolves the user record + role (via `oidc_role_mappings`) for a freshly-validated ID token.
  1087. x-internal: true
  1088. security:
  1089. - BearerAuth: []
  1090. requestBody:
  1091. required: true
  1092. content:
  1093. 'application/json':
  1094. schema:
  1095. type: object
  1096. properties:
  1097. subject:
  1098. type: string
  1099. email:
  1100. type: string
  1101. display_name:
  1102. type: string
  1103. groups:
  1104. type: array
  1105. items:
  1106. type: string
  1107. responses:
  1108. '200':
  1109. description: User record
  1110. content:
  1111. 'application/json':
  1112. schema:
  1113. '$ref': '#/components/schemas/User'
  1114. '/api/v1/auth/users/upsert-local':
  1115. post:
  1116. tags:
  1117. - Auth
  1118. summary: Upsert the local-admin user
  1119. description: '**UI BFF only.** Called after the UI validates the local-admin password.'
  1120. x-internal: true
  1121. security:
  1122. - BearerAuth: []
  1123. requestBody:
  1124. required: true
  1125. content:
  1126. 'application/json':
  1127. schema:
  1128. type: object
  1129. properties:
  1130. username:
  1131. type: string
  1132. responses:
  1133. '200':
  1134. description: User record
  1135. content:
  1136. 'application/json':
  1137. schema:
  1138. '$ref': '#/components/schemas/User'
  1139. '/api/v1/auth/users/{id}':
  1140. get:
  1141. tags:
  1142. - Auth
  1143. summary: Refetch a user record
  1144. description: '**UI BFF only.** Used to refresh role / display_name during a session.'
  1145. x-internal: true
  1146. security:
  1147. - BearerAuth: []
  1148. parameters:
  1149. - name: id
  1150. in: path
  1151. required: true
  1152. schema:
  1153. type: integer
  1154. responses:
  1155. '200':
  1156. description: User record
  1157. content:
  1158. 'application/json':
  1159. schema:
  1160. '$ref': '#/components/schemas/User'
  1161. components:
  1162. securitySchemes:
  1163. BearerAuth:
  1164. type: http
  1165. scheme: bearer
  1166. description: |
  1167. Token in the form `irdb_<kind>_<32 base32 chars>`.
  1168. See `doc/auth-flows.md` for the four token kinds.
  1169. parameters:
  1170. Page:
  1171. name: page
  1172. in: query
  1173. schema:
  1174. type: integer
  1175. minimum: 1
  1176. default: 1
  1177. PageSize:
  1178. name: page_size
  1179. in: query
  1180. schema:
  1181. type: integer
  1182. minimum: 1
  1183. maximum: 200
  1184. default: 50
  1185. ActingUserId:
  1186. name: X-Acting-User-Id
  1187. in: header
  1188. description: |
  1189. Required when authenticating with a `service` token.
  1190. The api applies RBAC for the named user. Ignored on other token kinds.
  1191. schema:
  1192. type: integer
  1193. schemas:
  1194. Error:
  1195. type: object
  1196. required:
  1197. - error
  1198. properties:
  1199. error:
  1200. type: string
  1201. example: unauthorized
  1202. details:
  1203. type: object
  1204. description: Field-level errors for `validation_failed`.
  1205. additionalProperties:
  1206. type: string
  1207. ReportRequest:
  1208. type: object
  1209. required:
  1210. - ip
  1211. - category
  1212. properties:
  1213. ip:
  1214. type: string
  1215. example: '203.0.113.42'
  1216. category:
  1217. type: string
  1218. example: brute_force
  1219. metadata:
  1220. type: object
  1221. description: Free-form per-report data, max 4 KB after json_encode.
  1222. additionalProperties: true
  1223. ReportResponse:
  1224. type: object
  1225. properties:
  1226. report_id:
  1227. type: integer
  1228. example: 12345
  1229. ip:
  1230. type: string
  1231. example: '203.0.113.42'
  1232. received_at:
  1233. type: string
  1234. format: date-time
  1235. BlocklistEntry:
  1236. type: object
  1237. properties:
  1238. ip_or_cidr:
  1239. type: string
  1240. example: '203.0.113.42'
  1241. categories:
  1242. type: array
  1243. items:
  1244. type: string
  1245. score:
  1246. type: number
  1247. format: float
  1248. example: 1.42
  1249. reason:
  1250. type: string
  1251. enum:
  1252. - scored
  1253. - manual
  1254. example: scored
  1255. BlocklistJson:
  1256. type: object
  1257. properties:
  1258. count:
  1259. type: integer
  1260. example: 42
  1261. generated_at:
  1262. type: string
  1263. format: date-time
  1264. policy:
  1265. type: string
  1266. example: moderate
  1267. entries:
  1268. type: array
  1269. items:
  1270. '$ref': '#/components/schemas/BlocklistEntry'
  1271. Token:
  1272. type: object
  1273. properties:
  1274. id:
  1275. type: integer
  1276. kind:
  1277. type: string
  1278. enum:
  1279. - reporter
  1280. - consumer
  1281. - admin
  1282. prefix:
  1283. type: string
  1284. example: irdb_adm
  1285. reporter_id:
  1286. type: integer
  1287. nullable: true
  1288. consumer_id:
  1289. type: integer
  1290. nullable: true
  1291. role:
  1292. type: string
  1293. nullable: true
  1294. enum:
  1295. - viewer
  1296. - operator
  1297. - admin
  1298. - null
  1299. expires_at:
  1300. type: string
  1301. format: date-time
  1302. nullable: true
  1303. revoked_at:
  1304. type: string
  1305. format: date-time
  1306. nullable: true
  1307. last_used_at:
  1308. type: string
  1309. format: date-time
  1310. nullable: true
  1311. TokenCreated:
  1312. allOf:
  1313. - '$ref': '#/components/schemas/Token'
  1314. - type: object
  1315. properties:
  1316. raw_token:
  1317. type: string
  1318. description: Returned ONCE on creation — copy it now, never displayed again.
  1319. example: irdb_adm_AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD
  1320. Reporter:
  1321. type: object
  1322. properties:
  1323. id:
  1324. type: integer
  1325. name:
  1326. type: string
  1327. example: web-prod-01
  1328. description:
  1329. type: string
  1330. nullable: true
  1331. trust_weight:
  1332. type: number
  1333. format: float
  1334. minimum: 0
  1335. maximum: 2
  1336. is_active:
  1337. type: boolean
  1338. Consumer:
  1339. type: object
  1340. properties:
  1341. id:
  1342. type: integer
  1343. name:
  1344. type: string
  1345. example: edge-fw-01
  1346. description:
  1347. type: string
  1348. nullable: true
  1349. policy_id:
  1350. type: integer
  1351. is_active:
  1352. type: boolean
  1353. last_pulled_at:
  1354. type: string
  1355. format: date-time
  1356. nullable: true
  1357. Category:
  1358. type: object
  1359. properties:
  1360. id:
  1361. type: integer
  1362. slug:
  1363. type: string
  1364. example: brute_force
  1365. name:
  1366. type: string
  1367. description:
  1368. type: string
  1369. nullable: true
  1370. decay_function:
  1371. type: string
  1372. enum:
  1373. - linear
  1374. - exponential
  1375. decay_param:
  1376. type: number
  1377. format: float
  1378. is_active:
  1379. type: boolean
  1380. Policy:
  1381. type: object
  1382. properties:
  1383. id:
  1384. type: integer
  1385. name:
  1386. type: string
  1387. example: moderate
  1388. description:
  1389. type: string
  1390. nullable: true
  1391. include_manual_blocks:
  1392. type: boolean
  1393. thresholds:
  1394. type: object
  1395. description: '`{category_slug: threshold}`'
  1396. additionalProperties:
  1397. type: number
  1398. format: float
  1399. ManualBlock:
  1400. type: object
  1401. properties:
  1402. id:
  1403. type: integer
  1404. kind:
  1405. type: string
  1406. enum:
  1407. - ip
  1408. - subnet
  1409. ip:
  1410. type: string
  1411. nullable: true
  1412. cidr:
  1413. type: string
  1414. nullable: true
  1415. reason:
  1416. type: string
  1417. nullable: true
  1418. expires_at:
  1419. type: string
  1420. format: date-time
  1421. nullable: true
  1422. created_at:
  1423. type: string
  1424. format: date-time
  1425. AllowlistEntry:
  1426. type: object
  1427. properties:
  1428. id:
  1429. type: integer
  1430. kind:
  1431. type: string
  1432. enum:
  1433. - ip
  1434. - subnet
  1435. ip:
  1436. type: string
  1437. nullable: true
  1438. cidr:
  1439. type: string
  1440. nullable: true
  1441. reason:
  1442. type: string
  1443. nullable: true
  1444. created_at:
  1445. type: string
  1446. format: date-time
  1447. IpDetail:
  1448. type: object
  1449. properties:
  1450. ip:
  1451. type: string
  1452. is_ipv4:
  1453. type: boolean
  1454. scores:
  1455. type: array
  1456. items:
  1457. type: object
  1458. properties:
  1459. category:
  1460. type: string
  1461. score:
  1462. type: number
  1463. format: float
  1464. last_report_at:
  1465. type: string
  1466. format: date-time
  1467. nullable: true
  1468. report_count_30d:
  1469. type: integer
  1470. enrichment:
  1471. type: object
  1472. properties:
  1473. country_code:
  1474. type: string
  1475. nullable: true
  1476. asn:
  1477. type: integer
  1478. nullable: true
  1479. as_org:
  1480. type: string
  1481. nullable: true
  1482. enriched_at:
  1483. type: string
  1484. format: date-time
  1485. nullable: true
  1486. status:
  1487. type: string
  1488. enum:
  1489. - scored
  1490. - manually_blocked
  1491. - allowlisted
  1492. - clean
  1493. manual_block:
  1494. type: object
  1495. nullable: true
  1496. allowlist:
  1497. type: object
  1498. nullable: true
  1499. history:
  1500. type: array
  1501. items:
  1502. type: object
  1503. has_more:
  1504. type: boolean
  1505. AuditEntry:
  1506. type: object
  1507. properties:
  1508. id:
  1509. type: integer
  1510. occurred_at:
  1511. type: string
  1512. format: date-time
  1513. actor_kind:
  1514. type: string
  1515. enum:
  1516. - user
  1517. - admin-token
  1518. - reporter
  1519. - consumer
  1520. - system
  1521. actor_id:
  1522. type: string
  1523. nullable: true
  1524. action:
  1525. type: string
  1526. example: manual_block.created
  1527. entity_type:
  1528. type: string
  1529. nullable: true
  1530. entity_id:
  1531. type: string
  1532. nullable: true
  1533. details:
  1534. type: object
  1535. nullable: true
  1536. additionalProperties: true
  1537. source_ip:
  1538. type: string
  1539. nullable: true
  1540. JobStatus:
  1541. type: object
  1542. properties:
  1543. name:
  1544. type: string
  1545. default_interval_seconds:
  1546. type: integer
  1547. max_runtime_seconds:
  1548. type: integer
  1549. overdue:
  1550. type: boolean
  1551. last_run:
  1552. type: object
  1553. nullable: true
  1554. properties:
  1555. id:
  1556. type: integer
  1557. status:
  1558. type: string
  1559. enum:
  1560. - success
  1561. - failure
  1562. - skipped_locked
  1563. - running
  1564. items_processed:
  1565. type: integer
  1566. triggered_by:
  1567. type: string
  1568. enum:
  1569. - schedule
  1570. - manual
  1571. - api
  1572. started_at:
  1573. type: string
  1574. format: date-time
  1575. nullable: true
  1576. finished_at:
  1577. type: string
  1578. format: date-time
  1579. nullable: true
  1580. error_message:
  1581. type: string
  1582. nullable: true
  1583. JobOutcome:
  1584. type: object
  1585. properties:
  1586. job:
  1587. type: string
  1588. status:
  1589. type: string
  1590. enum:
  1591. - success
  1592. - failure
  1593. - skipped_locked
  1594. - running
  1595. items_processed:
  1596. type: integer
  1597. duration_ms:
  1598. type: integer
  1599. run_id:
  1600. type: integer
  1601. nullable: true
  1602. error:
  1603. type: string
  1604. nullable: true
  1605. User:
  1606. type: object
  1607. properties:
  1608. id:
  1609. type: integer
  1610. email:
  1611. type: string
  1612. nullable: true
  1613. display_name:
  1614. type: string
  1615. role:
  1616. type: string
  1617. enum:
  1618. - viewer
  1619. - operator
  1620. - admin
  1621. source:
  1622. type: string
  1623. enum:
  1624. - oidc
  1625. - local
  1626. - admin-token
  1627. is_local:
  1628. type: boolean
  1629. Pagination:
  1630. type: object
  1631. properties:
  1632. page:
  1633. type: integer
  1634. minimum: 1
  1635. example: 1
  1636. page_size:
  1637. type: integer
  1638. minimum: 1
  1639. maximum: 200
  1640. example: 50
  1641. total:
  1642. type: integer
  1643. minimum: 0
  1644. example: 1284