Skip to content

Commit edcae98

Browse files
authored
redis tls (#1341)
* redis tls
1 parent 618e57f commit edcae98

File tree

8 files changed

+60
-14
lines changed

8 files changed

+60
-14
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ gem 'travis-support', git: 'https://github.com/travis-ci/travis-support'
99
gem 'travis-amqp', git: 'https://github.com/travis-ci/travis-amqp'
1010
gem 'travis-config', git: 'https://github.com/travis-ci/travis-config'
1111
gem 'travis-settings', git: 'https://github.com/travis-ci/travis-settings'
12-
gem 'travis-lock', git: 'https://github.com/travis-ci/travis-lock'
12+
gem 'travis-lock', git: 'https://github.com/travis-ci/travis-lock', branch: 'ga-tbt151-redistls'
1313
gem 'travis-github_apps', git: 'https://github.com/travis-ci/travis-github_apps'
1414
gem 'travis-rollout', git: 'https://github.com/travis-ci/travis-rollout'
1515
gem 'simple_states', git: 'https://github.com/travis-ci/simple_states', branch: 'prd-ruby-upgrade-dev'

Gemfile.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ GIT
9090

9191
GIT
9292
remote: https://github.com/travis-ci/travis-lock
93-
revision: aeee7b5d11e3d44f19d0a113c2e54ec54756f20f
93+
revision: 535bbe651e1d407c58b1f1c7f521dd1d7a08691c
94+
branch: ga-tbt151-redistls
9495
specs:
9596
travis-lock (0.2.0)
9697

lib/travis.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ def setup(options = {})
5252
end
5353

5454
def redis
55-
@redis ||= Redis.new(config.redis.to_h)
55+
cfg = config.redis.to_h
56+
cfg = cfg.merge(ssl_params: redis_ssl_params) if config.redis.ssl
57+
@redis ||= Redis.new(cfg.to_h)
5658
end
5759

5860
def pusher
@@ -66,6 +68,19 @@ def pusher
6668
end
6769
end
6870

71+
def redis_ssl_params
72+
@redis_ssl_params ||= begin
73+
return nil unless Travis.config.redis.ssl
74+
75+
value = {}
76+
value[:ca_file] = ENV['REDIS_SSL_CA_FILE'] if ENV['REDIS_SSL_CA_FILE']
77+
value[:cert] = OpenSSL::X509::Certificate.new(File.read(ENV['REDIS_SSL_CERT_FILE'])) if ENV['REDIS_SSL_CERT_FILE']
78+
value[:key] = OpenSSL::PKEY::RSA.new(File.read(ENV['REDIS_SSL_KEY_FILE'])) if ENV['REDIS_SSL_KEY_FILE']
79+
value[:verify_mode] = OpenSSL::SSL::VERIFY_NONE if Travis.config.ssl_verify == false
80+
value
81+
end
82+
end
83+
6984
def states_cache
7085
@states_cache ||= Travis::StatesCache.new
7186
end

lib/travis/api/app.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ def self.setup_travis
222222
setup_database_connections
223223

224224
Sidekiq.configure_client do |config|
225-
config.redis = Travis.config.redis.to_h
225+
cfg = Travis.config.redis.to_h
226+
cfg = cfg.merge(ssl_params: Travis.redis_ssl_params) if Travis.config.redis.ssl && Travis.redis_ssl_params
227+
config.redis = cfg
226228
end
227229

228230
if use_monitoring? && !console?

lib/travis/api/app/schedulers/schedule_cron_jobs.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@ def self.run
2121
end
2222

2323
def self.options
24-
@options ||= {
25-
strategy: :redis,
26-
url: Travis.config.redis.url,
27-
retries: 0
28-
}
24+
@options ||=
25+
begin
26+
opt = {
27+
strategy: :redis,
28+
url: Travis.config.redis.url,
29+
retries: 0,
30+
ssl: Travis.config.redis.ssl || false,
31+
}
32+
opt[:ca_file] ||= ENV['REDIS_SSL_CA_FILE'] if ENV['REDIS_SSL_CA_FILE']
33+
opt[:cert] ||= OpenSSL::X509::Certificate.new(File.read(ENV['REDIS_SSL_CERT_FILE'])) if ENV['REDIS_SSL_CERT_FILE']
34+
opt[:key] ||= OpenSSL::PKEY::RSA.new(File.read(ENV['REDIS_SSL_KEY_FILE'])) if ENV['REDIS_SSL_KEY_FILE']
35+
opt[:verify_mode] ||= OpenSSL::SSL::VERIFY_NONE if Travis.config.ssl_verify == false
36+
opt
37+
end
2938
end
3039

3140
def self.enqueue

lib/travis/api/sidekiq.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,25 @@ def gatekeeper_client
2727
def gatekeeper_pool
2828
::Sidekiq::RedisConnection.create(
2929
url: config.redis_gatekeeper.url,
30-
id: nil
30+
id: nil,
31+
ssl: config.redis_gatekeeper.ssl || false,
32+
ssl_params: redis_ssl_params
3133
)
3234
end
3335

36+
def redis_ssl_params
37+
@redis_ssl_params ||= begin
38+
return {} unless Travis.config.redis_gatekeeper.ssl
39+
40+
value = {}
41+
value[:ca_file] = ENV['REDIS_GATEKEEPER_SSL_CA_FILE'] if ENV['REDIS_GATEKEEPER_SSL_CA_FILE']
42+
value[:cert] = OpenSSL::X509::Certificate.new(File.read(ENV['REDIS_GATEKEEPER_SSL_CERT_FILE'])) if ENV['REDIS_GATEKEEPER_SSL_CERT_FILE']
43+
value[:key] = OpenSSL::PKEY::RSA.new(File.read(ENV['REDIS_GATEKEEPER_SSL_KEY_FILE'])) if ENV['REDIS_GATEKEEPER_SSL_KEY_FILE']
44+
value[:verify_mode] = OpenSSL::SSL::VERIFY_NONE if Travis.config.ssl_verify == false
45+
value
46+
end
47+
end
48+
3449
def config
3550
Travis.config
3651
end

lib/travis/config/defaults.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def fallback_logs_api_auth_token
7676
roles: {},
7777
archive: {},
7878
ssl: {},
79-
redis: { url: 'redis://localhost:6379' },
80-
redis_gatekeeper: { url: ENV['REDIS_GATEKEEPER_URL'] || 'redis://localhost:6379' },
79+
redis: { url: 'redis://localhost:6379' , ssl: ENV['REDIS_SSL'] || false },
80+
redis_gatekeeper: { url: ENV['REDIS_GATEKEEPER_URL'] || 'redis://localhost:6379', ssl: ENV['REDIS_GATEKEEPER_SSL'] || false },
8181
repository: { ssl_key: { size: 4096 } },
8282
encryption: Travis.env == 'development' || Travis.env == 'test' ? { key: 'secret' * 10 } : {},
8383
sync: { organizations: { repositories_limit: 1000 } },

lib/travis/sidekiq.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
Travis::Notification.setup
1414

1515
Sidekiq.configure_server do |config|
16-
config.redis = Travis.config.redis.to_h.merge(namespace: Travis.config.sidekiq.namespace, id: nil)
16+
cfg = Travis.config.redis.to_h.merge(id: nil)
17+
cfg = cfg.merge(ssl_params: Travis.redis_ssl_params) if Travis.config.redis.ssl
18+
config.redis = cfg
1719
end
1820

1921
Sidekiq.configure_client do |config|
20-
config.redis = Travis.config.redis.to_h.merge(size: 1, namespace: Travis.config.sidekiq.namespace, id: nil)
22+
cfg = Travis.config.redis.to_h.merge(size: 1, id: nil)
23+
cfg = cfg.merge(ssl_params: Travis.redis_ssl_params) if Travis.config.redis.ssl
24+
config.redis = cfg
2125
end

0 commit comments

Comments
 (0)