Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JWT Auth - RS512 unsupported, because cannot possibly supply private key in the JWT_APP_SECRET variable #1771

Open
DevelopingEntitiesWithFuntations opened this issue Mar 24, 2024 · 37 comments

Comments

@DevelopingEntitiesWithFuntations
Copy link
Contributor

In JWT Auth environment variables there's no alternative to provide a private key file or to add it directly to the JWT_APP_SECRET variable, because it will complain about the first "+" in the private key.

I wanted to implement RS512 JWT checking, but realized it's not possible to do that with Docker at least, because the Lua script will simply fail at one of those characters.

It would be nice to mention that in the documentation with the supported algs.

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

Weird because here they mention RS256 for example: https://github.com/jitsi/lib-jitsi-meet/blob/master/doc/tokens.md

@saghul
Copy link
Member

saghul commented Mar 24, 2024

What images version are you using and how does your .env file look like?

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

@saghul Thank you for your prompt reply. I am running stable-9364 and the .env looks like this (only the essential stuff so that I don't flood with unnecessary entries):

# Enable authentication
ENABLE_AUTH=1

# Enable guest access
ENABLE_GUESTS=1

# Select authentication type: internal, jwt, ldap or matrix
AUTH_TYPE=jwt

# JWT authentication
#

# Application identifier
JWT_APP_ID=myjitsiid

# Application secret known only to your token generator
JWT_APP_SECRET=-----BEGIN RSA PRIVATE KEY-----
keycontentshere
-----END RSA PRIVATE KEY-----

Perhaps I just need to dearmor it, but I haven't seen any functionality in the code to actually support RS512 like that as mentioned above

@damencho
Copy link
Member

To use RS512 you need to setup: JWT_ASAP_KEYSERVER

asap_key_server = "{{ .Env.JWT_ASAP_KEYSERVER }}"

For the Public Key Validation a key server must be provided via asap_key_server .... 

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

@damencho ahh the documentation states or looks as if the two variables JWT_APP_ID and JWT_APP_SECRET were required, but blog posts and similar seem to state that the latter one is optional in that case...

@damencho
Copy link
Member

Yep it is secret or asap server.

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

Yup, so that specific part of documentation is weirdly written, but the code is correct.

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

Please reopen, since when I try using RS512 with a static kid and a static pubkey and privkey I get the following error:

2024-03-26 19:14:22 meet.jitsi:auth_token                                        warn   Error verifying token err:not-allowed, reason:Invalid or incorrect alg

@damencho damencho reopened this Mar 26, 2024
@damencho
Copy link
Member

What it is the jwt header?

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

I've used static kid and pubkey to minimize the amount of variables at play here if you're wondering.. in an OIDC flow it would be hard to comprehend where is the error originating from

@saghul
Copy link
Member

saghul commented Mar 26, 2024

There is a parameter to co figure the key mode, did you set it?

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

What it is the jwt header?

{
  "alg": "RS512",
  "typ": "JWT",
  "kid": "RS512.key.pub"
}

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

There is a parameter to co figure the key mode, did you set it?

You mean JWT_AUTH_TYPE ?

@damencho
Copy link
Member

And you have on the public key server file with the public key: 1e498e0c1d6dd521618c0da2fd301aa9f9a5e44986b52a617c078cfb5c554c1b.pem?

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

And you have on the public key server file with the public key: 1e498e0c1d6dd521618c0da2fd301aa9f9a5e44986b52a617c078cfb5c554c1b.pem?

Yes, it doesn't get 404 anymore. I fixed it beforehand, initially I named it just the hash without the .pem file ending

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

It fetches the cert for sure, that's what I wanted to say. I don't get it why I get the error. It seems to originate from luajwtjitsi.lib.lua

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

I'm gonna post the contents of the payload for safety as well. For example, I didn't set nbf to 0...

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

{
  "context": {
    "user": {
      "avatar": "https://assets1.cbsnewsstatic.com/hub/i/r/2016/03/11/6c23251d-8ace-457d-a99b-55b7b8141354/thumbnail/1240x1748/60fcbf89ce937196e5a5bfc9f5af3ab2/gettyimages-514174416.jpg",
      "name": "Dev",
      "email": "me@homeboy.home"
    }
  },
  "moderator": true,
  "iat": 1711474277,
  "nbf": 1711474297,
  "exp": 1719363545,
  "aud": "jitsi-app",
  "iss": "jitsi-app",
  "sub": "meet.jitsi",
  "room": "*"
}

@saghul
Copy link
Member

saghul commented Mar 26, 2024

https://github.com/jitsi/jitsi-meet/blob/bb49c92cc40f23d8203173b5b538d5dc789216c9/resources/prosody-plugins/token/util.lib.lua#L47

This needs to be configured to RS512. If there is an ASAP key server we default to RS256.

I don't think we expose a setting for it in Docker, we'd need to add one.

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

https://github.com/jitsi/jitsi-meet/blob/bb49c92cc40f23d8203173b5b538d5dc789216c9/resources/prosody-plugins/token/util.lib.lua#L47

This needs to be configured to RS512. If there is an ASAP key server we default to RS256.

I don't think we expose a setting for it in Docker, we'd need to add one.

I tried manually setting the default to RS512, but I need to reload the config to test it. Is it possible somehow within the container? (only for testing purposes)

@saghul
Copy link
Member

saghul commented Mar 26, 2024

Alas i don't think so. You could volume mount a modified file.

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

Managed to reload it with prosodyctl --config /config/prosody.cfg.lua restart, that's the fix, yeah, silly silly default :P

@damencho
Copy link
Member

Not sure you can do that in docker, but:

prosodyctl reload
prosodyctl module reload auth_token

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

What's the best approach to fix this? To detect the alg instead of relying on defaults?

@damencho
Copy link
Member

To expose a setting to be able to change default in docker.

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

To expose a setting to be able to change default in docker.

The problem is that it's not part of the prosody/rootfs folder...

I wanted to add it like this:

{{ $JWT_TOKEN_TYPE := .Env.PROSODY_JWT_TOKEN_TYPE | default "RS512" -}}

but it would not work :/

@saghul
Copy link
Member

saghul commented Mar 30, 2024

It can be because it's a Prosody module setting.

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

How do I expose it then? With a static volume mount / bind mount?

@saghul
Copy link
Member

saghul commented Mar 30, 2024

An option with the name signature_algorithm needs to be exposed, akin to app_id.

DevelopingEntitiesWithFuntations added a commit to DevelopingEntitiesWithFuntations/docker-jitsi-meet that referenced this issue Mar 30, 2024
@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

Didn't have any rights to make a new branch and/or make a PR so forked it and edited it accordingly: https://github.com/DevelopingEntitiesWithFuntations/docker-jitsi-meet/ (it's forked from master though...) This should solve the issue

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

Nvm, managed to create a pull request, please look into it :)

DevelopingEntitiesWithFuntations added a commit to DevelopingEntitiesWithFuntations/docker-jitsi-meet that referenced this issue Mar 31, 2024
@saghul saghul closed this as completed in e939230 Apr 8, 2024
@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

Please reopen..

In the .env I added the following: JWT_SIGN_TYPE=RS512

And yet in the prosody latest stable container I get the following error:
Error verifying token err:not-allowed, reason:Invalid or incorrect alg

@damencho
Copy link
Member

And do you see in the result configuration the correct parameter signature_algorithm?

@damencho damencho reopened this Apr 26, 2024
@damencho
Copy link
Member

That param was added on the wrong place, just for jigasi virtual host.

@damencho
Copy link
Member

That needs to go under the VirtualHost "{{ $XMPP_DOMAIN }}" and you should remove it from the jigasi.meet.jitsi host.

@DevelopingEntitiesWithFuntations
Copy link
Contributor Author

Silly mistake from my side, sorry... Created new PR..

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

No branches or pull requests

3 participants