railwatch-sidecar 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3caab6dc710516c0b62a3bdbbf8fc9858961b927d1e9c2451c68ae8d3ae73a3
4
- data.tar.gz: c838bbd7ccbabdfe3090bea5fc6672a338b0131bfa35446f248e8648d86a070f
3
+ metadata.gz: 4266c894e8050af2ee1ceeac3e58a3713e5a351806d01753cbabbcdfabb87c24
4
+ data.tar.gz: e6f4a7ccf7a62f8a387f21c72086c499c310c92c8391f87ae85c706ebbbbc886
5
5
  SHA512:
6
- metadata.gz: 45504740307567be4f73cf1eafa8f9487d906e01298825d074d0a6e70ff3515f8b33e17575c33e9d9631b20460543851ae6f7351c9f9b975e63e9fdaab50a6d2
7
- data.tar.gz: 7e1260e0dc8e6b6b96d338a5250ba267b8bbc90c0d7c1399686f91416c784496c3b63c31aa577effb22870478807d0eed15f1ced2491c17d01d0248a2fe345cf
6
+ metadata.gz: 10c059c6485aabee137f32e9280819de6e738868ddd290d4ebdbfaaa6deb3de761410a90aed991d90ea1999e87e401bdeba3b4b00812d8ac89b461bef4a47745
7
+ data.tar.gz: b44fe3de638dab9787ae34846a9a39c101760761d4347c667c72badc8eec98fe7ab217092fb754ab47812923c2d73aa6cb13184b557d2f6ad545d23e9c065640
data/README.md CHANGED
@@ -6,6 +6,25 @@ and MCP included), behind your app's own login, with no server to install.
6
6
  The server runs as **its own process** next to the app, started by Puma's
7
7
  master. It never runs inside a Puma worker.
8
8
 
9
+ ## Upgrading to 0.2.2: security changes
10
+
11
+ 0.2.2 bundles railwatch-rs v0.3.5, the GA security and tenancy release. Its
12
+ first start runs three small control-database migrations in place; see that
13
+ release's CHANGELOG. Through the sidecar, a user now stays in the account the
14
+ sidecar serves, at most at the role it signs: no switching into other
15
+ accounts, and tokens made there keep that role.
16
+
17
+ - **A `config.user` that leaves out `role` makes a member, not an admin.**
18
+ 0.2.1 made every visitor an admin when the lambda returned only
19
+ `{ email:, name: }`. Return `role: "admin"` for the users who should
20
+ manage tokens, members and integrations.
21
+ - **`RAILWATCH_DASHBOARD_DEFAULT_ROLE` works.** The `railwatch` gem's
22
+ `c.dashboard_default_role` (`member` by default; `admin` is the only other
23
+ value) is now the role of every visitor whose role the app did not name:
24
+ the HTTP Basic user, the single operator, and a `config.user` without
25
+ `role`. 0.2.1 never read it. With a `railwatch` gem older than 1.6.1 the
26
+ environment variable is read directly.
27
+
9
28
  ## Upgrading to 0.2.1: security changes
10
29
 
11
30
  - **A dashboard without a gate is no longer served outside development.**
@@ -184,7 +203,9 @@ end
184
203
  ```
185
204
 
186
205
  Without it, the HTTP Basic user name (or "Operator") is a member; name
187
- admins with `config.user`. Users are
206
+ admins with `config.user`. A user `config.user` returns without a `role`
207
+ is a member too. `RAILWATCH_DASHBOARD_DEFAULT_ROLE=admin` (the `railwatch`
208
+ gem's `c.dashboard_default_role`) makes both admins instead. Users are
188
209
  created in the server on first sight. Nobody signs in to the server itself.
189
210
 
190
211
  ## AI agents
@@ -198,18 +198,22 @@ module Railwatch
198
198
  end
199
199
 
200
200
  # Who the server should see: Railwatch::Sidecar.config.user when the app
201
- # names its user, else the HTTP Basic user, else one operator (both
202
- # members).
201
+ # names its user, else the HTTP Basic user, else one operator. A role
202
+ # the app did not name is Railwatch::Sidecar.default_role (member):
203
+ # whoever passes a shared password, or a config.user that leaves the
204
+ # role out, is not known to be an admin.
203
205
  def visitor
204
206
  given = Railwatch::Sidecar.config.user&.call(self)
205
- return given.to_h.transform_keys(&:to_sym).reverse_merge(role: "admin") if given
207
+ if given
208
+ given = given.to_h.transform_keys(&:to_sym)
209
+ given = given.merge(role: Railwatch::Sidecar.default_role) if given[:role].blank?
210
+ return given
211
+ end
206
212
 
207
213
  basic_user = ActionController::HttpAuthentication::Basic.user_name_and_password(request).first if request.authorization.to_s.start_with?("Basic ")
208
214
  # Decoded base64 comes back binary; parameterize needs a real encoding.
209
215
  name = basic_user.to_s.dup.force_encoding(Encoding::UTF_8).scrub.presence || "Operator"
210
- # A member: whoever passes a shared password is not known to be an
211
- # admin. config.user names admins.
212
- { email: "#{name.parameterize.presence || 'operator'}@railwatch.invalid", name: name, role: "member" }
216
+ { email: "#{name.parameterize.presence || 'operator'}@railwatch.invalid", name: name, role: Railwatch::Sidecar.default_role }
213
217
  end
214
218
 
215
219
  def signed_header(secret)
@@ -47,7 +47,8 @@ module Railwatch
47
47
  # KILLed and the app boots without the server; the next start retries.
48
48
  @setup_timeout = Float(setting("RAILWATCH_SIDECAR_SETUP_TIMEOUT", "30"))
49
49
  # Who the dashboard's visitor is, as the server should see them:
50
- # ->(controller) { { email:, name:, role: "admin" | "member" } }.
50
+ # ->(controller) { { email:, name:, role: "admin" | "member" } }. A
51
+ # role left out is Railwatch::Sidecar.default_role (member).
51
52
  @user = nil
52
53
  # Whether <mount>/mcp and <mount>/api/ (what an AI agent calls) are
53
54
  # signed for the visitor like the dashboard, so the agent needs no
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Railwatch
4
4
  module Sidecar
5
- VERSION = "0.2.1"
5
+ VERSION = "0.2.2"
6
6
  # The published railwatch-rs commit the bundled binaries are built from
7
7
  # (README, "The server side"); its source.
8
- RAILWATCH_RS = "5b93417c3ea500a3f4f95a6f3416d9b916664ea9"
8
+ RAILWATCH_RS = "b2c5542eea4655a24e225abbc54ce4c7a0285151"
9
9
  end
10
10
  end
@@ -62,6 +62,18 @@ module Railwatch
62
62
  gem.http_basic_auth_enabled || gem.base_controller_class.to_s.delete_prefix("::") != default
63
63
  end
64
64
 
65
+ # The role of a visitor whose role the app did not name: the HTTP
66
+ # Basic user or the single operator (no config.user), and a user
67
+ # config.user returns without one. The railwatch gem's
68
+ # dashboard_default_role (RAILWATCH_DASHBOARD_DEFAULT_ROLE), "member"
69
+ # unless it says "admin"; a gem older than that setting has the same
70
+ # environment variable read here.
71
+ def default_role
72
+ gem = Railwatch.config
73
+ role = gem.respond_to?(:dashboard_default_role) ? gem.dashboard_default_role : ENV["RAILWATCH_DASHBOARD_DEFAULT_ROLE"]
74
+ role.to_s.strip.downcase == "admin" ? "admin" : "member"
75
+ end
76
+
65
77
  def ungated_message
66
78
  "The Railwatch dashboard at #{config.normalized_mount_path} has no gate, so it is not served in #{config.environment}: " \
67
79
  "HTTP Basic is off (RAILWATCH_HTTP_BASIC_AUTH_ENABLED=false) and Railwatch.config.base_controller_class is " \
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railwatch-sidecar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rebulk