railwatch-sidecar 0.2.0-aarch64-linux → 0.2.1-aarch64-linux
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/README.md +40 -6
- data/app/controllers/railwatch/sidecar/proxy_controller.rb +67 -11
- data/exe/aarch64-linux/railwatch +0 -0
- data/lib/railwatch/sidecar/data_dir.rb +22 -1
- data/lib/railwatch/sidecar/engine.rb +11 -0
- data/lib/railwatch/sidecar/process.rb +25 -0
- data/lib/railwatch/sidecar/version.rb +2 -2
- data/lib/railwatch/sidecar.rb +20 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d7736c21691d70cf35b1d523bad5b2a8e1a3f55e7cd2e5fffbf0daa0850dab29
|
|
4
|
+
data.tar.gz: b71d19b8681fc0186c1b3a1f0ef256dd68833c406d4ee539405b163c6e8fcfb5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b27b866ab01d15cee48c1926129a57719fa1ecf00ddaaf1f4e2020970bf2d65c1293ecad90922bb912547c90d3cc790ed21da7ba97d1f4f2d44aab8063609aab
|
|
7
|
+
data.tar.gz: 87baacc2cda40474f302f26319330410947526c684e758ffcbdcc2a3467c887ec9ecb087bd86ec5cfbaec3818c4069f56f6ab6bf50fb057a40ca1610fd849ecc
|
data/README.md
CHANGED
|
@@ -6,6 +6,27 @@ 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.1: security changes
|
|
10
|
+
|
|
11
|
+
- **A dashboard without a gate is no longer served outside development.**
|
|
12
|
+
With HTTP Basic off (`RAILWATCH_HTTP_BASIC_AUTH_ENABLED=false`) and
|
|
13
|
+
`Railwatch.config.base_controller_class` left at `ActionController::Base`,
|
|
14
|
+
every visitor got in as a Railwatch user, MCP included. Now `/railwatch`
|
|
15
|
+
answers 503 with a message saying so, and boot logs the same as an error.
|
|
16
|
+
Give it a gate: turn HTTP Basic back on (`http_basic_auth_user` and
|
|
17
|
+
`http_basic_auth_password`), or set `base_controller_class` to a
|
|
18
|
+
controller of your app that signs people in. Development is unchanged.
|
|
19
|
+
- **Without `Railwatch::Sidecar.config.user`, visitors are members, not
|
|
20
|
+
admins.** Name your admins with `config.user` (below) to keep admin
|
|
21
|
+
rights (settings, members, integrations) in the dashboard.
|
|
22
|
+
- A forwarded header or cookie with a line break or NUL byte is refused with
|
|
23
|
+
400 instead of being sent to the server.
|
|
24
|
+
- Only the server's own cookies (`_railwatch_session`, `XSRF-TOKEN`) are
|
|
25
|
+
forwarded; an app cookie named `session_token` or `account_id` stays in
|
|
26
|
+
the app.
|
|
27
|
+
- The data dir is set to 0700 and `server.log` to 0600 on every start, also
|
|
28
|
+
when they already existed.
|
|
29
|
+
|
|
9
30
|
## Coming from railwatch-server
|
|
10
31
|
|
|
11
32
|
This gem was called `railwatch-server` until 0.2.0. Replace the gem in your
|
|
@@ -150,7 +171,10 @@ serves only the dashboard.
|
|
|
150
171
|
**Who the server sees.** The dashboard's gate is the `railwatch` gem's:
|
|
151
172
|
HTTP Basic, on and closed by default; or, with Basic off,
|
|
152
173
|
`base_controller_class` (the proxy controller inherits from it, so your
|
|
153
|
-
`before_action :require_admin` runs first).
|
|
174
|
+
`before_action :require_admin` runs first). Outside development there must
|
|
175
|
+
be one of the two: with Basic off and `base_controller_class` left at
|
|
176
|
+
`ActionController::Base` the dashboard answers 503 and boot logs an error.
|
|
177
|
+
Past the gate, the visitor is
|
|
154
178
|
named to the server by `Railwatch::Sidecar.config.user`:
|
|
155
179
|
|
|
156
180
|
```ruby
|
|
@@ -159,7 +183,8 @@ Railwatch::Sidecar.configure do |c|
|
|
|
159
183
|
end
|
|
160
184
|
```
|
|
161
185
|
|
|
162
|
-
Without it, the HTTP Basic user name (or "Operator") is
|
|
186
|
+
Without it, the HTTP Basic user name (or "Operator") is a member; name
|
|
187
|
+
admins with `config.user`. Users are
|
|
163
188
|
created in the server on first sight. Nobody signs in to the server itself.
|
|
164
189
|
|
|
165
190
|
## AI agents
|
|
@@ -235,8 +260,11 @@ Puma workers, jobs ── railwatch agent ── /ingest ───────
|
|
|
235
260
|
and KILL past the deadline. `server.pid` records "server parent"; a
|
|
236
261
|
server orphaned by a SIGKILLed Puma is stopped by the next start.
|
|
237
262
|
- **Proxy.** `/railwatch/*` is a prepended route to
|
|
238
|
-
`Railwatch::Sidecar::ProxyController`. It forwards the server's
|
|
239
|
-
and Inertia headers,
|
|
263
|
+
`Railwatch::Sidecar::ProxyController`. It forwards the server's own
|
|
264
|
+
cookies (`_railwatch_session`, `XSRF-TOKEN`) and Inertia headers,
|
|
265
|
+
refusing with 400 any header or cookie with a line break or NUL byte
|
|
266
|
+
(Rack percent-decodes cookies, so one planted on your domain could
|
|
267
|
+
otherwise end the request and start a second, signed one), sets `Host`/`X-Forwarded-Proto`, sets
|
|
240
268
|
`X-Forwarded-For` to the visitor's `request.remote_ip` (replacing any the
|
|
241
269
|
browser sent; the server runs with `RAILWATCH_TRUST_PROXY`, so its per-IP
|
|
242
270
|
sign-in and MCP limits count visitors, not the app), adds the signed
|
|
@@ -284,7 +312,13 @@ Puma workers, jobs ── railwatch agent ── /ingest ───────
|
|
|
284
312
|
`email, name, role, exp`; the server refuses a bad signature, an expired
|
|
285
313
|
one, one valid for more than 5 minutes, and any role but admin/member
|
|
286
314
|
(401, logged). It never falls back to "signed out". The server binds
|
|
287
|
-
loopback only, so nothing outside the host can reach it unproxied.
|
|
315
|
+
loopback only, so nothing outside the host can reach it unproxied. The
|
|
316
|
+
data dir is 0700 and `server.log` (proxied users' emails) 0600, enforced
|
|
317
|
+
on every start. Another process on the same host can reach the loopback
|
|
318
|
+
port and, because the server trusts `X-Forwarded-For` from it, choose
|
|
319
|
+
the address its per-IP limits count; it can't choose who it is (that
|
|
320
|
+
takes the HMAC key in the data dir, a session or a token). railwatch-rs
|
|
321
|
+
binds TCP only, so a Unix socket in the data dir is not an option yet.
|
|
288
322
|
|
|
289
323
|
## The server side (Rebulk/railwatch-rs)
|
|
290
324
|
|
|
@@ -329,7 +363,7 @@ for Linux, and that image's MacOSX 11.3 SDK for both darwin targets. All
|
|
|
329
363
|
four built here (2-3 min each, 4 jobs).
|
|
330
364
|
|
|
331
365
|
**macOS: built natively, signed ad hoc, run in CI.** `.github/workflows/macos.yml`
|
|
332
|
-
builds the frontend once on Linux, then on `macos-
|
|
366
|
+
builds the frontend once on Linux, then on `macos-15` (arm64) and
|
|
333
367
|
`macos-15-intel` (x86_64; GitHub retired the macos-13 runners) builds the
|
|
334
368
|
server from the pinned railwatch-rs commit (`MACOSX_DEPLOYMENT_TARGET=11.0`, checked
|
|
335
369
|
with `vtool`: minos 11.0), signs it `codesign -s -`, verifies the
|
|
@@ -95,7 +95,10 @@ module Railwatch
|
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
# The server's cookies only; the app's own (its session) stay here.
|
|
98
|
-
|
|
98
|
+
# Not the server's generic session_token and account_id: an app may
|
|
99
|
+
# have cookies of those names, and a proxied visitor needs neither
|
|
100
|
+
# (the signed header names them, in the server's first account).
|
|
101
|
+
FORWARDED_COOKIES = %w[_railwatch_session XSRF-TOKEN].freeze
|
|
99
102
|
FORWARDED_HEADERS = %w[
|
|
100
103
|
Accept Accept-Encoding Accept-Language Content-Type Origin Referer User-Agent
|
|
101
104
|
X-Inertia X-Inertia-Version X-Inertia-Partial-Component X-Inertia-Partial-Data X-Inertia-Partial-Except
|
|
@@ -106,7 +109,24 @@ module Railwatch
|
|
|
106
109
|
# Host names that only reach this machine (agent_access?).
|
|
107
110
|
LOCAL_HOSTS = %w[localhost 127.0.0.1 ::1 [::1]].freeze
|
|
108
111
|
|
|
112
|
+
# A forwarded header name or value with one of these would end the
|
|
113
|
+
# header, or the request, on the server's socket (a cookie is
|
|
114
|
+
# percent-decoded, so %0D%0A in one planted on the app's domain is a
|
|
115
|
+
# real line break): a second request, signed for the visitor.
|
|
116
|
+
UNSAFE_HEADER_BYTES = /[\r\n\0]/
|
|
117
|
+
# A forwarded cookie's value is percent-decoded too: one with a pair
|
|
118
|
+
# delimiter in it ("x; session_token=chosen") would add cookies the
|
|
119
|
+
# proxy never forwards. The server's own values (a signed session, a
|
|
120
|
+
# CSRF token) never contain these, so such a cookie is dropped.
|
|
121
|
+
# Line breaks and NUL are not dropped here: UNSAFE_HEADER_BYTES refuses
|
|
122
|
+
# the whole request (400), which is the louder answer to a smuggling
|
|
123
|
+
# attempt.
|
|
124
|
+
COOKIE_VALUE_DELIMITERS = /[;, \t]/
|
|
125
|
+
|
|
126
|
+
class UnsafeHeader < StandardError; end
|
|
127
|
+
|
|
109
128
|
skip_forgery_protection if respond_to?(:skip_forgery_protection)
|
|
129
|
+
before_action :refuse_ungated
|
|
110
130
|
before_action :authenticate_by_http_basic
|
|
111
131
|
|
|
112
132
|
# An app on inertia_rails has its controller module in every
|
|
@@ -145,10 +165,24 @@ module Railwatch
|
|
|
145
165
|
else
|
|
146
166
|
stream(secret)
|
|
147
167
|
end
|
|
168
|
+
rescue UnsafeHeader => e
|
|
169
|
+
logger&.warn("[railwatch-sidecar] refused a dashboard request: its #{e.message} header has a line break or NUL byte")
|
|
170
|
+
render plain: "Bad request: a header or cookie for the dashboard contains a line break or NUL byte.", status: :bad_request
|
|
148
171
|
end
|
|
149
172
|
|
|
150
173
|
private
|
|
151
174
|
|
|
175
|
+
# Outside development the dashboard needs a gate: HTTP Basic, or the
|
|
176
|
+
# app's own controller (Railwatch::Sidecar.dashboard_gated?). Without
|
|
177
|
+
# one every visitor would be let through, MCP included.
|
|
178
|
+
def refuse_ungated
|
|
179
|
+
return if Railwatch::Sidecar.config.environment == "development" || Railwatch::Sidecar.dashboard_gated?
|
|
180
|
+
|
|
181
|
+
message = Railwatch::Sidecar.ungated_message
|
|
182
|
+
logger&.error("[railwatch-sidecar] #{message}")
|
|
183
|
+
render plain: message, status: :service_unavailable
|
|
184
|
+
end
|
|
185
|
+
|
|
152
186
|
# An agent's Bearer token takes the one Authorization header Basic would
|
|
153
187
|
# need, so a request to MCP or the API with one is left to the server,
|
|
154
188
|
# which checks the token (401 without a valid one) as a standalone
|
|
@@ -164,7 +198,8 @@ module Railwatch
|
|
|
164
198
|
end
|
|
165
199
|
|
|
166
200
|
# Who the server should see: Railwatch::Sidecar.config.user when the app
|
|
167
|
-
# names its user, else the HTTP Basic user, else one operator
|
|
201
|
+
# names its user, else the HTTP Basic user, else one operator (both
|
|
202
|
+
# members).
|
|
168
203
|
def visitor
|
|
169
204
|
given = Railwatch::Sidecar.config.user&.call(self)
|
|
170
205
|
return given.to_h.transform_keys(&:to_sym).reverse_merge(role: "admin") if given
|
|
@@ -172,7 +207,9 @@ module Railwatch
|
|
|
172
207
|
basic_user = ActionController::HttpAuthentication::Basic.user_name_and_password(request).first if request.authorization.to_s.start_with?("Basic ")
|
|
173
208
|
# Decoded base64 comes back binary; parameterize needs a real encoding.
|
|
174
209
|
name = basic_user.to_s.dup.force_encoding(Encoding::UTF_8).scrub.presence || "Operator"
|
|
175
|
-
|
|
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" }
|
|
176
213
|
end
|
|
177
214
|
|
|
178
215
|
def signed_header(secret)
|
|
@@ -206,12 +243,30 @@ module Railwatch
|
|
|
206
243
|
value if agent_request? && value.start_with?("Bearer ")
|
|
207
244
|
end
|
|
208
245
|
|
|
246
|
+
# Every header that goes to the server, on every path: refused whole
|
|
247
|
+
# (UnsafeHeader, a 400) rather than cleaned, before a byte is written.
|
|
248
|
+
def checked(headers)
|
|
249
|
+
headers.each do |name, value|
|
|
250
|
+
raise UnsafeHeader, name.to_s.gsub(UNSAFE_HEADER_BYTES, "?") if name.to_s.match?(UNSAFE_HEADER_BYTES) || value.to_s.match?(UNSAFE_HEADER_BYTES)
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
# The request line and headers as the server reads them (the hijacked
|
|
255
|
+
# request and the live channel's handshake).
|
|
256
|
+
def http_head(request_line, headers)
|
|
257
|
+
"#{request_line}\r\n#{checked(headers).map { |k, v| "#{k}: #{v}\r\n" }.join}\r\n"
|
|
258
|
+
end
|
|
259
|
+
|
|
209
260
|
def upstream_headers(secret)
|
|
210
261
|
headers = FORWARDED_HEADERS.each_with_object({}) do |name, h|
|
|
211
262
|
value = request.headers[name]
|
|
212
263
|
h[name] = value if value
|
|
213
264
|
end
|
|
214
|
-
|
|
265
|
+
# A line break or NUL keeps the cookie, so `checked` refuses the
|
|
266
|
+
# whole request; any other pair delimiter just drops it.
|
|
267
|
+
cookies = request.cookies.slice(*FORWARDED_COOKIES).reject do |_, v|
|
|
268
|
+
v.to_s.match?(COOKIE_VALUE_DELIMITERS) && !v.to_s.match?(UNSAFE_HEADER_BYTES)
|
|
269
|
+
end
|
|
215
270
|
headers["Cookie"] = cookies.map { |k, v| "#{k}=#{v}" }.join("; ") if cookies.any?
|
|
216
271
|
# The server compares Origin with Host, and builds absolute URLs (an
|
|
217
272
|
# Inertia version-mismatch reload) from Host and X-Forwarded-Proto.
|
|
@@ -254,12 +309,13 @@ module Railwatch
|
|
|
254
309
|
status: :service_unavailable)
|
|
255
310
|
end
|
|
256
311
|
|
|
257
|
-
upstream = connect
|
|
258
312
|
request_head, body = upstream_request(secret)
|
|
313
|
+
upstream = connect
|
|
259
314
|
request.env[ProxyHandoff::ENV_KEY] = ProxyHandoff::Handoff.new(upstream, request_head, body)
|
|
260
315
|
head :ok
|
|
261
316
|
rescue SystemCallError, IOError => e
|
|
262
317
|
upstream&.close rescue nil
|
|
318
|
+
body&.close rescue nil
|
|
263
319
|
unavailable("#{e.class}: #{e.message}")
|
|
264
320
|
end
|
|
265
321
|
|
|
@@ -278,7 +334,6 @@ module Railwatch
|
|
|
278
334
|
input = request.body
|
|
279
335
|
input.rewind if input.respond_to?(:rewind)
|
|
280
336
|
length = request.content_length.to_i
|
|
281
|
-
body = input.is_a?(::File) ? input.dup : nil
|
|
282
337
|
# The browser's HTTP version: an HTTP/1.0 client (nginx's default
|
|
283
338
|
# upstream protocol) can't read a chunked response, and the server
|
|
284
339
|
# doesn't send one to an HTTP/1.0 request.
|
|
@@ -287,8 +342,8 @@ module Railwatch
|
|
|
287
342
|
headers["Accept-Encoding"] = request.headers["Accept-Encoding"].presence || "identity"
|
|
288
343
|
headers["Content-Length"] = length.to_s if length.positive? || request.content_length
|
|
289
344
|
headers["Connection"] = "close"
|
|
290
|
-
head = "#{request.request_method} #{request.fullpath} #{version}
|
|
291
|
-
|
|
345
|
+
head = http_head("#{request.request_method} #{request.fullpath} #{version}", headers).b
|
|
346
|
+
body = input.is_a?(::File) ? input.dup : nil
|
|
292
347
|
head << input.read.to_s.b if body.nil? && length.positive?
|
|
293
348
|
[ head, body ]
|
|
294
349
|
end
|
|
@@ -298,7 +353,7 @@ module Railwatch
|
|
|
298
353
|
# server writes it (Upstream#each), so a large export never sits whole
|
|
299
354
|
# in this process. The request body is streamed too, from rack.input.
|
|
300
355
|
def stream(secret)
|
|
301
|
-
upstream = Upstream.new(request, upstream_headers(secret), port: Railwatch::Sidecar.config.port)
|
|
356
|
+
upstream = Upstream.new(request, checked(upstream_headers(secret)), port: Railwatch::Sidecar.config.port)
|
|
302
357
|
response = upstream.start
|
|
303
358
|
response.each_header do |name, _|
|
|
304
359
|
next if HOP_BY_HOP.include?(name) || Relay::APP_OWNED.include?(name)
|
|
@@ -332,7 +387,6 @@ module Railwatch
|
|
|
332
387
|
Rails.logger.warn("[railwatch-sidecar] #{relay.max(:live)} live-channel connections open (max_live_connections); refusing another")
|
|
333
388
|
return head(:service_unavailable)
|
|
334
389
|
end
|
|
335
|
-
upstream = connect
|
|
336
390
|
handshake = upstream_headers(secret).merge(
|
|
337
391
|
"Connection" => "Upgrade", "Upgrade" => "websocket",
|
|
338
392
|
"Sec-WebSocket-Key" => request.headers["Sec-WebSocket-Key"],
|
|
@@ -340,7 +394,9 @@ module Railwatch
|
|
|
340
394
|
"Sec-WebSocket-Protocol" => request.headers["Sec-WebSocket-Protocol"],
|
|
341
395
|
"Sec-WebSocket-Extensions" => request.headers["Sec-WebSocket-Extensions"]
|
|
342
396
|
).compact
|
|
343
|
-
|
|
397
|
+
head = http_head("GET #{request.fullpath} HTTP/1.1", handshake)
|
|
398
|
+
upstream = connect
|
|
399
|
+
upstream.write(head)
|
|
344
400
|
client = hijack.call
|
|
345
401
|
unless relay.add(client, upstream)
|
|
346
402
|
[ client, upstream ].each { |io| io.close rescue nil }
|
data/exe/aarch64-linux/railwatch
CHANGED
|
Binary file
|
|
@@ -68,7 +68,7 @@ module Railwatch
|
|
|
68
68
|
# provision (a bare `puma` in cluster mode) are not held up one after
|
|
69
69
|
# another. Returns what it did, for the log.
|
|
70
70
|
def provision!(binary:, env:, app_name:, env_name:, timeout:)
|
|
71
|
-
|
|
71
|
+
try_make_private
|
|
72
72
|
deadline = monotonic + timeout
|
|
73
73
|
done = []
|
|
74
74
|
File.open(path.join(SETUP_LOCK), File::RDWR | File::CREAT, 0o600) do |lock|
|
|
@@ -92,6 +92,27 @@ module Railwatch
|
|
|
92
92
|
done
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
+
# 0700 on the directory and 0600 on server.log, also when they already
|
|
96
|
+
# exist (made by hand, an older gem or a loose umask): the dir holds the
|
|
97
|
+
# proxy's HMAC key and the databases, the log the proxied users' emails.
|
|
98
|
+
#
|
|
99
|
+
# A volume another user owns refuses the chmod (EPERM). That is not
|
|
100
|
+
# fatal here: provisioning still works in a dir this user may write,
|
|
101
|
+
# and the server's start (Process#make_data_dir_private) logs that the
|
|
102
|
+
# dir could not be made private. Raised only for the server to log.
|
|
103
|
+
def make_private!
|
|
104
|
+
FileUtils.mkdir_p(path, mode: 0o700)
|
|
105
|
+
File.chmod(0o700, path)
|
|
106
|
+
File.open(log_file, File::WRONLY | File::APPEND | File::CREAT, 0o600) { _1.chmod(0o600) }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def try_make_private
|
|
110
|
+
make_private!
|
|
111
|
+
true
|
|
112
|
+
rescue Errno::EPERM
|
|
113
|
+
false
|
|
114
|
+
end
|
|
115
|
+
|
|
95
116
|
private
|
|
96
117
|
|
|
97
118
|
def write_secret(file, value)
|
|
@@ -17,6 +17,17 @@ module Railwatch
|
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
# Loud at boot, not only on the first visit: outside development a
|
|
21
|
+
# dashboard without a gate is refused (ProxyController#refuse_ungated).
|
|
22
|
+
# After the app's initializers, which set the gate.
|
|
23
|
+
initializer "railwatch_sidecar.gate", after: :load_config_initializers do
|
|
24
|
+
next unless Railwatch::Sidecar.enabled?
|
|
25
|
+
next if Railwatch::Sidecar.config.environment == "development" || Railwatch::Sidecar.dashboard_gated?
|
|
26
|
+
|
|
27
|
+
Rails.logger.error("[railwatch-sidecar] #{Railwatch::Sidecar.ungated_message}")
|
|
28
|
+
warn("[railwatch-sidecar] #{Railwatch::Sidecar.ungated_message}")
|
|
29
|
+
end
|
|
30
|
+
|
|
20
31
|
# Outside every other middleware (the railwatch agent's included), so
|
|
21
32
|
# the app's session and cookies are written before the browser's socket
|
|
22
33
|
# is handed to the relay (ProxyHandoff).
|
|
@@ -59,6 +59,21 @@ module Railwatch
|
|
|
59
59
|
# (and never passes the browser's on), so the server's per-IP
|
|
60
60
|
# limits (sign-in, MCP) see visitors, not the app. The agents post
|
|
61
61
|
# /ingest on loopback without one and are keyed on 127.0.0.1.
|
|
62
|
+
#
|
|
63
|
+
# Any other process on this host can reach 127.0.0.1 too and send
|
|
64
|
+
# its own X-Forwarded-For (a Unix socket in the 0700 data dir would
|
|
65
|
+
# shut it out, but railwatch-rs v0.2.17 binds TCP only: RAILWATCH_BIND
|
|
66
|
+
# takes no unix: path and LISTEN_FDS only TCP listeners). What that
|
|
67
|
+
# buys it: the address the per-IP limits count and the session row
|
|
68
|
+
# records, and X-Forwarded-Proto on its own responses' links. Never
|
|
69
|
+
# who it is: identity is the HMAC-signed header, whose key is in
|
|
70
|
+
# the 0700 data dir, or a session or API token. So it can dodge a
|
|
71
|
+
# per-IP limit (the per-email sign-in limit and the per-token API
|
|
72
|
+
# limit still hold, and the only password user has a random one
|
|
73
|
+
# nobody knows), or fill one visitor's bucket for a few minutes.
|
|
74
|
+
# Without trust_proxy every visitor and agent would share one
|
|
75
|
+
# bucket and one 256-connection cap (127.0.0.1), and MCP links
|
|
76
|
+
# behind TLS would say http.
|
|
62
77
|
"RAILWATCH_TRUST_PROXY" => "true",
|
|
63
78
|
# A second server on this data dir (the new container of a deploy,
|
|
64
79
|
# which has its own loopback) answers on its own port at once and
|
|
@@ -115,6 +130,7 @@ module Railwatch
|
|
|
115
130
|
# data dir. Ours waits on serve.lock and takes over when that one
|
|
116
131
|
# exits; meanwhile every agent here reports to it.
|
|
117
132
|
@standby = up?
|
|
133
|
+
make_data_dir_private
|
|
118
134
|
log = File.open(@data_dir.log_file, "a")
|
|
119
135
|
@log_offset_at_spawn = log.size
|
|
120
136
|
@relay_log_offset = nil
|
|
@@ -268,6 +284,15 @@ module Railwatch
|
|
|
268
284
|
Settings.new(Configuration.new, rails: nil).write!(@data_dir.settings_file.to_s)
|
|
269
285
|
end
|
|
270
286
|
|
|
287
|
+
# Loud, not fatal: a data dir owned by another user (a volume) can't be
|
|
288
|
+
# chmodded by this one, and the server still has to run.
|
|
289
|
+
def make_data_dir_private
|
|
290
|
+
@data_dir.make_private!
|
|
291
|
+
rescue Errno::EPERM => e
|
|
292
|
+
@log.call("#{@data_dir.path} could NOT be made private (0700, server.log 0600): #{e.message}. It holds the dashboard's " \
|
|
293
|
+
"HMAC key and the telemetry; chown it to this user or tighten it by hand")
|
|
294
|
+
end
|
|
295
|
+
|
|
271
296
|
def write_pid_file
|
|
272
297
|
File.write(@data_dir.path.join("server.pid"), "#{@pid} #{::Process.pid} #{Socket.gethostname}\n")
|
|
273
298
|
end
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module Railwatch
|
|
4
4
|
module Sidecar
|
|
5
|
-
VERSION = "0.2.
|
|
5
|
+
VERSION = "0.2.1"
|
|
6
6
|
# The published railwatch-rs commit the bundled binaries are built from
|
|
7
7
|
# (README, "The server side"); its source.
|
|
8
|
-
RAILWATCH_RS = "
|
|
8
|
+
RAILWATCH_RS = "5b93417c3ea500a3f4f95a6f3416d9b916664ea9"
|
|
9
9
|
end
|
|
10
10
|
end
|
data/lib/railwatch/sidecar.rb
CHANGED
|
@@ -50,6 +50,26 @@ module Railwatch
|
|
|
50
50
|
config.enabled
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
# Whether the dashboard has a gate in front of it: HTTP Basic on, or
|
|
54
|
+
# the app's own base controller (base_controller_class set to
|
|
55
|
+
# something other than ActionController::Base). The railwatch gem's
|
|
56
|
+
# own answer when it has one (dashboard_gate_configured?).
|
|
57
|
+
def dashboard_gated?
|
|
58
|
+
gem = Railwatch.config
|
|
59
|
+
return gem.dashboard_gate_configured? if gem.respond_to?(:dashboard_gate_configured?)
|
|
60
|
+
|
|
61
|
+
default = defined?(Railwatch::Configuration::DEFAULT_BASE_CONTROLLER) ? Railwatch::Configuration::DEFAULT_BASE_CONTROLLER : "ActionController::Base"
|
|
62
|
+
gem.http_basic_auth_enabled || gem.base_controller_class.to_s.delete_prefix("::") != default
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def ungated_message
|
|
66
|
+
"The Railwatch dashboard at #{config.normalized_mount_path} has no gate, so it is not served in #{config.environment}: " \
|
|
67
|
+
"HTTP Basic is off (RAILWATCH_HTTP_BASIC_AUTH_ENABLED=false) and Railwatch.config.base_controller_class is " \
|
|
68
|
+
"ActionController::Base, which would let every visitor in as a Railwatch user, MCP included. Turn HTTP Basic back on " \
|
|
69
|
+
"(Railwatch.config.http_basic_auth_user and _password), or set base_controller_class to a controller of your app " \
|
|
70
|
+
"that signs people in (its before_actions run first)."
|
|
71
|
+
end
|
|
72
|
+
|
|
53
73
|
# Whether the app reports somewhere of its own choosing, in which case
|
|
54
74
|
# the agent is left alone: a token set (RAILWATCH_TOKEN or the
|
|
55
75
|
# initializer).
|