bro_hub 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/README.md +175 -165
  4. data/app/controllers/bro_hub/apm/application_controller.rb +26 -0
  5. data/app/controllers/bro_hub/apm/deploys_controller.rb +7 -0
  6. data/app/controllers/bro_hub/apm/endpoints_controller.rb +8 -0
  7. data/app/controllers/bro_hub/apm/errors_controller.rb +15 -0
  8. data/app/controllers/bro_hub/apm/findings_controller.rb +8 -0
  9. data/app/controllers/bro_hub/apm/overview_controller.rb +7 -0
  10. data/app/controllers/bro_hub/apm/queries_controller.rb +11 -0
  11. data/app/controllers/bro_hub/apm/status_controller.rb +9 -0
  12. data/app/controllers/bro_hub/application_controller.rb +16 -0
  13. data/app/controllers/bro_hub/audit_events_controller.rb +2 -2
  14. data/app/controllers/bro_hub/cache/application_controller.rb +55 -0
  15. data/app/controllers/bro_hub/cache/audit_events_controller.rb +40 -0
  16. data/app/controllers/bro_hub/cache/flushes_controller.rb +34 -0
  17. data/app/controllers/bro_hub/cache/keys_controller.rb +41 -0
  18. data/app/controllers/bro_hub/cache/purges_controller.rb +40 -0
  19. data/app/controllers/bro_hub/env/application_controller.rb +27 -0
  20. data/app/controllers/bro_hub/env/audit_controller.rb +10 -0
  21. data/app/controllers/bro_hub/env/home_controller.rb +6 -0
  22. data/app/controllers/bro_hub/env/proposals_controller.rb +86 -0
  23. data/app/controllers/bro_hub/env/reviews_controller.rb +72 -0
  24. data/app/controllers/bro_hub/feature_controller.rb +21 -0
  25. data/app/controllers/bro_hub/safe/application_controller.rb +24 -0
  26. data/app/controllers/bro_hub/safe/flagged_commands_controller.rb +14 -0
  27. data/app/controllers/bro_hub/safe/reviews_controller.rb +39 -0
  28. data/app/controllers/bro_hub/safe/rules_controller.rb +18 -0
  29. data/app/controllers/bro_hub/safe/sessions_controller.rb +63 -0
  30. data/app/controllers/bro_hub/safe/unlocks_controller.rb +14 -0
  31. data/app/helpers/bro_hub/apm/application_helper.rb +104 -0
  32. data/app/helpers/bro_hub/application_helper.rb +5 -19
  33. data/app/helpers/bro_hub/cache/application_helper.rb +63 -0
  34. data/app/helpers/bro_hub/env/application_helper.rb +67 -0
  35. data/app/helpers/bro_hub/safe/application_helper.rb +59 -0
  36. data/app/jobs/bro_hub/safe/purge_job.rb +10 -0
  37. data/app/models/bro_hub/audit_event.rb +2 -6
  38. data/app/models/bro_hub/cache/audit_event.rb +15 -0
  39. data/app/models/bro_hub/env/audit_event.rb +72 -0
  40. data/app/models/bro_hub/safe/command.rb +22 -0
  41. data/app/models/bro_hub/safe/review.rb +22 -0
  42. data/app/models/bro_hub/safe/session.rb +57 -0
  43. data/app/models/bro_hub/safe/unlock.rb +15 -0
  44. data/app/views/bro_hub/apm/deploys/index.html.erb +21 -0
  45. data/app/views/bro_hub/apm/endpoints/index.html.erb +27 -0
  46. data/app/views/bro_hub/apm/errors/index.html.erb +22 -0
  47. data/app/views/bro_hub/apm/errors/not_found.html.erb +3 -0
  48. data/app/views/bro_hub/apm/errors/show.html.erb +43 -0
  49. data/app/views/bro_hub/apm/findings/index.html.erb +24 -0
  50. data/app/views/bro_hub/apm/overview/show.html.erb +59 -0
  51. data/app/views/bro_hub/apm/queries/index.html.erb +37 -0
  52. data/app/views/bro_hub/apm/shared/_page_styles.html.erb +15 -0
  53. data/app/views/bro_hub/apm/status/show.html.erb +47 -0
  54. data/app/views/bro_hub/audit_events/index.html.erb +1 -1
  55. data/app/views/bro_hub/cache/audit_events/index.html.erb +39 -0
  56. data/app/views/bro_hub/cache/audit_events/show.html.erb +48 -0
  57. data/app/views/bro_hub/cache/flushes/new.html.erb +19 -0
  58. data/app/views/bro_hub/cache/keys/index.html.erb +36 -0
  59. data/app/views/bro_hub/cache/keys/show.html.erb +57 -0
  60. data/app/views/bro_hub/cache/purges/new.html.erb +17 -0
  61. data/app/views/bro_hub/cache/purges/preview.html.erb +37 -0
  62. data/app/views/bro_hub/cache/shared/_store_tabs.html.erb +9 -0
  63. data/app/views/bro_hub/cache/shared/unsupported.html.erb +3 -0
  64. data/app/views/bro_hub/env/audit/index.html.erb +31 -0
  65. data/app/views/bro_hub/env/home/index.html.erb +25 -0
  66. data/app/views/bro_hub/env/proposals/_new_key_row.html.erb +7 -0
  67. data/app/views/bro_hub/env/proposals/new.html.erb +99 -0
  68. data/app/views/bro_hub/env/reviews/new.html.erb +29 -0
  69. data/app/views/bro_hub/env/reviews/show.html.erb +122 -0
  70. data/app/views/bro_hub/env/shared/_page_styles.html.erb +57 -0
  71. data/app/views/bro_hub/env/shared/_script.html.erb +114 -0
  72. data/app/views/bro_hub/env/shared/not_ready.html.erb +17 -0
  73. data/app/views/bro_hub/safe/flagged_commands/index.html.erb +22 -0
  74. data/app/views/bro_hub/safe/rules/show.html.erb +59 -0
  75. data/app/views/bro_hub/safe/sessions/index.html.erb +51 -0
  76. data/app/views/bro_hub/safe/sessions/show.html.erb +92 -0
  77. data/app/views/bro_hub/safe/unlocks/index.html.erb +25 -0
  78. data/app/views/bro_hub/shared/schema_missing.html.erb +25 -0
  79. data/app/views/layouts/bro_hub/application.html.erb +1 -1
  80. data/config/routes/apm.rb +10 -0
  81. data/config/routes/cache.rb +17 -0
  82. data/config/routes/env.rb +10 -0
  83. data/config/routes/safe.rb +10 -0
  84. data/config/routes.rb +9 -4
  85. data/db/migrate/20261129000000_create_bro_hub_tables.rb +85 -0
  86. data/lib/bro_hub/apm/api.rb +88 -0
  87. data/lib/bro_hub/apm/configuration.rb +58 -0
  88. data/lib/bro_hub/apm/local_status.rb +49 -0
  89. data/lib/bro_hub/apm.rb +28 -0
  90. data/lib/bro_hub/audit.rb +2 -9
  91. data/lib/bro_hub/cache/audit.rb +15 -0
  92. data/lib/bro_hub/cache/configuration.rb +105 -0
  93. data/lib/bro_hub/cache/errors.rb +26 -0
  94. data/lib/bro_hub/cache/redis_store.rb +220 -0
  95. data/lib/bro_hub/cache.rb +38 -0
  96. data/lib/bro_hub/configuration.rb +19 -4
  97. data/lib/bro_hub/controller_base.rb +3 -6
  98. data/lib/bro_hub/engine.rb +60 -1
  99. data/lib/bro_hub/env/audit.rb +17 -0
  100. data/lib/bro_hub/env/configuration.rb +72 -0
  101. data/lib/bro_hub/env/credentials.rb +135 -0
  102. data/lib/bro_hub/env/deployments.rb +45 -0
  103. data/lib/bro_hub/env/differ.rb +58 -0
  104. data/lib/bro_hub/env/editor.rb +104 -0
  105. data/lib/bro_hub/env/encrypted_blob.rb +18 -0
  106. data/lib/bro_hub/env/environment.rb +74 -0
  107. data/lib/bro_hub/env.rb +36 -0
  108. data/lib/bro_hub/features.rb +13 -0
  109. data/lib/bro_hub/layout.rb +2 -5
  110. data/lib/bro_hub/safe/cipher.rb +46 -0
  111. data/lib/bro_hub/safe/commands.rb +25 -0
  112. data/lib/bro_hub/safe/configuration.rb +191 -0
  113. data/lib/bro_hub/safe/encrypted_type.rb +16 -0
  114. data/lib/bro_hub/safe/errors.rb +48 -0
  115. data/lib/bro_hub/safe/executor.rb +142 -0
  116. data/lib/bro_hub/safe/guards/const_guard.rb +42 -0
  117. data/lib/bro_hub/safe/guards/credentials_guard.rb +31 -0
  118. data/lib/bro_hub/safe/guards/env_guard.rb +90 -0
  119. data/lib/bro_hub/safe/guards/file_guard.rb +28 -0
  120. data/lib/bro_hub/safe/guards/guarded.rb +51 -0
  121. data/lib/bro_hub/safe/guards/irb_context.rb +23 -0
  122. data/lib/bro_hub/safe/guards/method_guard.rb +32 -0
  123. data/lib/bro_hub/safe/guards/network_guard.rb +98 -0
  124. data/lib/bro_hub/safe/guards/sql_guard.rb +26 -0
  125. data/lib/bro_hub/safe/parsed_command.rb +66 -0
  126. data/lib/bro_hub/safe/recorder.rb +82 -0
  127. data/lib/bro_hub/safe/shield.rb +83 -0
  128. data/lib/bro_hub/safe/supervisor.rb +81 -0
  129. data/lib/bro_hub/safe/terminal.rb +55 -0
  130. data/lib/bro_hub/safe/trail.rb +24 -0
  131. data/lib/bro_hub/safe/validator.rb +74 -0
  132. data/lib/bro_hub/safe.rb +134 -0
  133. data/lib/bro_hub/schema.rb +36 -0
  134. data/lib/bro_hub/section.rb +7 -13
  135. data/lib/bro_hub/testing.rb +23 -6
  136. data/lib/bro_hub/version.rb +1 -1
  137. data/lib/bro_hub.rb +31 -6
  138. data/lib/generators/bro_hub/install/install_generator.rb +89 -71
  139. data/lib/generators/bro_hub/install/templates/bro_hub.rb.tt +115 -0
  140. data/lib/generators/bro_hub/uninstall/templates/drop_bro_hub_tables.rb.tt +16 -0
  141. data/lib/generators/bro_hub/uninstall/uninstall_generator.rb +57 -0
  142. data/lib/tasks/bro_hub.rake +9 -0
  143. metadata +148 -13
  144. data/db/migrate/20261116000000_create_bro_hub_audit_events.rb +0 -35
  145. data/lib/bro_hub/root_middleware.rb +0 -17
  146. data/lib/generators/bro_hub/install/templates/bro_hub.rb +0 -11
  147. data/lib/generators/bro_hub/installable.rb +0 -63
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e8d9cfb095f79b5ea95e8deec476ac616aba2c0fe7f13d7d82729bd70eca0a3
4
- data.tar.gz: bd8d3a62facfe12d4a8e5a8d0256e89decb3bc67df3b6e7f2dc4a57076ce7215
3
+ metadata.gz: 2147a478c6231177b6f68351407584a74dabd22e2547a358dd56d1c55b5239c7
4
+ data.tar.gz: 4824766699023e1004daf5e292ac2caa5f9c01dea14cdc43a7c39edc09d7db24
5
5
  SHA512:
6
- metadata.gz: 864864457131f346931a13f3f0b201a0f8909b9496e8a38f7f60c17dfbf246899d3ea244af8dab6f9d523e1f290327399406478e490bac667e08d1fc231599ef
7
- data.tar.gz: 954605adda26754b49835be5187d452e82459478fa6d8b28e95e920b77bf56dbd77e10116cc45a8f19eda676f19730e5158ac07c6f878b50cc0071281a1433ea
6
+ metadata.gz: ff92615ecba858ea9f002558d9d741427b7e1666e261ab102e10552614a75c1086897fb3ea5469ea5e2adf3514693e124ce094f691012a16bb288f3e6a94d6d2
7
+ data.tar.gz: ea5bd9b35a0b464f93101a14c50281ea51b9fe92b8404dd438370f9dd3dc3a2e5c631830de14ce0bc80278b3ae6dd13258ef990cb8f3e84164cb7907d20d5d8d
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0
4
+
5
+ The first release to use. Earlier versions are superseded and should be ignored.
6
+
7
+ BroHub is one Rails engine with four opt-in features, switched on with `config.features`:
8
+
9
+ - `:safe` (SafeBro): audited, guarded production console with a review UI.
10
+ - `:env` (EnvBro): propose and review changes to encrypted credentials without holding the key.
11
+ - `:cache` (CacheBro): browse, inspect, delete, purge and flush the Rails Redis cache.
12
+ - `:apm` (DeadBro): DeadBro stats inside the dashboard. Needs the separate `dead_bro` gem.
13
+
14
+ Highlights:
15
+
16
+ - `bin/rails g bro_hub:install [--features=env,safe] [--mount-path=/bro_hub] [--migrate]` writes the initializer, mounts the engine, copies the one migration and prints next steps. Running it again is safe.
17
+ - `bin/rails g bro_hub:uninstall` generates a migration that drops every BroHub table, and removes the initializer and the mount.
18
+ - One migration creates every table. When a table or column is missing, every hub page renders a 503 telling you to run the installer and `db:migrate`.
19
+ - A feature that is off has no routes, no sidebar section, no console patches, and does nothing at boot.
20
+ - One combined audit log at `/<mount>/audit`, with key names, patterns, counts and reasons only, never secret values, cache values or command text.
21
+ - Requires Ruby 3.3+, Rails 7.1+ and IRB 1.13+.
data/README.md CHANGED
@@ -1,254 +1,264 @@
1
1
  # BroHub
2
2
 
3
- One dashboard shell for the Bro gems ([EnvBro](https://github.com/rubydevro/env_bro), [SafeBro](https://github.com/rubydevro/safe_bro), [CacheBro](https://github.com/rubydevro/cache_bro), and whatever comes next).
3
+ One Rails engine, one mount point, one sidebar and one audit log for four tools you can turn on one by one: EnvBro, SafeBro, CacheBro and DeadBro.
4
4
 
5
- - **One mount point.** `/bro_hub/safe_bro`, `/bro_hub/env_bro`, ... BroHub mounts the gems' engines itself.
6
- - **One look.** Top bar, sidebar, breadcrumb bar and page styles are shared, so every gem feels the same.
7
- - **One sidebar.** Each gem registers its pages and shows up as a section. A section only appears for people allowed to use it.
8
- - **One place for "who is signed in".** Set it once for all gems.
9
- - **One audit log.** Every Bro gem writes its audit trail to one table, and BroHub shows them together.
5
+ | Feature | Key | URL | What it does |
6
+ | --- | --- | --- | --- |
7
+ | **SafeBro** · audit | `:safe` | `/<mount>/safe` | Records every production console session (who, why, every command, encrypted at rest), locks sensitive data until `unlock!`, checks commands before they run, and gives reviewers a UI to approve or flag sessions. |
8
+ | **EnvBro** · config | `:env` | `/<mount>/env` | Propose changes to Rails encrypted credentials without holding the key. A reviewer uploads the proposed file and sees which keys changed, values masked unless revealed. |
9
+ | **DeadBro** · performance | `:apm` | `/<mount>/apm` | Your DeadBro stats (endpoints, errors, SQL, findings, deploys, status) inside the dashboard. Needs the separate `dead_bro` gem. |
10
+ | **CacheBro** · cache | `:cache` | `/<mount>/cache` | Browse, inspect, delete and purge your Rails Redis cache, every action audited. |
10
11
 
11
- It is a shell, not a security boundary: hiding a section is navigation. Every Bro gem still authorizes its own pages.
12
+ The combined audit log of every feature is at `/<mount>/audit`. A feature that is off has no routes, no sidebar section, no console patches, and does nothing at boot.
12
13
 
13
- Rails 7.1+, Ruby 3.2+. One table (the audit log), no JavaScript, no asset pipeline.
14
+ BroHub is a shell, not a security boundary: hiding a section is navigation. Every page checks its own permission.
15
+
16
+ Rails 7.1+, Ruby 3.3+, IRB 1.13+. Never stores secret values, cache values or console command text in the audit log: key names, patterns, counts and reasons only.
17
+
18
+ > **Read [What this is not](#what-this-is-not).** SafeBro is a deterrent and an audit trail. It is not a sandbox.
14
19
 
15
20
  ## Install
16
21
 
17
22
  ```ruby
23
+ # Gemfile
18
24
  gem "bro_hub"
19
25
  ```
20
26
 
21
- Minimum versions: **env_bro 0.2.0** and **safe_bro 0.1.0**. Older EnvBro (0.1.x) has no BroHub support: the installer skips
22
- it with a warning and leaves its old mount alone, so `bundle update env_bro` first.
23
-
24
27
  ```sh
25
- bin/rails generate bro_hub:install
28
+ bundle install
29
+ bin/rails g bro_hub:install [--features=env,safe] [--mount-path=/bro_hub] [--migrate]
26
30
  ```
27
31
 
28
- This sets up the whole dashboard in one go:
32
+ The generator writes `config/initializers/bro_hub.rb`, mounts the engine (`mount BroHub::Engine => "/bro_hub"`), copies the migration and prints next steps. Without `--features` it asks for each feature in a terminal; otherwise it turns on env, safe and cache, plus apm when the `dead_bro` gem is installed. Without `--migrate` it asks whether to run `bin/rails db:migrate` (in a terminal) or leaves it to you. It never overwrites an existing initializer or mount, so running it again is safe, and is how an upgrade picks up new migrations.
29
33
 
30
- 1. adds `config/initializers/bro_hub.rb` and copies the audit table migration (run `bin/rails db:migrate` afterwards),
31
- 2. mounts BroHub (it asks where, default `/bro_hub`; or `--mount-path=/ops/bro`):
32
- ```ruby
33
- mount BroHub::Engine => "/bro_hub"
34
- ```
35
- 3. offers to comment out old direct mounts such as `mount SafeBro::Engine`, since BroHub now mounts those gems itself
36
- (`--remove-direct-mounts` says yes without asking; without a terminal the lines are left alone with a warning),
37
- 4. runs the installer of every Bro gem in your Gemfile (SafeBro's initializer and migrations, EnvBro's, ...).
34
+ Then say who may do what. **Everything is denied until you say so** (see [Configuration](#configuration)). If the tables are missing, every hub page renders a 503 telling you to run `bin/rails g bro_hub:install` and `bin/rails db:migrate`.
38
35
 
39
- Existing config is never overwritten: if `config/initializers/bro_hub.rb` (or `env_bro.rb` / `safe_bro.rb`) is there already,
40
- it is skipped, and `--skip` / `--force` / `--pretend` are passed on to every gem's installer. In scripts and agents, pass
41
- `--skip` and `--mount-path=...` so nothing waits on a prompt.
36
+ ### Which version
42
37
 
43
- You can also run a gem's own installer on its own: `bin/rails generate safe_bro:install` sets up BroHub first, then SafeBro.
44
- Running both, in any order, mounts BroHub once.
38
+ Use **0.3.0 or newer**. Earlier releases are superseded and should be ignored; nothing from them is read or migrated.
45
39
 
46
- Who is signed in: the default calls `current_user` on your controller, and falls back to `Current.user` (the Rails 8
47
- authentication generator has only that). The top-right label tries `email`, `email_address` (Rails 8) then `name`.
40
+ ### Turning a feature on later
41
+
42
+ Add it to `config.features` in the initializer and set its permissions:
48
43
 
49
44
  ```ruby
50
- # config/initializers/bro_hub.rb
51
45
  BroHub.configure do |config|
52
- config.current_user = ->(controller) { controller.current_user } # default: calls current_user if present
53
- config.user_label = ->(user) { user.email }
54
- config.parent_controller = "::ApplicationController"
46
+ config.features = %i[ env safe cache apm ]
55
47
  end
56
48
  ```
57
49
 
58
- Opening `/bro_hub` sends people to the first section they may use.
50
+ The `:apm` feature needs `gem "dead_bro"` in your Gemfile; without it BroHub raises an error at boot that says so. Re-run `bin/rails g bro_hub:install` and `bin/rails db:migrate` after upgrading the gem.
51
+
52
+ ## Configuration
59
53
 
60
- ## The Bro gems
54
+ Everything is in `config/initializers/bro_hub.rb`, as `BroHub.configure { |config| ... }`, readable afterwards as `BroHub.config.<key>`.
61
55
 
62
- Each gem is a mountable Rails engine that registers itself with BroHub. Add the gems you want to your Gemfile and run
63
- `bin/rails generate bro_hub:install`: BroHub finds every registered gem that ships an installer and runs it.
56
+ ### Shared settings
64
57
 
65
- | Gem | Section | What it does |
66
- | --- | --- | --- |
67
- | [EnvBro](https://github.com/rubydevro/env_bro) | `/bro_hub/env_bro` | Credentials and environment values, with its own approval flow. |
68
- | [SafeBro](https://github.com/rubydevro/safe_bro) | `/bro_hub/safe_bro` | Audits production console sessions: sessions, flagged commands, rules. |
69
- | [CacheBro](https://github.com/rubydevro/cache_bro) | `/bro_hub/cache_bro` | Browse, inspect and purge the Rails Redis cache, with every action audited. |
58
+ | Setting | What it does |
59
+ | --- | --- |
60
+ | `features` | Which features are on, any of `:safe :env :apm :cache`. Default none. |
61
+ | `current_user` | `->(controller) { user }`. Default calls `current_user`, then `Current.user` (Rails 8 authentication generator). |
62
+ | `user_label` | `->(user) { text }` shown top right. Default tries `email`, `email_address`, `name`. |
63
+ | `parent_controller` | Controller the hub's pages inherit from, so your authentication runs. Default `"::ApplicationController"`. |
64
+ | `require_ssl` | Refuse plain HTTP. Default `Rails.env.production?`. |
70
65
 
71
- ### How it fits together
66
+ Every hub response sends `Cache-Control: no-store`. Permissions are lambdas that receive the signed-in user (nil when signed out). A feature's section only shows for people holding one of its permissions.
72
67
 
73
- 1. A gem calls `BroHub.register` in its engine, before routes are drawn. That adds its section to the sidebar and tells BroHub which engine to mount.
74
- 2. BroHub mounts each registered engine under its own path (`<mount>/<key>`). You mount only `BroHub::Engine`.
75
- 3. Gem controllers include `BroHub::ControllerBase` and name their section, so pages render inside the shared shell.
76
- 4. Who is signed in comes from BroHub's `current_user` setting. Each gem keeps its own permissions, and a sidebar section only shows for people the gem allows.
77
- 5. BroHub keeps one table, the shared audit log, in your app's database (its migration is copied by the installer). SafeBro also keeps its session tables.
68
+ ### SafeBro (`BroHub.config.safe`)
78
69
 
79
- ### CacheBro
70
+ Audited, guarded Rails console access, with a built-in review UI. Every session records who opened it and why. Every command is checked before it runs and stored encrypted. Sensitive data stays locked until the person explains why they need it, and reviewers approve or flag each session.
80
71
 
81
72
  ```ruby
82
- gem "bro_hub"
83
- gem "cache_bro"
73
+ config.safe.can_audit = ->(user) { user.admin? } # who may review sessions
84
74
  ```
85
75
 
86
- ```sh
87
- bin/rails generate bro_hub:install # or: bin/rails generate cache_bro:install
88
- bin/rails db:migrate # creates the audit table
76
+ Nothing is installed by loading the gem. Protection starts when a console starts, in `config.safe.protected_environments` (default `production`).
77
+
78
+ **Telling SafeBro who is at the console.** It reads `CONSOLE_USER`. A name is only as trustworthy as whatever sets it. Prefer the server setting it:
79
+
80
+ ```
81
+ # ~/.ssh/authorized_keys on the server, one line per person
82
+ environment="CONSOLE_USER=jane" ssh-ed25519 AAAA... jane@laptop
89
83
  ```
90
84
 
91
- CacheBro works on a Redis cache store (`config.cache_store = :redis_cache_store`) and needs bro_hub 0.1.2 or newer. Give the store a `namespace:`: keys are shown without it, and Flush only works when there is one.
85
+ (needs `PermitUserEnvironment yes` in `sshd_config`). A client-side `SetEnv` works too, but then anyone can claim to be anyone. With no `CONSOLE_USER` the console refuses to start. Use `config.safe.username_resolver = -> { ... }`, or `config.safe.ask_for_username_if_empty = true` to ask on the terminal. With no terminal, set `CONSOLE_REASON` (for example `CONSOLE_REASON="deploy check" rails console`); `unlock!` always needs a terminal.
92
86
 
93
- | Page | What you can do |
87
+ **What it looks like**
88
+
89
+ ```
90
+ $ rails console
91
+ You have access to production data here. That's a big deal. ...
92
+ jane, why are you using this console today?
93
+ > Fixing invoice 12, ticket #4521
94
+
95
+ myapp(prod):002> ENV["STRIPE_SECRET_KEY"]
96
+ SafeBro: flagged for review - Access to env is protected. (STRIPE_SECRET_KEY) Run unlock! ...
97
+
98
+ myapp(prod):003> unlock! :env
99
+ > Ticket #4521: customer asked us to rotate their key
100
+ Unlocked. We pay extra close attention to everything you do now. Type lock! to protect it again.
101
+ ```
102
+
103
+ | Command | What it does |
94
104
  | --- | --- |
95
- | Keys | Search by text or with `*` and `?`, see expiry and size, reveal a value, delete a key. |
96
- | Purge | Delete every key matching a pattern, after a preview with the match count and a sample. |
97
- | Flush | Delete every key in the store's namespace (type the store name to confirm). |
98
- | Audit log | Every reveal, delete, purge and flush, with who, when, what and why. Filter and open any entry. |
105
+ | `unlock!` | Unlock everything. Asks for a justification and records it. |
106
+ | `unlock! :credentials` | Unlock only some resources (`encrypted_data`, `credentials`, `env`, `files`, `network`). |
107
+ | `lock!` | Lock again. |
108
+
109
+ **What is protected** (`protected_resources`, all on by default)
110
+
111
+ | Resource | While locked |
112
+ | --- | --- |
113
+ | `encrypted_data` | Active Record encrypted attributes read as ciphertext and can't be written. |
114
+ | `credentials` | `Rails.application.credentials`, `secret_key_base`, `key_generator`, `message_verifier` and the encrypted file classes raise when called from the console. |
115
+ | `env` | `ENV["SOME_SECRET"]` raises for names matching `protected_env_patterns`. Dumping `ENV` (`to_h`, `each`, `each_value`, `except`, `filter_map`, `inspect`, ...) filters those values. |
116
+ | `files` | `master.key`, `credentials/*.key` and `.env*` files can't be read or copied. |
117
+ | `network` | Connections to `protected_urls` fail, including writes on connections opened earlier. |
118
+
119
+ Library code is not affected: Rails reading its credentials while it runs your command works. Only calls made directly from what the person typed are blocked, except `network` and `inspect`, which apply to anything running during a command.
99
120
 
100
- Permissions are plain lambdas, all `false` until you set them (no Pundit needed):
121
+ **Guardrails.** Each command is checked before it runs. Blocked: reopening protected classes, referencing `BroHub`/`IRB`/`ObjectSpace`, and calling `eval`, `Binding#eval`, `instance_eval`, `class_eval`, `system`, `exec`, `spawn`, backticks, `IO.popen`, and others. `load` is blocked at runtime when called from the console. Flagged: commands mentioning `secret`, `credentials`, `ENV`, `master.key`, ... run but are marked suspicious. Runtime backstops cover `send(:eval, ...)` and `Object.const_get("Bro" + "Hub")`. `super_method` is forbidden, so a guard can't be walked past to the original method. A probe the command rescues itself (`ENV["X_SECRET"] rescue nil`) is still flagged. The audit trail is guarded from what's typed at the console: SQL mentioning BroHub's tables is refused, and `raw_connection` and `with_raw_connection` are locked (under `credentials`, so `unlock!` opens them). SafeBro's classes, its guard modules and its config are frozen once installed. See [What this is not](#what-this-is-not) for the limits.
122
+
123
+ | Setting | Default and purpose |
124
+ | --- | --- |
125
+ | `protected_environments` | `%w[production]`. Consoles in these environments are recorded and guarded. |
126
+ | `enabled` | Force on or off regardless of environment. |
127
+ | `audit_runner` | `false`. Also record `rails runner` as sessions (`CONSOLE_USER` and `CONSOLE_REASON` are used if set). Runners aren't shielded. |
128
+ | `username_resolver`, `ask_for_username_if_empty` | See above. |
129
+ | `client_ip_resolver` | Where the person connected from. Default `CONSOLE_CLIENT_IP`, then `SSH_CLIENT` / `SSH_CONNECTION`; anything that isn't an IP is ignored. Behind a container wrapper pass it in: `docker run -e CONSOLE_USER -e CONSOLE_CLIENT_IP="${SSH_CLIENT%% *}" ...`. |
130
+ | `protected_resources`, `protected_urls`, `protected_env_patterns`, `protected_file_patterns` | What is locked. |
131
+ | `forbidden_reopening`, `forbidden_constants`, `forbidden_methods`, `runtime_only_methods`, `suspicious_terms` | Guardrails, for example `config.safe.forbidden_methods += [ "Kernel#open" ]`, `config.safe.forbidden_constants[:locked] += [ "Net::HTTP" ]`, `config.safe.suspicious_terms += [ "DROP TABLE" ]`. |
132
+ | `freeze_internals` | `true`. Freeze the classes and config once installed. |
133
+ | `can_audit` | `->(user) { }` may review sessions. Denied by default. |
134
+ | `allow_self_audit` | `false`. May a reviewer approve their own sessions. |
135
+ | `console_username` | `->(user) { name }` the name a hub user goes by at the console (what `username_resolver` returns for them), so nobody reviews their own sessions. Default `BroHub.config.user_label`. **Set it:** `user_label` is usually an email and `CONSOLE_USER` a login name, so with the default they never match and self review isn't prevented. The Rules page warns until it's mapped, e.g. `config.safe.console_username = ->(user) { user.console_name }`. |
136
+ | `retention`, `keep_flagged` | `90.days`, `true`. Sessions older than this are removed (flagged ones kept). `nil` keeps everything. |
137
+ | `encryption_key` | 32 bytes (or a lambda) encrypting recorded commands. Default derived from `secret_key_base`. |
138
+ | `welcome_message`, `unlock_prompt`, `unlocked_message`, `locked_message` | Texts shown in the console. |
139
+
140
+ **Reviewing sessions** at `/<mount>/safe`: Sessions (filterable; open one to read it and approve it or flag it with notes), Flagged commands, Unlocks (who, which resources, the reason) and Rules (a read-only view of what's locked, blocked and flagged). Reviews are append-only: the latest decides the status and the history is kept. Command text and notes are encrypted at rest. When a session is purged, the hub audit trail rows for it are removed too.
141
+
142
+ **Retention.** Schedule `BroHub::Safe::PurgeJob` (daily) or run `bin/rails bro_hub:safe:purge`.
143
+
144
+ **Notifications.** SafeBro instruments `ActiveSupport::Notifications` with `<event>.bro_hub_safe`:
145
+
146
+ | Event | Payload |
147
+ | --- | --- |
148
+ | `session_started.bro_hub_safe` | `session:` |
149
+ | `unlocked.bro_hub_safe` | `session:`, `unlock:` |
150
+ | `command_flagged.bro_hub_safe` | `session:`, `command:`, `status:`, `reason:` |
151
+ | `session_flagged.bro_hub_safe` | `session:`, `reviewer:`, `notes:` |
101
152
 
102
153
  ```ruby
103
- # config/initializers/cache_bro.rb
104
- CacheBro.configure do |config|
105
- config.can_view_keys = ->(user) { user.developer? }
106
- config.can_view_values = ->(user) { user.lead? } # values can hold personal data
107
- config.can_delete = ->(user) { user.lead? }
108
- config.can_purge = ->(user) { user.lead? }
109
- config.can_flush = ->(user) { user.admin? }
110
- config.can_audit = ->(user) { user.auditor? }
154
+ ActiveSupport::Notifications.subscribe(/\.bro_hub_safe\z/) do |name, _start, _finish, _id, payload|
155
+ SecurityMailer.console_event(name, payload).deliver_later
111
156
  end
112
157
  ```
113
158
 
114
- A higher permission includes the lower ones: flush includes purge, purge includes delete, and any of them includes viewing keys. Viewing values and auditing stand alone.
159
+ **For gem authors.** Anything sensitive your gem exposes can use the same lock: add `config.safe.protected_resources += [ :billing ]` in the host app, and call `BroHub::Safe.guard!(:billing)` before revealing something. It does nothing outside a console command, and raises inside one until the person runs `unlock! :billing`.
115
160
 
116
- How it stays safe:
161
+ #### What this is not
117
162
 
118
- - Keys are found with Redis `SCAN` (never `KEYS`), a page at a time.
119
- - Everything is limited to the store's namespace, so a purge or flush cannot touch other keys in the same Redis.
120
- - Revealing a value is a POST and is written to the audit log before the value is shown. If the audit write fails, nothing is revealed.
121
- - Purge and flush ask for a reason by default, and a purge stops at 100,000 keys. A purge that fails partway is still logged, with the count so far.
122
- - The audit log is append-only and records keys and patterns, never values.
163
+ Ruby is too dynamic to sandbox. Someone determined who has a console on your production box can get around the static checks and the runtime guards, for example by reading process memory, speaking to the database driver directly, using `dbconsole`, or loading code from disk. SafeBro raises the cost, catches mistakes, makes honest people stop and explain, and leaves a record that dishonest attempts show up in. That's valuable, but it's not a boundary.
123
164
 
124
- See the [CacheBro README](https://github.com/rubydevro/cache_bro) for every setting.
165
+ Specifically:
125
166
 
126
- ## The audit log
167
+ - Someone at the console can still reach SafeBro's own objects and change their state with `instance_variable_set`. That is flagged for review, not blocked.
168
+ - The audit trail is not tamper-proof. After `unlock! :credentials` the driver connection (`raw_connection`) runs SQL that SafeBro doesn't see. Keep a copy elsewhere (backups, database audit logs) if you need one nobody at the console can touch.
169
+ - Code run outside the console (a `require` of a file, ERB, another thread) isn't seen by the console-call guards.
170
+ - `reload!` and `debug=` don't work once internals are frozen. `config.safe.freeze_internals = false` turns freezing off.
127
171
 
128
- Every Bro gem that keeps an audit trail writes it to one table, `bro_hub_audit_events`, through `BroHub::Audit.record`.
129
- BroHub shows them together under `<mount>/audit`: filter by gem, event, user or text, and open any entry. Each person
130
- sees the rows of the gems they may audit, and nothing else. Entries are append-only and hold names and patterns, never
131
- secret values. Gems without an audit trail (DeadBroHub) simply don't appear.
172
+ If you need a boundary, build it outside Ruby:
132
173
 
133
- | Column | Meaning |
134
- | --- | --- |
135
- | `source` | the gem (`env_bro`, `safe_bro`, `cache_bro`) |
136
- | `event`, `user_label`, `environment`, `created_at` | what happened, who did it, where, when |
137
- | `context` | where it happened inside the gem: a cache store name, a console host |
138
- | `target`, `count`, `reason`, `ip` | what it happened to, how many, why, from where |
139
- | `reference`, `digest`, `parent_id` | links for gems that tie rows together (EnvBro: a proposal's token, its file's digest, its deployment) |
140
- | `details` | anything else, as JSON |
174
+ - Don't leave the credentials key on machines people shell into. Deliver it to the app process only.
175
+ - Give console users a database role that can't read what they shouldn't.
176
+ - Control who can SSH in, and set `CONSOLE_USER` from the server side.
177
+ - Have a reviewer actually review sessions. An unreviewed audit trail deters nothing.
141
178
 
142
- Upgrading from 0.1: run `bin/rails g bro_hub:install` and `bin/rails db:migrate` to create the table. The gems that
143
- use it (env_bro 0.3, safe_bro 0.3, cache_bro 0.2) need bro_hub 0.2.
179
+ Not covered: `rails dbconsole`, a raw `psql`/`mysql` session, other process managers or shells, and Pry (SafeBro hooks IRB).
144
180
 
145
- ## For gem authors: plugging in
181
+ **Moving from console1984 and audits1984?** SafeBro is its own implementation, written from scratch, not a fork or copy of either. Don't run them side by side: both hook IRB and would record every command twice. Their `console1984_*` and `audits1984_*` tables are not read or migrated; keep them as long as you need the history. Map `protected_environments` to the same option and the auditor check to `config.safe.can_audit`.
146
182
 
147
- **1. Register your section** (in your engine file, so it runs before routes are drawn):
183
+ ### EnvBro (`BroHub.config.env`)
148
184
 
149
- ```ruby
150
- BroHub.register :safe_bro,
151
- label: "SafeBro · audit", # sidebar heading
152
- name: "SafeBro", # breadcrumb (default: label up to the "·")
153
- accent: :red, # :red :green :violet :amber :blue, or "#hex"
154
- engine: "SafeBro::Engine", # BroHub mounts it at /<key>
155
- order: 10, # lower comes first
156
- visible_to: ->(user) { SafeBro.config.can_audit.call(user) },
157
- audit_visible_to: ->(user) { SafeBro.config.can_audit.call(user) }, # who sees your rows in the hub's audit log (leave out: none)
158
- items: [
159
- { label: "Sessions", path: "/", badge: -> { SafeBro::Session.pending.count } },
160
- { label: "Flagged commands", path: "/flagged" },
161
- { label: "Rules", path: "/rules", match: %r{\A/rules} },
162
- { label: "Raw export", path: "/export", visible_to: ->(user) { user.admin? } } # per-item visibility
163
- ]
164
- ```
185
+ Propose changes to Rails encrypted credentials without holding the key. EnvBro manages the credentials of the environment it runs in (`production.yml.enc` on production). It never writes to the credentials file.
165
186
 
166
- - `path` is relative to your engine. Badges are hidden when `nil` or `0`, and a badge that raises is skipped.
167
- - Active item: exact match for `"/"`, prefix match otherwise, or your own `match:` regexp.
168
- - A section only shows up in the shared sidebar when you pass `engine:` (BroHub then knows where it lives). A gem the host mounts elsewhere still gets the shell, with just its own section.
169
- - Never put anything that came from a user in `accent` or `label`. `accent` is validated; `label` is escaped.
170
-
171
- **2. Render inside the shell:**
187
+ 1. **Propose.** The user sees key names, never values. EnvBro decrypts the deployed file in memory, applies the changes, re-encrypts it with the same key and returns it as a download to commit on a branch.
188
+ 2. **Metadata.** The new file includes a top-level key (`config.env.metadata_key`, default `env_bro`) with a proposal id, the SHA-256 of the file it was built on, the author, the time and the declared changes.
189
+ 3. **Review.** The reviewer uploads the proposed file and sees added, changed and removed keys, values masked unless revealed. *Outdated base* appears when it was built on a different version than the one compared against; *not built with EnvBro* when it has no metadata.
190
+ 4. **Audit.** Proposals, reviews and every reveal go to the audit log with key names only.
191
+ 5. **Deployment tracking.** On boot EnvBro records when the running credentials came from a proposal, so the log shows each as *live since ...*, *deployed, replaced since*, *superseded* or *not deployed yet*. Every deployment is recorded, so rollbacks show the right live proposal. The check never stops the app from booting.
172
192
 
173
193
  ```ruby
174
- class SafeBro::ApplicationController < ::ApplicationController
175
- include BroHub::ControllerBase
176
- bro_hub_section :safe_bro
177
- end
194
+ config.env.can_review = ->(user) { user.admin? } # upload a proposal and see what changed
195
+ config.env.can_create = ->(user) { user.developer? } # propose new keys
196
+ config.env.can_update = ->(user) { user.developer? } # propose new values
197
+ config.env.can_destroy = ->(user) { user.developer? } # propose removing keys
198
+ config.env.can_reveal = ->(user) { user.admin? } # see actual values in a review (audited)
178
199
  ```
179
200
 
180
- `BroHub::ControllerBase` includes `BroHub::Layout` (the layout, and `bro_hub_user`), turns on CSRF protection and opts out of the host app's Pundit `verify_authorized` checks, so every Bro controller behaves the same under any host `ApplicationController`. Override it if your gem has its own idea of who is signed in.
201
+ Higher includes lower: review includes create, update and destroy; reveal includes everything. `config.env.can_propose = ->(user) { ... }` sets create, update and destroy at once. Other settings: `metadata_key` (`nil` disables metadata, the outdated-base warning and deployment tracking), `track_deployments` (default `true`), `max_upload_bytes` (default 1 MB; caps both the uploaded files and the files the reveal form sends back).
202
+
203
+ ### CacheBro (`BroHub.config.cache`)
181
204
 
182
- **3. Write your audit trail to the shared table** (no migration of your own):
205
+ Browse, inspect and purge the Rails **Redis** cache: search keys (plain text matches anywhere, `*` and `?` make a pattern), see expiry and size, reveal a value (its own permission, always audited), delete one key, purge a pattern (you see the count and a sample first), flush a store's namespace (you type its name to confirm).
206
+
207
+ Give your cache store a namespace, so CacheBro stays out of keys that aren't the cache's:
183
208
 
184
209
  ```ruby
185
- BroHub::Audit.record(source: :cache_bro, event: :keys_purged, user: "jane@example.com",
186
- context: "Rails.cache", target: "posts/*", count: 12, reason: "stale", sample: [ "posts/1" ])
210
+ config.cache_store = :redis_cache_store, { url: ENV["REDIS_URL"], namespace: "myapp" }
187
211
  ```
188
212
 
189
- It fails closed: when the row can't be written the error is raised, so an action that must not go unaudited stops.
190
- To read your own rows, subclass the model with a default scope:
213
+ Without one you get a warning and Flush is disabled.
191
214
 
192
215
  ```ruby
193
- class CacheBro::AuditEvent < BroHub::AuditEvent
194
- default_scope { where(source: "cache_bro") }
195
- validates :event, inclusion: { in: %w[ keys_purged ] }
196
- end
216
+ config.cache.can_view_keys = ->(user) { user.developer? } # open CacheBro, search keys, TTL and size
217
+ config.cache.can_view_values = ->(user) { user.senior? } # reveal values (audited; may hold personal data)
218
+ config.cache.can_delete = ->(user) { user.developer? }
219
+ config.cache.can_purge = ->(user) { user.senior? }
220
+ config.cache.can_flush = ->(user) { user.admin? }
221
+ config.cache.can_audit = ->(user) { user.admin? }
197
222
  ```
198
223
 
199
- In your tests: `require "bro_hub/testing"; BroHub::Testing.load_schema` creates the table, and
200
- `BroHub::Testing.record_rails_commands` stubs BroHub's installer in generator tests.
224
+ Higher includes lower: flush includes purge and delete, purge includes delete, and all include view_keys. `can_view_values` and `can_audit` stand alone. Other settings: `stores` (`{ "Name" => -> { store } }`, only `:redis_cache_store` is supported), `reason_required_for` (any of `:reveal :delete :purge :flush`, default `%i[purge flush]`), `max_purge_keys` (100,000), `page_size`, `scan_count`, `scan_budget`, `value_preview_length`, `audit_sample_size`.
201
225
 
202
- **4. Give your gem an installer** that sets up BroHub first, then itself. Name it `<section key>:install` so
203
- `bro_hub:install` finds it:
226
+ ### DeadBro (`BroHub.config.apm`)
204
227
 
205
- ```ruby
206
- # lib/generators/safe_bro/install/install_generator.rb
207
- require "generators/bro_hub/installable"
208
-
209
- class SafeBro::Generators::InstallGenerator < Rails::Generators::Base
210
- include BroHub::Generators::Installable # keep this first: it adds the BroHub step and --mount-path
228
+ Reads DeadBro with the API key the `dead_bro` gem already uses, so there is nothing to configure except who may look. Pages: Overview, Endpoints, Errors, SQL queries, Findings, Deploys and Status. The pages show SQL, exception messages and request paths, so keep it to people who can already see that. It keeps no audit trail of its own.
211
229
 
212
- def copy_initializer ... end
213
- def next_steps
214
- say "Visit #{bro_hub_path}/safe_bro" # bro_hub_path: where BroHub ended up
215
- end
216
- end
230
+ ```ruby
231
+ config.apm.can_view = ->(user) { user.admin? }
217
232
  ```
218
233
 
219
- **5. Fill in the page:**
234
+ Other settings: `cache_ttl` (seconds a response is cached in `Rails.cache`, default 30, 0 = off), `api_key`, `base_url`, `open_timeout`, `read_timeout`. Needs `gem "dead_bro"` and `:apm` in `config.features`.
220
235
 
221
- ```erb
222
- <% bro_hub_crumb "Console sessions", "#5" %> <%# "SafeBro / Console sessions / #5" %>
223
- <% content_for :bro_hub_crumb_actions do %>
224
- <%= bro_hub_crumb_link "← All sessions", sessions_path %> <%# right side of the bar %>
225
- <% end %>
236
+ ### Audit log
226
237
 
227
- <%= bro_hub_hero eyebrow: "console · web-1 (pid 4417)", title: "Session #5", subtitle: "Pending",
228
- subtitle_tone: :green, # :red :green :amber :violet :muted
229
- lead: "jane was on a production console for 1m.",
230
- stats: [ [ 4, "unlocks", :amber ], [ 6, "flagged commands", :red ] ] %>
231
- ```
238
+ Every feature writes its key moments (a proposal, a reveal, a purge, a session starting, an unlock with its justification, a reviewer's verdict) to one table, shown at `/<mount>/audit`. People only see the rows of features whose audit they may read. Rows are append-only.
232
239
 
233
- Page styles are plain CSS classes prefixed `bh-` (see `lib/bro_hub/styles.css`): `bh-block`, `bh-split`, `bh-table`/`bh-row`, `bh-tag`, `bh-filters`, `bh-input`, `bh-btn`, `bh-seg`, `bh-log`/`bh-cmd`, `bh-dl`, `bh-pager`, and so on. `bh-tag` is uppercase; add `is-code` for case-sensitive text such as method names. Tables take their columns from `style="--cols: 150px 1fr 80px"`.
240
+ ## Uninstall
234
241
 
235
- ## Notes
242
+ ```sh
243
+ bin/rails g bro_hub:uninstall [--force]
244
+ bin/rails db:migrate
245
+ ```
236
246
 
237
- - The layout loads IBM Plex Mono and Archivo from Google Fonts, and embeds the skull as a `data:` image. Under a strict Content Security Policy allow `fonts.googleapis.com`, `fonts.gstatic.com` and `img-src data:`. Without the fonts it falls back to system fonts. The inline `<style>` uses your CSP nonce when you have one.
238
- - The shell's own pages send `Cache-Control: no-store` and refuse plain HTTP in production (`config.require_ssl`).
239
- - The look is dark only.
247
+ This writes a migration that drops every BroHub table (the audit history and console sessions go with it), removes the initializer and the mount, then you remove `gem "bro_hub"` from the Gemfile. Without a terminal it needs `--force`.
240
248
 
241
249
  ## Development
242
250
 
243
251
  ```sh
244
- bin/rails test # Rails 8.x
245
- BUNDLE_GEMFILE=gemfiles/rails_7_1.gemfile bundle exec rails test # Rails 7.1
252
+ bin/rails test
253
+ REDIS_URL=redis://localhost:6379/15 bin/rails test # includes the Redis tests
254
+ BUNDLE_GEMFILE=gemfiles/rails_7_1.gemfile bin/rails test # Rails 7.1
246
255
  bin/rubocop
247
- cd test/dummy && bin/rails server # try it: /hub (Alpha, Beta), /solo (Gamma)
248
256
  ```
249
257
 
250
- The dummy app has three fake Bro gems (`test/support/fake_bros`). Alpha and Beta live in the hub, Gamma is mounted on its own.
251
-
252
258
  ## License
253
259
 
254
260
  MIT.
261
+
262
+ ---
263
+
264
+ Built by the [DeadBro team](https://www.deadbro.com).
@@ -0,0 +1,26 @@
1
+ module BroHub
2
+ module Apm
3
+ class ApplicationController < BroHub::FeatureController
4
+ bro_hub_feature :apm
5
+
6
+ private
7
+ def apm_api
8
+ BroHub::Apm.api
9
+ end
10
+
11
+ # Runs the block (a call to DeadBro) and returns its data. When DeadBro can't answer, @error is set
12
+ # and the page renders a notice instead of failing: the hub must not 500 because DeadBro is down.
13
+ def apm_fetch
14
+ yield
15
+ rescue BroHub::Apm::Api::Error => error
16
+ @error = error
17
+ nil
18
+ end
19
+
20
+ # Only these reach DeadBro; everything else in the query string is dropped.
21
+ def apm_params(*keys)
22
+ params.permit(*keys).to_h.symbolize_keys
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module BroHub::Apm
2
+ class DeploysController < ApplicationController
3
+ def index
4
+ @data = apm_fetch { apm_api.deploys }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module BroHub::Apm
2
+ class EndpointsController < ApplicationController
3
+ def index
4
+ @filters = apm_params(:window, :sort)
5
+ @data = apm_fetch { apm_api.endpoints(@filters) }
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ module BroHub::Apm
2
+ class ErrorsController < ApplicationController
3
+ PER_PAGE = 25
4
+
5
+ def index
6
+ @offset = [ params[:offset].to_i, 0 ].max
7
+ @data = apm_fetch { apm_api.errors(offset: @offset, limit: PER_PAGE) }
8
+ end
9
+
10
+ def show
11
+ @error_issue = apm_fetch { apm_api.error(params[:id]) }
12
+ render :not_found, status: :not_found if @error&.kind == :not_found
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ module BroHub::Apm
2
+ class FindingsController < ApplicationController
3
+ def index
4
+ @filters = apm_params(:status)
5
+ @data = apm_fetch { apm_api.findings(@filters) }
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module BroHub::Apm
2
+ class OverviewController < ApplicationController
3
+ def show
4
+ @overview = apm_fetch { apm_api.overview }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module BroHub::Apm
2
+ class QueriesController < ApplicationController
3
+ PER_PAGE = 25
4
+
5
+ def index
6
+ @filters = apm_params(:window, :sort, :search)
7
+ @offset = [ params[:offset].to_i, 0 ].max
8
+ @data = apm_fetch { apm_api.queries(@filters.merge(offset: @offset, limit: PER_PAGE)) }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module BroHub::Apm
2
+ class StatusController < ApplicationController
3
+ # Two halves: what the gem has in memory here, and what DeadBro tells it to do.
4
+ def show
5
+ @local = LocalStatus.snapshot
6
+ @remote = apm_fetch { apm_api.settings }
7
+ end
8
+ end
9
+ end