Skip to content

Commit 701db6b

Browse files
committed
Another round of CI fixing
* A few specs depending on environment variables * CI prod setup smoketest can't decode the encrypted data - fall back to environment variables in this case
1 parent ac35768 commit 701db6b

4 files changed

Lines changed: 33 additions & 0 deletions

File tree

.github/workflows/prod-boot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ jobs:
1818
cp deploy/.env.example deploy/.env
1919
# Override secrets/SSL for CI boot
2020
ruby -e "require 'securerandom'; puts \"SECRET_KEY_BASE=#{SecureRandom.hex(64)}\"" >> deploy/.env
21+
# AR encryption keys — production.rb normally loads these from
22+
# credentials, but CI has no RAILS_MASTER_KEY. Inject random values
23+
# via env so db:prepare can boot.
24+
ruby -e "require 'securerandom'; puts \"RAILS_AR_ENCRYPTION_PRIMARY_KEY=#{SecureRandom.alphanumeric(32)}\"" >> deploy/.env
25+
ruby -e "require 'securerandom'; puts \"RAILS_AR_ENCRYPTION_DETERMINISTIC_KEY=#{SecureRandom.alphanumeric(32)}\"" >> deploy/.env
26+
ruby -e "require 'securerandom'; puts \"RAILS_AR_ENCRYPTION_SALT=#{SecureRandom.alphanumeric(32)}\"" >> deploy/.env
2127
echo "FORCE_SSL=false" >> deploy/.env
2228
echo "APP_HOST=localhost" >> deploy/.env
2329
# Copy Postgres config template and shrink memory settings

config/environments/production.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@
9898
# Only use :id for inspections in production.
9999
config.active_record.attributes_for_inspect = [ :id ]
100100

101+
# Active Record encryption keys. Default to credentials (decrypted with
102+
# RAILS_MASTER_KEY); allow RAILS_AR_ENCRYPTION_* env overrides so a smoke-test
103+
# boot (e.g. prod-boot CI) can run without baking a master key into the image.
104+
ar_enc_env = {
105+
primary_key: ENV["RAILS_AR_ENCRYPTION_PRIMARY_KEY"],
106+
deterministic_key: ENV["RAILS_AR_ENCRYPTION_DETERMINISTIC_KEY"],
107+
key_derivation_salt: ENV["RAILS_AR_ENCRYPTION_SALT"]
108+
}
109+
if ar_enc_env.values.all?(&:present?)
110+
config.active_record.encryption.primary_key = ar_enc_env[:primary_key]
111+
config.active_record.encryption.deterministic_key = ar_enc_env[:deterministic_key]
112+
config.active_record.encryption.key_derivation_salt = ar_enc_env[:key_derivation_salt]
113+
end
114+
101115
# Enable DNS rebinding protection and other `Host` header attacks.
102116
# config.hosts = [
103117
# "example.com", # Allow requests from example.com

deploy/.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ SECRET_KEY_BASE=change-me
2020
# leaving the previous values present so existing rows stay decryptable.
2121
RAILS_MASTER_KEY=change-me
2222

23+
# Optional ENV override for Active Record encryption keys. If all three are set,
24+
# production.rb uses them instead of credentials — handy for smoke-test boots
25+
# (e.g. prod-boot CI) where a master key is not available. Leave unset in real
26+
# deployments so credentials remain the single source of truth.
27+
# RAILS_AR_ENCRYPTION_PRIMARY_KEY=
28+
# RAILS_AR_ENCRYPTION_DETERMINISTIC_KEY=
29+
# RAILS_AR_ENCRYPTION_SALT=
30+
2331
# Database (used by DATABASE_URL below)
2432
POSTGRES_USER=hackorum
2533
POSTGRES_PASSWORD=hackorum

spec/services/oauth/token_refresher_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
require 'rails_helper'
22

33
RSpec.describe OAuth::TokenRefresher do
4+
before do
5+
ENV['GOOGLE_CLIENT_ID'] ||= 'test-client-id'
6+
ENV['GOOGLE_CLIENT_SECRET'] ||= 'test-client-secret'
7+
end
8+
49
let(:identity) {
510
create(:identity, refresh_token: 'r1', access_token: nil,
611
access_token_expires_at: nil)

0 commit comments

Comments
 (0)