blindsidenetworks / scalelite

Scalable load balancer for BigBlueButton.
GNU Affero General Public License v3.0
470 stars 247 forks source link

encoding problem in recording_ready_notifier_service #1016

Open afelpeto opened 1 year ago

afelpeto commented 1 year ago

Describe the bug When scalelite tries to send a notification to greenlight in order to let it know that the new recordings are available, greenlight returns a 500 error.

Steps to reproduce the behavior: Just record a meeting with bigbluebutton and wait until it is processed and post_published to scalelite.

Once scalelite unpacks de spool file and inserts all the data o the database, it is sent a POST to https://GREENLIGHT_HOST/recording_ready

Greenlight returns something like this:

I, [2023-08-24T13:36:44.668928 #158] INFO -- : [a22d8093-bdfa-4547-bfe5-b957c8acd4d5] method=POST path=/recording_ready format=/ controller=ExternalController action=recording_ready status=500 allocations=2056 duration=62.76 view=0.00 db=4.26 time=2023-08-24 13:36:44 UTC host=greenlight F, [2023-08-24T13:36:44.670347 #158] FATAL -- : [a22d8093-bdfa-4547-bfe5-b957c8acd4d5] [a22d8093-bdfa-4547-bfe5-b957c8acd4d5] NoMethodError (undefined method []' for nil:NilClass): [a22d8093-bdfa-4547-bfe5-b957c8acd4d5] [a22d8093-bdfa-4547-bfe5-b957c8acd4d5] app/services/recording_creator.rb:25:incall' [a22d8093-bdfa-4547-bfe5-b957c8acd4d5] app/controllers/external_controller.rb:93:in `recording_ready'

Scalelite-recording-importer shows:

I, [2023-08-24T13:36:44.576407 #7] INFO -- : Recording Ready Notify for [zyxhbx9q60cmdi8btaf0eokcmpzsel2ndldnlk3y] starts I, [2023-08-24T13:36:44.576449 #7] INFO -- : Making callback for recording ready notification I, [2023-08-24T13:36:44.577499 #7] INFO -- : Sending request to https://MY-GREENLIGHT/recording_ready I, [2023-08-24T13:36:44.671697 #7] INFO -- : Callback HTTP request failed: 500 Internal Server Error (code 500)

Deployment:

  1. Haproxy server (public ip) serving connections towards greenlight v3.0.6 (docker deployment)(private ip)
  2. Scalelite v1.5.1.5 (docker deployment) configured with public ip (no tenants)
  3. 3 BBB 2.6 servers (traditional setup) configured with public ip per host

Expected behavior Greenlight should return

I, [2023-08-24T13:36:45.274107 #158] INFO -- : [47426e61-ca9e-463c-bc7d-bef4a733934a] method=POST path=/recording_ready format=/ controller=ExternalController action=recording_ready status=200 allocations=8125 duration=108.14 view=4.27 db=26.19 time=2023-08-24 13:36:45 UTC host=greenlight I, [2023-08-24T13:36:45.830841 #158] INFO -- : BigBlueButtonAPI: request=https://MY-SCALELITE/bigbluebutton/api/getRecordings?recordID=1bf3973c5430f1b513334fc8288bef8635ba79a1-1692884157778&checksum=ad5ca096925b5df5630e0223aedcdd4e25814866 response_status=Net::HTTPOK response_code=200 message_key=OK

scalelite-recording-importer should return:

I, [2023-08-24T13:36:45.147553 #7] INFO -- : Recording Ready Notify for [zyxhbx9q60cmdi8btaf0eokcmpzsel2ndldnlk3y] starts I, [2023-08-24T13:36:45.147609 #7] INFO -- : Making callback for recording ready notification I, [2023-08-24T13:36:45.148003 #7] INFO -- : Sending request to https://MY-GREENLIGHT/recording_ready I, [2023-08-24T13:36:45.274474 #7] INFO -- : Recording notifier successful: zyxhbx9q60cmdi8btaf0eokcmpzsel2ndldnlk3y (code 200)

source code from scalelite (app/services/recording_ready_notifier_service.rb) Scalelite encodes without using any algorithm

    def encoded_payload(meeting_id, record_id, tenant_name)
      secret = fetch_secrets(tenant_name: tenant_name)[0]
      payload = { meeting_id: meeting_id, record_id: record_id }
      JWT.encode(payload, secret)
    end

source code from greenlight (app/services/big_blue_button_api.rb) Meanwhile greenlight decodes the BBB/scalelite response using HS256

  def decode_jwt(token)
    JWT.decode token, @secret, true, { algorithm: 'HS256' }
  end

SOLUTION on app/services/recording_ready_notifier_service.rb JWT.encode(payload, secret,'HS256')