-
Notifications
You must be signed in to change notification settings - Fork 174
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
if auth_opt_jwt_skip_user_expiration
enabled, in case of receive bad token the code crashes. also README descriptions added.
#337
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1000,11 +1000,14 @@ auth_opt_jwt_userquery select count(*) from test_user where username = $1 limit | |
Thus, the following specific JWT local options are supported: | ||
|
||
|
||
| Option | default | Mandatory | Meaning | | ||
| ----------------------- | --------- | :-------: | -------------------------------------------------------- | | ||
| auth_opt_jwt_db | postgres | N | The DB backend to be used, either `postgres` or `mysql` | | ||
| auth_opt_jwt_userquery | | Y | SQL query for users | | ||
|
||
| Option | default | Mandatory | Meaning | | ||
| ----------------------------- | --------- | :-------: | -------------------------------------------------------- | | ||
| auth_opt_jwt_db | postgres | N | The DB backend to be used, either `postgres` or `mysql` | | ||
| auth_opt_jwt_userquery | | Y | SQL query for users | | ||
| auth_opt_jwt_mysql_dbname | | Y/N | must set if auth_opt_jwt_db set is `mysql` | | ||
| auth_opt_jwt_mysql_user | | Y/N | must set if auth_opt_jwt_db set is `mysql` | | ||
| auth_opt_jwt_mysql_password | | Y/N | must set if auth_opt_jwt_db set is `mysql` | | ||
| auth_opt_jwt_mysql_aclquery | | Y/N | ACL query must set if auth_opt_jwt_db set is `mysql` | | ||
|
||
Notice that general `jwt_secret` is mandatory when using this mode. | ||
`jwt_userfield` is still optional and serves as a mean to extract the username from either the claim's `Subject` (`sub` field), | ||
|
@@ -1022,7 +1025,7 @@ auth_opt_jwt_userquery select count(*) from "user" where username = $1 and is_ac | |
For mysql: | ||
|
||
``` | ||
auth_opt_jwt_userquery select count(*) from "user" where username = ? and is_active = true limit 1 | ||
auth_opt_jwt_mysql_aclquery select count(*) from "user" where username = ? and is_active = true limit 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need to remove the valid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, but you wrote an example for PG in a few lines earlier. This line is an example for MySQL, however, this is similar to the previous topic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm not against the addition but the replacement. |
||
``` | ||
|
||
*Important note:* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,15 +132,19 @@ func getJWTClaims(secret string, tokenStr string, skipExpiration bool) (*jwtGo.M | |
}) | ||
|
||
expirationError := false | ||
if err != nil { | ||
if !skipExpiration { | ||
log.Debugf("jwt parse error: %s", err) | ||
return nil, err | ||
} | ||
|
||
if err != nil { | ||
if v, ok := err.(*jwtGo.ValidationError); ok && v.Errors == jwtGo.ValidationErrorExpired { | ||
expirationError = true | ||
} | ||
log.Debugf("token expired: %s", err) | ||
if skipExpiration { | ||
expirationError = true | ||
}else{ | ||
log.Debugf("jwt parse error: %s", err) | ||
return nil, err | ||
} | ||
}else{ | ||
log.Debugf("jwt parse error: %s", err) | ||
return nil, err | ||
} | ||
Comment on lines
+135
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The format is a bit weird, Go's formatter should have caught missing spaces. Also, I'd structure it like this instead to skip the inner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On another note, I'd also add a test with some wrong token that previously would crash and now doesn't. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great good job There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mahdizadsar let me know if you plan on adding that test and addressing other concerns so we may merge. |
||
} | ||
|
||
if !jwtToken.Valid && !expirationError { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree the explanation could be a bit better, but it's all stated in https://github.com/iegomez/mosquitto-go-auth?tab=readme-ov-file#local-mode.
My nitpick here is that this table doesn't include all the rest of the options that are still valid, albeit not mandatory, but doing so for both PG and MySQL is a bit repetitive.
So maybe just change a bit the wording instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but I suggest that the tables should be completed in order to explicitly specify which items are mandatory for a particular situation. In this case, to use MySQL in JWT mode, the fields I wrote seem mandatory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I was just saying that besides the user query, which becomes irrelevant, all the options still follow the same mandatoriness that's spelled on PG and MySQL sections.
That said, I'm not really against being super clear, so if you want to throw in exhaustive tables for both DBs in the JWT case, all the better.