Skip to content

Commit

Permalink
Merge pull request #29 from SonicGarden/dev
Browse files Browse the repository at this point in the history
次回リリース
  • Loading branch information
interu authored Nov 27, 2023
2 parents 44c2e32 + 0b8b93d commit c8a6260
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 76 deletions.
110 changes: 70 additions & 40 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
PATH
remote: .
specs:
sg_fargate_rails (0.1.11)
sg_fargate_rails (0.1.12)
aws-sdk-ec2 (~> 1.413)
aws-sdk-scheduler (~> 1.10)
lograge (~> 0.12)
puma
rack-attack (~> 6.6)

GEM
remote: https://rubygems.org/
specs:
actionpack (7.0.4.2)
actionview (= 7.0.4.2)
activesupport (= 7.0.4.2)
rack (~> 2.0, >= 2.2.0)
actionpack (7.1.1)
actionview (= 7.1.1)
activesupport (= 7.1.1)
nokogiri (>= 1.8.5)
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actionview (7.0.4.2)
activesupport (= 7.0.4.2)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actionview (7.1.1)
activesupport (= 7.1.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activesupport (7.0.4.2)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activesupport (7.1.1)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
aws-eventstream (1.2.0)
aws-partitions (1.835.0)
Expand All @@ -44,50 +50,71 @@ GEM
aws-sigv4 (~> 1.1)
aws-sigv4 (1.6.0)
aws-eventstream (~> 1, >= 1.0.2)
base64 (0.2.0)
bigdecimal (3.1.4)
builder (3.2.4)
concurrent-ruby (1.2.0)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
crass (1.0.6)
diff-lcs (1.5.0)
drb (2.2.0)
ruby2_keywords
erubi (1.12.0)
i18n (1.12.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
io-console (0.6.0)
irb (1.8.3)
rdoc
reline (>= 0.3.8)
jmespath (1.6.2)
lograge (0.12.0)
actionpack (>= 4)
activesupport (>= 4)
railties (>= 4)
request_store (~> 1.0)
loofah (2.19.1)
loofah (2.21.4)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
method_source (1.0.0)
minitest (5.17.0)
nokogiri (>= 1.12.0)
minitest (5.20.0)
mutex_m (0.2.0)
nio4r (2.5.9)
nokogiri (1.14.2-arm64-darwin)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.14.2-x86_64-linux)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
psych (5.1.1.1)
stringio
puma (6.3.0)
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)
racc (1.7.3)
rack (3.0.8)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
rack (>= 1.3)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
rackup (2.1.0)
rack (>= 3)
webrick (~> 1.8)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.5.0)
loofah (~> 2.19, >= 2.19.1)
railties (7.0.4.2)
actionpack (= 7.0.4.2)
activesupport (= 7.0.4.2)
method_source
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.1.1)
actionpack (= 7.1.1)
activesupport (= 7.1.1)
irb
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rake (13.1.0)
rdoc (6.6.0)
psych (>= 4.0.0)
reline (0.4.0)
io-console (~> 0.5)
request_store (1.5.1)
rack (>= 1.4)
rspec (3.12.0)
Expand All @@ -103,10 +130,13 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
thor (1.2.1)
ruby2_keywords (0.0.5)
stringio (3.0.9)
thor (1.3.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
zeitwerk (2.6.7)
webrick (1.8.1)
zeitwerk (2.6.12)

PLATFORMS
arm64-darwin-22
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ Add this line to your application's Gemfile:
```ruby
gem 'sg_fargate_rails', git: 'https://github.com/SonicGarden/sg_fargate_rails.git'
```

Blazerを利用している場合は、以下のgemをインストールしてください。

```ruby
gem 'blazer-plus'
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sg_fargate_rails.
Expand Down
7 changes: 6 additions & 1 deletion lib/sg_fargate_rails/config.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
module SgFargateRails
class Config
attr_accessor :paths_to_allow_access_only_from_proxy
attr_reader :proxy_ip_addresses
attr_accessor :middleware_enabled

# 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?
self.middleware_enabled = !Rails.env.development? && !Rails.env.test?
end

def proxy_ip_addresses=(ip_addresses)
Expand Down
4 changes: 2 additions & 2 deletions lib/sg_fargate_rails/maintenance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(app, options = {})
end

def call(env)
if maintenance_mode?(env) && !public_file_access?(env) && !proxy_access?(Rack::Request.new(env))
if maintenance_mode?(env) && !public_file_access?(env) && !proxy_access?(ActionDispatch::Request.new(env))
headers = { 'Content-Type' => 'text/html' }
[503, headers, File.open(maintenance_file_path)]
else
Expand Down Expand Up @@ -38,7 +38,7 @@ def maintenance_file_path
end

def proxy_access?(req)
SgFargateRails.config.proxy_access?(req.ip) || req.forwarded_for&.any? { |forwarded_for| SgFargateRails.config.proxy_access?(forwarded_for) }
SgFargateRails.config.proxy_access?(req.remote_ip)
end
end
end
24 changes: 0 additions & 24 deletions lib/sg_fargate_rails/rack_attack.rb

This file was deleted.

27 changes: 21 additions & 6 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 @@ -11,14 +10,30 @@ class Railtie < ::Rails::Railtie
load File.expand_path('../tasks/sg_fargate_rails.rake', __dir__)
end

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

initializer :initialize_sg_fargate_rails, after: :load_config_initializers do |app|
if SgFargateRails.config.middleware_enabled
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
app.config.middleware.insert_after SgFargateRails::RemoteIp, SgFargateRails::Maintenance
end

if defined?(::Blazer)
unless defined?(::Blazer::Plus)
raise SgFargateRails::Error, 'Please install blazer-plus gem.'
end

Blazer::Plus.blazer_danger_actionable_method ||= ->(blazer_user) { blazer_user.email.ends_with?('@sonicgarden.jp') }
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
Expand Down
2 changes: 1 addition & 1 deletion lib/sg_fargate_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SgFargateRails
VERSION = "0.1.11"
VERSION = "0.1.12"
end
2 changes: 0 additions & 2 deletions sg_fargate_rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ 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'

spec.add_development_dependency 'rspec'
end

0 comments on commit c8a6260

Please sign in to comment.