mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- Refuse to start with a placeholder or short SECRET_KEY_BASE (under 32 characters); warn and fail sam:doctor under 64. .env.example no longer ships a placeholder. - First-run setup needs a one-time code printed only in the server log, so only whoever runs the server can create the admin account. - AirTrail: the server resolves the address and connects to exactly that; never the server itself or link-local addresses (cloud metadata); private-network addresses only for admins or hosts in AIRTRAIL_ALLOWED_HOSTS. - Host authorization when APP_HOST is set: APP_HOST, the APP_URL host, ALLOWED_HOSTS, localhost and IP addresses; /up exempt. A blocked name gets a short explanation instead of a blank 403. - docker-compose.direct.yml: HTTPS without a proxy via Thruster's built-in Let's Encrypt (TLS_DOMAIN). - Notes' Markdown no longer allows the unused class attribute. - README, .env.example and the user guide updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.2 KiB
Ruby
34 lines
1.2 KiB
Ruby
# Until the first account exists, whoever reaches the server could create the
|
|
# admin account. The setup page asks for this one-time code, which is only in
|
|
# the server's log, so only whoever runs the server can finish setup.
|
|
module SetupCode
|
|
ALPHABET = "ABCDEFGHJKMNPQRSTUVWXYZ23456789".chars.freeze # no look-alikes (0/O, 1/I/L)
|
|
|
|
module_function
|
|
|
|
# (Each parallel test process has its own.)
|
|
def file = Rails.env.test? ? Rails.root.join("tmp", "setup_code-#{Process.pid}") : Rails.root.join("storage", "setup_code")
|
|
|
|
# The code, made the first time it's needed and kept until setup is done.
|
|
def current
|
|
return file.read.strip if file.exist?
|
|
code = Array.new(8) { ALPHABET[SecureRandom.random_number(ALPHABET.size)] }.join.insert(4, "-")
|
|
file.dirname.mkpath
|
|
File.write(file, code, perm: 0o600)
|
|
code
|
|
end
|
|
|
|
def announce
|
|
Rails.logger.warn("Setup code: #{current} (enter it on the setup page to create the admin account)")
|
|
end
|
|
|
|
def matches?(given)
|
|
normalize = ->(s) { s.to_s.upcase.gsub(/[^A-Z0-9]/, "") }
|
|
ActiveSupport::SecurityUtils.secure_compare(normalize.(given), normalize.(current))
|
|
end
|
|
|
|
def clear
|
|
file.delete if file.exist?
|
|
end
|
|
end
|