docker-library / ruby

Docker Official Image packaging for Ruby
http://www.ruby-lang.org/
BSD 2-Clause "Simplified" License
590 stars 334 forks source link

Strange issue with OpenSSL on linux/arm64 variant #468

Closed heyvito closed 3 months ago

heyvito commented 3 months ago

Hi there, folks! I just stumbled across a weird scenario with OpenSSL.

Running a container on macOS M2 Max under the host's architecture (linux/arm64), OpenSSL fails with their own examples:

key = "key"
data = "message-to-be-authenticated"
mac = OpenSSL::HMAC.hexdigest("SHA256", key, data)
#=> "cddb0db23f469c8bf072b21fd837149bd6ace9ab771cceef14c9e517cc93282"

Under linux/arm64:

docker run --rm -it ruby:3
or
docker run --rm -it --platform linux/arm64 ruby:3
irb(main):002> key = "key"
irb(main):003> data = "message-to-be-authenticated"
irb(main):004> mac = OpenSSL::HMAC.hexdigest("SHA256", key, data)
/usr/local/lib/ruby/3.3.0/openssl/hmac.rb:55:in `initialize': wrong number of arguments (given 2, expected 0) (ArgumentError)

        hmac = new(key, digest)
                   ^^^^^^^^^^^
    from /usr/local/lib/ruby/3.3.0/openssl/hmac.rb:55:in `new'
    from /usr/local/lib/ruby/3.3.0/openssl/hmac.rb:55:in `hexdigest'
    from (irb):4:in `<main>'
    from <internal:kernel>:187:in `loop'
    from /usr/local/lib/ruby/gems/3.3.0/gems/irb-1.13.1/exe/irb:9:in `<top (required)>'
    from /usr/local/bin/irb:25:in `load'
    from /usr/local/bin/irb:25:in `<main>'

Under linux/amd64:

docker run --rm -it --platform linux/amd64 ruby:3
irb(main):005> key = "key"
irb(main):006> data = "message-to-be-authenticated"
irb(main):007> mac = OpenSSL::HMAC.hexdigest("SHA256", key, data)
=> "cddb0db23f469c8bf072b21fd837149bd6ace9ab771cceef14c9e517cc93282e"

Is this expected? Did I miss something?

Appreciate any kind of help or direction!

tianon commented 3 months ago

This feels really familiar, but I can't seem to find whatever issue it was that is triggering my memory. :sob:

This is definitely weird, however, I can't seem to actually reproduce? :sweat_smile:

require 'openssl'
key = "key"
data = "message-to-be-authenticated"
mac = OpenSSL::HMAC.hexdigest("SHA256", key, data)
$ docker run -it --rm --pull=always --platform linux/amd64 ruby:3
3: Pulling from library/ruby
Digest: sha256:d4233f4242ea25346f157709bb8417c615e7478468e2699c8e86a4e1f0156de8
Status: Image is up to date for ruby:3
irb(main):001> require 'openssl'
irb(main):002> key = "key"
irb(main):003> data = "message-to-be-authenticated"
irb(main):004> mac = OpenSSL::HMAC.hexdigest("SHA256", key, data)
=> "cddb0db23f469c8bf072b21fd837149bd6ace9ab771cceef14c9e517cc93282e"

$ docker run -it --rm --pull=always --platform linux/arm64/v8 ruby:3
3: Pulling from library/ruby
Digest: sha256:d4233f4242ea25346f157709bb8417c615e7478468e2699c8e86a4e1f0156de8
Status: Image is up to date for ruby:3
irb(main):001> require 'openssl'
irb(main):002> key = "key"
irb(main):003> data = "message-to-be-authenticated"
irb(main):004> mac = OpenSSL::HMAC.hexdigest("SHA256", key, data)
=> "cddb0db23f469c8bf072b21fd837149bd6ace9ab771cceef14c9e517cc93282e"
heyvito commented 3 months ago

Okay, it seems I can't reproduce it either, but it also downloaded a newer image, so I'm not really sure what happened now. 😓

I'll close this one! Sorry for the spurious issue, and thank you for replying! 💛

 λ | docker run -it --rm --pull=always ruby:3
3: Pulling from library/ruby
Digest: sha256:d4233f4242ea25346f157709bb8417c615e7478468e2699c8e86a4e1f0156de8
Status: Downloaded newer image for ruby:3
irb(main):001> require 'openssl'
=> true
irb(main):002> key = "key"
=> "key"
irb(main):003> data = "message-to-be-authenticated"
=> "message-to-be-authenticated"
irb(main):004> mac = OpenSSL::HMAC.hexdigest("SHA256", key, data)
=> "cddb0db23f469c8bf072b21fd837149bd6ace9ab771cceef14c9e517cc93282e"
irb(main):005>
λ | docker run -it --rm --pull=always --platform linux/amd64 ruby:3
3: Pulling from library/ruby
Digest: sha256:d4233f4242ea25346f157709bb8417c615e7478468e2699c8e86a4e1f0156de8
Status: Downloaded newer image for ruby:3
irb(main):001> require 'openssl'
=> true
irb(main):002> key = "key"
=> "key"
irb(main):003> data = "message-to-be-authenticated"
=> "message-to-be-authenticated"
irb(main):004> mac = OpenSSL::HMAC.hexdigest("SHA256", key, data)
=> "cddb0db23f469c8bf072b21fd837149bd6ace9ab771cceef14c9e517cc93282e"