-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into kzkn-20230930-task-protection
- Loading branch information
Showing
7 changed files
with
37 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
module SgFargateRails | ||
class Config | ||
attr_accessor :proxy_ip_addresses, :paths_to_allow_access_only_from_proxy | ||
attr_accessor :paths_to_allow_access_only_from_proxy | ||
attr_reader :proxy_ip_addresses | ||
|
||
def initialize | ||
self.proxy_ip_addresses = ENV['SG_PROXY_IP_ADDRESSES'] | ||
end | ||
|
||
def proxy_ip_addresses=(ip_addresses) | ||
@proxy_ip_addresses = Array(ip_addresses).flat_map do |ip_address_str| | ||
ip_address_str.split(',').map(&:strip).reject(&:blank?).map { |ip| IPAddr.new(ip) } | ||
end | ||
end | ||
|
||
def proxy_access?(ip_address) | ||
@proxy_ip_addresses.any? { |proxy_ip_address| proxy_ip_address.include?(ip_address) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module SgFargateRails | ||
# NOTE: HTTP_CLOUDFRONT_VIEWER_ADDRESSを考慮するように上書きしている | ||
# SEE: https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/middleware/remote_ip.rb | ||
class RemoteIp < ActionDispatch::RemoteIp | ||
def call(env) | ||
req = ActionDispatch::Request.new env | ||
# NOTE: HTTP_CLOUDFRONT_VIEWER_ADDRESSヘッダには127.0.0.1:3000といったIP4アドレスや2406:2d40:3090:af00:25c1:6071:b820:8e47:3000といったIP6アドレスが入っている | ||
req.remote_ip = req.headers['HTTP_CLOUDFRONT_VIEWER_ADDRESS'] ? req.headers['HTTP_CLOUDFRONT_VIEWER_ADDRESS'].remove(/:\d+$/) : ActionDispatch::RemoteIp::GetIp.new(req, check_ip, proxies) | ||
@app.call(req.env) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module SgFargateRails | ||
VERSION = "0.1.6" | ||
VERSION = "0.1.8" | ||
end |