Skip to content

Commit c75dac7

Browse files
kcdragonclaude
andauthored
Gate the site behind HTTP Basic Auth for pre-release (#33)
The app is deployed but not ready for public release, so add a coarse shared-password lock in front of the whole site, on top of the existing session auth. - ApplicationController runs http_basic_authenticate_with in production only, reading credentials from Rails encrypted credentials. The /up health check is unaffected (Rails::HealthController doesn't inherit it), so Kamal proxy health checks keep working. - Store the basic_auth username/password in environment-specific production credentials (config/credentials/production.yml.enc). - .kamal/secrets pulls RAILS_MASTER_KEY (the production key) from 1Password with an env-var fallback. - Ignore config/credentials/*.key so the production key is never committed. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f5ef3f0 commit c75dac7

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@
4040
/app/assets/builds/*
4141
!/app/assets/builds/.keep
4242
/.idea
43+
44+
# Ignore key files for decrypting credentials and more.
45+
/config/credentials/*.key
46+

.kamal/secrets

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
# Grab the registry password from ENV
1717
# KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD
1818

19-
# Improve security by using a password manager. Never check config/master.key into git!
20-
RAILS_MASTER_KEY=$(cat config/master.key)
19+
# Decrypts config/credentials/production.yml.enc. Read the production key from
20+
# 1Password on the laptop; falls back to the env var if `op` is unavailable.
21+
RAILS_MASTER_KEY=$(op read "op://Personal/Community Foundations/keys/PRODUCTION" 2>/dev/null || printenv RAILS_MASTER_KEY)
2122

2223
# GHCR personal access token (write:packages/read:packages). Read from 1Password
2324
# on the laptop; falls back to the env var if `op` is unavailable.

app/controllers/application_controller.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
class ApplicationController < ActionController::Base
2+
# Pre-release lock: gate the whole site behind a shared HTTP Basic password.
3+
# Runs before tenant/session resolution. Production only; the /up health check
4+
# is unaffected because Rails::HealthController does not inherit from here.
5+
if Rails.env.production?
6+
http_basic_authenticate_with(
7+
name: Rails.application.credentials.dig(:basic_auth, :username),
8+
password: Rails.application.credentials.dig(:basic_auth, :password)
9+
)
10+
end
11+
212
include SetCurrentOrganization # resolves Current.organization first
313
include Authentication # then resumes the session / Current.user
414

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
97luwAcQGslJIAFEcWNvbdiLnvhLy9ny+kayvBRiXK83C3BtpBFggxRuc2V4uZWeU00+PRBLPN6aQWSk/1wEtRvyl7I5eFRkS7ThCfKc51dJilEm7R2e4ENHV3pN+jQB9oxRIeKE2TYBtIZaMKpmt7bWbvpkN+9qKl0BjnIa0AbkX8/LmAzK5crUsm75HbSaW7f7244WpQ/vjWcuICH8BE+6E4MX0ketNeS9hi3YMD/Ry6vs+oSMTTb4uPT50QugZMfbSz/pLVJHKcnIUtpxmV4ocUOFCSuJOV5ehAuzDRv4au/xwvP+84/pVzenW/a61BShaS0/KziqbFD6BN99du4E4lUkb0yhHxainSIVqB1iBlV38h3iWSerytxSYTJRk7nH1dx9MxGwftdMdbNGMVygHO4HL4ppdEz6sp4=--UBnYSBFV6lXze2Ay--sDdwbw7FX5+HMnpVK/18Aw==

0 commit comments

Comments
 (0)