You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to EMQX, and trying to set up jwt-auth from vanilla in a dev environment. I am following the docs.
emqx_auth_jwt.conf is:
# etc/plugins/emqx_auth_jwt.conf## Key
auth.jwt.secret = emqxsecret
## The way the client carries the token## Value: username | password
auth.jwt.from = password
## Advanced options## Public key file, certificate is used when signing the key
auth.jwt.pubkey = etc/certs/jwt_public_key.pem
## Value: on | off
auth.jwt.verify_claims = off
## auth.jwt.verify_claims.$name = expected## Variables:## - %u: username## - %c: clientid# auth.jwt.verify_claims.username = %u
etc/certs/jwt_public_key.pem does not exist from clean install (Ubuntu 18.04), and I cannot find instructions for creating it from "emqxsecret".
I have tried:
creating fresh private / public keys and using the new public.pem
commenting out auth.jwt.pubkey = etc/certs/jwt_public_key.pem
But in all circumstances, when trying to start the emqx_auth_jwt plugin from dashboard, I am getting the following error:
I resolved the first of my issues: auth.jwt.pubkey = etc/certs/jwt_public_key.pem needs to locate to an absolute OS dir, it is not an alias or relative path.
For Ubuntu 18.04 install from repo: auth.jwt.pubkey = /etc/emqx/certs/jwt_public_key.pem
I am still struggling with the next one:
What does jwt_public_key.pem do?
I am able to drop in any public cert at that filename, and:
The emqx behaviour stays the same for the default JWT provided in the docs. (Client is authorised)
I create a new HS256 JWT from the secret, which gives a much shorter string than the default JWT, and the client is still authorised.
I create a new JWT from RSA 2048 private key (with corresponding public.pem in EMQX), and the client is not authorised.
I am guessing that the trick is to create a RSA private/public keypair from the HMAC Hash Secret which supports HS256 validation - but how do I do that???? The googling is now becoming EPIC...
Ok, solved.....
Please excuse my temporary stupidity.
This is an either/or situation,
so use either [HMAC HS256] OR [RSA / ECDSA]
So, using jose in node.js as an example:
const{JWK: { generateSync, asKey },JWT}=require('jose');//for HMACconstsecretKey=asKey('emqxsecret',{alg: 'HS256'});//OR for RSAconstprivateKey=generateSync('RSA',2048,{alg: 'RS256'})constpublicKey=privateKey.toPEM()console.log(publicKey);//this is /etc/emqx/certs/jwt_public_key.pem//SIGNconsttestToken=JWT.sign({test: 'test'},(privateKey||secretKey),{expiresIn: '1 day'});console.log(testToken);//the JWT token to be passed to EMQx
EMQX v4.0.6
Ubuntu 18.04 - installed from repo
I am new to EMQX, and trying to set up jwt-auth from vanilla in a dev environment. I am following the docs.
emqx_auth_jwt.conf
is:etc/certs/jwt_public_key.pem
does not exist from clean install (Ubuntu 18.04), and I cannot find instructions for creating it from "emqxsecret".I have tried:
auth.jwt.pubkey = etc/certs/jwt_public_key.pem
But in all circumstances, when trying to start the
emqx_auth_jwt
plugin from dashboard, I am getting the following error:I believe that this is not an error, but me missing some basic key/cert concept here, but I cannot find documentation to help get me up and running.
Thanks in advance...
The text was updated successfully, but these errors were encountered: