Skip to content

Commit

Permalink
use encrypted credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
JackBlackLight committed Jan 7, 2025
1 parent 750c841 commit d01de29
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ yarn-debug.log*
.yarn-integrity
# Ignore sitemaps
/public/sitemap*.xml.gz
/public/sitemaps/*.xml.gz
/public/sitemaps/*.xml.gz
/config/credentials/*.key
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ RUN chmod +x /usr/bin/entrypoint.sh

WORKDIR /app

RUN gem install activesupport

RUN bundle install

RUN yarn install --ignore-engines
Expand Down
65 changes: 39 additions & 26 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,64 @@
require 'active_support'
require 'active_support/core_ext'
require 'yaml'

source 'https://rubygems.org'

def font_awesome_token
return ENV['FONT_AWESOME_TOKEN'] if ENV['FONT_AWESOME_TOKEN'] && ENV['FONT_AWESOME_TOKEN'] != ''
YAML.load(File.read("./config/secrets.yml")).dig('shared', 'font_awesome_token') if File.exist?("./config/secrets.yml")

encrypted_data = File.binread('./config/credentials/development.yml.enc')
master_key = File.read('./config/credentials/development.key').strip

crypt = ActiveSupport::MessageEncryptor.new(
[master_key].pack('H*'),
cipher: 'aes-128-gcm'
)

decrypted_credentials = crypt.decrypt_and_verify(encrypted_data)
credentials = YAML.safe_load(decrypted_credentials)
credentials.dig('shared', 'font_awesome_token')
end

gem 'bigdecimal', '~>3.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'font-awesome-sass', '~> 6.4.0'
gem 'rails', '~> 6.1.0'
gem 'shakapacker', '7.2.2'
gem 'sassc'
gem "font-awesome-sass", "~> 6.4.0"
gem 'shakapacker', '7.2.2'
fa_token = font_awesome_token
if fa_token
source "https://token:#{fa_token}@dl.fontawesome.com/basic/fontawesome-pro/ruby/" do
gem "font-awesome-pro-sass", "~> 6.4.0"
gem 'font-awesome-pro-sass', '~> 6.4.0'
end
else
raise 'ERROR: You are missing font_awesome_token in secrets.yml. It is required for `bundle install` to work.'
end
gem 'bootsnap', '~> 1.9.3'
gem 'actionpack-action_caching'
gem 'bootsnap', '~> 1.9.3'
# Hydra stack
gem 'nokogiri', '~> 1.15.2' # update past 1.10 requires alma
gem 'blacklight', '~> 7.33.1'
gem 'view_component', '~>2.82.0'
gem 'active-fedora', '~> 8.7'
gem 'blacklight', '~> 7.33.1'
gem 'nokogiri', '~> 1.15.2' # update past 1.10 requires alma
gem 'rdf', '>= 1.1.5'
gem 'rdf-vocab'
gem 'view_component', '~>2.82.0'

# carrierwave for file uploads
gem 'carrierwave', '~> 1.3'
#gem 'rubydora', :path => '../rubydora'
# gem 'rubydora', :path => '../rubydora'
gem 'rubydora'

gem 'cul_omniauth', '~> 0.7.0'
gem 'cancancan'
#gem 'cul_omniauth', git: 'https://github.com/cul/cul_omniauth', branch: '0.5.x'
gem 'cul_omniauth', '~> 0.7.0'
# gem 'cul_omniauth', git: 'https://github.com/cul/cul_omniauth', branch: '0.5.x'
gem 'active-triples', git: 'https://github.com/cul/ActiveTriples', branch: 'deprecation_update'

# Use wowza token gem for generating tokens
gem 'wowza-secure_token', '0.0.1'

# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"
gem 'sqlite3', '~> 1.4'

# Use mysql2 gem for mysql connections
gem 'mysql2', '~> 0.5.2'
Expand Down Expand Up @@ -87,53 +100,53 @@ gem 'addressable', '~> 2.8.0'
# gem 'debugger', group: [:development, :test]

gem 'devise'
gem "devise-guests", "~> 0.3"
gem 'devise-guests', '~> 0.3'

# Gem min versions that are only specified here because of vulnerabilities in earlier versions:
gem 'rubyzip', '>= 1.2.1'
gem 'rack-protection', '>= 1.5.5'
gem 'loofah', '>= 2.2.1'
gem 'best_type'
gem 'loofah', '>= 2.2.1'
gem 'rack-protection', '>= 1.5.5'
gem 'rubyzip', '>= 1.2.1'

gem 'sitemap_generator'

group :development, :test do
# Use Capistrano for deployment
gem 'capistrano', '~> 3.17.3', require: false
# Rails and Bundler integrations were moved out from Capistrano 3
gem 'capistrano-rails', '~> 1.4', require: false
gem 'capistrano-bundler', '~> 1.1', require: false
gem 'capistrano-rails', '~> 1.4', require: false
# "idiomatic support for your preferred ruby version manager"
gem 'capistrano-rvm', '~> 0.1', require: false
# The `deploy:restart` hook for passenger applications is now in a separate gem
# Just add it to your Gemfile and require it in your Capfile.
gem 'capistrano-passenger', '~> 0.2', require: false
# Use net-ssh >= 4.2 to prevent warnings with Ruby 2.4
gem 'capybara', '~> 3.32'
gem 'net-ssh', '>= 4.2'
gem 'rspec-rails'
gem 'rspec-json_expectations'
gem 'react_on_rails'
gem 'capybara', '~> 3.32'
gem 'rspec-json_expectations'
gem 'rspec-rails'
# For testing with chromedriver for headless-browser JavaScript testing
gem 'selenium-webdriver', '~> 4.16.0'
gem 'database_cleaner'
gem 'factory_bot_rails'
gem 'selenium-webdriver', '~> 4.16.0'
gem 'rubocop', '~> 0.53.0', require: false
gem 'rubocop-rspec', '>= 1.20.1', require: false
gem 'rubocop-rails_config', require: false
gem 'listen'
gem 'rubocop-rails_config', require: false
gem 'rubocop-rspec', '>= 1.20.1', require: false
end

# Add unicorn as available app server
#gem 'unicorn'
# gem 'unicorn'

# Use Thin for local development
#gem "thin"
# gem "thin"

# everybody loves rainbows
gem 'rainbow', '~> 3.0'

# Use Puma for local development
gem 'puma', '~> 5.2'

gem "ox", "~> 2.14"
gem 'ox', '~> 2.14'
1 change: 1 addition & 0 deletions config/credentials/development.yml.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kDGK4xn/oPFgPC8i8M2f7vXz4JMQcJ9kIfV74FoJl3r18SEscaenr/ukvigsrllLTuYFGUd4+LqaK0IlurYM7bTuqVwlex1gD4uL8frxvIW3ndsl4/005mDxw+RnoOidvd684gWGczAgm663PQDT5l2SThbAQ+e+WDIO5wD1RCRnpHI8KcoSYDGrOoQF02XjSDtxSIce2BZcU123t1sSntWRzaRJhsSRb4MKB7sc7p7ruJNPFMB3bgoC7B682JCS0zc/tCMAJNiQFThBQetgnTOQef8tFBpo1dCDyo2lniQGs9h3oD7KS8pX0GfvBT1OLauC57bvSuhcRyQO34GwfB8ohcZ3F2+py83Lr6vNXuHCRgNH8yhAHVxLkQwCGKSrJHTpIZKnezvDjmbvHQok68P7YLIN9RdM+Hu8+PGuooIHJTQZSq36hOcf6MSVYQcjAnyfLI3/c1AgZC7moI7qbTCFvwi0/mVN0kWEi2Hiy0yL85HjTMH1vn99IjBBARaFRyZ9SdWehFoxFlJwuneSw5v83PqWRdf5k5ziVq0x6IWY6TVYpbq/i6Cf3IsM--gsv8Dy8iqoJyezVI--knbK6R45DH+40kUwiERIcQ==
6 changes: 5 additions & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
set :log_level, :info

# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log','tmp/pids', 'public/images/sites', 'node_modules', 'public/packs', 'public/sitemaps')
set :linked_dirs, fetch(:linked_dirs, []).push('log','tmp/pids', 'public/images/sites', 'node_modules', 'public/packs', 'public/sitemaps','config/credentials')

# Default value for keep_releases is 5
set :keep_releases, 3
Expand All @@ -56,6 +56,10 @@
"public/robots.txt"
)

Dir.glob('config/credentials/*.yml.enc').each do |file|
append :linked_files, file
end

namespace :deploy do
desc "Report the environment"
task :report do
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing
# confirmation, reset password and unlock tokens in the database.
config.secret_key = Rails.application.config_for(:secrets)[:devise_secret_key]
config.secret_key = Rails.application.credentials.dig(Rails.env.to_sym, :devise_secret_key)

# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/secret_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Make sure your secret_key_base is kept private
# if you're sharing your code publicly.
Rails.application.config.secret_key_base = Rails.application.config_for(:secrets)[:secret_key_base]
Rails.application.config.secret_key_base = Rails.application.credentials.dig(Rails.env.to_sym, :secret_key_base)
if Blacklight.respond_to? :secret_key
Blacklight.secret_key = Rails.application.config.secret_key_base
end
2 changes: 1 addition & 1 deletion config/initializers/session_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

cookie_opts = ["development", "test"].include?(Rails.env.to_s) ? {} : { same_site: :none, secure: true }
Rails.application.config.session_store(:cookie_store,
key: Rails.application.config.secret_key_base = Rails.application.config_for(:secrets)[:session_store_key],
key: Rails.application.config.secret_key_base = Rails.application.credentials.dig(Rails.env.to_sym, :session_store_key),
**cookie_opts
)
10 changes: 0 additions & 10 deletions config/templates/secrets.template.yml.erb

This file was deleted.

0 comments on commit d01de29

Please sign in to comment.