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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +204 -87
- data/app/controllers/bro_hub/apm/application_controller.rb +26 -0
- data/app/controllers/bro_hub/apm/deploys_controller.rb +7 -0
- data/app/controllers/bro_hub/apm/endpoints_controller.rb +8 -0
- data/app/controllers/bro_hub/apm/errors_controller.rb +15 -0
- data/app/controllers/bro_hub/apm/findings_controller.rb +8 -0
- data/app/controllers/bro_hub/apm/overview_controller.rb +7 -0
- data/app/controllers/bro_hub/apm/queries_controller.rb +11 -0
- data/app/controllers/bro_hub/apm/status_controller.rb +9 -0
- data/app/controllers/bro_hub/application_controller.rb +16 -0
- data/app/controllers/bro_hub/audit_events_controller.rb +56 -0
- data/app/controllers/bro_hub/cache/application_controller.rb +55 -0
- data/app/controllers/bro_hub/cache/audit_events_controller.rb +40 -0
- data/app/controllers/bro_hub/cache/flushes_controller.rb +34 -0
- data/app/controllers/bro_hub/cache/keys_controller.rb +41 -0
- data/app/controllers/bro_hub/cache/purges_controller.rb +40 -0
- data/app/controllers/bro_hub/env/application_controller.rb +27 -0
- data/app/controllers/bro_hub/env/audit_controller.rb +10 -0
- data/app/controllers/bro_hub/env/home_controller.rb +6 -0
- data/app/controllers/bro_hub/env/proposals_controller.rb +86 -0
- data/app/controllers/bro_hub/env/reviews_controller.rb +72 -0
- data/app/controllers/bro_hub/feature_controller.rb +21 -0
- data/app/controllers/bro_hub/safe/application_controller.rb +24 -0
- data/app/controllers/bro_hub/safe/flagged_commands_controller.rb +14 -0
- data/app/controllers/bro_hub/safe/reviews_controller.rb +39 -0
- data/app/controllers/bro_hub/safe/rules_controller.rb +18 -0
- data/app/controllers/bro_hub/safe/sessions_controller.rb +63 -0
- data/app/controllers/bro_hub/safe/unlocks_controller.rb +14 -0
- data/app/helpers/bro_hub/apm/application_helper.rb +104 -0
- data/app/helpers/bro_hub/application_helper.rb +28 -18
- data/app/helpers/bro_hub/cache/application_helper.rb +63 -0
- data/app/helpers/bro_hub/env/application_helper.rb +67 -0
- data/app/helpers/bro_hub/safe/application_helper.rb +59 -0
- data/app/jobs/bro_hub/safe/purge_job.rb +10 -0
- data/app/models/bro_hub/application_record.rb +5 -0
- data/app/models/bro_hub/audit_event.rb +40 -0
- data/app/models/bro_hub/cache/audit_event.rb +15 -0
- data/app/models/bro_hub/env/audit_event.rb +72 -0
- data/app/models/bro_hub/safe/command.rb +22 -0
- data/app/models/bro_hub/safe/review.rb +22 -0
- data/app/models/bro_hub/safe/session.rb +57 -0
- data/app/models/bro_hub/safe/unlock.rb +15 -0
- data/app/views/bro_hub/apm/deploys/index.html.erb +21 -0
- data/app/views/bro_hub/apm/endpoints/index.html.erb +27 -0
- data/app/views/bro_hub/apm/errors/index.html.erb +22 -0
- data/app/views/bro_hub/apm/errors/not_found.html.erb +3 -0
- data/app/views/bro_hub/apm/errors/show.html.erb +43 -0
- data/app/views/bro_hub/apm/findings/index.html.erb +24 -0
- data/app/views/bro_hub/apm/overview/show.html.erb +59 -0
- data/app/views/bro_hub/apm/queries/index.html.erb +37 -0
- data/app/views/bro_hub/apm/shared/_page_styles.html.erb +15 -0
- data/app/views/bro_hub/apm/status/show.html.erb +47 -0
- data/app/views/bro_hub/audit_events/index.html.erb +38 -0
- data/app/views/bro_hub/audit_events/show.html.erb +54 -0
- data/app/views/bro_hub/cache/audit_events/index.html.erb +39 -0
- data/app/views/bro_hub/cache/audit_events/show.html.erb +48 -0
- data/app/views/bro_hub/cache/flushes/new.html.erb +19 -0
- data/app/views/bro_hub/cache/keys/index.html.erb +36 -0
- data/app/views/bro_hub/cache/keys/show.html.erb +57 -0
- data/app/views/bro_hub/cache/purges/new.html.erb +17 -0
- data/app/views/bro_hub/cache/purges/preview.html.erb +37 -0
- data/app/views/bro_hub/cache/shared/_store_tabs.html.erb +9 -0
- data/app/views/bro_hub/cache/shared/unsupported.html.erb +3 -0
- data/app/views/bro_hub/env/audit/index.html.erb +31 -0
- data/app/views/bro_hub/env/home/index.html.erb +25 -0
- data/app/views/bro_hub/env/proposals/_new_key_row.html.erb +7 -0
- data/app/views/bro_hub/env/proposals/new.html.erb +99 -0
- data/app/views/bro_hub/env/reviews/new.html.erb +29 -0
- data/app/views/bro_hub/env/reviews/show.html.erb +122 -0
- data/app/views/bro_hub/env/shared/_page_styles.html.erb +57 -0
- data/app/views/bro_hub/env/shared/_script.html.erb +114 -0
- data/app/views/bro_hub/env/shared/not_ready.html.erb +17 -0
- data/app/views/bro_hub/safe/flagged_commands/index.html.erb +22 -0
- data/app/views/bro_hub/safe/rules/show.html.erb +59 -0
- data/app/views/bro_hub/safe/sessions/index.html.erb +51 -0
- data/app/views/bro_hub/safe/sessions/show.html.erb +92 -0
- data/app/views/bro_hub/safe/unlocks/index.html.erb +25 -0
- data/app/views/bro_hub/shared/schema_missing.html.erb +25 -0
- data/app/views/layouts/bro_hub/application.html.erb +11 -2
- data/config/routes/apm.rb +10 -0
- data/config/routes/cache.rb +17 -0
- data/config/routes/env.rb +10 -0
- data/config/routes/safe.rb +10 -0
- data/config/routes.rb +12 -3
- data/db/migrate/20261129000000_create_bro_hub_tables.rb +85 -0
- data/lib/bro_hub/apm/api.rb +88 -0
- data/lib/bro_hub/apm/configuration.rb +58 -0
- data/lib/bro_hub/apm/local_status.rb +49 -0
- data/lib/bro_hub/apm.rb +28 -0
- data/lib/bro_hub/audit.rb +41 -0
- data/lib/bro_hub/cache/audit.rb +15 -0
- data/lib/bro_hub/cache/configuration.rb +105 -0
- data/lib/bro_hub/cache/errors.rb +26 -0
- data/lib/bro_hub/cache/redis_store.rb +220 -0
- data/lib/bro_hub/cache.rb +38 -0
- data/lib/bro_hub/configuration.rb +19 -4
- data/lib/bro_hub/controller_base.rb +3 -6
- data/lib/bro_hub/engine.rb +60 -1
- data/lib/bro_hub/env/audit.rb +17 -0
- data/lib/bro_hub/env/configuration.rb +72 -0
- data/lib/bro_hub/env/credentials.rb +135 -0
- data/lib/bro_hub/env/deployments.rb +45 -0
- data/lib/bro_hub/env/differ.rb +58 -0
- data/lib/bro_hub/env/editor.rb +104 -0
- data/lib/bro_hub/env/encrypted_blob.rb +18 -0
- data/lib/bro_hub/env/environment.rb +74 -0
- data/lib/bro_hub/env.rb +36 -0
- data/lib/bro_hub/features.rb +13 -0
- data/lib/bro_hub/layout.rb +2 -5
- data/lib/bro_hub/registry.rb +5 -0
- data/lib/bro_hub/safe/cipher.rb +46 -0
- data/lib/bro_hub/safe/commands.rb +25 -0
- data/lib/bro_hub/safe/configuration.rb +191 -0
- data/lib/bro_hub/safe/encrypted_type.rb +16 -0
- data/lib/bro_hub/safe/errors.rb +48 -0
- data/lib/bro_hub/safe/executor.rb +142 -0
- data/lib/bro_hub/safe/guards/const_guard.rb +42 -0
- data/lib/bro_hub/safe/guards/credentials_guard.rb +31 -0
- data/lib/bro_hub/safe/guards/env_guard.rb +90 -0
- data/lib/bro_hub/safe/guards/file_guard.rb +28 -0
- data/lib/bro_hub/safe/guards/guarded.rb +51 -0
- data/lib/bro_hub/safe/guards/irb_context.rb +23 -0
- data/lib/bro_hub/safe/guards/method_guard.rb +32 -0
- data/lib/bro_hub/safe/guards/network_guard.rb +98 -0
- data/lib/bro_hub/safe/guards/sql_guard.rb +26 -0
- data/lib/bro_hub/safe/parsed_command.rb +66 -0
- data/lib/bro_hub/safe/recorder.rb +82 -0
- data/lib/bro_hub/safe/shield.rb +83 -0
- data/lib/bro_hub/safe/supervisor.rb +81 -0
- data/lib/bro_hub/safe/terminal.rb +55 -0
- data/lib/bro_hub/safe/trail.rb +24 -0
- data/lib/bro_hub/safe/validator.rb +74 -0
- data/lib/bro_hub/safe.rb +134 -0
- data/lib/bro_hub/schema.rb +36 -0
- data/lib/bro_hub/section.rb +14 -10
- data/lib/bro_hub/testing.rb +62 -0
- data/lib/bro_hub/version.rb +1 -1
- data/lib/bro_hub.rb +32 -6
- data/lib/generators/bro_hub/install/install_generator.rb +93 -69
- data/lib/generators/bro_hub/install/templates/bro_hub.rb.tt +115 -0
- data/lib/generators/bro_hub/uninstall/templates/drop_bro_hub_tables.rb.tt +16 -0
- data/lib/generators/bro_hub/uninstall/uninstall_generator.rb +57 -0
- data/lib/tasks/bro_hub.rake +9 -0
- metadata +155 -10
- data/lib/bro_hub/root_middleware.rb +0 -17
- data/lib/generators/bro_hub/install/templates/bro_hub.rb +0 -11
- data/lib/generators/bro_hub/installable.rb +0 -63
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2147a478c6231177b6f68351407584a74dabd22e2547a358dd56d1c55b5239c7
|
|
4
|
+
data.tar.gz: 4824766699023e1004daf5e292ac2caa5f9c01dea14cdc43a7c39edc09d7db24
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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,147 +1,264 @@
|
|
|
1
1
|
# BroHub
|
|
2
2
|
|
|
3
|
-
One
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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. |
|
|
9
11
|
|
|
10
|
-
|
|
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.
|
|
11
13
|
|
|
12
|
-
|
|
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.
|
|
13
19
|
|
|
14
20
|
## Install
|
|
15
21
|
|
|
16
22
|
```ruby
|
|
23
|
+
# Gemfile
|
|
17
24
|
gem "bro_hub"
|
|
18
25
|
```
|
|
19
26
|
|
|
20
|
-
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
|
|
21
|
-
it with a warning and leaves its old mount alone, so `bundle update env_bro` first.
|
|
22
|
-
|
|
23
27
|
```sh
|
|
24
|
-
|
|
28
|
+
bundle install
|
|
29
|
+
bin/rails g bro_hub:install [--features=env,safe] [--mount-path=/bro_hub] [--migrate]
|
|
25
30
|
```
|
|
26
31
|
|
|
27
|
-
|
|
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.
|
|
33
|
+
|
|
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`.
|
|
28
35
|
|
|
29
|
-
|
|
30
|
-
2. mounts BroHub (it asks where, default `/bro_hub`; or `--mount-path=/ops/bro`):
|
|
31
|
-
```ruby
|
|
32
|
-
mount BroHub::Engine => "/bro_hub"
|
|
33
|
-
```
|
|
34
|
-
3. offers to comment out old direct mounts such as `mount SafeBro::Engine`, since BroHub now mounts those gems itself
|
|
35
|
-
(`--remove-direct-mounts` says yes without asking; without a terminal the lines are left alone with a warning),
|
|
36
|
-
4. runs the installer of every Bro gem in your Gemfile (SafeBro's initializer and migrations, EnvBro's, ...).
|
|
36
|
+
### Which version
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
it is skipped, and `--skip` / `--force` / `--pretend` are passed on to every gem's installer. In scripts and agents, pass
|
|
40
|
-
`--skip` and `--mount-path=...` so nothing waits on a prompt.
|
|
38
|
+
Use **0.3.0 or newer**. Earlier releases are superseded and should be ignored; nothing from them is read or migrated.
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
Running both, in any order, mounts BroHub once.
|
|
40
|
+
### Turning a feature on later
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
authentication generator has only that). The top-right label tries `email`, `email_address` (Rails 8) then `name`.
|
|
42
|
+
Add it to `config.features` in the initializer and set its permissions:
|
|
47
43
|
|
|
48
44
|
```ruby
|
|
49
|
-
# config/initializers/bro_hub.rb
|
|
50
45
|
BroHub.configure do |config|
|
|
51
|
-
config.
|
|
52
|
-
config.user_label = ->(user) { user.email }
|
|
53
|
-
config.parent_controller = "::ApplicationController"
|
|
46
|
+
config.features = %i[ env safe cache apm ]
|
|
54
47
|
end
|
|
55
48
|
```
|
|
56
49
|
|
|
57
|
-
|
|
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
|
|
53
|
+
|
|
54
|
+
Everything is in `config/initializers/bro_hub.rb`, as `BroHub.configure { |config| ... }`, readable afterwards as `BroHub.config.<key>`.
|
|
55
|
+
|
|
56
|
+
### Shared settings
|
|
58
57
|
|
|
59
|
-
|
|
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?`. |
|
|
60
65
|
|
|
61
|
-
|
|
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.
|
|
67
|
+
|
|
68
|
+
### SafeBro (`BroHub.config.safe`)
|
|
69
|
+
|
|
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.
|
|
62
71
|
|
|
63
72
|
```ruby
|
|
64
|
-
|
|
65
|
-
label: "SafeBro · audit", # sidebar heading
|
|
66
|
-
name: "SafeBro", # breadcrumb (default: label up to the "·")
|
|
67
|
-
accent: :red, # :red :green :violet :amber :blue, or "#hex"
|
|
68
|
-
engine: "SafeBro::Engine", # BroHub mounts it at /<key>
|
|
69
|
-
order: 10, # lower comes first
|
|
70
|
-
visible_to: ->(user) { SafeBro.config.can_audit.call(user) },
|
|
71
|
-
items: [
|
|
72
|
-
{ label: "Sessions", path: "/", badge: -> { SafeBro::Session.pending.count } },
|
|
73
|
-
{ label: "Flagged commands", path: "/flagged" },
|
|
74
|
-
{ label: "Rules", path: "/rules", match: %r{\A/rules} },
|
|
75
|
-
{ label: "Raw export", path: "/export", visible_to: ->(user) { user.admin? } } # per-item visibility
|
|
76
|
-
]
|
|
73
|
+
config.safe.can_audit = ->(user) { user.admin? } # who may review sessions
|
|
77
74
|
```
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
83
|
+
```
|
|
83
84
|
|
|
84
|
-
|
|
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.
|
|
86
|
+
|
|
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 |
|
|
104
|
+
| --- | --- |
|
|
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.
|
|
120
|
+
|
|
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:` |
|
|
85
152
|
|
|
86
153
|
```ruby
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
bro_hub_section :safe_bro
|
|
154
|
+
ActiveSupport::Notifications.subscribe(/\.bro_hub_safe\z/) do |name, _start, _finish, _id, payload|
|
|
155
|
+
SecurityMailer.console_event(name, payload).deliver_later
|
|
90
156
|
end
|
|
91
157
|
```
|
|
92
158
|
|
|
93
|
-
|
|
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`.
|
|
160
|
+
|
|
161
|
+
#### What this is not
|
|
162
|
+
|
|
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.
|
|
164
|
+
|
|
165
|
+
Specifically:
|
|
166
|
+
|
|
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.
|
|
171
|
+
|
|
172
|
+
If you need a boundary, build it outside Ruby:
|
|
173
|
+
|
|
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.
|
|
178
|
+
|
|
179
|
+
Not covered: `rails dbconsole`, a raw `psql`/`mysql` session, other process managers or shells, and Pry (SafeBro hooks IRB).
|
|
180
|
+
|
|
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`.
|
|
182
|
+
|
|
183
|
+
### EnvBro (`BroHub.config.env`)
|
|
184
|
+
|
|
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.
|
|
186
|
+
|
|
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.
|
|
192
|
+
|
|
193
|
+
```ruby
|
|
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)
|
|
199
|
+
```
|
|
200
|
+
|
|
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).
|
|
94
202
|
|
|
95
|
-
|
|
96
|
-
|
|
203
|
+
### CacheBro (`BroHub.config.cache`)
|
|
204
|
+
|
|
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:
|
|
97
208
|
|
|
98
209
|
```ruby
|
|
99
|
-
|
|
100
|
-
|
|
210
|
+
config.cache_store = :redis_cache_store, { url: ENV["REDIS_URL"], namespace: "myapp" }
|
|
211
|
+
```
|
|
101
212
|
|
|
102
|
-
|
|
103
|
-
include BroHub::Generators::Installable # keep this first: it adds the BroHub step and --mount-path
|
|
213
|
+
Without one you get a warning and Flush is disabled.
|
|
104
214
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
215
|
+
```ruby
|
|
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? }
|
|
110
222
|
```
|
|
111
223
|
|
|
112
|
-
|
|
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`.
|
|
225
|
+
|
|
226
|
+
### DeadBro (`BroHub.config.apm`)
|
|
113
227
|
|
|
114
|
-
|
|
115
|
-
<% bro_hub_crumb "Console sessions", "#5" %> <%# "SafeBro / Console sessions / #5" %>
|
|
116
|
-
<% content_for :bro_hub_crumb_actions do %>
|
|
117
|
-
<%= bro_hub_crumb_link "← All sessions", sessions_path %> <%# right side of the bar %>
|
|
118
|
-
<% end %>
|
|
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.
|
|
119
229
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
lead: "jane was on a production console for 1m.",
|
|
123
|
-
stats: [ [ 4, "unlocks", :amber ], [ 6, "flagged commands", :red ] ] %>
|
|
230
|
+
```ruby
|
|
231
|
+
config.apm.can_view = ->(user) { user.admin? }
|
|
124
232
|
```
|
|
125
233
|
|
|
126
|
-
|
|
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`.
|
|
235
|
+
|
|
236
|
+
### Audit log
|
|
237
|
+
|
|
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.
|
|
127
239
|
|
|
128
|
-
##
|
|
240
|
+
## Uninstall
|
|
129
241
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
242
|
+
```sh
|
|
243
|
+
bin/rails g bro_hub:uninstall [--force]
|
|
244
|
+
bin/rails db:migrate
|
|
245
|
+
```
|
|
246
|
+
|
|
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`.
|
|
133
248
|
|
|
134
249
|
## Development
|
|
135
250
|
|
|
136
251
|
```sh
|
|
137
|
-
bin/rails test
|
|
138
|
-
|
|
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
|
|
139
255
|
bin/rubocop
|
|
140
|
-
cd test/dummy && bin/rails server # try it: /hub (Alpha, Beta), /solo (Gamma)
|
|
141
256
|
```
|
|
142
257
|
|
|
143
|
-
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.
|
|
144
|
-
|
|
145
258
|
## License
|
|
146
259
|
|
|
147
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,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,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
|
|
@@ -2,10 +2,26 @@ module BroHub
|
|
|
2
2
|
class ApplicationController < BroHub.config.parent_controller.constantize
|
|
3
3
|
include BroHub::ControllerBase
|
|
4
4
|
|
|
5
|
+
# First among BroHub's own callbacks, so BroHub's and the features' authorization never query a table that
|
|
6
|
+
# doesn't exist yet. Callbacks on the host's parent_controller (say authenticate_user!) run earlier and are
|
|
7
|
+
# out of our control.
|
|
8
|
+
before_action :bro_hub_require_schema
|
|
5
9
|
before_action :bro_hub_require_ssl
|
|
6
10
|
before_action :bro_hub_no_store
|
|
7
11
|
|
|
12
|
+
rescue_from BroHub::Forbidden do
|
|
13
|
+
render "bro_hub/shared/forbidden", status: :forbidden
|
|
14
|
+
end
|
|
15
|
+
|
|
8
16
|
private
|
|
17
|
+
def bro_hub_require_schema
|
|
18
|
+
return if BroHub::Schema.ready?
|
|
19
|
+
|
|
20
|
+
bro_hub_no_store
|
|
21
|
+
@missing = BroHub::Schema.missing
|
|
22
|
+
render "bro_hub/shared/schema_missing", layout: false, status: :service_unavailable
|
|
23
|
+
end
|
|
24
|
+
|
|
9
25
|
def bro_hub_require_ssl
|
|
10
26
|
head :forbidden if BroHub.config.require_ssl && !request.ssl?
|
|
11
27
|
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module BroHub
|
|
2
|
+
# The audit trail of every Bro gem in one place. Each person sees the rows of the gems they may audit.
|
|
3
|
+
class AuditEventsController < ApplicationController
|
|
4
|
+
PER_PAGE = 50
|
|
5
|
+
|
|
6
|
+
before_action :require_auditor
|
|
7
|
+
helper_method :filter_params, :sections
|
|
8
|
+
|
|
9
|
+
def index
|
|
10
|
+
@filter = filter_params
|
|
11
|
+
@events = filtered.recent.limit(PER_PAGE).offset(page * PER_PAGE)
|
|
12
|
+
@total = filtered.count
|
|
13
|
+
@page = page
|
|
14
|
+
@counts = visible.group(:source).count
|
|
15
|
+
@event_names = visible.distinct.order(:event).pluck(:event)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def show
|
|
19
|
+
@event = visible.find(params[:id])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
def require_auditor
|
|
24
|
+
render "bro_hub/shared/forbidden", status: :forbidden if sections.empty?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def sections
|
|
28
|
+
@sections ||= BroHub.registry.audited_by(bro_hub_user)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Only the rows of enabled features this person may audit (sections are registered per enabled feature).
|
|
32
|
+
def visible
|
|
33
|
+
sections.map { |section| AuditEvent.for_feature(section.key) }.reduce(AuditEvent.none, :or)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def filtered
|
|
37
|
+
scope = visible
|
|
38
|
+
scope = scope.where(source: filter_params[:source]) if filter_params[:source].present?
|
|
39
|
+
scope = scope.where(event: filter_params[:event]) if filter_params[:event].present?
|
|
40
|
+
scope = scope.where(user_label: filter_params[:user]) if filter_params[:user].present?
|
|
41
|
+
if filter_params[:q].present?
|
|
42
|
+
like = "%#{AuditEvent.sanitize_sql_like(filter_params[:q])}%"
|
|
43
|
+
scope = scope.where("target LIKE :like OR reason LIKE :like", like: like)
|
|
44
|
+
end
|
|
45
|
+
scope
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def filter_params
|
|
49
|
+
@filter_params ||= params.permit(:source, :event, :user, :q).to_h.symbolize_keys.compact_blank
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def page
|
|
53
|
+
[ params[:page].to_i, 0 ].max
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|