sidekiq-encrypted_args 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: 8ca6bc1fc5d72297d12bd0f232a87d4ecaa25979c92eba55ea127822fad621c2
4
- data.tar.gz: 869bb08e744fa7366e3115a9c1ad7fc8d2d3887a88bee0af7465b0d6b62f5490
3
+ metadata.gz: bcde4f8a47a8b5b7e5a4c0d6fe8f351a5d62ec8b9390caac4697359b7efe0912
4
+ data.tar.gz: 135e9fd5a910bf450812fa8406b25579857bcd320c93ea6b6660ce4242376650
5
5
  SHA512:
6
- metadata.gz: 4fc68145cdcfdc34ee2a07cbfd18357a73de96ac5b14a03a4ff09de3376bbba0e501bff181cbda9c964fa79c8e492637e9c7b40c3c4a5cbb82d348bc72be2654
7
- data.tar.gz: 75418905177a4bea81d7995967d24dbcdb500b4ca6dcf6d528110676569e87dd857b33c04b3fd4aa821cc3200d956b9cd8de037730f08efeebca1cdc60e18378
6
+ metadata.gz: 1cb7e169a1dd94f2c081e75147a467984d1e9d0457ca0337b44a8b6cfd4db5e6217a1d41261f52f7a81ed1f9dbcfa837a7ef1d9a4498d694472e4df43289f321
7
+ data.tar.gz: e238bdd98f374db76e6363b46abd0b8ea2269723d780e30e8150fbb9aca958410fb759f12148abae4ffd418323fa58005b6229ed063db1bbbe02d59cd916e9e0
data/CHANGE_LOG.md CHANGED
@@ -1,24 +1,58 @@
1
- # Change Log
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## 1.2.0
8
+
9
+ ### Removed
10
+
11
+ - Removed deprecated method of setting encrypted args with a hash with numeric keys. This method stopped working with Sidekiq 7.1.
12
+ - Removed deprecated method of setting encrypted args with an array of booleans.
13
+ - Removed deprecated method of setting encrypted args with a mix of symbols and integers.
14
+
15
+ ## 1.1.1
16
+
17
+ ### Fixed
18
+
19
+ - Client middleware will no longer encrypt already encrypted arguments when a job is retried.
2
20
 
3
21
  ## 1.1.0
4
22
 
5
- * Use `to_json` if it is defined when serializing encrypted args to JSON.
6
- * Add client middleware to the server default configuration. This ensures that arguments will be encrypted if a worker enqueues a job with encrypted arguments.
7
- * Client middleware now reads sidekiq options from the job hash instead of from the worker class so that the list of encrypted arguments is always in sync on the job payload.
8
- * Don't blow up if class name that is not defined is passed to client middleware.
9
- * Added additional option to specify encrypted args with array of argument indexes.
10
- * Deprecated setting encrypted args as hash or array of booleans.
11
- * Client middleware is prepended while server middleware is appended.
23
+ ### Added
24
+
25
+ - Use `to_json` if it is defined when serializing encrypted args to JSON.
26
+ - Add client middleware to the server default configuration. This ensures that arguments will be encrypted if a worker enqueues a job with encrypted arguments.
27
+ - Client middleware now reads sidekiq options from the job hash instead of from the worker class so that the list of encrypted arguments is always in sync on the job payload.
28
+ - Added additional option to specify encrypted args with array of argument indexes.
29
+
30
+ ### Changed
31
+
32
+ - Client middleware is now prepended while server middleware is appended.
33
+
34
+ ### Fixed
35
+
36
+ - Don't raise error if undefined class name is passed to client middleware as a string.
37
+
38
+ ### Deprecated
39
+
40
+ - Deprecated setting encrypted args as hash or array of booleans.
12
41
 
13
42
  ## 1.0.2
14
43
 
15
- * Remove overly noisy log warning when running without the secret set
44
+ ### Changed
45
+
46
+ - Remove overly noisy log warning when running without the secret set
16
47
 
17
48
  ## 1.0.1
18
49
 
19
- * Now works with scheduled jobs
20
- * Scheduled jobs dispatch by class name instead of `Class`, requiring a constant lookup
50
+ ### Fixed
51
+
52
+ - Added support for scheduled jobs
21
53
 
22
54
  ## 1.0.0
23
55
 
24
- * Initial release
56
+ ### Added
57
+
58
+ - Initial release
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Sidekiq Encrypted Args
2
2
 
3
- [![Continuous Integration](https://github.com/bdurand/sidekiq-encrypted_args/workflows/Continuous%20Integration/badge.svg?branch=master)](https://github.com/bdurand/sidekiq-encrypted_args/actions?query=workflow%3A%22Continuous+Integration%22)
4
- [![Maintainability](https://api.codeclimate.com/v1/badges/70ab3782e4d5285eb173/maintainability)](https://codeclimate.com/github/bdurand/sidekiq-encrypted_args/maintainability)
3
+ [![Continuous Integration](https://github.com/bdurand/sidekiq-encrypted_args/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/bdurand/sidekiq-encrypted_args/actions/workflows/continuous_integration.yml)
5
4
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
5
+ [![Gem Version](https://badge.fury.io/rb/sidekiq-encrypted_args.svg)](https://badge.fury.io/rb/sidekiq-encrypted_args)
6
6
 
7
7
  Support for encrypting arguments for [Sidekiq](https://github.com/mperham/sidekiq).
8
8
 
@@ -106,3 +106,31 @@ You can also safely add encryption to an existing worker. Any jobs that are alre
106
106
  ## Encryption
107
107
 
108
108
  Encrypted arguments are stored using AES-256-GCM with a key derived from your secret using PBKDF2. For more info on the underlying encryption, refer to the [SecretKeys](https://github.com/bdurand/secret_keys) gem.
109
+
110
+ ## Installation
111
+
112
+ Add this line to your application's Gemfile:
113
+
114
+ ```ruby
115
+ gem "sidekiq-encrypted_args"
116
+ ```
117
+
118
+ And then execute:
119
+ ```bash
120
+ $ bundle
121
+ ```
122
+
123
+ Or install it yourself as:
124
+ ```bash
125
+ $ gem install sidekiq-encrypted_args
126
+ ```
127
+
128
+ ## Contributing
129
+
130
+ Open a pull request on GitHub.
131
+
132
+ Please use the [standardrb](https://github.com/testdouble/standard) syntax and lint your code with `standardrb --fix` before submitting.
133
+
134
+ ## License
135
+
136
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -4,6 +4,11 @@ module Sidekiq
4
4
  module EncryptedArgs
5
5
  # Sidekiq client middleware for encrypting arguments on jobs for workers
6
6
  # with `encrypted_args` set in the `sidekiq_options`.
7
+ #
8
+ # This middleware is responsible for encrypting job arguments before they
9
+ # are sent to Redis. It runs on the client side when jobs are enqueued.
10
+ #
11
+ # @see ServerMiddleware
7
12
  class ClientMiddleware
8
13
  # Encrypt specified arguments before they're sent off to the queue
9
14
  def call(worker_class, job, queue, redis_pool = nil)
@@ -21,14 +26,14 @@ module Sidekiq
21
26
  #
22
27
  # Additionally, set `job["encrypted_args"]` to the canonicalized version (i.e. `Array<Integer>`)
23
28
  #
24
- # @param [Hash]
29
+ # @param [Hash] job The Sidekiq job hash containing arguments and metadata
25
30
  # @param [Array<Integer>] encrypted_args array of indexes in job to encrypt
26
31
  # @return [void]
27
32
  def encrypt_job_arguments!(job, encrypted_args)
28
33
  if encrypted_args
29
34
  job_args = job["args"]
30
35
  job_args.each_with_index do |value, position|
31
- if encrypted_args.include?(position)
36
+ if encrypted_args.include?(position) && !EncryptedArgs.encrypted?(value)
32
37
  job_args[position] = EncryptedArgs.encrypt(value)
33
38
  end
34
39
  end
@@ -3,6 +3,12 @@
3
3
  module Sidekiq
4
4
  module EncryptedArgs
5
5
  # Sidekiq server middleware for decrypting arguments on jobs that have encrypted args.
6
+ #
7
+ # This middleware is responsible for decrypting job arguments before they
8
+ # are passed to the worker's perform method. It runs on the server side
9
+ # when jobs are processed.
10
+ #
11
+ # @see ClientMiddleware
6
12
  class ServerMiddleware
7
13
  # Wrap the server process to decrypt incoming arguments
8
14
  def call(worker, job, queue)
@@ -5,6 +5,11 @@ require "secret_keys"
5
5
  require "sidekiq"
6
6
 
7
7
  module Sidekiq
8
+ # Provides middleware for encrypting sensitive arguments in Sidekiq jobs.
9
+ #
10
+ # This module allows you to specify which job arguments should be encrypted
11
+ # in Redis to protect sensitive information like API keys, passwords, or
12
+ # personally identifiable information.
8
13
  module EncryptedArgs
9
14
  # Error thrown when the secret is invalid
10
15
  class InvalidSecretError < StandardError
@@ -25,18 +30,31 @@ module Sidekiq
25
30
  # when decrypting the arguments when the job gets run. If you are using the
26
31
  # environment variable, separate the keys with spaces.
27
32
  #
28
- # @param [String] value One or more secrets to use for encrypting arguments.
33
+ # @example Setting a single secret
34
+ # Sidekiq::EncryptedArgs.secret = "your_secret_key"
35
+ #
36
+ # @example Rolling secrets (multiple keys for backward compatibility)
37
+ # Sidekiq::EncryptedArgs.secret = ["new_secret", "old_secret", "older_secret"]
38
+ #
39
+ # @param [String, Array<String>] value One or more secrets to use for encrypting arguments.
29
40
  # @return [void]
30
41
  def secret=(value)
31
42
  @encryptors = make_encryptors(value)
32
43
  end
33
44
 
34
- # Add the client and server middleware to the Sidekiq
45
+ # Add the client and server middleware to the default Sidekiq
35
46
  # middleware chains. If you need to ensure the order of where the middleware is
36
47
  # added, you can forgo this method and add it yourself.
37
48
  #
38
49
  # This method prepends client middleware and appends server middleware.
39
50
  #
51
+ # @example Basic configuration
52
+ # Sidekiq::EncryptedArgs.configure!(secret: "your_secret_key")
53
+ #
54
+ # @example Configuration using environment variable
55
+ # ENV['SIDEKIQ_ENCRYPTED_ARGS_SECRET'] = "your_secret_key"
56
+ # Sidekiq::EncryptedArgs.configure!
57
+ #
40
58
  # @param [String] secret optionally set the secret here. See {.secret=}
41
59
  def configure!(secret: nil)
42
60
  self.secret = secret unless secret.nil?
@@ -59,11 +77,18 @@ module Sidekiq
59
77
 
60
78
  # Encrypt a value.
61
79
  #
80
+ # @example Encrypting a simple value
81
+ # EncryptedArgs.encrypt("secret_value") #=> "encrypted_string"
82
+ #
83
+ # @example Encrypting complex data
84
+ # EncryptedArgs.encrypt({api_key: "secret", user_id: 123}) #=> "encrypted_string"
85
+ #
62
86
  # @param [#to_json, Object] data Data to encrypt. You can pass any JSON compatible data types or structures.
63
87
  #
64
88
  # @return [String]
65
89
  def encrypt(data)
66
90
  return nil if data.nil?
91
+
67
92
  json = (data.respond_to?(:to_json) ? data.to_json : JSON.generate(data))
68
93
  encrypted = encrypt_string(json)
69
94
  if encrypted == json
@@ -75,6 +100,12 @@ module Sidekiq
75
100
 
76
101
  # Decrypt data
77
102
  #
103
+ # @example Decrypting an encrypted value
104
+ # EncryptedArgs.decrypt("encrypted_string") #=> "original_value"
105
+ #
106
+ # @example Handling unencrypted data
107
+ # EncryptedArgs.decrypt("unencrypted_string") #=> "unencrypted_string"
108
+ #
78
109
  # @param [String] encrypted_data Data that was previously encrypted. If the value passed in is
79
110
  # an unencrypted string, then the string itself will be returned.
80
111
  #
@@ -85,6 +116,13 @@ module Sidekiq
85
116
  JSON.parse(json)
86
117
  end
87
118
 
119
+ # Check if a value is encrypted.
120
+ #
121
+ # @return [Boolean]
122
+ def encrypted?(value)
123
+ SecretKeys::Encryptor.encrypted?(value)
124
+ end
125
+
88
126
  # Private helper method to get the encrypted args option from an options hash. The value of this option
89
127
  # can be `true` or an array indicating if each positional argument should be encrypted, or a hash
90
128
  # with keys for the argument position and true as the value.
@@ -99,11 +137,9 @@ module Sidekiq
99
137
  if option == true
100
138
  job["args"].size.times { |i| indexes << i }
101
139
  elsif option.is_a?(Hash)
102
- deprecation_warning("hash")
103
- indexes = replace_argument_positions(worker_class, option)
140
+ raise ArgumentError.new("Hash-based argument encryption is no longer supported.")
104
141
  else
105
142
  array_type = nil
106
- deprecation_message = nil
107
143
  Array(option).each_with_index do |val, position|
108
144
  current_type = nil
109
145
  if val.is_a?(Integer)
@@ -115,16 +151,15 @@ module Sidekiq
115
151
  indexes << position if position
116
152
  current_type = :symbol
117
153
  else
118
- deprecation_message = "boolean array"
119
- indexes << position if val
154
+ raise ArgumentError.new("Encrypted args must be specified as integers or symbols.")
120
155
  end
156
+
121
157
  if array_type && current_type
122
- deprecation_message = "array of mixed types"
158
+ raise ArgumentError.new("Encrypted args cannot mix integers and symbols.")
123
159
  else
124
160
  array_type ||= current_type
125
161
  end
126
162
  end
127
- deprecation_warning(deprecation_message) if deprecation_message
128
163
  end
129
164
  indexes
130
165
  end
@@ -164,10 +199,6 @@ module Sidekiq
164
199
  Array(secrets).map { |val| val.nil? ? nil : SecretKeys::Encryptor.from_password(val, SALT) }
165
200
  end
166
201
 
167
- def deprecation_warning(message)
168
- warn("Sidekiq::EncryptedArgs: setting encrypted_args to #{message} is deprecated; support will be removed in version 1.2.")
169
- end
170
-
171
202
  # @param [String] class_name name of a class
172
203
  # @return [Class] class that was referenced by name
173
204
  def constantize(class_name)
@@ -183,11 +214,12 @@ module Sidekiq
183
214
  encrypted_indexes = []
184
215
  encrypt_option_hash.each do |key, value|
185
216
  next unless value
186
- if key.is_a?(Symbol) || key.is_a?(String)
217
+
218
+ if key.is_a?(Integer) || (key.is_a?(String) && key.match?(INTEGER_PATTERN))
219
+ encrypted_indexes << key.to_i
220
+ elsif key.is_a?(Symbol) || key.is_a?(String)
187
221
  position = perform_method_parameter_index(worker_class, key)
188
222
  encrypted_indexes << position if position
189
- elsif key.is_a?(Integer)
190
- encrypted_indexes << key
191
223
  end
192
224
  end
193
225
  encrypted_indexes
@@ -8,6 +8,12 @@ Gem::Specification.new do |spec|
8
8
  spec.homepage = "https://github.com/bdurand/sidekiq-encrypted_args"
9
9
  spec.license = "MIT"
10
10
 
11
+ spec.metadata = {
12
+ "homepage_uri" => spec.homepage,
13
+ "source_code_uri" => spec.homepage,
14
+ "changelog_uri" => "#{spec.homepage}/blob/main/CHANGE_LOG.md"
15
+ }
16
+
11
17
  # Specify which files should be added to the gem when it is released.
12
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
13
19
  ignore_files = %w[
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-encrypted_args
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
  - Brian Durand
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-15 00:00:00.000000000 Z
12
+ date: 2025-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
@@ -75,7 +75,10 @@ files:
75
75
  homepage: https://github.com/bdurand/sidekiq-encrypted_args
76
76
  licenses:
77
77
  - MIT
78
- metadata: {}
78
+ metadata:
79
+ homepage_uri: https://github.com/bdurand/sidekiq-encrypted_args
80
+ source_code_uri: https://github.com/bdurand/sidekiq-encrypted_args
81
+ changelog_uri: https://github.com/bdurand/sidekiq-encrypted_args/blob/main/CHANGE_LOG.md
79
82
  post_install_message:
80
83
  rdoc_options: []
81
84
  require_paths:
@@ -91,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
94
  - !ruby/object:Gem::Version
92
95
  version: '0'
93
96
  requirements: []
94
- rubygems_version: 3.1.2
97
+ rubygems_version: 3.4.10
95
98
  signing_key:
96
99
  specification_version: 4
97
100
  summary: Support for encrypting arguments that contain sensitive information in sidekiq