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

THREESCALE-8404: Add ACL and TLS support for Redis #350

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
89fe2ef
Update gems
jlledom Oct 25, 2023
bde5ea1
Use Boolifyed API
jlledom Oct 25, 2023
0677638
Use the new pipeline API
jlledom Oct 25, 2023
08e5a3b
Use new pipeline API for async mode
jlledom Oct 25, 2023
be9c1e6
Fix tests
jlledom Oct 25, 2023
b99e307
Accept new parameters and ENV variables
jlledom Oct 25, 2023
f0418d7
Update ENV vars descriptions
jlledom Nov 20, 2023
b739462
Gemfile: require redis ~> 5.0
jlledom Nov 20, 2023
c91b00a
Create a separate context for pipelines
jlledom Nov 21, 2023
c94bd27
Thread-isolate redis client in async mode
jlledom Nov 22, 2023
8d8c4af
Implement SSL and ACL in async mode
jlledom Nov 23, 2023
d5fd900
Fix config file missing quotes
jlledom Nov 27, 2023
5e8f66c
Revert async gems upgrade
jlledom Dec 1, 2023
8c28110
Remove thread-safety for the async client
jlledom Dec 14, 2023
cdc25bb
Fix worker_async_spec test suite
jlledom Dec 14, 2023
e928e84
Fix TLS connection in async mode
jlledom Dec 20, 2023
b7ffd43
Functions: start a redis TLS server
jlledom Dec 19, 2023
a2ef569
StorageSync: Add tests for TLS connections
jlledom Dec 19, 2023
a9c4dd9
Add connection tests for StorageAsync::Client
jlledom Dec 19, 2023
d12c72d
Update redis gems
jlledom Jan 16, 2024
6065bbe
Merge branch 'master' into THREESCALE-8404-redis-acl-tls
jlledom Jan 16, 2024
cbc9fec
Merge branch 'master' into THREESCALE-8404-redis-acl-tls
jlledom Jan 17, 2024
0972555
Storage config: ignore empty ssl params
jlledom Jan 18, 2024
f53877f
Add CA_PATH env variables for SSL
jlledom Jan 18, 2024
a81a4e9
Load a default CA cert if present
jlledom Jan 18, 2024
c429e71
Redis config: remove all empty keys
jlledom Jan 22, 2024
73da74b
Monkey patch the redis gem to fix timeout bug
jlledom Jan 22, 2024
decfeb9
Rename `compact` lambda to `empty`
jlledom Jan 22, 2024
312179a
Remove Airbrake integration
jlledom Jan 23, 2024
ad3dc2a
Update Bugsnag
jlledom Jan 23, 2024
18a0840
Fix Resque-Bugsnag integration
jlledom Jan 23, 2024
fc397b7
Remove comment: The limitation doesn't exist anymore
jlledom Feb 9, 2024
1ff0b66
Merge branch 'master' into THREESCALE-8404-redis-acl-tls
jlledom Feb 19, 2024
70034ab
Fix config compact method
jlledom Feb 19, 2024
e6d1e5d
Fix typo
jlledom Feb 22, 2024
70c95db
Merge branch 'master' into THREESCALE-8404-redis-acl-tls
jlledom Mar 7, 2024
c8bdef8
Redis: Add SSL Param
jlledom Mar 8, 2024
1279b06
Merge branch 'master' into THREESCALE-8404-redis-acl-tls
jlledom Mar 8, 2024
19dda59
Fix tests after merging master
jlledom Mar 8, 2024
048904b
Merge branch 'master' into THREESCALE-8404-redis-acl-tls
jlledom Apr 26, 2024
a126a9b
Use single redis protocol
jlledom Apr 26, 2024
4dc7cab
Remove fake certificates for tests
jlledom Apr 29, 2024
821f08c
Async: Add support for logical databases
jlledom Apr 29, 2024
0970789
Redis protocol: Don't force DB 0
jlledom May 2, 2024
2bc318c
Path `async-redis` `SentinelsClient` class
jlledom May 2, 2024
e64a151
Add new Env variables
jlledom May 2, 2024
64d0f22
Fix tests
jlledom May 2, 2024
da556bf
Generate strongest keys for tests
jlledom May 3, 2024
f9bb6fa
Integrate with the operator
jlledom May 3, 2024
40d9932
Fix typo
jlledom May 6, 2024
6c45bca
Don't crash the fetcher on timeouts
jlledom May 6, 2024
34dfc4f
Update comments
jlledom May 6, 2024
6bbf375
Fix comment
jlledom May 8, 2024
7093a8c
Add empty line at EOF
jlledom May 8, 2024
c002ab2
Merge branch 'master' into THREESCALE-8404-redis-acl-tls
jlledom May 8, 2024
578a0e2
Merge branch 'master' into THREESCALE-8404-redis-acl-tls
jlledom May 20, 2024
4b6e8cf
Small fixes after merging from master
jlledom May 20, 2024
d996c17
Merge branch 'master' into THREESCALE-8404-redis-acl-tls
jlledom May 22, 2024
f0d0c53
Adapt to last changes to master
jlledom May 23, 2024
1cc4c2c
Refactor Async client
jlledom May 23, 2024
470e9d5
Move macros to helper
jlledom May 23, 2024
1e1e257
Simplify helper
jlledom May 23, 2024
cb28b7e
Set some default configs
jlledom May 23, 2024
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
16 changes: 6 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gemspec
# implementations (ie. pure Ruby, java, etc).
#
platform :ruby do
gem 'hiredis', '~> 0.6.1'
gem 'hiredis-client'
gem 'yajl-ruby', '~> 1.4.3', require: 'yajl'
gem 'pry-byebug', '~> 3.5.1', groups: [:development]
end
Expand All @@ -24,7 +24,7 @@ group :test do
gem 'mocha', '~> 1.3'
gem 'nokogiri', '~> 1.14.3'
gem 'pkg-config', '~> 1.1.7'
gem 'resque_unit', '~> 0.4.4', source: 'https://rubygems.org'
gem 'resque_unit', '~> 0.4.4'
gem 'test-unit', '~> 3.5'
gem 'resque_spec', '~> 0.17.0'
gem 'timecop', '~> 0.9.1'
Expand Down Expand Up @@ -55,21 +55,17 @@ gem 'daemons', '= 1.2.4'
# Production gems
gem 'rake', '~> 13.0'
gem 'builder', '= 3.2.3'
# Use a patched resque to allow reusing their Airbrake Failure class
gem 'resque', git: 'https://github.com/3scale/resque', branch: '3scale'
gem 'redis', '~> 5'
jlledom marked this conversation as resolved.
Show resolved Hide resolved
gem 'resque', '~> 2.6.0'
gem 'redis-namespace', '~>1.8'
gem 'rack', '~> 2.2.6'
gem 'sinatra', '~> 2.2.4'
gem 'sinatra-contrib', '~> 2.2.4'
# Optional external error logging services
gem 'bugsnag', '~> 6', require: nil
gem 'yabeda-prometheus', '~> 0.5.0'
gem 'async-redis', '~> 0.7.0'
gem 'async-pool', '~> 0.3.12'
jlledom marked this conversation as resolved.
Show resolved Hide resolved
gem 'async-redis', '~> 0.8'
gem 'async-pool', '~> 0.4'
gem 'falcon', '~> 0.35'
gem 'webrick', '~> 1.8'

# Use a patched redis-rb that fixes an issue when trying to connect with
# sentinels and avoids retrying calls when there's a timeout to prevent
# duplicated commands. It's based on version 4.1.3.
gem 'redis', git: 'https://github.com/3scale/redis-rb', branch: 'apisonator'
82 changes: 37 additions & 45 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@ GIT
puma (4.3.9)
nio4r (~> 2.0)

GIT
remote: https://github.com/3scale/redis-rb
revision: 7210a9d6cf733fe5a1ad0dd20f5f613167743810
branch: apisonator
specs:
redis (4.1.3)

GIT
remote: https://github.com/3scale/resque
revision: db327e389cf2fc572a503c47b19871ed899356d1
branch: 3scale
specs:
resque (1.27.4)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.3)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)

GIT
remote: https://github.com/3scale/source2swagger
revision: 9a787007577fc58b5822b55720e977cc063057fd
Expand Down Expand Up @@ -63,16 +44,16 @@ GEM
traces (>= 0.8.0)
async-http-cache (0.4.3)
async-http (~> 0.56)
async-io (1.34.3)
async-io (1.36.0)
async
async-pool (0.3.12)
async-pool (0.4.0)
async (>= 1.25)
async-redis (0.7.0)
async-redis (0.8.0)
async (>= 1.8, < 3.0)
async-io (~> 1.10)
async-pool (~> 0.2)
protocol-redis (~> 0.6.0)
async-rspec (1.13.0)
protocol-redis (~> 0.8.0)
async-rspec (1.17.0)
rspec (~> 3.0)
rspec-files (~> 1.0)
rspec-memory (~> 1.0)
Expand All @@ -86,10 +67,12 @@ GEM
simplecov (>= 0.7.1, < 1.0.0)
coderay (1.1.3)
concurrent-ruby (1.1.6)
console (1.16.2)
connection_pool (2.4.1)
console (1.23.2)
fiber-annotation
fiber-local
daemons (1.2.4)
diff-lcs (1.3)
diff-lcs (1.5.0)
docile (1.1.5)
dry-initializer (3.0.3)
falcon (0.42.3)
Expand All @@ -105,12 +88,14 @@ GEM
process-metrics (~> 0.2.0)
protocol-rack (~> 0.1)
samovar (~> 2.1)
fiber-annotation (0.2.0)
fiber-local (1.0.0)
gli (2.16.1)
hiredis (0.6.3)
hiredis-client (0.17.0)
redis-client (= 0.17.0)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
json (2.3.1)
json (2.6.3)
license_finder (7.1.0)
bundler
rubyzip (>= 1, < 3)
Expand All @@ -126,7 +111,7 @@ GEM
minitest (5.18.0)
mocha (1.3.0)
metaclass (~> 0.0.1)
mono_logger (1.1.0)
mono_logger (1.1.2)
multi_json (1.15.0)
mustache (1.0.5)
mustermann (2.0.2)
Expand Down Expand Up @@ -155,7 +140,7 @@ GEM
protocol-rack (0.2.4)
protocol-http (~> 0.23)
rack (>= 1.0)
protocol-redis (0.6.1)
protocol-redis (0.8.0)
pry (0.14.0)
coderay (~> 1.1)
method_source (~> 1.0)
Expand All @@ -166,14 +151,23 @@ GEM
pry (~> 0.11)
yard (~> 0.9.11)
racc (1.6.2)
rack (2.2.6.4)
rack (2.2.8)
rack-protection (2.2.4)
rack
rack-test (0.8.2)
rack (>= 1.0, < 3)
rake (13.0.1)
redis-namespace (1.10.0)
redis (5.0.7)
redis-client (>= 0.9.0)
redis-client (0.17.0)
connection_pool
redis-namespace (1.11.0)
redis (>= 4)
resque (2.6.0)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.6)
sinatra (>= 0.9.2)
resque_spec (0.17.0)
resque (>= 1.19.0)
rspec-core (>= 3.0.0)
Expand All @@ -186,19 +180,19 @@ GEM
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-files (1.0.1)
rspec-files (1.1.3)
rspec (~> 3.0)
rspec-memory (1.0.1)
rspec-memory (1.0.4)
rspec (~> 3.0)
rspec-mocks (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.0)
rspec-support (3.7.1)
rspec_api_documentation (5.1.0)
activesupport (>= 3.0.0)
mustache (~> 1.0, >= 0.99.4)
Expand Down Expand Up @@ -231,15 +225,13 @@ GEM
power_assert
thor (1.2.1)
thread_safe (0.3.6)
tilt (2.1.0)
tilt (2.3.0)
timecop (0.9.1)
timers (4.3.5)
tomlrb (2.0.3)
traces (0.9.1)
tzinfo (1.2.7)
thread_safe (~> 0.1)
vegas (0.1.11)
rack (>= 1.0.0)
webrick (1.8.1)
with_env (1.1.0)
xml-simple (1.1.9)
Expand All @@ -258,8 +250,8 @@ PLATFORMS

DEPENDENCIES
apisonator!
async-pool (~> 0.3.12)
async-redis (~> 0.7.0)
async-pool (~> 0.4)
async-redis (~> 0.8)
async-rspec
benchmark-ips (~> 2.7.2)
bugsnag (~> 6)
Expand All @@ -268,7 +260,7 @@ DEPENDENCIES
daemons (= 1.2.4)
falcon (~> 0.35)
gli (~> 2.16.1)
hiredis (~> 0.6.1)
hiredis-client
license_finder (~> 7.0)
mocha (~> 1.3)
nokogiri (~> 1.14.3)
Expand All @@ -280,11 +272,11 @@ DEPENDENCIES
rack (~> 2.2.6)
rack-test (= 0.8.2)
rake (~> 13.0)
redis!
redis (~> 5)
redis-namespace (~> 1.8)
resque!
resque (~> 2.6.0)
resque_spec (~> 0.17.0)
resque_unit (~> 0.4.4)!
resque_unit (~> 0.4.4)
rspec (~> 3.7.0)
rspec_api_documentation (~> 5.0)
sinatra (~> 2.2.4)
Expand Down
70 changes: 70 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,41 @@ variables.
- Applies to: listener, worker, cron.
- Format: string.

### CONFIG_REDIS_USERNAME

- Redis ACL user name
- Optional. Defaults to empty.
- Applies to: listener, worker, cron.
- Format: string.

### CONFIG_REDIS_PASSWORD

- Redis ACL password
- Optional. Defaults to empty.
- Applies to: listener, worker, cron.
- Format: string.

### CONFIG_REDIS_CA_FILE

- Certification authority to validate Redis server TLS connections with
- Optional. Defaults to empty.
- Applies to: listener, worker, cron.
- Format: path to file as string.

### CONFIG_REDIS_CERT

- User certificate to connect to Redis through TLS
jlledom marked this conversation as resolved.
Show resolved Hide resolved
- Optional. Defaults to empty.
- Applies to: listener, worker, cron.
- Format: path to file as string.

### CONFIG_REDIS_PRIVATE_KEY

- User key to connect to Redis through TLS
jlledom marked this conversation as resolved.
Show resolved Hide resolved
- Optional. Defaults to empty.
- Applies to: listener, worker, cron.
- Format: path to file as string.

### CONFIG_REDIS_SENTINEL_HOSTS

- URL of Redis sentinels.
Expand Down Expand Up @@ -80,6 +115,41 @@ sentinels.
- Applies to: listener, worker, cron.
- Format: string.

### CONFIG_QUEUES_USERNAME
jlledom marked this conversation as resolved.
Show resolved Hide resolved

- Redis ACL user name
- Optional. Defaults to empty.
- Applies to: listener, worker, cron.
- Format: string.

### CONFIG_QUEUES_PASSWORD

- Redis ACL password
- Optional. Defaults to empty.
- Applies to: listener, worker, cron.
- Format: string.

### CONFIG_QUEUES_CA_FILE

- Certification authority certificate Redis should trust to accept TLS connections
- Optional. Defaults to empty.
- Applies to: listener, worker, cron.
- Format: path to file as string.

### CONFIG_QUEUES_CERT

- User certificate to connect to Redis through TLS
- Optional. Defaults to empty.
- Applies to: listener, worker, cron.
- Format: path to file as string.

### CONFIG_QUEUES_PRIVATE_KEY

- User key to connect to Redis through TLS
- Optional. Defaults to empty.
- Applies to: listener, worker, cron.
- Format: path to file as string.

### CONFIG_QUEUES_SENTINEL_HOSTS

- URL of Redis sentinels.
Expand Down
2 changes: 1 addition & 1 deletion lib/3scale/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_relative 'bundler_shim'

require 'builder'
require 'hiredis'
require 'hiredis-client'

require 'redis'

Expand Down
4 changes: 2 additions & 2 deletions lib/3scale/backend/alert_limit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AlertLimit
attr_accessor :service_id, :value

def save
storage.sadd(key_allowed_set(service_id), value.to_i) if valid?
storage.sadd?(key_allowed_set(service_id), value.to_i) if valid?
end

def to_hash
Expand All @@ -32,7 +32,7 @@ def self.save(service_id, value)
end

def self.delete(service_id, value)
storage.srem(key_allowed_set(service_id), value.to_i) if valid_value?(value)
storage.srem?(key_allowed_set(service_id), value.to_i) if valid_value?(value)
end

def self.valid_value?(value)
Expand Down
12 changes: 6 additions & 6 deletions lib/3scale/backend/alerts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ def update_utilization(service_id, app_id, max_utilization, max_record, timestam

keys = alert_keys(service_id, app_id, discrete)

already_alerted, allowed = storage.pipelined do
storage.get(keys[:already_notified])
storage.sismember(keys[:allowed], discrete)
already_alerted, allowed = storage.pipelined do |pipeline|
pipeline.get(keys[:already_notified])
pipeline.sismember(keys[:allowed], discrete)
end

if already_alerted.nil? && allowed && discrete.to_i > 0
next_id, _ = storage.pipelined do
storage.incr(keys[:current_id])
storage.setex(keys[:already_notified], ALERT_TTL, "1")
next_id, _ = storage.pipelined do |pipeline|
pipeline.incr(keys[:current_id])
pipeline.setex(keys[:already_notified], ALERT_TTL, "1")
end

alert = { :id => next_id,
Expand Down
Loading