Skip to content

fix: declare bigdecimal and logger, drop the need for base64 and the full cgi library - #224

Merged
aaron-congo merged 5 commits into
mainfrom
fix/declare-default-gem-dependencies
Oct 28, 2026
Merged

aaron-congo merged 5 commits into
mainfrom
fix/declare-default-gem-dependencies

Conversation

@aaron-congo

Copy link
Copy Markdown
Contributor

Summary

Make the wrapper load on Ruby 3.4 and 4.0 in bundles that don't include the gems Ruby stopped installing by default.

Description

The wrapper requires base64, bigdecimal, logger and cgi but declared none of them. Ruby stopped installing base64 and bigdecimal by default in 3.4, and logger in 4.0, and 4.0 also removed the cgi library except for cgi/escape. So on Ruby 3.4+ a bundle that doesn't pull these in some other way raises LoadError as soon as it requires the wrapper (confirmed on Ruby 4.0.9), and on Ruby 3.3 it loads but prints deprecation warnings. Active Record apps are mostly unaffected, because ActiveSupport already depends on base64, bigdecimal and logger; apps using pg or mysql2 directly are not.

  • Gemspec: declare bigdecimal and logger as runtime dependencies, unconstrained. On Ruby 3.3 Bundler uses the copies Ruby already ships. Both are needed: bigdecimal is how Active Record represents decimal values, which the KMS plugin round-trips, and logger is the default logger.
  • KMS key manager: encode and decode data keys with Array#pack('m0') / String#unpack1('m0') instead of Base64.strict_encode64 / strict_decode64, which are thin wrappers over them. The output and the ArgumentError on invalid input are identical, and the wrapper no longer needs the base64 gem.
  • AD FS and Okta plugins: require 'cgi/escape' instead of require 'cgi'. They only use CGI.escape and CGI.unescapeHTML, which cgi/escape provides on every supported Ruby. On 4.0, require 'cgi' still loads but prints a removal warning.

fiddle is not added: the wrapper never requires it. mysql2 does, but only on Windows and without declaring it; that belongs in the docs (aws/aws-advanced-wrapper-docs#46), not in our gemspec.

Testing

  • In the ruby:4.0 image (Ruby 4.0.9), with a bundle of only the wrapper and pg: the PG and MySQL clients, the KMS key manager and both federated plugins load with no warnings (-W), data key base64 round-trips through the new helpers, and Base64 is never loaded. Without this change, base64, bigdecimal and logger each raise LoadError there.
  • On Ruby 3.3, the same minimal bundle loads with no deprecation warnings.
  • Unit: 3231 examples, 0 failures on the default Gemfile and the ActiveRecord 7.2/8.0/8.1 gemfiles. RuboCop and bundle-audit are clean.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The wrapper requires base64, bigdecimal and logger. Ruby stopped
installing base64 and bigdecimal by default in 3.4, and logger in 4.0,
so on those versions a bundle that does not otherwise include them -
such as an app using pg or mysql2 without Active Record - raised
LoadError when it required the wrapper. On Ruby 3.3 the same bundle
loaded but printed deprecation warnings.

Declaring them in the gemspec makes Bundler install them wherever they
are needed. On older Rubies Bundler uses the copies Ruby already ships.
The AD FS and Okta plugins use only CGI.escape and CGI.unescapeHTML, which
cgi/escape provides. Ruby 4.0 no longer ships the rest of the cgi library,
so require cgi/escape instead of cgi.
The KMS key manager only used Base64.strict_encode64 and strict_decode64,
which are thin wrappers over Array#pack('m0') and String#unpack1('m0').
Using those directly removes the wrapper's need for the base64 gem, so it
no longer has to be declared as a dependency.
@aaron-congo
aaron-congo requested a review from a team as a code owner October 27, 2026 15:32
@aaron-congo
aaron-congo merged commit c10f4a4 into main Oct 28, 2026
17 of 24 checks passed
@aaron-congo
aaron-congo deleted the fix/declare-default-gem-dependencies branch October 28, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants