Allow specifying multiple ips for webclients #2744

This commit is contained in:
Martin Lensment 2015-07-20 16:57:12 +03:00 committed by Priit Tark
parent 7743f7caac
commit dff7e3047d
6 changed files with 15 additions and 12 deletions

View file

@ -8,7 +8,8 @@ module Repp
end end
before do before do
if request.ip != ENV['webclient_ip'] webclient_request = ENV['webclient_ips'].split(',').map(&:strip).include?(request.ip)
unless webclient_request
error! I18n.t('ip_is_not_whitelisted'), 401 unless @current_user.registrar.api_ip_white?(request.ip) error! I18n.t('ip_is_not_whitelisted'), 401 unless @current_user.registrar.api_ip_white?(request.ip)
end end
@ -20,7 +21,7 @@ module Repp
message = 'Certificate mismatch! Cert common name should be:' message = 'Certificate mismatch! Cert common name should be:'
request_name = env['HTTP_SSL_CLIENT_S_DN_CN'] request_name = env['HTTP_SSL_CLIENT_S_DN_CN']
if request.ip == ENV['webclient_ip'] if webclient_request
webclient_cert_name = ENV['webclient_cert_common_name'] || 'webclient' webclient_cert_name = ENV['webclient_cert_common_name'] || 'webclient'
error! "Webclient #{message} #{webclient_cert_name}", 401 if webclient_cert_name != request_name error! "Webclient #{message} #{webclient_cert_name}", 401 if webclient_cert_name != request_name
else else

View file

@ -13,7 +13,8 @@ class Epp::SessionsController < EppController
success = true success = true
@api_user = ApiUser.find_by(login_params) @api_user = ApiUser.find_by(login_params)
if request.ip == ENV['webclient_ip'] && !Rails.env.test? && !Rails.env.development? webclient_request = ENV['webclient_ips'].split(',').map(&:strip).include?(request.ip)
if webclient_request && !Rails.env.test? && !Rails.env.development?
client_md5 = Certificate.parse_md_from_string(request.env['HTTP_SSL_CLIENT_CERT']) client_md5 = Certificate.parse_md_from_string(request.env['HTTP_SSL_CLIENT_CERT'])
server_md5 = Certificate.parse_md_from_string(File.read(ENV['cert_path'])) server_md5 = Certificate.parse_md_from_string(File.read(ENV['cert_path']))
if client_md5 != server_md5 if client_md5 != server_md5
@ -22,7 +23,7 @@ class Epp::SessionsController < EppController
end end
end end
if request.ip != ENV['webclient_ip'] && @api_user if !webclient_request && @api_user
unless @api_user.api_pki_ok?(request.env['HTTP_SSL_CLIENT_CERT'], request.env['HTTP_SSL_CLIENT_S_DN_CN']) unless @api_user.api_pki_ok?(request.env['HTTP_SSL_CLIENT_CERT'], request.env['HTTP_SSL_CLIENT_S_DN_CN'])
@msg = 'Authentication error; server closing connection (certificate is not valid)' @msg = 'Authentication error; server closing connection (certificate is not valid)'
success = false success = false
@ -71,7 +72,8 @@ class Epp::SessionsController < EppController
# rubocop: enable Metrics/CyclomaticComplexity # rubocop: enable Metrics/CyclomaticComplexity
def ip_white? def ip_white?
return true if request.ip == ENV['webclient_ip'] webclient_request = ENV['webclient_ips'].split(',').map(&:strip).include?(request.ip)
return true if webclient_request
if @api_user if @api_user
return false unless @api_user.registrar.api_ip_white?(request.ip) return false unless @api_user.registrar.api_ip_white?(request.ip)
end end

View file

@ -4,7 +4,7 @@ app_name: '.EE Registry'
zonefile_export_dir: 'export/zonefiles' zonefile_export_dir: 'export/zonefiles'
bank_statement_import_dir: 'import/bank_statements' bank_statement_import_dir: 'import/bank_statements'
legal_documents_dir: 'import/legal_documents' legal_documents_dir: 'import/legal_documents'
time_zone: 'Tallinn' # more zones by rake time:zones:all time_zone: 'Tallinn' # more zones by rake time:zones:all
# New Relic app name, keep only current mode, remove other names. # New Relic app name, keep only current mode, remove other names.
# Example: 'Admin, EPP, REPP' will have name 'Admin, EPP, REPP - production' at New Relic. # Example: 'Admin, EPP, REPP' will have name 'Admin, EPP, REPP - production' at New Relic.
@ -25,7 +25,7 @@ ca_key_path: '/home/registry/registry/shared/ca/private/ca.key.pem'
ca_key_password: 'your-root-key-password' ca_key_password: 'your-root-key-password'
# EPP server configuration # EPP server configuration
webclient_ip: '127.0.0.1' webclient_ips: '127.0.0.1,0.0.0.0' #ips, separated with commas
webclient_cert_common_name: 'webclient' webclient_cert_common_name: 'webclient'
# Contact epp will not accept org value by default # Contact epp will not accept org value by default
# and returns 2306 "Parameter value policy error" # and returns 2306 "Parameter value policy error"
@ -72,7 +72,7 @@ sk_digi_doc_service_name: 'EIS test'
# Autotest config overwrites # Autotest config overwrites
test: test:
webclient_ip: '127.0.0.1' # it should match to localhost ip address webclient_ips: '127.0.0.1' # it should match to localhost ip address
crl_dir: '/var/lib/jenkins/workspace/registry/ca/crl' crl_dir: '/var/lib/jenkins/workspace/registry/ca/crl'
crl_path: '/var/lib/jenkins/workspace/registry/ca/crl/crl.pem' crl_path: '/var/lib/jenkins/workspace/registry/ca/crl/crl.pem'
ca_cert_path: '/var/lib/jenkins/workspace/registry/ca/certs/ca.crt.pem' ca_cert_path: '/var/lib/jenkins/workspace/registry/ca/certs/ca.crt.pem'

View file

@ -7,7 +7,7 @@ required = %w(
ca_cert_path ca_cert_path
ca_key_path ca_key_path
ca_key_password ca_key_password
webclient_ip webclient_ips
legal_documents_dir legal_documents_dir
bank_statement_import_dir bank_statement_import_dir
time_zone time_zone

View file

@ -100,7 +100,7 @@ Configure registry registry/shared/config/application.yml to match the CA settin
Configure registry epp registry-epp/shared/config/application.yml: Configure registry epp registry-epp/shared/config/application.yml:
webclient_ip: '54.154.91.240' webclient_ips: '54.154.91.240'
Configure EPP port 700 virtual host: Configure EPP port 700 virtual host:

View file

@ -2,7 +2,7 @@ require 'rails_helper'
describe Repp::AccountV1 do describe Repp::AccountV1 do
it 'should fail without whitelisted IP' do it 'should fail without whitelisted IP' do
ENV['webclient_ip'] = '192.188.1.1' ENV['webclient_ips'] = '192.188.1.1'
@registrar1 = Fabricate(:registrar, white_ips: [Fabricate(:white_ip_registrar)]) @registrar1 = Fabricate(:registrar, white_ips: [Fabricate(:white_ip_registrar)])
@api_user = Fabricate(:api_user, registrar: @registrar1) @api_user = Fabricate(:api_user, registrar: @registrar1)
@ -11,7 +11,7 @@ describe Repp::AccountV1 do
body = JSON.parse(response.body) body = JSON.parse(response.body)
body['error'].should == 'IP is not whitelisted' body['error'].should == 'IP is not whitelisted'
ENV['webclient_ip'] = '127.0.0.1' ENV['webclient_ips'] = '127.0.0.1'
end end
context 'with valid registrar' do context 'with valid registrar' do