Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[review] 本番環境のgood_jobダッシュボードにはproxy経由以外ではアクセス不可に #28

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ PATH
aws-sdk-scheduler (~> 1.10)
lograge (~> 0.12)
puma
rack-attack (~> 6.6)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -71,8 +70,6 @@ GEM
nio4r (~> 2.0)
racc (1.6.2)
rack (2.2.6.2)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-test (2.0.2)
rack (>= 1.3)
rails-dom-testing (2.0.3)
Expand Down
5 changes: 4 additions & 1 deletion lib/sg_fargate_rails/config.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
module SgFargateRails
class Config
attr_accessor :paths_to_allow_access_only_from_proxy
attr_reader :proxy_ip_addresses

# NOTE: good_jobダッシュボードへのアクセスをproxy経由のアクセスに制限するかどうか
attr_accessor :restrict_access_to_good_job_dashboard

def initialize
self.proxy_ip_addresses = ENV['SG_PROXY_IP_ADDRESSES']
self.restrict_access_to_good_job_dashboard = Rails.env.production?
end

def proxy_ip_addresses=(ip_addresses)
Expand Down
24 changes: 0 additions & 24 deletions lib/sg_fargate_rails/rack_attack.rb

This file was deleted.

13 changes: 10 additions & 3 deletions lib/sg_fargate_rails/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'sg_fargate_rails/adjust_cloudfront_headers'
require 'sg_fargate_rails/healthcheck'
require 'sg_fargate_rails/maintenance'
require 'sg_fargate_rails/rack_attack'
require 'sg_fargate_rails/remote_ip'
require 'sg_fargate_rails/task_protection'

Expand All @@ -13,13 +12,21 @@ class Railtie < ::Rails::Railtie

initializer :initialize_sg_fargate_rails do |app|
unless ::Rails.env.in?(%w[development test])
SgFargateRails::RackAttack.setup

app.config.middleware.insert 0, SgFargateRails::AdjustCloudfrontHeaders
app.config.middleware.insert 1, SgFargateRails::Healthcheck
app.config.middleware.insert 2, SgFargateRails::Maintenance
app.config.middleware.swap ActionDispatch::RemoteIp, SgFargateRails::RemoteIp, app.config.action_dispatch.ip_spoofing_check, app.config.action_dispatch.trusted_proxies
end

ActiveSupport.on_load(:good_job_application_controller) do
before_action :sg_fargate_rails_proxy_access!, if: -> { SgFargateRails.config.restrict_access_to_good_job_dashboard }

def sg_fargate_rails_proxy_access!
unless SgFargateRails.config.proxy_access?(request.remote_ip)
render plain: 'Forbidden', status: :forbidden
end
end
end
end
end
end
1 change: 0 additions & 1 deletion sg_fargate_rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Gem::Specification.new do |spec|

spec.add_dependency 'puma'
spec.add_dependency 'lograge', '~> 0.12'
spec.add_dependency 'rack-attack', '~> 6.6'
spec.add_dependency 'aws-sdk-ec2', '~> 1.413'
spec.add_dependency 'aws-sdk-scheduler', '~> 1.10'

Expand Down