gitlab-mail_room 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e8a5af986fff787ca0cd1ba45293f44a2f5130ddc8f1a2e762258d397d3eb7d
4
- data.tar.gz: 6056b4c396bb63fd769ddd26c0860f65095045f84c334e7531f40b465c7f2326
3
+ metadata.gz: af85ac3afea2ae7872cce6fc431f960f9363d4e584a151e31ce9d725e117950b
4
+ data.tar.gz: 43b48ddebb1e853791b829a2702d4df288f1bd5adf52fe3e7650b4818db251fa
5
5
  SHA512:
6
- metadata.gz: c100b13d4179d816a39c308c36f0bb47e4c43bba80d549ef0a7f37cc70fb73d03dc3ecd554a50b4f350beb527bcff7cbeee999d737dcb7527d872d1606e204aa
7
- data.tar.gz: d483eb80b21ee39e54b3a08ca18c3dad015027684dbb2d87b2b2d8b0c71a6bd72931932408034a6014b013ee653698703d9571a07385a162cfee0054fcd1fe8b
6
+ metadata.gz: 236dd78dcead247d9e69009f5698f9796e0b4eeccce286e6c0027176bb2214f1251b8ee8ffb48620e2fda064647512af928cb3a63c01842700ad91869bb111ed
7
+ data.tar.gz: '0368c5b56018dee27c2468a53d6530f07f3d79a23abcc3322495ef24f438b85b6f47f7fa29734dfd2820b6593e15321aa8076ee09691ec03d8ca0577d3471b21'
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
- ## Unreleased ##
1
+ ## gitlab-mail_room 1.2.0 ##
2
+
3
+ * Add Redis cloud auth support (rotating short-lived tokens, such as Microsoft Entra on Azure Managed Redis) via the new `redis_credentials_provider` and `redis_username` options for Sidekiq delivery and Redis arbitration
4
+ * Add `redis-cloud-auth` and `az-identity` runtime dependencies
5
+
6
+ ## gitlab-mail_room 1.1.0 ##
2
7
 
3
8
  * Bump `net-imap` to `>= 0.5, < 0.7` (allows the 0.6.x line on Ruby 3.2+)
4
9
  * Raise minimum Ruby to 3.1 (`required_ruby_version >= 3.1`), required by `net-imap` 0.5+
data/README.md CHANGED
@@ -282,6 +282,10 @@ Delivery options:
282
282
  Required, defaults to `redis://localhost:6379`.
283
283
  - **sentinels**: A list of sentinels servers used to provide HA to Redis. (see [Sentinel Support](#sentinel-support))
284
284
  Optional.
285
+ - **redis_username**: The Redis AUTH username, applied with or without `redis_credentials_provider`. When using `redis_credentials_provider`, set this to the identity (for Azure, the managed identity's object ID). The identity may instead be supplied in the `redis_url` userinfo, or inside the `redis_credentials_provider` descriptor itself (ElastiCache carries it as `user_id`; other providers as `username`); `redis_username` takes precedence, and the descriptor identity is used only when `redis_username` is unset.
286
+ Optional.
287
+ - **redis_credentials_provider**: Authenticate with a short-lived, rotating token (for example Microsoft Entra on Azure Managed Redis) instead of a static password. A hash of provider options, for example `{ :provider: azure, :resource: https://redis.azure.com }`. Use a `rediss://` URL. Uses the [`redis-cloud-auth`](https://gitlab.com/gitlab-org/ruby/gems/redis-cloud-auth) gem, which loads the per-provider SDK lazily on first connect. The `azure` provider's SDK, [`az-identity`](https://gitlab.com/gitlab-org/ruby/gems/az-identity), is a runtime dependency of mail_room, so you do not need to add it yourself. The `gcp` and `elasticache` providers need `googleauth` and `aws-sigv4` respectively; these are not bundled, so a standalone install (such as the CNG mailroom image, which installs only mail_room's runtime dependencies) must add them to its environment. When mail_room runs inside the GitLab Rails bundle (Omnibus or source), all three are already present. The same options are supported under `arbitration_options`.
288
+ Optional.
285
289
  - **namespace**: [DEPRECATED] The Redis namespace Sidekiq works under. Use the same Redis namespace that's used to configure Sidekiq.
286
290
  Optional.
287
291
  - **queue**: The Sidekiq queue the job is pushed onto. Make sure Sidekiq actually reads off this queue.
@@ -1,9 +1,13 @@
1
1
  require "redis"
2
+ require "mail_room/redis_client_builder"
2
3
 
3
4
  module MailRoom
4
5
  module Arbitration
5
6
  class Redis
6
- Options = Struct.new(:redis_url, :redis_ssl_params, :namespace, :redis_db, :sentinels, :sentinel_username, :sentinel_password) do
7
+ Options = Struct.new(
8
+ :redis_url, :redis_ssl_params, :namespace, :redis_db, :sentinels,
9
+ :sentinel_username, :sentinel_password, :redis_username, :redis_credentials_provider
10
+ ) do
7
11
  def initialize(mailbox)
8
12
  redis_url = mailbox.arbitration_options[:redis_url] || "redis://localhost:6379"
9
13
  redis_ssl_params = mailbox.arbitration_options[:redis_ssl_params]
@@ -12,6 +16,8 @@ module MailRoom
12
16
  sentinels = mailbox.arbitration_options[:sentinels]
13
17
  sentinel_username = mailbox.arbitration_options[:sentinel_username]
14
18
  sentinel_password = mailbox.arbitration_options[:sentinel_password]
19
+ redis_username = mailbox.arbitration_options[:redis_username]
20
+ redis_credentials_provider = mailbox.arbitration_options[:redis_credentials_provider]
15
21
 
16
22
  if namespace
17
23
  warn <<~MSG
@@ -20,7 +26,7 @@ module MailRoom
20
26
  MSG
21
27
  end
22
28
 
23
- super(redis_url, redis_ssl_params, namespace, redis_db, sentinels, sentinel_username, sentinel_password)
29
+ super(redis_url, redis_ssl_params, namespace, redis_db, sentinels, sentinel_username, sentinel_password, redis_username, redis_credentials_provider)
24
30
  end
25
31
  end
26
32
 
@@ -48,26 +54,7 @@ module MailRoom
48
54
  private
49
55
 
50
56
  def client
51
- @client ||= begin
52
- sentinels = options.sentinels
53
- redis_options = { url: options.redis_url, db: options.redis_db }
54
- # Needed for redis-client 0.26.2 and older: https://github.com/redis-rb/redis-client/pull/277
55
- redis_options[:ssl] = true if options.redis_url.start_with?("rediss://")
56
- redis_options[:ssl_params] = options.redis_ssl_params if options.redis_ssl_params
57
- redis_options[:sentinels] = sentinels if sentinels
58
- redis_options[:sentinel_username] = options.sentinel_username if options.sentinel_username
59
- redis_options[:sentinel_password] = options.sentinel_password if options.sentinel_password
60
-
61
- redis = ::Redis.new(redis_options)
62
-
63
- namespace = options.namespace
64
- if namespace
65
- require 'redis/namespace'
66
- ::Redis::Namespace.new(namespace, redis: redis)
67
- else
68
- redis
69
- end
70
- end
57
+ @client ||= MailRoom::RedisClientBuilder.build(options)
71
58
  end
72
59
  end
73
60
  end
@@ -2,13 +2,18 @@ require "redis"
2
2
  require "securerandom"
3
3
  require "json"
4
4
  require "charlock_holmes"
5
+ require "mail_room/redis_client_builder"
5
6
 
6
7
  module MailRoom
7
8
  module Delivery
8
9
  # Sidekiq Delivery method
9
10
  # @author Douwe Maan
10
11
  class Sidekiq
11
- Options = Struct.new(:redis_url, :redis_ssl_params, :namespace, :sentinels, :queue, :worker, :logger, :redis_db, :sentinel_username, :sentinel_password) do
12
+ Options = Struct.new(
13
+ :redis_url, :redis_ssl_params, :namespace, :sentinels, :queue, :worker,
14
+ :logger, :redis_db, :sentinel_username, :sentinel_password, :redis_username,
15
+ :redis_credentials_provider
16
+ ) do
12
17
  def initialize(mailbox)
13
18
  redis_url = mailbox.delivery_options[:redis_url] || "redis://localhost:6379"
14
19
  redis_ssl_params = mailbox.delivery_options[:redis_ssl_params]
@@ -20,6 +25,8 @@ module MailRoom
20
25
  queue = mailbox.delivery_options[:queue] || "default"
21
26
  worker = mailbox.delivery_options[:worker]
22
27
  logger = mailbox.logger
28
+ redis_username = mailbox.delivery_options[:redis_username]
29
+ redis_credentials_provider = mailbox.delivery_options[:redis_credentials_provider]
23
30
 
24
31
  if namespace
25
32
  warn <<~MSG
@@ -28,7 +35,7 @@ module MailRoom
28
35
  MSG
29
36
  end
30
37
 
31
- super(redis_url, redis_ssl_params, namespace, sentinels, queue, worker, logger, redis_db, sentinel_username, sentinel_password)
38
+ super(redis_url, redis_ssl_params, namespace, sentinels, queue, worker, logger, redis_db, sentinel_username, sentinel_password, redis_username, redis_credentials_provider)
32
39
  end
33
40
  end
34
41
 
@@ -54,26 +61,7 @@ module MailRoom
54
61
  private
55
62
 
56
63
  def client
57
- @client ||= begin
58
- sentinels = options.sentinels
59
- redis_options = { url: options.redis_url, db: options.redis_db }
60
- # Needed for redis-client 0.26.2 and older: https://github.com/redis-rb/redis-client/pull/277
61
- redis_options[:ssl] = true if options.redis_url.start_with?("rediss://")
62
- redis_options[:ssl_params] = options.redis_ssl_params if options.redis_ssl_params
63
- redis_options[:sentinels] = sentinels if sentinels
64
- redis_options[:sentinel_username] = options.sentinel_username if options.sentinel_username
65
- redis_options[:sentinel_password] = options.sentinel_password if options.sentinel_password
66
-
67
- redis = ::Redis.new(redis_options)
68
-
69
- namespace = options.namespace
70
- if namespace
71
- require 'redis/namespace'
72
- Redis::Namespace.new(namespace, redis: redis)
73
- else
74
- redis
75
- end
76
- end
64
+ @client ||= MailRoom::RedisClientBuilder.build(options)
77
65
  end
78
66
 
79
67
  def item_for(message)
@@ -0,0 +1,35 @@
1
+ require "redis"
2
+ require "mail_room/redis_credentials_provider"
3
+
4
+ module MailRoom
5
+ # Builds the Redis client shared by the arbitration and Sidekiq-delivery
6
+ # paths. Both take the same Redis connection fields and optional
7
+ # credentials-provider (rotating-token) auth, so the wiring lives here once.
8
+ module RedisClientBuilder
9
+ class << self
10
+ # +options+ is an arbitration/delivery Options struct.
11
+ def build(options)
12
+ redis = ::Redis.new(redis_options(options))
13
+ return redis unless options.namespace
14
+
15
+ require "redis/namespace"
16
+ ::Redis::Namespace.new(options.namespace, redis: redis)
17
+ end
18
+
19
+ private
20
+
21
+ def redis_options(options)
22
+ redis_options = { url: options.redis_url, db: options.redis_db }
23
+ # Needed for redis-client 0.26.2 and older: https://github.com/redis-rb/redis-client/pull/277
24
+ redis_options[:ssl] = true if options.redis_url.start_with?("rediss://")
25
+ redis_options[:ssl_params] = options.redis_ssl_params if options.redis_ssl_params
26
+ redis_options[:sentinels] = options.sentinels if options.sentinels
27
+ redis_options[:sentinel_username] = options.sentinel_username if options.sentinel_username
28
+ redis_options[:sentinel_password] = options.sentinel_password if options.sentinel_password
29
+ redis_options[:username] = options.redis_username if options.redis_username
30
+
31
+ MailRoom::RedisCredentialsProvider.configure(redis_options, options)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,52 @@
1
+ module MailRoom
2
+ # Wires rotating-token (cloud identity) Redis authentication into the
3
+ # arbitration and Sidekiq-delivery Redis clients, via the redis-cloud-auth
4
+ # gem. The connection authenticates with a short-lived token instead of a
5
+ # static password, and long-lived connections are re-authenticated before the
6
+ # token expires.
7
+ module RedisCredentialsProvider
8
+ class << self
9
+ # Augments +redis_options+ (a Hash passed to Redis.new) with a callable
10
+ # token password and the middleware descriptor, when +options+ carries a
11
+ # credentials_provider. +options+ is an arbitration/delivery Options
12
+ # struct. Returns the same Hash.
13
+ def configure(redis_options, options)
14
+ provider = options.redis_credentials_provider
15
+ return redis_options unless provider
16
+
17
+ require "redis_cloud_auth"
18
+ register!
19
+
20
+ descriptor = symbolize(provider)
21
+ descriptor[:username] ||= options.redis_username
22
+
23
+ # The AUTH identity is the Redis username; the caller has already applied
24
+ # redis_username (if set). Fall back to a descriptor identity for
25
+ # providers that carry it there: ElastiCache as :user_id, others as
26
+ # :username. Otherwise redis-client reads it from the URL userinfo.
27
+ # GCP MemoryStore needs no username.
28
+ redis_options[:username] ||= descriptor[:username] || descriptor[:user_id]
29
+ redis_options[:password] = ::RedisCloudAuth.credential(descriptor)
30
+ redis_options[:custom] = { credentials_provider: descriptor }
31
+ redis_options
32
+ end
33
+
34
+ private
35
+
36
+ # RedisClient.register appends on each call, so only register the
37
+ # middleware once per process. The gem's default logger is a no-op; we do
38
+ # not wire mail_room's structured logger because it raises on the plain
39
+ # string messages the middleware logs. Re-auth failures are non-fatal.
40
+ def register!
41
+ return if @registered
42
+
43
+ ::RedisCloudAuth.register!
44
+ @registered = true
45
+ end
46
+
47
+ def symbolize(hash)
48
+ hash.transform_keys(&:to_sym)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,4 +1,4 @@
1
1
  module MailRoom
2
2
  # Current version of gitlab-mail_room gem
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
data/mail_room.gemspec CHANGED
@@ -22,7 +22,9 @@ Gem::Specification.new do |gem|
22
22
  gem.add_dependency "net-imap", [">= 0.5", "< 0.7"]
23
23
  gem.add_dependency "oauth2", [">= 2.0.9", "< 3"]
24
24
  gem.add_dependency "jwt", [">= 2.0", "< 4"]
25
+ gem.add_dependency "az-identity", "~> 0.1"
25
26
  gem.add_dependency "redis", [">= 5", "< 6"]
27
+ gem.add_dependency "redis-cloud-auth", "~> 0.1"
26
28
  gem.add_dependency "redis-namespace", [">= 1.8.2", "< 2"]
27
29
 
28
30
  gem.add_development_dependency "rake"
@@ -192,5 +192,45 @@ describe MailRoom::Arbitration::Redis do
192
192
  expect(raw_client.config.ssl_params).to eq(redis_ssl_params)
193
193
  end
194
194
  end
195
+
196
+ context 'when a credentials_provider is configured' do
197
+ let(:redis_username) { "identity-object-id" }
198
+ let(:mailbox) {
199
+ build_mailbox(
200
+ arbitration_options: {
201
+ redis_url: 'rediss://cache.example.com:10000',
202
+ redis_username: redis_username,
203
+ redis_credentials_provider: { provider: 'azure', resource: 'https://redis.azure.com' }
204
+ }
205
+ )
206
+ }
207
+
208
+ # Read the raw callable without calling it: RedisClient::Config#password
209
+ # invokes the callable (which would need the provider backend and network).
210
+ let(:raw_password) { raw_client.config.instance_variable_get(:@password) }
211
+
212
+ it 'authenticates with a rotating-token callable password and a middleware descriptor' do
213
+ expect(raw_client.config.username).to eq(redis_username)
214
+ expect(raw_password).to be_a(RedisCloudAuth::TokenCredential)
215
+ expect(raw_client.config.custom[:credentials_provider]).to eq(
216
+ provider: 'azure', resource: 'https://redis.azure.com', username: redis_username
217
+ )
218
+ end
219
+ end
220
+
221
+ context 'with an ElastiCache credentials_provider and no redis_username' do
222
+ let(:mailbox) {
223
+ build_mailbox(
224
+ arbitration_options: {
225
+ redis_url: 'rediss://cache.example.com:6379',
226
+ redis_credentials_provider: { provider: 'elasticache', user_id: 'ec-user' }
227
+ }
228
+ )
229
+ }
230
+
231
+ it 'uses the descriptor user_id as the AUTH username' do
232
+ expect(raw_client.config.username).to eq('ec-user')
233
+ end
234
+ end
195
235
  end
196
236
  end
@@ -138,5 +138,47 @@ describe MailRoom::Delivery::Sidekiq do
138
138
  expect(raw_client.config.ssl_params).to eq(redis_ssl_params)
139
139
  end
140
140
  end
141
+
142
+ context 'when a credentials_provider is configured' do
143
+ let(:redis_username) { "identity-object-id" }
144
+ let(:mailbox) {
145
+ build_mailbox(
146
+ delivery_method: :sidekiq,
147
+ delivery_options: {
148
+ redis_url: 'rediss://cache.example.com:10000',
149
+ redis_username: redis_username,
150
+ redis_credentials_provider: { provider: 'azure', resource: 'https://redis.azure.com' }
151
+ }
152
+ )
153
+ }
154
+
155
+ # Read the raw callable without calling it: RedisClient::Config#password
156
+ # invokes the callable (which would need the provider backend and network).
157
+ let(:raw_password) { raw_client.config.instance_variable_get(:@password) }
158
+
159
+ it 'authenticates with a rotating-token callable password and a middleware descriptor' do
160
+ expect(raw_client.config.username).to eq(redis_username)
161
+ expect(raw_password).to be_a(RedisCloudAuth::TokenCredential)
162
+ expect(raw_client.config.custom[:credentials_provider]).to eq(
163
+ provider: 'azure', resource: 'https://redis.azure.com', username: redis_username
164
+ )
165
+ end
166
+ end
167
+
168
+ context 'when a redis_username is set without a credentials_provider' do
169
+ let(:mailbox) {
170
+ build_mailbox(
171
+ delivery_method: :sidekiq,
172
+ delivery_options: {
173
+ redis_url: 'redis://localhost:6379',
174
+ redis_username: 'acl-user'
175
+ }
176
+ )
177
+ }
178
+
179
+ it 'applies the username to the connection' do
180
+ expect(raw_client.config.username).to eq('acl-user')
181
+ end
182
+ end
141
183
  end
142
184
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-mail_room
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Pitale
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-06-18 00:00:00.000000000 Z
10
+ date: 2026-11-20 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: net-imap
@@ -69,6 +69,20 @@ dependencies:
69
69
  - - "<"
70
70
  - !ruby/object:Gem::Version
71
71
  version: '4'
72
+ - !ruby/object:Gem::Dependency
73
+ name: az-identity
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - "~>"
77
+ - !ruby/object:Gem::Version
78
+ version: '0.1'
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '0.1'
72
86
  - !ruby/object:Gem::Dependency
73
87
  name: redis
74
88
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +103,20 @@ dependencies:
89
103
  - - "<"
90
104
  - !ruby/object:Gem::Version
91
105
  version: '6'
106
+ - !ruby/object:Gem::Dependency
107
+ name: redis-cloud-auth
108
+ requirement: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '0.1'
113
+ type: :runtime
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '0.1'
92
120
  - !ruby/object:Gem::Dependency
93
121
  name: redis-namespace
94
122
  requirement: !ruby/object:Gem::Requirement
@@ -330,6 +358,8 @@ files:
330
358
  - lib/mail_room/message.rb
331
359
  - lib/mail_room/microsoft_graph.rb
332
360
  - lib/mail_room/microsoft_graph/connection.rb
361
+ - lib/mail_room/redis_client_builder.rb
362
+ - lib/mail_room/redis_credentials_provider.rb
333
363
  - lib/mail_room/version.rb
334
364
  - logfile.log
335
365
  - mail_room.gemspec