mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Sign-in hardening: lockout, stronger passwords, authenticator codes
- 10 failed sign-ins in a row (password, authenticator code, or password at signing) lock an account for 15 minutes from any address; the user is emailed; admins can unlock. Same message as a wrong password. - Passwords: at least 12 characters (max 72), refused if found in Have I Been Pwned (k-anonymity range API; fails open; PWNED_PASSWORDS_CHECK=false) - Optional TOTP (authenticator app) with 10 recovery codes for password and emailed-link sign-in, and at signing (auth method password_totp); codes accepted once; admins can reset; SSO sign-in unaffected - Demo/test passwords updated; guide, README and procedures document Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a6bfe922be
commit
14316bb60f
41 files changed
+600
-45
No files matched your search
@@ -1,6 +1,6 @@
|
||||
class Admin::UsersController < ApplicationController
|
||||
before_action :require_admin!
|
||||
before_action :set_user, only: %i[edit update destroy disable enable]
|
||||
before_action :set_user, only: %i[edit update destroy disable enable unlock reset_two_factor]
|
||||
|
||||
def index
|
||||
@users = User.order(:email_address).includes(:certificates, aircraft_roles: :aircraft)
|
||||
@@ -39,6 +39,19 @@ class Admin::UsersController < ApplicationController
|
||||
|
||||
# Ends their access and their ability to sign (AC 120-78B 2.2.6.4) while
|
||||
# keeping their account, so the signatures they made stay attributed.
|
||||
def unlock
|
||||
@user.unlock!
|
||||
redirect_to admin_users_path, notice: "#{@user.email_address} unlocked."
|
||||
end
|
||||
|
||||
# For a user who lost their authenticator: they sign in with their password
|
||||
# alone and can set it up again.
|
||||
def reset_two_factor
|
||||
@user.disable_otp!
|
||||
Rails.logger.info("[auth] #{current_user.email_address} turned off two-factor for #{@user.email_address}")
|
||||
redirect_to admin_users_path, notice: "Two-factor turned off for #{@user.email_address}. Ask them to set it up again from their profile."
|
||||
end
|
||||
|
||||
def disable
|
||||
return redirect_to admin_users_path, alert: "You can't disable yourself." if @user == current_user
|
||||
@user.update!(disabled_at: Time.current)
|
||||
|
||||
@@ -58,6 +58,29 @@ module Authentication
|
||||
end
|
||||
end
|
||||
|
||||
# Password or emailed-link sign-in: straight in, or first the
|
||||
# authenticator code if the user has one set up (SSO skips this; the
|
||||
# provider handles its own second factor).
|
||||
OTP_PENDING_FOR = 5.minutes
|
||||
|
||||
def begin_sign_in(user, return_to:, notice: nil)
|
||||
reset_session # fresh session id after signing in
|
||||
if user.otp_enabled?
|
||||
session[:otp_user_id] = user.id
|
||||
session[:otp_started_at] = Time.current.to_i
|
||||
session[:return_to_after_authenticating] = return_to
|
||||
redirect_to two_factor_session_path
|
||||
else
|
||||
start_new_session_for user
|
||||
redirect_to return_to, notice: notice
|
||||
end
|
||||
end
|
||||
|
||||
def pending_otp_user
|
||||
return unless (id = session[:otp_user_id]) && Time.zone.at(session[:otp_started_at].to_i) > OTP_PENDING_FOR.ago
|
||||
User.active.find_by(id: id)
|
||||
end
|
||||
|
||||
def terminate_session
|
||||
Current.session.destroy
|
||||
cookies.delete(:session_id)
|
||||
|
||||
@@ -11,10 +11,20 @@ module EntrySigning
|
||||
session[:after_reauth] = signing_page_path # where single sign-on returns after signing in again
|
||||
end
|
||||
|
||||
# Password re-entered now, or single sign-on completed in the last few minutes.
|
||||
# Password re-entered now (with an authenticator code too, if the user has
|
||||
# one), or single sign-on completed in the last few minutes. Wrong
|
||||
# passwords and codes count toward the account lockout.
|
||||
def reauthenticated_method
|
||||
if params[:password].present?
|
||||
return "password" if current_user.authenticate_password(params[:password])
|
||||
return if current_user.locked?
|
||||
unless current_user.authenticate_password(params[:password])
|
||||
current_user.register_failed_sign_in!
|
||||
return
|
||||
end
|
||||
return "password" unless current_user.otp_enabled?
|
||||
return "password_totp" if current_user.verify_second_factor(params[:otp_code])
|
||||
current_user.register_failed_sign_in!
|
||||
return
|
||||
elsif current_user.sso_uid? && (at = session[:reauthenticated_at]) && Time.zone.at(at) > EntrySigner::REAUTH_WINDOW.ago
|
||||
return "sso"
|
||||
end
|
||||
@@ -27,7 +37,11 @@ module EntrySigning
|
||||
unless params[:confirm] == "1"
|
||||
return signing_failed(entry, "Tick the box to confirm you're signing this entry.")
|
||||
end
|
||||
return signing_failed(entry, "Re-enter your password (or sign in again with #{Sso.label}) to sign.") unless method
|
||||
unless method
|
||||
return signing_failed(entry, "This account is locked for a few minutes after too many failed tries.") if current_user.reload.locked?
|
||||
return signing_failed(entry, "Re-enter your password#{' and a current authenticator code' if current_user.otp_enabled?} (or sign in again with #{Sso.label}) to sign.")
|
||||
end
|
||||
current_user.clear_failed_sign_ins!
|
||||
|
||||
signature = EntrySigner.new(entry, user: current_user, certificate: certificate, auth_method: method, request: request).sign!
|
||||
session.delete(:reauthenticated_at)
|
||||
|
||||
@@ -24,7 +24,7 @@ class PasswordsController < ApplicationController
|
||||
@user.sessions.destroy_all # a reset signs out every device
|
||||
redirect_to new_session_path, notice: "Password has been reset."
|
||||
else
|
||||
redirect_to edit_password_path(params[:token]), alert: "Passwords did not match."
|
||||
redirect_to edit_password_path(params[:token]), alert: @user.errors.full_messages.to_sentence.presence || "Enter a new password."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
class SessionsController < ApplicationController
|
||||
allow_unauthenticated_access only: %i[ new create ]
|
||||
rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_url, alert: "Try again later." }
|
||||
allow_unauthenticated_access only: %i[new create two_factor verify_two_factor]
|
||||
rate_limit to: 10, within: 3.minutes, only: %i[create verify_two_factor], with: -> { redirect_to new_session_url, alert: "Try again later." }
|
||||
|
||||
FAILED = "Try another email address or password. After #{User::LOCK_AFTER} failed tries in a row an account is locked for #{User::LOCK_FOR.inspect}.".freeze
|
||||
|
||||
def new
|
||||
end
|
||||
@@ -8,15 +10,36 @@ class SessionsController < ApplicationController
|
||||
def create
|
||||
return redirect_to new_session_path, alert: "Sign in with #{Sso.label}." unless Sso.password_login?
|
||||
|
||||
if (user = User.authenticate_by(params.permit(:email_address, :password))) && user.disabled?
|
||||
if (user = User.authenticate_with_lockout(email_address: params[:email_address], password: params[:password])) && user.disabled?
|
||||
redirect_to new_session_path, alert: "This account is disabled."
|
||||
elsif user
|
||||
return_to = after_authentication_url
|
||||
reset_session # fresh session id after signing in
|
||||
start_new_session_for user
|
||||
redirect_to return_to
|
||||
begin_sign_in user, return_to: after_authentication_url
|
||||
else
|
||||
redirect_to new_session_path, alert: "Try another email address or password."
|
||||
redirect_to new_session_path(email_address: params[:email_address].to_s.first(200)), alert: FAILED
|
||||
end
|
||||
end
|
||||
|
||||
# Second step for accounts with an authenticator app.
|
||||
def two_factor
|
||||
redirect_to new_session_path, alert: "Sign in again." unless pending_otp_user
|
||||
end
|
||||
|
||||
def verify_two_factor
|
||||
user = pending_otp_user
|
||||
return redirect_to(new_session_path, alert: "That took too long. Sign in again.") unless user
|
||||
if user.locked?
|
||||
reset_session
|
||||
redirect_to new_session_path, alert: FAILED
|
||||
elsif user.verify_second_factor(params[:code])
|
||||
user.clear_failed_sign_ins!
|
||||
return_to = after_authentication_url
|
||||
reset_session
|
||||
start_new_session_for user
|
||||
notice = user.recovery_codes_left < 3 ? "Signed in. You have #{user.recovery_codes_left} recovery codes left: make new ones on your profile." : nil
|
||||
redirect_to return_to, notice: notice
|
||||
else
|
||||
user.register_failed_sign_in!
|
||||
redirect_to two_factor_session_path, alert: "That code didn't match. Try the current code from your authenticator app, or a recovery code."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -26,9 +26,7 @@ class SignInLinksController < ApplicationController
|
||||
|
||||
def consume
|
||||
return redirect_to new_session_path, alert: "This account is disabled." if @user.disabled?
|
||||
reset_session # fresh session id after signing in
|
||||
start_new_session_for @user # also spends the link
|
||||
redirect_to root_path, notice: "Signed in."
|
||||
begin_sign_in @user, return_to: root_path, notice: "Signed in." # signing in also spends the link
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# Profile → Two-factor: set up an authenticator app (TOTP) for password and
|
||||
# emailed-link sign-in, turn it off, or make new recovery codes.
|
||||
class TwoFactorsController < ApplicationController
|
||||
rate_limit to: 10, within: 5.minutes, only: %i[create destroy recovery_codes], with: -> { redirect_to edit_profile_path(anchor: "two-factor"), alert: "Try again later." }
|
||||
|
||||
def new
|
||||
return redirect_to(back_path, notice: "Two-factor is already on.") if current_user.otp_enabled?
|
||||
session[:pending_otp_secret] ||= User.new_otp_secret
|
||||
@secret = session[:pending_otp_secret]
|
||||
svg = RQRCode::QRCode.new(User.otp_uri(@secret, current_user.email_address)).as_svg(module_size: 4, use_path: true, viewbox: true)
|
||||
@qr_data_uri = "data:image/svg+xml;base64,#{Base64.strict_encode64(svg)}"
|
||||
end
|
||||
|
||||
def create
|
||||
secret = session[:pending_otp_secret]
|
||||
return redirect_to(new_two_factor_path(return_to: params[:return_to])) unless secret
|
||||
if User.valid_otp?(secret, params[:code])
|
||||
session.delete(:pending_otp_secret)
|
||||
@codes = current_user.enable_otp!(secret)
|
||||
log_security("turned on two-factor")
|
||||
render :codes
|
||||
else
|
||||
redirect_to new_two_factor_path(return_to: params[:return_to]), alert: "That code didn't match. Check the time on your phone and try the current code."
|
||||
end
|
||||
end
|
||||
|
||||
def recovery_codes
|
||||
return redirect_to(edit_profile_path(anchor: "two-factor"), alert: "That code didn't match.") unless current_user.verify_second_factor(params[:code])
|
||||
@codes = current_user.enable_otp!(current_user.otp_secret)
|
||||
log_security("made new recovery codes")
|
||||
render :codes
|
||||
end
|
||||
|
||||
def destroy
|
||||
return redirect_to(edit_profile_path(anchor: "two-factor"), alert: "That code didn't match.") unless current_user.verify_second_factor(params[:code])
|
||||
current_user.disable_otp!
|
||||
log_security("turned off two-factor")
|
||||
redirect_to edit_profile_path(anchor: "two-factor"), notice: "Two-factor is off."
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Back to a signing invitation the user came from, else the profile.
|
||||
def back_path = params[:return_to].to_s.match?(%r{\A/sign/[\w-]+\z}) ? params[:return_to] : edit_profile_path(anchor: "two-factor")
|
||||
helper_method :back_path
|
||||
|
||||
def log_security(what) = Rails.logger.info("[auth] #{current_user.email_address} #{what}")
|
||||
end
|
||||
@@ -4,4 +4,9 @@ class SessionsMailer < ApplicationMailer
|
||||
@token = user.generate_token_for(:email_sign_in)
|
||||
mail subject: "Your sign-in link", to: user.email_address
|
||||
end
|
||||
|
||||
def locked(user)
|
||||
@user = user
|
||||
mail subject: "Your account was locked after failed sign-ins", to: user.email_address
|
||||
end
|
||||
end
|
||||
@@ -7,7 +7,8 @@
|
||||
# by this server, so the signature record can't be altered unnoticed either.
|
||||
class EntrySignature < ApplicationRecord
|
||||
include Versioned
|
||||
AUTH_METHODS = { "password" => "password re-entered", "sso" => "single sign-on, signed in again" }.freeze
|
||||
AUTH_METHODS = { "password" => "password re-entered", "password_totp" => "password and authenticator code re-entered",
|
||||
"sso" => "single sign-on, signed in again" }.freeze
|
||||
# "Certified by" conveys the intent to sign (2.2.2).
|
||||
LABEL = "Certified by".freeze
|
||||
|
||||
|
||||
+89
-1
@@ -22,7 +22,86 @@ class User < ApplicationRecord
|
||||
|
||||
validates :email_address, presence: true, uniqueness: true,
|
||||
format: { with: URI::MailTo::EMAIL_REGEXP }
|
||||
validates :password, length: { minimum: 8 }, allow_nil: true
|
||||
PASSWORD_MIN = 12
|
||||
validates :password, length: { minimum: PASSWORD_MIN, maximum: 72 }, allow_nil: true
|
||||
validate :password_not_breached
|
||||
|
||||
# Lockout: this many failed sign-ins in a row (password, authenticator
|
||||
# code, or password at signing) locks the account for a while, from
|
||||
# whatever address they come. The user is emailed.
|
||||
LOCK_AFTER = 10
|
||||
LOCK_FOR = 15.minutes
|
||||
|
||||
encrypts :otp_secret
|
||||
OTP_ISSUER = "Simple Aircraft Manager".freeze
|
||||
RECOVERY_CODES = 10
|
||||
|
||||
# Password sign-in with lockout. Returns the user, or nil (wrong details,
|
||||
# or locked: the same answer, so it doesn't reveal which).
|
||||
def self.authenticate_with_lockout(email_address:, password:)
|
||||
user = find_by(email_address: email_address.to_s.strip.downcase)
|
||||
return if user&.locked?
|
||||
authed = authenticate_by(email_address: email_address.to_s, password: password.to_s)
|
||||
authed ? authed.tap(&:clear_failed_sign_ins!) : user&.register_failed_sign_in!
|
||||
end
|
||||
|
||||
def locked? = locked_until&.future?
|
||||
|
||||
# Counts a failed attempt; locks the account (and returns nil) at the limit.
|
||||
def register_failed_sign_in!
|
||||
self.class.where(id: id).update_all("failed_sign_ins = failed_sign_ins + 1")
|
||||
reload
|
||||
if failed_sign_ins >= LOCK_AFTER
|
||||
update_columns(failed_sign_ins: 0, locked_until: LOCK_FOR.from_now)
|
||||
SessionsMailer.locked(self).deliver_later if MailSettings.configured?
|
||||
Rails.logger.warn("[auth] #{email_address} locked after #{LOCK_AFTER} failed sign-ins")
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def clear_failed_sign_ins!
|
||||
update_columns(failed_sign_ins: 0, locked_until: nil) if failed_sign_ins.positive? || locked_until
|
||||
end
|
||||
|
||||
def unlock! = update_columns(failed_sign_ins: 0, locked_until: nil)
|
||||
|
||||
# --- Authenticator app (TOTP) ---
|
||||
|
||||
def otp_enabled? = otp_enabled_at.present? && otp_secret.present?
|
||||
|
||||
def self.new_otp_secret = ROTP::Base32.random
|
||||
|
||||
def self.otp_uri(secret, email) = ROTP::TOTP.new(secret, issuer: OTP_ISSUER).provisioning_uri(email)
|
||||
|
||||
# A code from the authenticator for this secret, allowing 30 s of clock drift.
|
||||
def self.valid_otp?(secret, code, after: nil)
|
||||
ROTP::TOTP.new(secret, issuer: OTP_ISSUER).verify(code.to_s.gsub(/\s/, ""), drift_behind: 30, drift_ahead: 30, after: after)
|
||||
end
|
||||
|
||||
# Turns it on with a confirmed secret; returns the recovery codes to show once.
|
||||
def enable_otp!(secret)
|
||||
codes = Array.new(RECOVERY_CODES) { SecureRandom.alphanumeric(10).downcase.scan(/.{5}/).join("-") }
|
||||
update!(otp_secret: secret, otp_enabled_at: Time.current, otp_last_used_at: nil, otp_recovery_codes: codes.map { recovery_digest(_1) })
|
||||
codes
|
||||
end
|
||||
|
||||
def disable_otp! = update!(otp_secret: nil, otp_enabled_at: nil, otp_last_used_at: nil, otp_recovery_codes: nil)
|
||||
|
||||
# An authenticator code (each accepted once) or an unused recovery code.
|
||||
def verify_second_factor(code)
|
||||
return false unless otp_enabled?
|
||||
code = code.to_s.strip.downcase
|
||||
if code.gsub(/\s/, "").match?(/\A\d{6}\z/)
|
||||
step = self.class.valid_otp?(otp_secret, code, after: otp_last_used_at)
|
||||
step ? update_columns(otp_last_used_at: step) && true : false
|
||||
else
|
||||
digests = Array(otp_recovery_codes)
|
||||
match = digests.find { ActiveSupport::SecurityUtils.secure_compare(_1, recovery_digest(code)) }
|
||||
match ? update_columns(otp_recovery_codes: digests - [ match ]) && true : false
|
||||
end
|
||||
end
|
||||
|
||||
def recovery_codes_left = Array(otp_recovery_codes).size
|
||||
|
||||
# Aircraft visible to this user: admins see the whole fleet.
|
||||
def accessible_aircraft
|
||||
@@ -38,4 +117,13 @@ class User < ApplicationRecord
|
||||
def display_name
|
||||
name.presence || email_address
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def recovery_digest(code) = OpenSSL::HMAC.hexdigest("SHA256", Rails.application.key_generator.generate_key("otp-recovery", 32), code.to_s.strip.downcase)
|
||||
|
||||
def password_not_breached
|
||||
return if password.blank? || errors.include?(:password)
|
||||
errors.add(:password, "has appeared in a data breach (Have I Been Pwned); choose a different one") if PwnedPasswords.breached?(password)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
require "net/http"
|
||||
|
||||
# Checks a password against the Have I Been Pwned breach corpus with the
|
||||
# k-anonymity range API: only the first 5 characters of its SHA-1 are sent,
|
||||
# never the password. If the service can't be reached the password is
|
||||
# allowed (logged), so an outage doesn't stop anyone changing a password.
|
||||
# PWNED_PASSWORDS_CHECK=false turns it off (e.g. no outbound internet).
|
||||
module PwnedPasswords
|
||||
API = "https://api.pwnedpasswords.com/range/".freeze
|
||||
|
||||
mattr_accessor :checker, default: ->(password) { lookup(password) }
|
||||
|
||||
def self.enabled? = ENV["PWNED_PASSWORDS_CHECK"] != "false"
|
||||
def self.breached?(password) = enabled? && password.present? && checker.call(password)
|
||||
|
||||
def self.lookup(password)
|
||||
sha1 = Digest::SHA1.hexdigest(password).upcase
|
||||
prefix, suffix = sha1[0, 5], sha1[5..]
|
||||
uri = URI("#{API}#{prefix}")
|
||||
req = Net::HTTP::Get.new(uri)
|
||||
req["Add-Padding"] = "true"
|
||||
req["User-Agent"] = "Simple-Aircraft-Manager"
|
||||
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 3, read_timeout: 3) { _1.request(req) }
|
||||
return false unless res.is_a?(Net::HTTPSuccess)
|
||||
res.body.each_line.any? do |line|
|
||||
hash, count = line.strip.split(":")
|
||||
hash == suffix && count.to_i.positive?
|
||||
end
|
||||
rescue StandardError => e
|
||||
Rails.logger.warn("[pwned passwords] check skipped: #{e.class}: #{e.message}")
|
||||
false
|
||||
end
|
||||
end
|
||||
@@ -62,7 +62,7 @@
|
||||
<ol class="<%= p_ %> list-decimal pl-5">
|
||||
<li>The signer opens the entry and chooses Sign. The entry is shown in full exactly as it will be certified (AC 2.2.4).</li>
|
||||
<li>They choose one of their own current certificates. The statement they will certify is shown with it, under the heading “Certified by” (2.2.2): for maintenance, “I certify that the work described in this entry was performed in accordance with 14 CFR Part 43, and I approve it for return to service with respect to that work”; for inspections, the 43.11(a)(5) statement; for preventive maintenance by a pilot, the corresponding statement.</li>
|
||||
<li>They prove who they are again: their password, or signing in again with single sign-on within the last five minutes (2.2.6), and confirm that they are signing with intent to sign (2.1.2.4–5).</li>
|
||||
<li>They prove who they are again: their password (with a code from their authenticator app, if they use one), or signing in again with single sign-on within the last five minutes (2.2.6), and confirm that they are signing with intent to sign (2.1.2.4–5).</li>
|
||||
<li>The system records the signer, the certificate (kind and number), the statement, the time (UTC), how they authenticated, their network address and browser, a SHA-256 fingerprint of the entry's content and a readable copy of it, and a server seal (HMAC) over the signature record (2.1.2.6, 2.2.5). The signer is told on screen and by email (2.2.3).</li>
|
||||
<li>Once signed, the entry and its components can't be edited or deleted (2.1.2.7–8, 2.2.7). A correction is made as a new entry that, once signed, supersedes the original; the original and its signature are kept and marked superseded (2.2.8).</li>
|
||||
<li>When someone no longer needs access, the responsible person disables their account: they can no longer sign in or sign, and their past signatures stay valid (2.2.6.4).</li>
|
||||
@@ -71,7 +71,7 @@
|
||||
|
||||
<h2 class="<%= h2 %>">7. Recordkeeping system controls</h2>
|
||||
<ul class="<%= p_ %> list-disc pl-5">
|
||||
<li><strong>Controlled access (3.2.1):</strong> personal accounts; roles per aircraft; sessions end after 30 days unused; rate-limited sign-in; changing an email or password needs the current password.</li>
|
||||
<li><strong>Controlled access (3.2.1):</strong> personal accounts; roles per aircraft; passwords of at least 12 characters, refused if known from a data breach; optional authenticator-app codes; accounts locked for 15 minutes after 10 failed sign-ins (the user is emailed); rate-limited sign-in; sessions end after 30 days unused; changing an email or password needs the current password.</li>
|
||||
<li><strong>Record preservation (3.2.2):</strong> every change to a maintenance record is kept with who, when and what changed, in a hash chain per aircraft that can't be edited; signed entries are locked.</li>
|
||||
<li><strong>Confidential information (3.2.3):</strong> records are visible only to the aircraft's users, and to share links an owner creates (scoped and optionally expiring).</li>
|
||||
<li><strong>Data corruption (3.2.4):</strong> nightly, the history chains and every signature's seal and fingerprint are checked; administrators are emailed on any problem.</li>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<%= f.errors_summary %>
|
||||
<%= f.field :name %>
|
||||
<%= f.field :email_address, as: :email, label: "Email", required: true %>
|
||||
<%= f.field :password, as: :password, hint: (user.persisted? ? "Leave blank to keep current password." : "At least 8 characters."), autocomplete: "new-password" %>
|
||||
<%= f.field :password, as: :password, hint: (user.persisted? ? "Leave blank to keep current password." : "At least #{User::PASSWORD_MIN} characters; not one known from a data breach."), autocomplete: "new-password" %>
|
||||
<%= f.field :password_confirmation, as: :password %>
|
||||
<%= f.field :admin, as: :checkbox, label: "Administrator", hint: "Admins can see and edit every aircraft and manage users." %>
|
||||
<div class="flex gap-2"><%= f.submit "Save" %><%= link_to "Cancel", admin_users_path, class: "btn-secondary" %></div>
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
<section class="card"><table class="table">
|
||||
<thead><tr><th>Name</th><th>Email</th><th>Aircraft</th><th>Last sign-in</th><th></th></tr></thead>
|
||||
<tbody><% @users.each do |u| %><tr>
|
||||
<td><%= u.name %> <% if u.admin? %><span class="badge-blue">Admin</span><% end %><% if u.sso_uid? %> <span class="badge-gray" title="Signs in with <%= Sso.label %>"><%= Sso.label %></span><% end %></td>
|
||||
<td><%= u.name %> <% if u.admin? %><span class="badge-blue">Admin</span><% end %><% if u.sso_uid? %> <span class="badge-gray" title="Signs in with <%= Sso.label %>"><%= Sso.label %></span><% end %><% if u.otp_enabled? %> <span class="badge-green" title="Authenticator app on">2FA</span><% end %><% if u.locked? %> <span class="badge-red" title="Too many failed sign-ins">Locked</span><% end %></td>
|
||||
<td><%= u.email_address %><% if u.certificates.any? %><div class="text-xs text-slate-500"><%= u.certificates.map { "#{_1.short_label} #{_1.number}" }.join(", ") %></div><% end %></td>
|
||||
<td class="text-xs"><%= u.aircraft_roles.map { "#{_1.aircraft.tail_number} (#{_1.role})" }.join(", ").presence || "—" %></td>
|
||||
<td class="text-xs text-slate-500"><%= u.last_signed_in_at ? "#{time_ago_in_words(u.last_signed_in_at)} ago" : "never" %></td>
|
||||
<td class="whitespace-nowrap text-right">
|
||||
<% if u.disabled? %><span class="badge-red mr-1">Disabled</span><%= button_to "Enable", enable_admin_user_path(u), method: :patch, class: "btn-secondary btn-sm", form: { class: "inline" } %>
|
||||
<% elsif u != current_user %><%= button_to "Disable", disable_admin_user_path(u), method: :patch, class: "btn-secondary btn-sm", form: { class: "inline", data: { turbo_confirm: "Disable #{u.email_address}? They'll be signed out and can't sign in or sign entries. Their past signatures are kept." } } %><% end %>
|
||||
<% if u.locked? %><%= button_to "Unlock", unlock_admin_user_path(u), method: :patch, class: "btn-secondary btn-sm", form: { class: "inline" } %><% end %>
|
||||
<% if u.otp_enabled? %><%= button_to "Reset 2FA", reset_two_factor_admin_user_path(u), method: :patch, class: "btn-secondary btn-sm", title: "Turn off their authenticator app (lost phone)", form: { class: "inline", data: { turbo_confirm: "Turn off two-factor for #{u.email_address}? Only do this after confirming it's really them." } } %><% end %>
|
||||
<%= link_to "Edit", edit_admin_user_path(u), class: "btn-secondary btn-sm" %></td>
|
||||
</tr><% end %></tbody>
|
||||
</table></section>
|
||||
|
||||
@@ -32,6 +32,12 @@
|
||||
<%= password_field_tag :password, nil, class: "input", autocomplete: "current-password" %>
|
||||
<p class="hint">Proves it's you signing, not someone at your keyboard.<%= " Or sign in again with #{Sso.label} below." if Sso.enabled? && current_user.sso_uid? %></p>
|
||||
</div>
|
||||
<% if current_user.otp_enabled? %>
|
||||
<div class="max-w-xs">
|
||||
<%= label_tag :otp_code, "Authenticator code", class: "label" %>
|
||||
<%= text_field_tag :otp_code, nil, class: "input w-32 tracking-widest", autocomplete: "one-time-code", inputmode: "numeric", maxlength: 20 %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if Sso.enabled? && current_user.sso_uid? %>
|
||||
<% fresh = session[:reauthenticated_at] && Time.zone.at(session[:reauthenticated_at]) > EntrySigner::REAUTH_WINDOW.ago %>
|
||||
|
||||
@@ -10,3 +10,6 @@
|
||||
</section>
|
||||
<% end %>
|
||||
<%= render "entry_signatures/form", entry: @entry, url: invited_signing_path(params[:token]), cancel_path: root_path %>
|
||||
<% unless current_user.otp_enabled? %>
|
||||
<p class="mx-auto mt-4 max-w-3xl text-sm text-slate-600">Recommended: <%= link_to "add an authenticator app", new_two_factor_path(return_to: request.path), class: "link" %> to your account, so your signature can't be made with a stolen password alone.</p>
|
||||
<% end %>
|
||||
@@ -11,7 +11,7 @@
|
||||
<% if @account_errors.present? %><div class="rounded-md bg-red-50 p-2 text-sm text-red-700"><%= @account_errors.to_sentence %></div><% end %>
|
||||
<div><label class="label">Email</label><input class="input" value="<%= @invitation.email %>" disabled></div>
|
||||
<div><%= label_tag :name, "Your name", class: "label" %><%= text_field_tag :name, params[:name], class: "input", required: true %></div>
|
||||
<div><%= label_tag :password, "Password", class: "label" %><%= password_field_tag :password, nil, class: "input", required: true, autocomplete: "new-password" %></div>
|
||||
<div><%= label_tag :password, "Password", class: "label" %><%= password_field_tag :password, nil, class: "input", required: true, autocomplete: "new-password", minlength: User::PASSWORD_MIN, maxlength: 72 %><p class="hint">At least <%= User::PASSWORD_MIN %> characters; not one known from a data breach.</p></div>
|
||||
<div><%= label_tag :password_confirmation, "Confirm password", class: "label" %><%= password_field_tag :password_confirmation, nil, class: "input", required: true, autocomplete: "new-password" %></div>
|
||||
<%= submit_tag "Create account", class: "btn-secondary" %>
|
||||
<% end %>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<%= f.field :email_address, as: :email, label: "Email" %>
|
||||
<%= f.field :reminder_emails, as: :checkbox, label: "Weekly maintenance reminders",
|
||||
hint: "A Monday email about overdue and upcoming inspections, ADs, parts and documents on aircraft you own, and certificates of yours about to expire. Only sent when something needs attention#{' (once email is set up)' unless MailSettings.configured?}." %>
|
||||
<%= f.field :password, as: :password, label: "New password", hint: "Leave blank to keep your current password.", autocomplete: "new-password" %>
|
||||
<%= f.field :password, as: :password, label: "New password", hint: "Leave blank to keep your current password. At least #{User::PASSWORD_MIN} characters; not one known from a data breach.", autocomplete: "new-password" %>
|
||||
<%= f.field :password_confirmation, as: :password, label: "Confirm new password", autocomplete: "new-password" %>
|
||||
<div>
|
||||
<%= label_tag "user[current_password]", "Current password", class: "label" %>
|
||||
@@ -31,6 +31,21 @@
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
<section class="card card-body mt-5 max-w-md" id="two-factor">
|
||||
<h2 class="card-title">Two-factor sign-in</h2>
|
||||
<% if @user.otp_enabled? %>
|
||||
<p class="mt-1 text-sm text-slate-600"><span class="badge-green">On</span> since <%= @user.otp_enabled_at.to_date %>: signing in with your password or an emailed link also asks for a code from your authenticator app. <%= @user.recovery_codes_left %> recovery codes left.</p>
|
||||
<%= form_with url: two_factor_path, class: "mt-3 flex flex-wrap items-end gap-2" do |f| %>
|
||||
<div><%= label_tag :code, "Current code or a recovery code", class: "label" %><%= text_field_tag :code, nil, required: true, autocomplete: "one-time-code", class: "input w-44" %></div>
|
||||
<%= button_tag "New recovery codes", type: "submit", formaction: recovery_codes_two_factor_path, class: "btn-secondary btn-sm" %>
|
||||
<%= button_tag "Turn off", type: "submit", name: "_method", value: "delete", class: "btn-secondary btn-sm", data: { turbo_confirm: "Turn off two-factor sign-in?" } %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<p class="mt-1 text-sm text-slate-600">Add a code from an authenticator app on your phone to password and emailed-link sign-in, so a stolen password alone can't get in.<%= " (Signing in with #{Sso.label} uses its own second factor.)" if Sso.enabled? %></p>
|
||||
<div class="mt-3"><%= link_to "Set up", new_two_factor_path, class: "btn-secondary btn-sm" %></div>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
<section class="card card-body mt-5 max-w-md" id="certificates">
|
||||
<h2 class="card-title">Certificates</h2>
|
||||
<p class="mt-1 text-sm text-slate-600">Your FAA certificates, for signing logbook entries: “Sign as” fills in your name, the kind of certificate and its number.</p>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<% content_for :title, "Sign in" %>
|
||||
<div class="mx-auto max-w-sm">
|
||||
<h1 class="mb-4 text-2xl font-bold">Authenticator code</h1>
|
||||
<%= form_with url: two_factor_session_path, class: "card card-body space-y-4" do |form| %>
|
||||
<p class="text-sm text-slate-600">Enter the 6-digit code from your authenticator app. Lost your phone? Enter one of your recovery codes instead.</p>
|
||||
<div><%= form.label :code, "Code", class: "label" %>
|
||||
<%= form.text_field :code, required: true, autofocus: true, autocomplete: "one-time-code", inputmode: "text", maxlength: 20, class: "input text-lg tracking-widest" %></div>
|
||||
<%= form.submit "Continue", class: "btn-primary w-full justify-center" %>
|
||||
<p class="text-center text-sm"><%= link_to "Start again", new_session_path, class: "link" %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -0,0 +1,2 @@
|
||||
<p>Your Simple Aircraft Manager account (<%= @user.email_address %>) was locked for <%= User::LOCK_FOR.inspect %> after <%= User::LOCK_AFTER %> failed sign-in attempts in a row.</p>
|
||||
<p>If that was you, wait and try again. If it wasn't, someone may be guessing your password: change it once you're back in (Profile), turn on an authenticator app, and tell your administrator.</p>
|
||||
@@ -0,0 +1,3 @@
|
||||
Your Simple Aircraft Manager account (<%= @user.email_address %>) was locked for <%= User::LOCK_FOR.inspect %> after <%= User::LOCK_AFTER %> failed sign-in attempts in a row.
|
||||
|
||||
If that was you, wait and try again. If it wasn't, someone may be guessing your password: change it once you're back in (Profile), turn on an authenticator app, and tell your administrator.
|
||||
@@ -5,7 +5,7 @@
|
||||
<%= f.errors_summary %>
|
||||
<%= f.field :name %>
|
||||
<%= f.field :email_address, as: :email, label: "Email", required: true %>
|
||||
<%= f.field :password, as: :password, required: true, hint: "At least 8 characters." %>
|
||||
<%= f.field :password, as: :password, required: true, hint: "At least #{User::PASSWORD_MIN} characters; not one known from a data breach." %>
|
||||
<%= f.field :password_confirmation, as: :password, required: true %>
|
||||
<%= f.submit "Create Admin Account", class: "btn-primary w-full justify-center" %>
|
||||
<% end %>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<% content_for :title, "Recovery codes" %>
|
||||
<section class="card card-body mx-auto max-w-md space-y-4">
|
||||
<h1 class="text-2xl font-bold">Save your recovery codes</h1>
|
||||
<p class="text-sm text-slate-600">Two-factor is on. If you lose your phone, each of these codes signs you in once in place of an authenticator code. Print them or keep them in a password manager: they won't be shown again.</p>
|
||||
<ul class="grid grid-cols-2 gap-2 rounded-md bg-slate-50 p-4 font-mono text-sm ring-1 ring-slate-200">
|
||||
<% @codes.each do |c| %><li><%= c %></li><% end %>
|
||||
</ul>
|
||||
<%= link_to "Done", back_path, class: "btn-primary self-start" %>
|
||||
</section>
|
||||
@@ -0,0 +1,17 @@
|
||||
<% content_for :title, "Set up two-factor" %>
|
||||
<section class="card card-body mx-auto max-w-md space-y-4">
|
||||
<h1 class="text-2xl font-bold">Set up an authenticator app</h1>
|
||||
<p class="text-sm text-slate-600">After your password (or an emailed sign-in link) you'll also enter a 6-digit code from an app on your phone, so a stolen password alone can't get in. Any authenticator app works: Google Authenticator, Microsoft Authenticator, 1Password, Authy…</p>
|
||||
<ol class="list-decimal space-y-3 pl-5 text-sm">
|
||||
<li>In the app, add an account and scan this code:
|
||||
<div class="mt-2 inline-block rounded bg-white p-2"><%= image_tag @qr_data_uri, alt: "QR code for your authenticator app", class: "h-48 w-48" %></div>
|
||||
<p class="mt-1 text-xs text-slate-500">Can't scan it? Enter this key instead: <code class="break-all"><%= @secret.scan(/.{4}/).join(" ") %></code></p></li>
|
||||
<li>Enter the code the app shows:
|
||||
<%= form_with url: two_factor_path, class: "mt-2 flex flex-wrap items-end gap-2" do |f| %>
|
||||
<%= hidden_field_tag :return_to, params[:return_to] %>
|
||||
<%= f.text_field :code, required: true, autocomplete: "one-time-code", inputmode: "numeric", maxlength: 7, class: "input w-32 text-lg tracking-widest", "aria-label": "Code" %>
|
||||
<%= f.submit "Turn on", class: "btn-primary" %>
|
||||
<% end %></li>
|
||||
</ol>
|
||||
<p class="text-sm"><%= link_to "Not now", back_path, class: "link" %></p>
|
||||
</section>
|
||||
Reference in new issue
Block a user