bro_hub 0.1.2 → 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 (149) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/README.md +204 -87
  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 +56 -0
  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 +28 -18
  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/application_record.rb +5 -0
  38. data/app/models/bro_hub/audit_event.rb +40 -0
  39. data/app/models/bro_hub/cache/audit_event.rb +15 -0
  40. data/app/models/bro_hub/env/audit_event.rb +72 -0
  41. data/app/models/bro_hub/safe/command.rb +22 -0
  42. data/app/models/bro_hub/safe/review.rb +22 -0
  43. data/app/models/bro_hub/safe/session.rb +57 -0
  44. data/app/models/bro_hub/safe/unlock.rb +15 -0
  45. data/app/views/bro_hub/apm/deploys/index.html.erb +21 -0
  46. data/app/views/bro_hub/apm/endpoints/index.html.erb +27 -0
  47. data/app/views/bro_hub/apm/errors/index.html.erb +22 -0
  48. data/app/views/bro_hub/apm/errors/not_found.html.erb +3 -0
  49. data/app/views/bro_hub/apm/errors/show.html.erb +43 -0
  50. data/app/views/bro_hub/apm/findings/index.html.erb +24 -0
  51. data/app/views/bro_hub/apm/overview/show.html.erb +59 -0
  52. data/app/views/bro_hub/apm/queries/index.html.erb +37 -0
  53. data/app/views/bro_hub/apm/shared/_page_styles.html.erb +15 -0
  54. data/app/views/bro_hub/apm/status/show.html.erb +47 -0
  55. data/app/views/bro_hub/audit_events/index.html.erb +38 -0
  56. data/app/views/bro_hub/audit_events/show.html.erb +54 -0
  57. data/app/views/bro_hub/cache/audit_events/index.html.erb +39 -0
  58. data/app/views/bro_hub/cache/audit_events/show.html.erb +48 -0
  59. data/app/views/bro_hub/cache/flushes/new.html.erb +19 -0
  60. data/app/views/bro_hub/cache/keys/index.html.erb +36 -0
  61. data/app/views/bro_hub/cache/keys/show.html.erb +57 -0
  62. data/app/views/bro_hub/cache/purges/new.html.erb +17 -0
  63. data/app/views/bro_hub/cache/purges/preview.html.erb +37 -0
  64. data/app/views/bro_hub/cache/shared/_store_tabs.html.erb +9 -0
  65. data/app/views/bro_hub/cache/shared/unsupported.html.erb +3 -0
  66. data/app/views/bro_hub/env/audit/index.html.erb +31 -0
  67. data/app/views/bro_hub/env/home/index.html.erb +25 -0
  68. data/app/views/bro_hub/env/proposals/_new_key_row.html.erb +7 -0
  69. data/app/views/bro_hub/env/proposals/new.html.erb +99 -0
  70. data/app/views/bro_hub/env/reviews/new.html.erb +29 -0
  71. data/app/views/bro_hub/env/reviews/show.html.erb +122 -0
  72. data/app/views/bro_hub/env/shared/_page_styles.html.erb +57 -0
  73. data/app/views/bro_hub/env/shared/_script.html.erb +114 -0
  74. data/app/views/bro_hub/env/shared/not_ready.html.erb +17 -0
  75. data/app/views/bro_hub/safe/flagged_commands/index.html.erb +22 -0
  76. data/app/views/bro_hub/safe/rules/show.html.erb +59 -0
  77. data/app/views/bro_hub/safe/sessions/index.html.erb +51 -0
  78. data/app/views/bro_hub/safe/sessions/show.html.erb +92 -0
  79. data/app/views/bro_hub/safe/unlocks/index.html.erb +25 -0
  80. data/app/views/bro_hub/shared/schema_missing.html.erb +25 -0
  81. data/app/views/layouts/bro_hub/application.html.erb +11 -2
  82. data/config/routes/apm.rb +10 -0
  83. data/config/routes/cache.rb +17 -0
  84. data/config/routes/env.rb +10 -0
  85. data/config/routes/safe.rb +10 -0
  86. data/config/routes.rb +12 -3
  87. data/db/migrate/20261129000000_create_bro_hub_tables.rb +85 -0
  88. data/lib/bro_hub/apm/api.rb +88 -0
  89. data/lib/bro_hub/apm/configuration.rb +58 -0
  90. data/lib/bro_hub/apm/local_status.rb +49 -0
  91. data/lib/bro_hub/apm.rb +28 -0
  92. data/lib/bro_hub/audit.rb +41 -0
  93. data/lib/bro_hub/cache/audit.rb +15 -0
  94. data/lib/bro_hub/cache/configuration.rb +105 -0
  95. data/lib/bro_hub/cache/errors.rb +26 -0
  96. data/lib/bro_hub/cache/redis_store.rb +220 -0
  97. data/lib/bro_hub/cache.rb +38 -0
  98. data/lib/bro_hub/configuration.rb +19 -4
  99. data/lib/bro_hub/controller_base.rb +3 -6
  100. data/lib/bro_hub/engine.rb +60 -1
  101. data/lib/bro_hub/env/audit.rb +17 -0
  102. data/lib/bro_hub/env/configuration.rb +72 -0
  103. data/lib/bro_hub/env/credentials.rb +135 -0
  104. data/lib/bro_hub/env/deployments.rb +45 -0
  105. data/lib/bro_hub/env/differ.rb +58 -0
  106. data/lib/bro_hub/env/editor.rb +104 -0
  107. data/lib/bro_hub/env/encrypted_blob.rb +18 -0
  108. data/lib/bro_hub/env/environment.rb +74 -0
  109. data/lib/bro_hub/env.rb +36 -0
  110. data/lib/bro_hub/features.rb +13 -0
  111. data/lib/bro_hub/layout.rb +2 -5
  112. data/lib/bro_hub/registry.rb +5 -0
  113. data/lib/bro_hub/safe/cipher.rb +46 -0
  114. data/lib/bro_hub/safe/commands.rb +25 -0
  115. data/lib/bro_hub/safe/configuration.rb +191 -0
  116. data/lib/bro_hub/safe/encrypted_type.rb +16 -0
  117. data/lib/bro_hub/safe/errors.rb +48 -0
  118. data/lib/bro_hub/safe/executor.rb +142 -0
  119. data/lib/bro_hub/safe/guards/const_guard.rb +42 -0
  120. data/lib/bro_hub/safe/guards/credentials_guard.rb +31 -0
  121. data/lib/bro_hub/safe/guards/env_guard.rb +90 -0
  122. data/lib/bro_hub/safe/guards/file_guard.rb +28 -0
  123. data/lib/bro_hub/safe/guards/guarded.rb +51 -0
  124. data/lib/bro_hub/safe/guards/irb_context.rb +23 -0
  125. data/lib/bro_hub/safe/guards/method_guard.rb +32 -0
  126. data/lib/bro_hub/safe/guards/network_guard.rb +98 -0
  127. data/lib/bro_hub/safe/guards/sql_guard.rb +26 -0
  128. data/lib/bro_hub/safe/parsed_command.rb +66 -0
  129. data/lib/bro_hub/safe/recorder.rb +82 -0
  130. data/lib/bro_hub/safe/shield.rb +83 -0
  131. data/lib/bro_hub/safe/supervisor.rb +81 -0
  132. data/lib/bro_hub/safe/terminal.rb +55 -0
  133. data/lib/bro_hub/safe/trail.rb +24 -0
  134. data/lib/bro_hub/safe/validator.rb +74 -0
  135. data/lib/bro_hub/safe.rb +134 -0
  136. data/lib/bro_hub/schema.rb +36 -0
  137. data/lib/bro_hub/section.rb +14 -10
  138. data/lib/bro_hub/testing.rb +62 -0
  139. data/lib/bro_hub/version.rb +1 -1
  140. data/lib/bro_hub.rb +32 -6
  141. data/lib/generators/bro_hub/install/install_generator.rb +93 -69
  142. data/lib/generators/bro_hub/install/templates/bro_hub.rb.tt +115 -0
  143. data/lib/generators/bro_hub/uninstall/templates/drop_bro_hub_tables.rb.tt +16 -0
  144. data/lib/generators/bro_hub/uninstall/uninstall_generator.rb +57 -0
  145. data/lib/tasks/bro_hub.rake +9 -0
  146. metadata +155 -10
  147. data/lib/bro_hub/root_middleware.rb +0 -17
  148. data/lib/generators/bro_hub/install/templates/bro_hub.rb +0 -11
  149. data/lib/generators/bro_hub/installable.rb +0 -63
@@ -0,0 +1,37 @@
1
+ <% bro_hub_crumb "Purge", "Confirm" %>
2
+ <% content_for :bro_hub_crumb_actions do %>
3
+ <%= bro_hub_crumb_link "← Change pattern", cache_purge_path(store: cache_current_store.name) %>
4
+ <% end %>
5
+
6
+ <%= bro_hub_hero eyebrow: "#{cache_current_store.name} · #{@pattern}",
7
+ title: "#{number_with_delimiter(@matches.count)}#{"+" if @matches.truncated}",
8
+ subtitle: @matches.count == 1 ? "key matches" : "keys match", tone: (@matches.count.zero? ? nil : :red),
9
+ lead: @matches.count.zero? ? "Nothing matches. Nothing to delete." : "Nothing has been deleted yet." %>
10
+
11
+ <% if @matches.count.positive? %>
12
+ <div class="bh-split">
13
+ <section class="bh-split-main">
14
+ <div class="bh-block-head"><h2 class="bh-h2">For example</h2></div>
15
+ <div class="bh-log">
16
+ <% @matches.sample.each do |key| %>
17
+ <div class="bh-cmd"><pre class="bh-cmd-code" style="white-space:pre-wrap;overflow-wrap:anywhere"><%= key %></pre></div>
18
+ <% end %>
19
+ </div>
20
+ <% if @matches.truncated %>
21
+ <p class="bh-hint is-error">More than <%= number_with_delimiter(BroHub.config.cache.max_purge_keys) %> keys match. One purge deletes at most that many, so run it again for the rest.</p>
22
+ <% end %>
23
+ </section>
24
+ <div class="bh-split-aside">
25
+ <section class="bh-block">
26
+ <h2 class="bh-h2">Delete them</h2>
27
+ <p class="bh-hint">The count can change by the time you confirm. What is deleted is recorded, with this pattern<%= " and your reason" if @reason %>.</p>
28
+ <%= form_with url: cache_purge_path, method: :post do %>
29
+ <%= hidden_field_tag :store, cache_current_store.name %>
30
+ <%= hidden_field_tag :pattern, @pattern %>
31
+ <%= hidden_field_tag :reason, @reason %>
32
+ <%= submit_tag "Purge #{cache_count(@matches.count, "key")}#{"+" if @matches.truncated}", name: nil, class: "bh-btn is-auto", style: "margin-top:14px;background:var(--bh-red)" %>
33
+ <% end %>
34
+ </section>
35
+ </div>
36
+ </div>
37
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <%# Tabs on the right of the breadcrumb bar when there is more than one cache store. `path` builds the link for a store name. %>
2
+ <% if BroHub.config.cache.store_names.size > 1 %>
3
+ <% current = params[:store].presence || BroHub.config.cache.store_names.first %>
4
+ <% content_for :bro_hub_crumb_actions do %>
5
+ <% BroHub.config.cache.store_names.each do |name| %>
6
+ <%= bro_hub_crumb_link name, path.call(name), active: name == current %>
7
+ <% end %>
8
+ <% end %>
9
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% bro_hub_crumb "Unsupported store" %>
2
+ <%= render "bro_hub/cache/shared/store_tabs", path: ->(name) { cache_root_path(store: name) } %>
3
+ <%= bro_hub_hero eyebrow: "Cache", title: "Can't manage this store", tone: :amber, lead: @unsupported %>
@@ -0,0 +1,31 @@
1
+ <% env_styles %>
2
+ <% bro_hub_crumb "Audit log" %>
3
+ <%= bro_hub_hero eyebrow: "Audit log · #{@environment.name}", title: @events.size.to_s, subtitle: (@events.size == 1 ? "event" : "events"), tone: :green,
4
+ lead: "Who proposed, reviewed or revealed what, and when proposals went live. Key names only, never values." %>
5
+
6
+ <% if @events.empty? %>
7
+ <div class="bh-table-wrap"><div class="bh-empty">Nothing recorded yet.</div></div>
8
+ <% else %>
9
+ <div class="bh-table-wrap">
10
+ <div class="bh-table eb-cols-audit">
11
+ <div class="bh-row is-head"><span>When</span><span>Who</span><span>Event</span><span>Keys</span><span>Status</span></div>
12
+ <% @events.each do |event| %>
13
+ <div class="bh-row">
14
+ <span class="bh-cell-muted" title="<%= event.created_at.utc.iso8601 %>"><%= env_time(event.created_at) %></span>
15
+ <span class="bh-cell-strong"><%= event.user_label %></span>
16
+ <span><span class="bh-tag"><%= event.event.humanize %></span></span>
17
+ <span><%= safe_join(event.keys, tag.br) %></span>
18
+ <span>
19
+ <% if event.event == "proposal_created" %>
20
+ <%= env_deployment_badge(event, @live_proposal) %>
21
+ <% elsif event.event == "credentials_deployed" %>
22
+ <span class="bh-tag is-amber" title="The running file is not from an EnvBro proposal (edited by hand, say).">not from a proposal</span>
23
+ <% elsif event.modified_after_review? %>
24
+ <span class="bh-tag is-amber" title="The deployed file is not the one EnvBro built. It was re-encrypted after review.">modified after review</span>
25
+ <% end %>
26
+ </span>
27
+ </div>
28
+ <% end %>
29
+ </div>
30
+ </div>
31
+ <% end %>
@@ -0,0 +1,25 @@
1
+ <% env_styles %>
2
+ <% bro_hub_crumb "Environments" %>
3
+ <%= bro_hub_hero eyebrow: "Encrypted credentials", title: "1", subtitle: "environment", tone: :green,
4
+ lead: "Pick an environment to propose a change. Existing values stay hidden." %>
5
+
6
+ <div class="bh-table-wrap">
7
+ <div class="bh-table eb-cols-envs">
8
+ <div class="bh-row is-head"><span>File</span><span>Keys</span><span>Groups</span><span>Last change</span><span>By</span></div>
9
+ <% credentials = (@environment.current_credentials if @environment.ready?) %>
10
+ <% meta = credentials&.metadata %>
11
+ <% meta = nil unless meta.is_a?(Hash) %>
12
+ <%= link_to (env_can?(:propose) ? env_new_proposal_path : env_new_review_path), class: "bh-row eb-env-row" do %>
13
+ <span class="eb-env-name"><%= @environment.name %><small>.yml.enc</small></span>
14
+ <% if credentials %>
15
+ <span><%= credentials.key_paths.size %></span>
16
+ <span><%= credentials.outline.count(&:group) %></span>
17
+ <span class="bh-cell-muted"><%= meta&.fetch("proposed_at", nil).presence || "-" %></span>
18
+ <span><%= meta&.fetch("proposed_by", nil).presence || "-" %></span>
19
+ <% else %>
20
+ <span class="bh-cell-muted">-</span><span class="bh-cell-muted">-</span>
21
+ <span><%= env_environment_badge(@environment.status) %></span><span></span>
22
+ <% end %>
23
+ <% end %>
24
+ </div>
25
+ </div>
@@ -0,0 +1,7 @@
1
+ <div class="newkey-row" data-new-key-row>
2
+ <input type="text" name="new_keys[<%= index %>][key]" value="<%= change.key %>" placeholder="stripe.publishable_key"
3
+ autocomplete="off" spellcheck="false" aria-label="New key" class="mono" data-track>
4
+ <textarea name="new_keys[<%= index %>][secret_value]" rows="1" placeholder="Value"
5
+ autocomplete="off" spellcheck="false" aria-label="Value" data-track data-autogrow><%= change.value %></textarea>
6
+ <button type="button" class="icon-btn" data-remove-new-key title="Remove" aria-label="Remove this new key">×</button>
7
+ </div>
@@ -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>