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
@@ -0,0 +1,99 @@
1
+ <% env_styles %>
2
+ <% bro_hub_crumb @environment.name, "Propose a change" %>
3
+ <% content_for :bro_hub_crumb_actions do %>
4
+ <%= bro_hub_crumb_link @environment.name, env_new_proposal_path, active: true %>
5
+ <% end %>
6
+ <% abilities = [] %>
7
+ <% abilities << "add new keys" if can_create? %>
8
+ <% abilities << "type a value to replace one" if can_update? %>
9
+ <% abilities << "tick <em>remove</em> to drop a key".html_safe if can_destroy? %>
10
+ <%= bro_hub_hero eyebrow: "#{@environment.filename} · #{@outline.count { |line| !line.group }} keys",
11
+ title: "Propose a change", subtitle: content_tag(:span, "to #{@environment.name}", class: "bh-tone-green"),
12
+ lead: safe_join([ "Existing values stay hidden. You can ", safe_join(abilities, ", "), "." ]) %>
13
+
14
+ <% if @error %>
15
+ <div class="eb-banner is-error"><%= @error %></div>
16
+ <% end %>
17
+
18
+ <%= form_with url: env_proposal_path, method: :post, local: true, data: { proposal_form: true, turbo: false } do %>
19
+ <% if can_create? %>
20
+ <section class="bh-block">
21
+ <div class="bh-block-head">
22
+ <h2 class="bh-h2">Add new keys</h2>
23
+ <button type="button" class="eb-add" data-add-new-key>+ Another key</button>
24
+ </div>
25
+ <div data-new-keys>
26
+ <% @new_keys.each_with_index do |change, i| %>
27
+ <%= render "new_key_row", change: change, index: i %>
28
+ <% end %>
29
+ </div>
30
+ <p class="eb-note">Nest keys with dots: <code>stripe.publishable_key</code> goes under <code>stripe:</code>. A new group is created if needed.</p>
31
+ </section>
32
+ <% end %>
33
+
34
+ <section class="bh-block">
35
+ <div class="bh-block-head">
36
+ <h2 class="bh-h2" style="text-transform:none"><code><%= @environment.filename %></code></h2>
37
+ <input type="search" class="bh-input" style="flex:0 1 260px" placeholder="Filter keys…" data-filter aria-label="Filter keys">
38
+ </div>
39
+
40
+ <% if @outline.empty? %>
41
+ <p class="bh-hint">This file has no keys yet.<%= " Add some above." if can_create? %></p>
42
+ <% else %>
43
+ <div class="bh-log eb-keys">
44
+ <% index = 0 %>
45
+ <% @outline.each do |line| %>
46
+ <% if line.group %>
47
+ <div class="yaml-line yaml-group" data-group="<%= line.path %>">
48
+ <span class="yaml-key depth-<%= [ line.depth, 6 ].min %>"><%= line.name %>:</span>
49
+ </div>
50
+ <% else %>
51
+ <% edit = @edits[line.path] %>
52
+ <% removed = edit&.action == "delete" %>
53
+ <div class="yaml-line yaml-leaf<%= ' is-removed' if removed %><%= ' is-changed' if edit&.value.present? %>" data-leaf="<%= line.path %>">
54
+ <label class="yaml-key depth-<%= [ line.depth, 6 ].min %>" for="edit_<%= index %>"><%= line.name %>:</label>
55
+ <% if can_update? || can_destroy? %>
56
+ <input type="hidden" name="edits[<%= index %>][key]" value="<%= line.path %>">
57
+ <% end %>
58
+ <% if can_update? %>
59
+ <textarea name="edits[<%= index %>][secret_value]" id="edit_<%= index %>" rows="1" placeholder="•••••• unchanged"
60
+ autocomplete="off" spellcheck="false" data-track data-autogrow<%= ' disabled' if removed %>><%= edit&.value unless removed %></textarea>
61
+ <% else %>
62
+ <span class="bh-cell-muted">••••••</span>
63
+ <% end %>
64
+ <% if can_destroy? %>
65
+ <label class="remove-toggle" title="Remove <%= line.path %>">
66
+ <input type="checkbox" name="edits[<%= index %>][remove]" value="1" data-track data-remove-toggle<%= ' checked' if removed %>> remove
67
+ </label>
68
+ <% end %>
69
+ </div>
70
+ <% index += 1 %>
71
+ <% end %>
72
+ <% end %>
73
+ <p class="bh-hint hidden" data-filter-empty>No keys match.</p>
74
+ </div>
75
+ <% end %>
76
+ </section>
77
+
78
+ <div id="download-notice" class="eb-banner is-ok" hidden>
79
+ <strong>Your download should start now.</strong> Next:
80
+ <ol class="eb-steps">
81
+ <li>Create a branch in the app repo.</li>
82
+ <li>Replace <code><%= env_display_path(@environment.content_path) %></code> with the downloaded file.</li>
83
+ <li>Commit, push and open a pull request. Mention which keys you changed and why.</li>
84
+ <li>A reviewer checks it in EnvBro and merges.</li>
85
+ </ol>
86
+ <p class="eb-note">If someone else's change merges first, build your file again. Encrypted files can't be merged.</p>
87
+ </div>
88
+
89
+ <div class="bh-sticky">
90
+ <span class="eb-summary" data-summary>No changes yet</span>
91
+ <button type="submit" class="bh-btn is-green is-auto" data-submit>Build &amp; download <%= @environment.filename %></button>
92
+ </div>
93
+ <% end %>
94
+
95
+ <template id="new-key-template">
96
+ <%= render "new_key_row", change: BroHub::Env::Editor::Change.new(action: "set"), index: "__INDEX__" %>
97
+ </template>
98
+
99
+ <%= render "bro_hub/env/shared/script" %>
@@ -0,0 +1,29 @@
1
+ <% env_styles %>
2
+ <% bro_hub_crumb @environment.name, "Review a proposed file" %>
3
+ <%= bro_hub_hero eyebrow: @environment.filename, title: "Review", subtitle: "a proposed file", tone: :green,
4
+ lead: safe_join([ "Upload the ", tag.code(@environment.filename), " from the pull request to see which keys it changes." ]) %>
5
+
6
+ <% if @error %>
7
+ <div class="eb-banner is-error"><%= @error %></div>
8
+ <% end %>
9
+
10
+ <%= form_with url: env_review_path, method: :post, multipart: true, local: true, data: { turbo: false } do %>
11
+ <section class="bh-block eb-file">
12
+ <div class="field">
13
+ <label class="bh-field" for="proposed_file">Proposed file
14
+ <input type="file" name="proposed_file" id="proposed_file" accept=".enc" required class="bh-input">
15
+ </label>
16
+ <p class="eb-note">Download it from the PR branch, e.g. <code>git show my-branch:<%= env_display_path(@environment.content_path) %> &gt; <%= @environment.filename %></code>.</p>
17
+ </div>
18
+
19
+ <details class="eb-details" style="margin-top:28px">
20
+ <summary>Compare against another version (optional)</summary>
21
+ <label class="bh-field" for="base_file">Base file
22
+ <input type="file" name="base_file" id="base_file" accept=".enc" class="bh-input">
23
+ </label>
24
+ <p class="eb-note">By default the proposal is compared with the file deployed on this server. Upload the file from <code>main</code> if it is ahead of what's deployed.</p>
25
+ </details>
26
+
27
+ <button type="submit" class="bh-btn is-green is-auto" style="margin-top:28px">Show changes</button>
28
+ </section>
29
+ <% end %>
@@ -0,0 +1,122 @@
1
+ <% env_styles %>
2
+ <% can_reveal = env_can?(:reveal) %>
3
+ <% meta = @differ.proposed_metadata %>
4
+ <% changes = @differ.changes %>
5
+ <% unchanged = @differ.entries.reject(&:changed?) %>
6
+ <% bro_hub_crumb @environment.name, "Review" %>
7
+ <% content_for :bro_hub_crumb_actions do %><%= bro_hub_crumb_link "Review another file", env_new_review_path %><% end %>
8
+
9
+ <%= bro_hub_hero eyebrow: "#{@environment.name} · #{@environment.filename}", title: changes.size.to_s,
10
+ subtitle: "changed #{changes.size == 1 ? 'key' : 'keys'}", tone: (changes.any? ? :amber : :green),
11
+ lead: safe_join([ "Proposed changes to #{@environment.name}, compared against the #{@base_enc ? 'uploaded base file' : 'file deployed on this server'} (",
12
+ tag.code(env_short_digest(@base_digest)), ")." ]),
13
+ stats: [ [ @differ.counts[:added] || 0, "added", :green ], [ @differ.counts[:changed] || 0, "changed", :amber ],
14
+ [ @differ.counts[:removed] || 0, "removed", :red ] ] %>
15
+
16
+ <% case @base_status %>
17
+ <% when :current %>
18
+ <div class="eb-banner is-ok">Built on the same version it is compared against. The diff below is exactly what this PR changes.</div>
19
+ <% when :stale %>
20
+ <div class="eb-banner is-warn">
21
+ <strong>Outdated base.</strong> This file was built on version <code><%= env_short_digest(meta["base_digest"]) %></code>,
22
+ not <code><%= env_short_digest(@base_digest) %></code>. Changes made since then may be reverted by this PR. Look for unexpected removals or changes,
23
+ and ask the author to rebuild the file if in doubt.
24
+ </div>
25
+ <% else %>
26
+ <div class="eb-banner is-warn">
27
+ <strong>Not built with EnvBro.</strong> The file has no EnvBro metadata, so it may have been edited by hand or be an older copy of the file.
28
+ Check every change below carefully.
29
+ </div>
30
+ <% end %>
31
+
32
+ <div class="bh-split">
33
+ <div class="bh-split-main">
34
+ <%= form_with url: env_reveal_review_path, method: :post, local: true, data: { turbo: false } do %>
35
+ <%= hidden_field_tag :proposed_enc, @proposed_enc %>
36
+ <%= hidden_field_tag :base_enc, @base_enc %>
37
+
38
+ <div class="bh-block-head">
39
+ <h2 class="bh-h2">Changed keys</h2>
40
+ <% if can_reveal && changes.any? %>
41
+ <button type="submit" name="reveal_key" value="*" class="eb-add">Reveal all values</button>
42
+ <% end %>
43
+ </div>
44
+
45
+ <div class="eb-summary-tags">
46
+ <% %i[added changed removed].each do |status| %>
47
+ <%= content_tag :span, "#{@differ.counts[status] || 0} #{status}", class: "bh-tag #{BroHub::Env::ApplicationHelper::STATUS_TAGS[status.to_s]}" %>
48
+ <% end %>
49
+ <span class="bh-tag"><%= unchanged.size %> unchanged</span>
50
+ </div>
51
+
52
+ <% if changes.empty? %>
53
+ <p class="bh-hint">No key or value differs from the base file.</p>
54
+ <% else %>
55
+ <div class="bh-table eb-cols-diff<%= ' no-reveal' unless can_reveal %>" style="--min: 0">
56
+ <div class="bh-row is-head"><span>Key</span><span>Status</span><span>Before</span><span>After</span><% if can_reveal %><span></span><% end %></div>
57
+ <% changes.each do |entry| %>
58
+ <% revealed = @revealed.include?(entry.key) %>
59
+ <div class="bh-row row-<%= entry.status %> <%= { 'added' => 'bh-edge-violet', 'changed' => 'bh-edge-amber', 'removed' => 'bh-edge-red' }[entry.status.to_s] %>">
60
+ <span class="bh-cell-strong" style="font-family:var(--bh-mono);font-weight:500;font-size:14px;overflow-wrap:anywhere"><%= entry.key %></span>
61
+ <span><%= env_status_badge(entry.status) %></span>
62
+ <span><%= revealed ? env_value(entry.old_value) : env_masked(entry.old_value) %></span>
63
+ <span><%= revealed ? env_value(entry.new_value) : env_masked(entry.new_value) %></span>
64
+ <% if can_reveal %>
65
+ <span>
66
+ <% unless revealed %>
67
+ <button type="submit" name="reveal_key" value="<%= entry.key %>" class="btn-link">reveal</button>
68
+ <% end %>
69
+ </span>
70
+ <% end %>
71
+ </div>
72
+ <% end %>
73
+ </div>
74
+ <% if can_reveal %>
75
+ <p class="eb-note">Revealing values is recorded in the audit log.</p>
76
+ <% end %>
77
+ <% end %>
78
+
79
+ <% if unchanged.any? %>
80
+ <details class="eb-details" style="margin-top:32px">
81
+ <summary><%= unchanged.size %> unchanged keys</summary>
82
+ <% unchanged.each do |entry| %>
83
+ <div class="eb-unchanged-key row-unchanged"><%= entry.key %></div>
84
+ <% end %>
85
+ </details>
86
+ <% end %>
87
+ <% end %>
88
+ </div>
89
+
90
+ <div class="bh-split-aside">
91
+ <section class="bh-block">
92
+ <h2 class="bh-h2">Proposal</h2>
93
+ <% if meta %>
94
+ <dl class="bh-dl">
95
+ <dt>Author</dt><dd><%= meta["proposed_by"].presence || "unknown" %></dd>
96
+ <dt>Built at</dt><dd><%= meta["proposed_at"] %></dd>
97
+ <dt>Built on</dt><dd><code><%= env_short_digest(meta["base_digest"]) %></code></dd>
98
+ <% if @proposal_event %>
99
+ <dt>Status</dt><dd><%= env_deployment_badge(@proposal_event, BroHub::Env::AuditEvent.live_proposal) %></dd>
100
+ <% end %>
101
+ </dl>
102
+ <% if Array(meta["changes"]).any? %>
103
+ <p class="eb-note">Changes declared by the author:</p>
104
+ <ul class="eb-steps">
105
+ <% Array(meta["changes"]).each do |c| %><li><code><%= c %></code></li><% end %>
106
+ </ul>
107
+ <% end %>
108
+ <% else %>
109
+ <p class="bh-hint">No EnvBro metadata in this file.</p>
110
+ <% end %>
111
+ </section>
112
+
113
+ <section class="bh-block">
114
+ <h2 class="bh-h2">Before merging</h2>
115
+ <ol class="eb-steps">
116
+ <li>Every changed key is expected and matches the PR description.</li>
117
+ <li>No unexpected removals (a sign of an outdated or replaced file).</li>
118
+ <li>The PR changes only <code><%= @environment.filename %></code>, nothing else.</li>
119
+ </ol>
120
+ </section>
121
+ </div>
122
+ </div>
@@ -0,0 +1,57 @@
1
+ <%# What EnvBro's pages need on top of BroHub's shared styles. %>
2
+ <style<%= %( nonce="#{content_security_policy_nonce}").html_safe if content_security_policy_nonce %>>
3
+ .bh-main code { font: 500 .92em var(--bh-mono); color: var(--bh-text); overflow-wrap: anywhere; }
4
+ .hidden { display: none !important; }
5
+ .eb-cols-envs { --cols: minmax(200px, 1fr) 80px 80px 190px 130px; --min: 700px; }
6
+ .eb-cols-diff { --cols: minmax(150px, 1.2fr) 100px minmax(110px, 1fr) minmax(110px, 1fr) 80px; --min: 640px; }
7
+ .eb-cols-diff.no-reveal { --cols: minmax(150px, 1.2fr) 100px minmax(110px, 1fr) minmax(110px, 1fr); }
8
+ .eb-cols-audit { --cols: 170px 130px 150px minmax(180px, 1fr) minmax(170px, 1fr); --min: 840px; }
9
+ .eb-env-name { font: 700 20px var(--bh-sans); font-stretch: 85%; color: var(--bh-text); }
10
+ .eb-env-name small { font: 400 13px var(--bh-mono); color: var(--bh-muted); }
11
+ a.bh-row.eb-env-row:hover { border-left-color: var(--bh-green); }
12
+ .eb-keys { margin-top: 0; }
13
+ .eb-banner { padding: 14px var(--bh-pad); border-bottom: 1px solid var(--bh-line); border-left: 4px solid var(--bh-muted); font: 500 13px/1.5 var(--bh-mono); text-wrap: pretty; }
14
+ .eb-banner[hidden] { display: none; }
15
+ .eb-banner.is-ok { border-left-color: var(--bh-green); background: rgba(46, 204, 122, .08); }
16
+ .eb-banner.is-warn { border-left-color: var(--bh-amber); background: rgba(245, 184, 74, .1); }
17
+ .eb-banner.is-error { border-left-color: var(--bh-red); background: rgba(240, 79, 84, .12); }
18
+ .eb-banner strong { color: var(--bh-text); }
19
+ .eb-steps { margin: 12px 0 0; padding-left: 20px; line-height: 1.7; }
20
+ .eb-note { margin: 12px 0 0; font: 400 12px var(--bh-mono); color: var(--bh-muted); text-wrap: pretty; }
21
+
22
+ /* Propose a change */
23
+ .newkey-row { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; margin-bottom: 10px; }
24
+ .newkey-row input, .newkey-row textarea { background: transparent; border: 0; border-bottom: 2px solid var(--bh-text); color: var(--bh-text); font: 500 14px var(--bh-mono); padding: 10px 0; outline: none; min-width: 0; resize: none; overflow: hidden; }
25
+ .newkey-row input { flex: 1 1 220px; }
26
+ .newkey-row textarea { flex: 2 1 280px; }
27
+ .newkey-row input:focus, .newkey-row textarea:focus { border-bottom-color: var(--bh-green); }
28
+ .icon-btn { background: none; border: 0; cursor: pointer; font: 600 16px var(--bh-mono); color: var(--bh-muted); padding: 6px 8px; }
29
+ .icon-btn:hover { color: var(--bh-red); }
30
+ .eb-add { cursor: pointer; padding: 6px 10px; font: 600 12px var(--bh-mono); border: 1px solid var(--bh-green); background: transparent; color: var(--bh-green); }
31
+ .eb-add:hover { background: var(--bh-green); color: var(--bh-bg); }
32
+ .yaml-line.yaml-group { padding: 16px 0 6px 14px; font: 600 14px var(--bh-mono); color: var(--bh-violet-l); }
33
+ .yaml-line.yaml-leaf { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(160px, 1.5fr) auto; gap: 16px; align-items: center; padding: 8px 0 8px 10px; border-bottom: 1px solid var(--bh-line); border-left: 4px solid transparent; }
34
+ .yaml-line.is-changed { border-left-color: var(--bh-violet); background: rgba(124, 109, 250, .12); }
35
+ .yaml-line.is-removed { border-left-color: var(--bh-red); background: rgba(240, 79, 84, .12); }
36
+ .yaml-key { font: 500 15px var(--bh-mono); overflow-wrap: anywhere; }
37
+ .yaml-key.depth-1 { padding-left: 24px; } .yaml-key.depth-2 { padding-left: 48px; } .yaml-key.depth-3 { padding-left: 72px; }
38
+ .yaml-key.depth-4 { padding-left: 96px; } .yaml-key.depth-5 { padding-left: 120px; } .yaml-key.depth-6 { padding-left: 144px; }
39
+ .is-removed .yaml-key { color: var(--bh-red); text-decoration: line-through; }
40
+ .yaml-leaf textarea { min-width: 0; background: transparent; border: 0; border-bottom: 1px solid var(--bh-line-2); color: var(--bh-text); font: 500 14px var(--bh-mono); padding: 8px 0; outline: none; resize: none; overflow: hidden; }
41
+ .yaml-leaf textarea:focus { border-bottom-color: var(--bh-violet); }
42
+ .yaml-leaf textarea:disabled { color: var(--bh-muted); }
43
+ .remove-toggle { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; padding: 6px 10px; font: 600 12px var(--bh-mono); border: 1px solid var(--bh-line-2); color: var(--bh-text); }
44
+ .remove-toggle input { accent-color: var(--bh-red); margin: 0; }
45
+ .is-removed .remove-toggle { border-color: var(--bh-red); background: var(--bh-red); color: var(--bh-bg); }
46
+ .eb-summary { font: 500 13px var(--bh-mono); color: var(--bh-muted); }
47
+ .eb-summary.has-changes { color: var(--bh-text); }
48
+
49
+ /* Review */
50
+ .mask { letter-spacing: .1em; }
51
+ .btn-link { background: none; border: 0; padding: 0; cursor: pointer; font: 600 12px var(--bh-mono); color: var(--bh-violet-l); text-decoration: underline; }
52
+ .eb-details summary { cursor: pointer; font: 600 13px var(--bh-mono); color: var(--bh-muted); }
53
+ .eb-details[open] summary { margin-bottom: 12px; }
54
+ .eb-file input[type="file"] { padding: 12px 0; font: 500 13px var(--bh-mono); color: var(--bh-text); border-bottom: 2px solid var(--bh-line-2); }
55
+ .eb-summary-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
56
+ .eb-unchanged-key { padding: 6px 0 6px 10px; border-bottom: 1px solid var(--bh-line); font: 500 13px var(--bh-mono); color: var(--bh-muted); }
57
+ </style>
@@ -0,0 +1,114 @@
1
+ <script nonce="<%= content_security_policy_nonce %>">
2
+ (function () {
3
+ "use strict";
4
+
5
+ var nextIndex = 1000;
6
+ var each = function (selector, fn, root) { Array.prototype.forEach.call((root || document).querySelectorAll(selector), fn); };
7
+
8
+ function autogrow(textarea) {
9
+ textarea.style.height = "auto";
10
+ textarea.style.height = textarea.scrollHeight + 2 + "px";
11
+ }
12
+
13
+ // Highlights edited/removed keys and summarizes what the download will contain.
14
+ function refresh() {
15
+ var changed = 0, removed = 0, added = 0;
16
+
17
+ each("[data-leaf]", function (line) {
18
+ var value = line.querySelector("textarea");
19
+ var remove = line.querySelector("[data-remove-toggle]");
20
+ var isRemoved = !!remove && remove.checked;
21
+ var isChanged = !isRemoved && !!value && value.value.trim() !== "";
22
+ if (value) value.disabled = isRemoved;
23
+ line.classList.toggle("is-removed", isRemoved);
24
+ line.classList.toggle("is-changed", isChanged);
25
+ if (isRemoved) removed++;
26
+ if (isChanged) changed++;
27
+ });
28
+
29
+ each("[data-new-key-row]", function (row) {
30
+ if (row.querySelector("input").value.trim() !== "") added++;
31
+ });
32
+
33
+ var summary = document.querySelector("[data-summary]");
34
+ var submit = document.querySelector("[data-submit]");
35
+ if (!summary) return;
36
+ var parts = [];
37
+ if (added) parts.push(added + " new");
38
+ if (changed) parts.push(changed + " changed");
39
+ if (removed) parts.push(removed + " removed");
40
+ summary.textContent = parts.length ? parts.join(" · ") : "No changes yet";
41
+ summary.classList.toggle("has-changes", parts.length > 0);
42
+ if (submit) submit.disabled = parts.length === 0;
43
+ }
44
+
45
+ function addNewKey() {
46
+ var template = document.getElementById("new-key-template");
47
+ var list = document.querySelector("[data-new-keys]");
48
+ if (!template || !list) return;
49
+ var holder = document.createElement("div");
50
+ holder.innerHTML = template.innerHTML.replace(/__INDEX__/g, String(nextIndex++)).trim();
51
+ var row = holder.firstElementChild;
52
+ list.appendChild(row);
53
+ row.querySelector("input").focus();
54
+ }
55
+
56
+ function filter(query) {
57
+ query = query.toLowerCase();
58
+ var visible = [];
59
+ each("[data-leaf]", function (line) {
60
+ var path = line.getAttribute("data-leaf");
61
+ var show = path.toLowerCase().indexOf(query) !== -1;
62
+ line.classList.toggle("hidden", !show);
63
+ if (show) visible.push(path);
64
+ });
65
+ each("[data-group]", function (group) {
66
+ var prefix = group.getAttribute("data-group") + ".";
67
+ group.classList.toggle("hidden", !visible.some(function (p) { return p.indexOf(prefix) === 0; }));
68
+ });
69
+ each("[data-filter-empty]", function (el) { el.classList.toggle("hidden", visible.length > 0); });
70
+ }
71
+
72
+ document.addEventListener("click", function (event) {
73
+ var el = event.target.closest("[data-add-new-key], [data-remove-new-key]");
74
+ if (!el) return;
75
+ event.preventDefault();
76
+
77
+ if (el.hasAttribute("data-add-new-key")) {
78
+ addNewKey();
79
+ } else {
80
+ var row = el.closest("[data-new-key-row]");
81
+ if (document.querySelectorAll("[data-new-key-row]").length > 1) {
82
+ row.remove();
83
+ } else {
84
+ each("input, textarea", function (i) { i.value = ""; }, row);
85
+ }
86
+ }
87
+ refresh();
88
+ });
89
+
90
+ document.addEventListener("input", function (event) {
91
+ var target = event.target;
92
+ if (target.matches("[data-filter]")) filter(target.value);
93
+ if (target.matches("[data-autogrow]")) autogrow(target);
94
+ if (target.matches("[data-track]")) refresh();
95
+ });
96
+
97
+ document.addEventListener("change", function (event) {
98
+ if (!event.target.matches("[data-remove-toggle]")) return;
99
+ refresh();
100
+ var textarea = event.target.closest("[data-leaf]").querySelector("textarea");
101
+ if (!event.target.checked && textarea) textarea.focus();
102
+ });
103
+
104
+ // The proposal form answers with a file download, so the page itself does not change.
105
+ document.addEventListener("submit", function (event) {
106
+ if (!event.target.matches("[data-proposal-form]")) return;
107
+ var notice = document.getElementById("download-notice");
108
+ if (notice) setTimeout(function () { notice.hidden = false; notice.scrollIntoView({ behavior: "smooth", block: "nearest" }); }, 400);
109
+ });
110
+
111
+ each("[data-autogrow]", autogrow);
112
+ refresh();
113
+ })();
114
+ </script>
@@ -0,0 +1,17 @@
1
+ <% status = @environment.status %>
2
+ <% bro_hub_crumb @environment.name, "Not available" %>
3
+ <%= bro_hub_hero eyebrow: "#{@environment.name} credentials", title: "Not available", tone: :red,
4
+ lead: begin
5
+ case status
6
+ when :missing_file
7
+ safe_join([ "There is no credentials file at ", tag.code(env_display_path(@environment.content_path)), " on this server." ])
8
+ when :missing_key
9
+ safe_join([ "This server has no key for ", tag.code(@environment.filename), ". Set ", tag.code(@environment.env_key),
10
+ " or add ", tag.code(env_display_path(@environment.key_path)), "." ])
11
+ else
12
+ safe_join([ "The key on this server (", tag.code(@environment.env_key), " or ", tag.code(env_display_path(@environment.key_path)),
13
+ ") cannot decrypt ", tag.code(@environment.filename), "." ])
14
+ end
15
+ end do %>
16
+ <p style="margin-top:16px"><%= env_environment_badge(status) %></p>
17
+ <% end %>
@@ -0,0 +1,22 @@
1
+ <% bro_hub_crumb "Flagged commands" %>
2
+ <%= bro_hub_hero eyebrow: "Flagged commands", title: @total, tone: (:red if @total > 0), subtitle: (@total == 1 ? "command" : "commands"),
3
+ lead: "Everything that was blocked before it ran, or that ran and looked suspicious. Newest first.",
4
+ stats: [ [ @blocked_total, "blocked", :red ], [ @total - @blocked_total, "ran, flagged", :amber ] ] %>
5
+
6
+ <div class="bh-table-wrap">
7
+ <div class="bh-table" style="--cols: 150px 120px minmax(240px,1.2fr) minmax(200px,1fr) 90px 80px; --min: 940px">
8
+ <div class="bh-row is-head"><span>When</span><span>User</span><span>Command</span><span>Why</span><span>Outcome</span><span>Session</span></div>
9
+ <% @commands.each do |command| %>
10
+ <%= link_to safe_session_path(command.session_id), class: "bh-row bh-edge-red" do %>
11
+ <span class="bh-tone-violet"><%= safe_time(command.created_at) %></span>
12
+ <span class="bh-cell-strong"><%= command.session.username %></span>
13
+ <span style="overflow-wrap:anywhere"><%= truncate(command.statements.to_s, length: 140) %></span>
14
+ <span class="bh-cell-text"><%= command.flag_reason %></span>
15
+ <span class="bh-status <%= command.blocked? ? "bh-tone-red" : "bh-tone-amber" %>"><%= command.blocked? ? "Blocked" : "Ran" %></span>
16
+ <span class="bh-tone-violet">#<%= command.session_id %></span>
17
+ <% end %>
18
+ <% end %>
19
+ <% if @commands.empty? %><div class="bh-empty">Nothing flagged.</div><% end %>
20
+ <%= safe_pager total: @total, page: @page, noun: "flagged command" %>
21
+ </div>
22
+ </div>
@@ -0,0 +1,59 @@
1
+ <% bro_hub_crumb "Rules" %>
2
+ <% protected_now = @config.enabled? %>
3
+ <%= bro_hub_hero eyebrow: "Effective configuration · read only", title: "Rules", subtitle: (protected_now ? "active here" : "off here"),
4
+ tone: (protected_now ? :green : :muted),
5
+ lead: "What the console locks, blocks and flags right now. Change BroHub.config.safe in config/initializers/bro_hub.rb." %>
6
+
7
+ <% tags = ->(values, tone = nil) {
8
+ values.any? ? tag.div(safe_join(values.map { |value| tag.span(safe_rule(value), class: [ "bh-tag", tone ].compact.join(" "), style: "text-transform:none") }, " "), class: "bh-tags") : tag.span("none", class: "bh-cell-muted")
9
+ } %>
10
+
11
+ <% if @config.self_review_unguarded? %>
12
+ <div class="bh-alert bh-alert-error" id="self-review-warning">Self review isn't prevented yet: <code>console_username</code> isn't mapped, so a reviewer's hub name (<code>user_label</code>, usually an email) is compared with the console name (<code>CONSOLE_USER</code>, usually a login) and they never match. Set <code>config.safe.console_username = -&gt;(user) { user.console_name }</code> in config/initializers/bro_hub.rb.</div>
13
+ <% end %>
14
+
15
+ <div class="bh-split">
16
+ <section class="bh-split-main">
17
+ <h2 class="bh-h2">Locked until <code>unlock!</code></h2>
18
+ <dl class="bh-dl">
19
+ <dt>Resources</dt><dd><%= tags.call(@config.protected_resources, "is-amber") %></dd>
20
+ <dt>ENV names</dt><dd><%= tags.call(@config.protected_env_patterns) %></dd>
21
+ <dt>Files</dt><dd><%= tags.call(@config.protected_file_patterns) %></dd>
22
+ <dt>Systems</dt><dd><%= tags.call(@protected_hosts) %></dd>
23
+ </dl>
24
+
25
+ <h2 class="bh-h2" style="margin-top:36px">Blocked before it runs</h2>
26
+ <dl class="bh-dl">
27
+ <dt>Can't reopen</dt><dd><%= tags.call(@config.forbidden_reopening, "is-red") %></dd>
28
+ <dt>Never referenced</dt><dd><%= tags.call(Array(@config.forbidden_constants[:always]), "is-red") %></dd>
29
+ <dt>While locked</dt><dd><%= tags.call(Array(@config.forbidden_constants[:locked]), "is-red") %></dd>
30
+ <dt>Can't be called</dt><dd><%= tags.call(@config.forbidden_methods, "is-red") %></dd>
31
+ <dt>Not from the console</dt><dd><%= tags.call(@config.runtime_only_methods, "is-red") %></dd>
32
+ </dl>
33
+
34
+ <h2 class="bh-h2" style="margin-top:36px">Flagged when mentioned</h2>
35
+ <%= tags.call(@config.suspicious_terms, "is-amber") %>
36
+ </section>
37
+
38
+ <div class="bh-split-aside">
39
+ <section class="bh-block">
40
+ <h2 class="bh-h2">Where it runs</h2>
41
+ <dl class="bh-dl">
42
+ <dt>Environments</dt><dd><%= @config.protected_environments.join(", ") %></dd>
43
+ <dt>Forced</dt><dd><%= @config.enabled.nil? ? "no" : @config.enabled ? "on" : "off" %></dd>
44
+ <dt>Runners</dt><dd><%= @config.audit_runner ? "recorded" : "not recorded" %></dd>
45
+ <dt>Ask for a name</dt><dd><%= @config.ask_for_username_if_empty ? "yes" : "no, console refuses to start" %></dd>
46
+ </dl>
47
+ </section>
48
+ <section class="bh-block">
49
+ <h2 class="bh-h2">Review</h2>
50
+ <dl class="bh-dl">
51
+ <dt>Keep sessions</dt><dd><%= @config.retention ? distance_of_time_in_words(@config.retention) : "forever" %></dd>
52
+ <dt>Keep flagged</dt><dd><%= @config.keep_flagged ? "yes, even past that" : "no" %></dd>
53
+ <dt>Self review</dt><dd><%= @config.allow_self_audit ? "allowed" : "not allowed" %></dd>
54
+ <dt>Console names</dt><dd><%= @config.console_username_mapped? ? "mapped by console_username" : "not mapped (user_label is compared)" %></dd>
55
+ <dt>Require SSL</dt><dd><%= BroHub.config.require_ssl ? "yes" : "no" %></dd>
56
+ </dl>
57
+ </section>
58
+ </div>
59
+ </div>
@@ -0,0 +1,51 @@
1
+ <% status = @filter[:status] || "all" %>
2
+ <% bro_hub_crumb "Console sessions" %>
3
+ <% content_for :bro_hub_crumb_actions do %>
4
+ <% [ [ "Pending", "pending" ], [ "Appropriate", "approved" ], [ "Flagged", "flagged" ], [ "All", "all" ] ].each do |label, value| %>
5
+ <%= bro_hub_crumb_link label, safe_root_path(@filter.merge(status: value)), active: status == value %>
6
+ <% end %>
7
+ <% end %>
8
+
9
+ <%= bro_hub_hero eyebrow: "Console sessions",
10
+ title: @total,
11
+ tone: { "approved" => :green, "flagged" => :red }[status],
12
+ subtitle: { "pending" => "awaiting a verdict", "approved" => "approved", "flagged" => "flagged" }.fetch(status, @total == 1 ? "session" : "sessions"),
13
+ lead: "Who used a console, why, and what they did. Review each one: approve it or flag it.",
14
+ stats: [ [ @unlock_total, "unlocks", :amber ], [ @flag_total, "flagged commands", :red ] ] %>
15
+
16
+ <%= form_with url: safe_root_path, method: :get, class: "bh-filters" do %>
17
+ <%= hidden_field_tag :status, status %>
18
+ <%= text_field_tag :username, @filter[:username], placeholder: "Filter by user", class: "bh-input is-strong", "aria-label": "Filter by user" %>
19
+ <label class="bh-field">From <%= date_field_tag :from, @filter[:from], class: "bh-input" %></label>
20
+ <label class="bh-field">To <%= date_field_tag :to, @filter[:to], class: "bh-input" %></label>
21
+ <% attention = @filter[:attention] == "1" %>
22
+ <%= link_to "Needs attention only", safe_root_path(@filter.merge(status: status, attention: (attention ? nil : "1"))),
23
+ class: [ "bh-chip", ("is-on" if attention) ], title: "Unlocked sensitive data or flagged commands" %>
24
+ <%= hidden_field_tag :attention, "1" if attention %>
25
+ <%= submit_tag "Filter", name: nil, class: "bh-chip" %>
26
+ <%= link_to "Reset", safe_root_path(status: status), class: "bh-link-quiet" %>
27
+ <% end %>
28
+
29
+ <div class="bh-table-wrap">
30
+ <div class="bh-table" style="--cols: 150px 120px minmax(220px,1fr) 80px 64px 200px 110px; --min: 920px">
31
+ <div class="bh-row is-head"><span>Started</span><span>User</span><span>Reason</span><span>Source</span><span>Length</span><span>Flags</span><span>Review</span></div>
32
+ <% @sessions.each do |session| %>
33
+ <% unlocked = @unlock_counts.fetch(session.id, 0) %>
34
+ <% flagged = @flag_counts.fetch(session.id, 0) %>
35
+ <%= link_to safe_session_path(session, @filter), class: [ "bh-row", ("bh-edge-red" if flagged > 0), ("bh-edge-amber" if flagged.zero? && unlocked > 0) ] do %>
36
+ <span class="bh-tone-violet"><%= safe_time(session.started_at) %></span>
37
+ <span class="bh-cell-strong"><%= session.username %></span>
38
+ <span class="bh-cell-text"><%= truncate(session.reason, length: 90) %></span>
39
+ <span class="bh-cell-muted"><%= session.source %></span>
40
+ <span><%= safe_duration(session.duration) %><%= " (open)" if session.open? %></span>
41
+ <span class="bh-tags">
42
+ <%= content_tag(:span, safe_count(unlocked, "unlock"), class: "bh-tag is-amber") if unlocked > 0 %>
43
+ <%= content_tag(:span, "#{flagged} flagged", class: "bh-tag is-red") if flagged > 0 %>
44
+ </span>
45
+ <%= safe_review_status(session.review_status) %>
46
+ <% end %>
47
+ <% end %>
48
+ <% if @sessions.empty? %><div class="bh-empty">Nothing to review.</div><% end %>
49
+ <%= safe_pager total: @total, page: @page, noun: "session" %>
50
+ </div>
51
+ </div>