bullion 0.12.1 → 0.12.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: 9cef665959a8cadbb7227013c2680c914772f9f61a33c230fd405f0d9f0a414a
4
- data.tar.gz: 106020f0549902f1f3966270a4ba9cfc135935ccc9fe1969dd6671a9dcb91738
3
+ metadata.gz: e3f045be66d6e2b4dcf448edd875bec385862e2b67741a615d53a2b60bff5ceb
4
+ data.tar.gz: 896eb9e41ecbd96b2333c9bd3cc647388f469547efe4ee1b3e90611d81c66d16
5
5
  SHA512:
6
- metadata.gz: ec17f3d4a94faf7215513fcdb871f0f6fbc92fc2cf149f41b373bcd125a87889cd014d00fee9534fe75aa4f82aa50745fd82eebbd6a7b0f6cacabeb454ec32a3
7
- data.tar.gz: d7366593b009bfe773fcdb7eb8ce20b862ee08c5633081249f3c5ad8d559a5dec3809440983eea6fd98e3ec7645eacf12d3380cc5784c5d80e81ed1263974075
6
+ metadata.gz: 30edde9b4403f74aaa1e678425c38f9fc946fca13f75c1d482dde1d605ab10f16d71f79d9e31117a4f79881f508fb276f9d2ed36fe3c374ce911bab93734fcca
7
+ data.tar.gz: 25effef65ad92e025752e3182667a71eb13f6a1e4343cd9e8a71d08cf8b5aa6a6080c214d2f7803e8a8d614cadc4a2a1be30a0feca8d2b81655d7f05e2ae51f0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.12.2](https://github.com/jgnagy/bullion/compare/bullion/v0.12.1...bullion/v0.12.2) (2026-12-03)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * address review findings on ACME error responses ([0cd7a03](https://github.com/jgnagy/bullion/commit/0cd7a032f1c7854b49f6aa5965aca1e442b029b8))
9
+ * return ACME problem+json errors from the CA service ([bba9382](https://github.com/jgnagy/bullion/commit/bba9382d5f90675d7991446477eddab19e1c869e))
10
+ * return ACME problem+json errors from the CA service ([b595460](https://github.com/jgnagy/bullion/commit/b595460b8df8e33f6ac5a2db789fc6f0ba417a87)), closes [#110](https://github.com/jgnagy/bullion/issues/110)
11
+
3
12
  ## [0.12.1](https://github.com/jgnagy/bullion/compare/bullion/v0.12.0...bullion/v0.12.1) (2026-11-02)
4
13
 
5
14
 
data/README.md CHANGED
@@ -84,7 +84,7 @@ Install the gem:
84
84
  gem install bullion
85
85
  ```
86
86
 
87
- Bullion is a Rack application served by [Itsi](https://itsi.fyi/). After installing the gem, you'll need a `config.ru` and an `Itsi.rb` configuration file. The simplest approach is to create a working directory with your CA key pair and a minimal Rack config:
87
+ Bullion is a Rack application served by [Puma](https://puma.io/). After installing the gem, you'll need a `config.ru` and a `config/puma.rb` configuration file. The simplest approach is to create a working directory with your CA key pair and a minimal Rack config:
88
88
 
89
89
  ```bash
90
90
  mkdir bullion-server && cd bullion-server
@@ -116,13 +116,12 @@ mappings = {
116
116
  run Rack::URLMap.new(mappings)
117
117
  RUBY
118
118
 
119
- # Initialize Itsi and run database migrations
120
- itsi init
119
+ # Run database migrations
121
120
  DATABASE_URL=sqlite3:./bullion.db bullion-exec rake db:migrate
122
121
 
123
122
  # Start the server
124
123
  CA_DIR=. CA_SECRET=your-key-password CA_DOMAINS=example.com \
125
- DATABASE_URL=sqlite3:./bullion.db itsi
124
+ DATABASE_URL=sqlite3:./bullion.db bundle exec puma -C config/puma.rb
126
125
  ```
127
126
 
128
127
  ### Database Setup
@@ -164,12 +163,11 @@ Whether run locally or via Docker, the following environment variables configure
164
163
  | `DNS01_NAMESERVERS` | _None_ | A comma-delimited list of nameservers to use for resolving [DNS-01](https://letsencrypt.org/docs/challenge-types/#dns-01-challenge) challenges. Usually you'll want this to be set to your _internal_ nameservers so internal names resolve correctly. When not set, it'll use the host's DNS. |
165
164
  | `LOG_LEVEL` | `warn` | Log level for Bullion. Supported levels (starting with the noisiest) are debug, info, warn, error, and fatal. |
166
165
  | `BULLION_PORT` | `9292` | TCP port Bullion will listen on. |
167
- | `THREADS` | `3` | Number of [Itsi threads](https://itsi.fyi/options/threads/) for processing requests. |
168
- | `WORKERS` | `1` | Number of [Itsi workers](https://itsi.fyi/options/workers/) to spawn. |
169
- | `WORKER_MEMORY_LIMIT` | `1024**3` | [Itsi worker memory limit](https://itsi.fyi/options/worker_memory_limit/) for each worker process (in bytes). Default is 1GiB. |
166
+ | `THREADS` | `3` | Number of [Puma threads](https://puma.io/puma/file.deployment.html) for processing requests. |
167
+ | `WORKERS` | `1` | Number of [Puma workers](https://puma.io/puma/file.deployment.html) to spawn. |
170
168
  | `RACK_ENV` | `production`* | When run via Docker, the default is `production`, when run via `rake local_demo` it is `development`. Used to tell Bullion if it is run in development mode or for testing. |
171
169
 
172
- Because Bullion serves requests through Itsi's [fiber scheduler](https://itsi.fyi/options/fiber_scheduler/), each in-flight request leases its own database connection. ActiveRecord's connection pool defaults to 5 connections, so raise `max_connections` on `DATABASE_URL` if you expect more concurrent requests. `checkout_timeout` (default 5 seconds) controls how long a request waits for a connection before failing.
170
+ Because Bullion serves requests through Puma's [fiber-per-request](https://puma.io/puma/file.deployment.html), each in-flight request leases its own database connection. ActiveRecord's connection pool defaults to 5 connections, so raise `max_connections` on `DATABASE_URL` if you expect more concurrent requests. `checkout_timeout` (default 5 seconds) controls how long a request waits for a connection before failing.
173
171
 
174
172
  #### CA Secret
175
173
 
@@ -199,7 +197,7 @@ Then start Bullion with that same passphrase in the environment:
199
197
 
200
198
  ```bash
201
199
  export CA_SECRET='<the passphrase you encrypted the key with>'
202
- itsi
200
+ bundle exec puma -C config/puma.rb
203
201
  ```
204
202
 
205
203
  In development and test environments (`RACK_ENV=development` or `RACK_ENV=test`),
data/Rakefile CHANGED
@@ -25,17 +25,20 @@ if %w[development test].include? ENV["RACK_ENV"]
25
25
  rack_env = "test"
26
26
  database_url = "sqlite3:#{File.expand_path(".")}/tmp/db/#{rack_env}.sqlite3"
27
27
  system("RACK_ENV=\"#{rack_env}\" DATABASE_URL=\"#{database_url}\" bundle exec rake db:migrate")
28
- system(
29
- "RACK_ENV=\"#{rack_env}\" DATABASE_URL=\"#{database_url}\" " \
30
- "LOG_LEVEL='#{ENV.fetch("LOG_LEVEL", "info")}' " \
31
- "itsi --daemonize"
28
+ pid = Process.spawn(
29
+ { "RACK_ENV" => rack_env, "DATABASE_URL" => database_url,
30
+ "LOG_LEVEL" => ENV.fetch("LOG_LEVEL", "info") },
31
+ "bundle", "exec", "puma", "-C", "config/puma.rb",
32
+ out: File.join(File.expand_path("."), "tmp", "puma.log"),
33
+ err: File.join(File.expand_path("."), "tmp", "puma.log"),
34
+ pgroup: true
32
35
  )
33
- FileUtils.touch(File.join(File.expand_path("."), "tmp", "daemon.pid"))
36
+ File.write(File.join(File.expand_path("."), "tmp", "daemon.pid"), pid.to_s)
34
37
  end
35
38
 
36
39
  desc "Runs a foregrounded demo environment"
37
40
  task :foreground_demo do
38
- system("itsi")
41
+ system("bundle exec puma -C config/puma.rb")
39
42
  end
40
43
 
41
44
  desc "Cleans up test or demo environment"
@@ -43,7 +46,12 @@ if %w[development test].include? ENV["RACK_ENV"]
43
46
  at_exit do
44
47
  pid_file = File.join(File.expand_path("."), "tmp", "daemon.pid")
45
48
  if File.exist?(pid_file)
46
- system("itsi stop")
49
+ pid = File.read(pid_file).to_i
50
+ begin
51
+ Process.kill("TERM", -pid) # kill the whole process group
52
+ rescue Errno::ESRCH
53
+ nil
54
+ end
47
55
  FileUtils.rm_f(pid_file)
48
56
  end
49
57
  FileUtils.rm_f(File.join(File.expand_path("."), "tmp", "tls.crt"))
data/config/puma.rb ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Puma configuration for Bullion. Replaces the Itsi configuration file.
4
+ #
5
+ # Each request is served in its own fiber (via `fiber_per_request`) so that
6
+ # ActiveSupport execution state and ActiveRecord connection leases stay
7
+ # isolated per request, matching the fiber-per-request semantics Itsi provided.
8
+
9
+ env = ENV.fetch("APP_ENV", ENV.fetch("RACK_ENV", "development"))
10
+
11
+ # Number of worker processes to spawn. 0 means single mode (one process).
12
+ workers ENV["WORKERS"]&.to_i || (env == "development" ? 1 : 0)
13
+
14
+ # Number of threads to spawn per worker process.
15
+ threads ENV.fetch("THREADS", 3).to_i
16
+
17
+ # Load the application before forking workers.
18
+ preload_app!
19
+
20
+ bind "tcp://0.0.0.0:#{ENV.fetch("BULLION_PORT", 9292)}"
21
+
22
+ rackup "./config.ru"
23
+
24
+ # Run each request in its own fiber (clean slate per request).
25
+ fiber_per_request
26
+
27
+ # Number of seconds to wait for workers to gracefully shut down before killing them.
28
+ worker_shutdown_timeout 5
29
+
30
+ # Clean up any non-threadsafe resources before forking a new worker.
31
+ before_fork do
32
+ end
33
+
34
+ # Reinitialize any non-threadsafe resources after forking a new worker.
35
+ before_worker_boot do
36
+ end
@@ -5,8 +5,11 @@ module Bullion
5
5
  # ACME protocol errors super class
6
6
  class Error < Bullion::Error
7
7
  # @see https://tools.ietf.org/html/rfc8555#section-6.7
8
+ # RFC 8555 section 6.7 says the ACME URN namespace must not be used for
9
+ # unregistered error types, so the generic fallback is the registered
10
+ # "serverInternal" type.
8
11
  def acme_type
9
- "genericError"
12
+ "serverInternal"
10
13
  end
11
14
 
12
15
  def acme_preface
@@ -39,9 +42,14 @@ module Bullion
39
42
  def acme_type = "badPublicKey"
40
43
  end
41
44
 
42
- # ACME exception for bad certificates
45
+ # ACME exception for unidentifiable certificates, e.g. a revocation
46
+ # request for a certificate this CA never issued. RFC 8555 section 6.7
47
+ # and the IANA ACME Error Types registry have no dedicated type for
48
+ # this situation, and a client-correctable 400 must not be labelled a
49
+ # server-internal error, so this uses the Bullion-specific URN
50
+ # namespace (as with UnsupportedChallengeType).
43
51
  class BadCertificate < Bullion::Acme::Error
44
- def acme_type = "badCertificate"
52
+ def acme_error = "urn:ietf:params:bullion:error:badCertificate"
45
53
  end
46
54
 
47
55
  # ACME exception for already-revoked certificates
@@ -54,16 +62,22 @@ module Bullion
54
62
  def acme_type = "invalidContact"
55
63
  end
56
64
 
57
- # ACME exception for invalid orders
58
- class InvalidOrder < Bullion::Acme::Error
59
- def acme_type = "invalidOrder"
60
- end
61
-
62
65
  # ACME exception for malformed requests
63
66
  class Malformed < Bullion::Acme::Error
64
67
  def acme_type = "malformed"
65
68
  end
66
69
 
70
+ # ACME exception for identifiers the server will not issue
71
+ # certificates for
72
+ class RejectedIdentifier < Bullion::Acme::Error
73
+ def acme_type = "rejectedIdentifier"
74
+ end
75
+
76
+ # ACME exception for unsupported identifier types
77
+ class UnsupportedIdentifier < Bullion::Acme::Error
78
+ def acme_type = "unsupportedIdentifier"
79
+ end
80
+
67
81
  # ACME exception for orders that aren't ready to be finalized
68
82
  class OrderNotReady < Bullion::Acme::Error
69
83
  def acme_type = "orderNotReady"
@@ -84,7 +98,9 @@ module Bullion
84
98
  def acme_type = "unauthorized"
85
99
  end
86
100
 
87
- # Non-standard exception for unsupported challenge types
101
+ # Non-standard exception for unsupported challenge types. Per RFC 8555
102
+ # section 6.7, non-registered error types must not use the ACME URN
103
+ # namespace, so this uses the Bullion-specific one.
88
104
  class UnsupportedChallengeType < Bullion::Acme::Error
89
105
  def acme_error = "urn:ietf:params:bullion:error:unsupportedChallengeType"
90
106
  end
@@ -266,14 +266,17 @@ module Bullion
266
266
  def order_valid?(hash)
267
267
  validate_order_nb_and_na(hash["notBefore"], hash["notAfter"])
268
268
 
269
+ identifiers = hash["identifiers"]
270
+ validate_identifiers(identifiers)
271
+
269
272
  # Don't approve empty orders
270
- raise Bullion::Acme::Errors::InvalidOrder, "Empty order!" if hash["identifiers"].empty?
273
+ raise Bullion::Acme::Errors::Malformed, "Empty order!" if identifiers.empty?
271
274
 
272
- order_domains = hash["identifiers"].select { it["type"] == "dns" }
275
+ order_domains = identifiers.select { it["type"] == "dns" }
273
276
 
274
277
  # Don't approve an order with identifiers that _aren't_ of type 'dns'
275
- unless hash["identifiers"] == order_domains
276
- raise Bullion::Acme::Errors::InvalidOrder, 'Only type "dns" allowed'
278
+ unless identifiers == order_domains
279
+ raise Bullion::Acme::Errors::UnsupportedIdentifier, 'Only type "dns" allowed'
277
280
  end
278
281
 
279
282
  # Extract domains that end with something in our allowed domains list
@@ -282,7 +285,7 @@ module Bullion
282
285
  # Only allow configured domains...
283
286
  unless order_domains == valid_domains
284
287
  raise(
285
- Bullion::Acme::Errors::InvalidOrder,
288
+ Bullion::Acme::Errors::RejectedIdentifier,
286
289
  "Domains #{order_domains - valid_domains} not allowed"
287
290
  )
288
291
  end
@@ -299,25 +302,52 @@ module Bullion
299
302
 
300
303
  return unless not_before && not_after
301
304
 
302
- nb = Time.parse(not_before)
303
- na = Time.parse(not_after)
305
+ nb = parse_time(not_before)
306
+ na = parse_time(not_after)
304
307
 
305
308
  # don't allow nonsense certs
306
- raise Bullion::Acme::Errors::InvalidOrder unless nb < na
309
+ raise Bullion::Acme::Errors::Malformed, "notBefore must be before notAfter" unless nb < na
307
310
  # don't allow far-future certs
308
311
  if nb > Time.now + (7 * 86_400) || na > Time.now + Bullion.config.ca.cert_validity_duration
309
- raise Bullion::Acme::Errors::InvalidOrder
312
+ raise Bullion::Acme::Errors::Malformed, "notBefore/notAfter outside the allowed window"
310
313
  end
311
314
 
312
315
  # don't allow really "old" certs
313
- raise Bullion::Acme::Errors::InvalidOrder if nb < Time.now - (14 * 86_400)
316
+ if nb < Time.now - (14 * 86_400)
317
+ raise Bullion::Acme::Errors::Malformed, "notBefore is too far in the past"
318
+ end
314
319
  # don't allow creating certs that are already expired
315
- raise Bullion::Acme::Errors::InvalidOrder if na <= Time.now
320
+ raise Bullion::Acme::Errors::Malformed, "notAfter is in the past" if na <= Time.now
316
321
  end
317
322
  # rubocop:enable Metrics/AbcSize
318
323
  # rubocop:enable Metrics/CyclomaticComplexity
319
324
  # rubocop:enable Metrics/PerceivedComplexity
320
325
 
326
+ # Parses an ISO-8601-ish timestamp; an unparseable value is a
327
+ # client-malformed request, never a server fault.
328
+ def parse_time(value)
329
+ Time.parse(value)
330
+ rescue ArgumentError, TypeError
331
+ raise Bullion::Acme::Errors::Malformed, "Unparseable time value: #{value.inspect}"
332
+ end
333
+
334
+ # Validates that the newOrder identifiers are objects with string
335
+ # "type" and "value" members; anything else is a malformed request.
336
+ def validate_identifiers(identifiers)
337
+ unless identifiers.is_a?(Array)
338
+ raise Bullion::Acme::Errors::Malformed, "identifiers must be an array of objects"
339
+ end
340
+
341
+ identifiers.each do |identifier|
342
+ next if identifier.is_a?(Hash) &&
343
+ identifier["type"].is_a?(String) &&
344
+ identifier["value"].is_a?(String)
345
+
346
+ raise Bullion::Acme::Errors::Malformed,
347
+ 'each identifier must be an object with string "type" and "value"'
348
+ end
349
+ end
350
+
321
351
  def extract_valid_order_domains(order_domains)
322
352
  order_domains.reject do |domain|
323
353
  # Only allow a configured domain itself or a proper subdomain of it;
@@ -38,7 +38,11 @@ module Bullion
38
38
  OpenSSL::PKey::RSA.new(outer_sequence.to_der)
39
39
  end
40
40
 
41
- def key_data_to_ecdsa(key_data)
41
+ # Maps a JWK "crv" name to an OpenSSL curve name. RFC 7518 requires
42
+ # that an unknown or unsupported curve be rejected as a bad public
43
+ # key, never as an unhandled exception.
44
+ # @see https://tools.ietf.org/html/rfc7518#page-30
45
+ def ec_curve_name(crv)
42
46
  crv_mapping = {
43
47
  "P-256" => "prime256v1",
44
48
  "secp256k1" => "secp256k1",
@@ -46,10 +50,18 @@ module Bullion
46
50
  "P-521" => "secp521r1"
47
51
  }
48
52
 
53
+ curve_name = crv_mapping[crv]
54
+ return curve_name if curve_name
55
+
56
+ raise Bullion::Acme::Errors::BadPublicKey,
57
+ "Unsupported EC curve: #{crv.inspect}; " \
58
+ "supported curves are #{crv_mapping.keys.join(", ")}"
59
+ end
60
+
61
+ def key_data_to_ecdsa(key_data)
49
62
  x = base64_to_octet(key_data["x"])
50
63
  y = base64_to_octet(key_data["y"])
51
- curve_name = crv_mapping[key_data["crv"]]
52
- raise "Unknown curve" unless curve_name
64
+ curve_name = ec_curve_name(key_data["crv"])
53
65
 
54
66
  key_group = OpenSSL::PKey::EC::Group.new(curve_name)
55
67
  key_point = ec_point_from_jwk(key_group, x, y)
@@ -6,11 +6,15 @@ module Bullion
6
6
  class OrderCsr
7
7
  class << self
8
8
  def from_acme_request(order, raw_data)
9
- decoded_data = Base64.urlsafe_decode64(raw_data)
9
+ decoded_data = Base64.urlsafe_decode64(raw_data.to_s)
10
10
  reencoded_data = Base64.encode64(decoded_data)
11
11
  csr_string = openssl_compat_csr(reencoded_data)
12
12
 
13
13
  new(order, csr_string)
14
+ rescue ArgumentError, OpenSSL::X509::RequestError
15
+ # A payload that is not valid base64url or does not parse as a
16
+ # PKCS#10 request is an unacceptable CSR, not a server fault.
17
+ raise Bullion::Acme::Errors::BadCsr, "Unable to parse CSR from the request payload"
14
18
  end
15
19
 
16
20
  private
@@ -79,7 +79,7 @@ module Bullion
79
79
  write_service_log("ERROR", text)
80
80
  end
81
81
 
82
- # Prefer Rack's error stream: Itsi wires it to its own log pipeline, while
82
+ # Prefer Rack's error stream: Puma wires it to its own log pipeline, while
83
83
  # a Logger captured at boot can point at a worker's closed/inherited stream.
84
84
  def write_service_log(level, text)
85
85
  message = text.dup.force_encoding(Encoding::UTF_8).scrub("?")
@@ -132,7 +132,7 @@ module Bullion
132
132
  if @payload_data["onlyReturnExisting"]
133
133
  content_type "application/problem+json"
134
134
  unless user
135
- raise Bullion::Acme::Error::AccountDoesNotExist,
135
+ raise Bullion::Acme::Errors::AccountDoesNotExist,
136
136
  "onlyReturnExisting requested and account does not exist"
137
137
  end
138
138
  end
@@ -161,10 +161,9 @@ module Bullion
161
161
  parse_acme_jwt
162
162
 
163
163
  unless params[:id].to_i == @user.id
164
- content_type "application/json"
165
164
  add_acme_headers @new_nonce
166
-
167
- halt 403, { error: "Accounts can only view or update themselves" }.to_json
165
+ halt_acme_error(403, Bullion::Acme::Errors::Unauthorized,
166
+ "Accounts can only view or update themselves")
168
167
  end
169
168
 
170
169
  content_type "application/json"
@@ -180,10 +179,9 @@ module Bullion
180
179
  parse_acme_jwt
181
180
 
182
181
  unless params[:id].to_i == @user.id
183
- content_type "application/json"
184
182
  add_acme_headers @new_nonce
185
-
186
- halt 403, { error: "Accounts can only view or update themselves" }.to_json
183
+ halt_acme_error(403, Bullion::Acme::Errors::Unauthorized,
184
+ "Accounts can only view or update themselves")
187
185
  end
188
186
 
189
187
  content_type "application/json"
@@ -199,11 +197,11 @@ module Bullion
199
197
  post "/orders" do
200
198
  parse_acme_jwt
201
199
 
200
+ order_valid?(@payload_data)
201
+
202
202
  # Only identifiers of type "dns" are supported
203
203
  identifiers = @payload_data["identifiers"].select { it["type"] == "dns" }
204
204
 
205
- order_valid?(@payload_data)
206
-
207
205
  order = @user.start_order(
208
206
  identifiers:,
209
207
  not_before: @payload_data["notBefore"],
@@ -370,7 +368,7 @@ module Bullion
370
368
 
371
369
  cert.data + Bullion.ca_cert_file
372
370
  else
373
- halt(422, { error: "Order not valid" }.to_json)
371
+ halt_acme_error(422, Bullion::Acme::Errors::OrderNotReady, "Order not valid")
374
372
  end
375
373
  end
376
374
 
@@ -378,9 +376,13 @@ module Bullion
378
376
  # @see https://tools.ietf.org/html/rfc8555#section-7.6
379
377
  post "/revokecert" do
380
378
  # The certificate is base64url-encoded DER
381
- cert = OpenSSL::X509::Certificate.new(
382
- Base64.urlsafe_decode64(extract_payload_data["certificate"])
383
- )
379
+ cert = begin
380
+ OpenSSL::X509::Certificate.new(
381
+ Base64.urlsafe_decode64(extract_payload_data["certificate"].to_s)
382
+ )
383
+ rescue ArgumentError, TypeError, OpenSSL::X509::CertificateError
384
+ raise Bullion::Acme::Errors::Malformed, "The certificate could not be decoded"
385
+ end
384
386
 
385
387
  # RFC 8555 section 7.6: a revocation is accepted from the account
386
388
  # that was issued the certificate, from an account holding valid
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bullion
4
- VERSION = "0.12.1"
4
+ VERSION = "0.12.2"
5
5
  end
data/lib/bullion.rb CHANGED
@@ -204,16 +204,15 @@ Bullion.configure do |config|
204
204
  config.nameservers = nameservers if nameservers
205
205
  end
206
206
 
207
- # Itsi processes each request inside its own Fiber, but all fibers on a thread
208
- # share an ActiveSupport execution context by default. ActiveRecord leases a
209
- # database connection per execution context, so without fiber isolation every
210
- # concurrent request fiber on a thread shares (and races on) the same
211
- # connection. Trilogy detects this and raises Trilogy::SynchronizationError.
212
- # Mirror Itsi's own scheduler_mode hook (which itsi-server 0.2.27 never loads)
213
- # and the Rails 8.1+ default by opting into fiber isolation, honoring Itsi's
214
- # opt-out.
207
+ # Puma serves each request inside its own Fiber (via `fiber_per_request`), but
208
+ # all fibers on a thread share an ActiveSupport execution context by default.
209
+ # ActiveRecord leases a database connection per execution context, so without
210
+ # fiber isolation every concurrent request fiber on a thread shares (and races
211
+ # on) the same connection. Trilogy detects this and raises
212
+ # Trilogy::SynchronizationError. Opt into fiber isolation, honoring Puma's
213
+ # fiber_per_request opt-out.
215
214
  # @see https://github.com/jgnagy/bullion/issues/116
216
- unless ENV["ITSI_DISABLE_AS_AUTO_FIBER_ISOLATION_LEVEL"]
215
+ unless ENV["PUMA_DISABLE_AS_AUTO_FIBER_ISOLATION_LEVEL"]
217
216
  ActiveSupport::IsolatedExecutionState.isolation_level = :fiber
218
217
  end
219
218
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
@@ -52,19 +52,19 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0.21'
54
54
  - !ruby/object:Gem::Dependency
55
- name: itsi
55
+ name: puma
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0.2'
60
+ version: '8.0'
61
61
  type: :runtime
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0.2'
67
+ version: '8.0'
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: json
70
70
  requirement: !ruby/object:Gem::Requirement
@@ -449,13 +449,13 @@ extra_rdoc_files: []
449
449
  files:
450
450
  - ".ruby-version"
451
451
  - CHANGELOG.md
452
- - Itsi.rb
453
452
  - LICENSE.txt
454
453
  - README.md
455
454
  - Rakefile
456
455
  - bin/console
457
456
  - bin/setup
458
457
  - config.ru
458
+ - config/puma.rb
459
459
  - db/migrate/20210104000000_create_accounts.rb
460
460
  - db/migrate/20210104060422_create_certificates.rb
461
461
  - db/migrate/20210105060406_create_orders.rb
data/Itsi.rb DELETED
@@ -1,123 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This is the default Itsi configuration file, installed when you run `itsi init`
4
- # It contains a sane starting point for configuring your Itsi server.
5
- # You can use this file in both development and production environments.
6
- # Most of the options in this file can be overridden by command line options.
7
- # Check out itsi -h to learn more about the command line options available to you.
8
-
9
- env = ENV.fetch("APP_ENV") { ENV.fetch("RACK_ENV", "development") }
10
-
11
- # Number of worker processes to spawn
12
- # If more than 1, Itsi will be booted in Cluster mode
13
- workers ENV["WORKERS"]&.to_i || (env == "development" ? 1 : nil)
14
-
15
- # Number of threads to spawn per worker process
16
- # For pure CPU bound applicationss, you'll get the best results keeping this number low
17
- # Setting a value of 1 is great for superficial benchmarks, but in reality
18
- # it's better to set this a bit higher to allow expensive requests to get overtaken and minimize head-of-line blocking
19
- threads ENV.fetch("THREADS", 3).to_i
20
-
21
- # If your application is IO bound (e.g. performing a lot of proxied HTTP requests, or heavy queries etc)
22
- # you can see *substantial* benefits from enabling this option.
23
- # To set this option, pass a string, not a class (as we will not have loaded the class yet)
24
- # E.g.
25
- # `fiber_scheduler "Itsi::Scheduler"` - The default fast and light-weight scheduler that comes with Itsi
26
- # `fiber_scheduler "Async::Scheduler"` - Bring your own scheduler!
27
- fiber_scheduler "Itsi::Scheduler"
28
-
29
- # If you bind to https, without specifying a certificate, Itsi will use a self-signed certificate.
30
- # The self-signed certificate will use a CA generated for your
31
- # host and stored inside `ITSI_LOCAL_CA_DIR` (Defaults to ~/.itsi)
32
- # bind "https://0.0.0.0:3000"
33
- # bind "https://0.0.0.0:3000?domains=dev.itsi.fyi"
34
- #
35
- # If you want to use let's encrypt to generate you a real certificate you
36
- # and pass cert=acme and an acme_email address to generate one.
37
- # bind "https://itsi.fyi?cert=acme&acme_email=admin@itsi.fyi"
38
- # You can generate certificates for multiple domains at once, by passing a comma-separated list of domains
39
- # bind "https://0.0.0.0?domains=foo.itsi.fyi,bar.itsi.fyi&cert=acme&acme_email=admin@itsi.fyi"
40
- #
41
- # If you already have a certificate you can specify it using the cert and key parameters
42
- # bind "https://itsi.fyi?cert=/path/to/cert.pem&key=/path/to/key.pem"
43
- #
44
- # You can also bind to a unix socket or a tls unix socket. E.g.
45
- # bind "unix:///tmp/itsi.sock"
46
- # bind "tls:///tmp/itsi.secure.sock"
47
-
48
- bind "http://0.0.0.0:#{ENV.fetch("BULLION_PORT", 9292)}"
49
-
50
- # If you want to preload the application, set preload to true
51
- # to load the entire rack-app defined in rack_file_name before forking.
52
- # Alternatively, you can preload just a specific set of gems in a group in your gemfile,
53
- # by providing the group name here.
54
- # E.g.
55
- #
56
- # preload :preload # Load gems inside the preload group
57
- # preload false # Don't preload.
58
- #
59
- # If you want to be able to perform zero-downtime deploys using a single itsi process,
60
- # you should disable preloads, so that the application is loaded fresh each time a new worker boots
61
- preload true
62
-
63
- # Set the maximum memory limit for each worker process in bytes
64
- # When this limit is reached, the worker will be gracefully restarted.
65
- # Only one worker is restarted at a time to ensure we don't take down
66
- # all of them at once, if they reach the threshold simultaneously.
67
- worker_memory_limit ENV.fetch("WORKER_MEMORY_LIMIT") { 1024 * 1024 * 1024 } # Default to 1GB
68
-
69
- # You can provide an optional block of code to run, when a worker hits its memory threshold
70
- # (Use this to send yourself an alert,
71
- # write metrics to disk etc. etc.)
72
- after_memory_limit_reached do |pid|
73
- puts "Worker #{pid} has reached its memory threshold and will restart"
74
- end
75
-
76
- # Do clean up of any non-threadsafe resources before forking a new worker here.
77
- before_fork {}
78
-
79
- # Reinitialize any non-threadsafe resources after forking a new worker here.
80
- after_fork {}
81
-
82
- # Shutdown timeout
83
- # Number of seconds to wait for workers to gracefully shutdown before killing them.
84
- shutdown_timeout 5
85
-
86
- # Set this to false for application environments that require rack.input to be a rewindable body
87
- # (like Rails). For rack applications that can stream inputs, you can set this to true for a more
88
- # memory-efficient approach.
89
- stream_body false
90
-
91
- # OOB GC responses threshold
92
- # Specifies how frequently OOB gc should be triggered during periods where there is a gap in queued requests.
93
- # Setting this too low can substantially worsen performance
94
- oob_gc_responses_threshold 512
95
-
96
- # Log level
97
- # Set this to one of the following values: debug, info, warn, error, fatal
98
- # Can also be set using the ITSI_LOG environment variable
99
- log_level ENV.fetch("LOG_LEVEL", "warn").to_sym
100
-
101
- # Log Format
102
- # Set this to be either :plain or :json. If you leave it blank Itsi will try
103
- # and auto-detect the format based on the TTY environment.
104
- log_format :plain
105
- # You can mount several Ruby apps as either
106
- # 1. rackup files
107
- # 2. inline rack apps
108
- # 3. inline Ruby endpoints
109
- #
110
- # 1. rackup_file
111
- rackup_file "./config.ru"
112
- #
113
- # 2. inline rack app
114
- # require 'rack'
115
- # run(Rack::Builder.app do
116
- # use Rack::CommonLogger
117
- # run ->(env) { [200, { 'content-type' => 'text/plain' }, ['OK']] }
118
- # end)
119
- #
120
- # 3. Endpoints
121
- # endpoint "/" do |req|
122
- # req.ok "Hello from Itsi"
123
- # end