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

handle bearer token #4262

Merged
merged 1 commit into from
Apr 23, 2024
Merged

handle bearer token #4262

merged 1 commit into from
Apr 23, 2024

Conversation

LesnyRumcajs
Copy link
Member

@LesnyRumcajs LesnyRumcajs commented Apr 23, 2024

Summary of changes

Changes introduced in this pull request:

  • align JWT usage with Lotus (and in general JSON Web Token specification) - header values shall include the Bearer prefix. This is necessary, e.g., for the api compare to support sending write tokens to Lotus, see Go JSON-RPC authorization handling.
  • Added some tests to untested code.

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@LesnyRumcajs LesnyRumcajs marked this pull request as ready for review April 23, 2024 13:37
@LesnyRumcajs LesnyRumcajs requested a review from a team as a code owner April 23, 2024 13:37
@LesnyRumcajs LesnyRumcajs requested review from lemmih, hanabi1224, a team and elmattic and removed request for a team and lemmih April 23, 2024 13:37
@ruseinov ruseinov self-requested a review April 23, 2024 14:12
Copy link
Contributor

@ruseinov ruseinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we now require Bearer prefix too - we need to make sure api compare and other tools that are parsing tokens from env or arguments prepend Bearer, when the token is available.
Another solution would be just to specify a token already with a Bearer prefix, but that's not very handy, because there is a space between the prefix and the actual token, so it'd require quotation marks and it potentially won't work for api compare token:host format.

It had already bitten me when I was testing a Write permissioned endpoint. Even though we don't have any automated tests for those endpoints yet.

@LesnyRumcajs
Copy link
Member Author

Since we now require Bearer prefix too - we need to make sure api compare and other tools that are parsing tokens from env or arguments prepend Bearer, when the token is available. Another solution would be just to specify a token already with a Bearer prefix, but that's not very handy, because there is a space between the prefix and the actual token, so it'd require quotation marks and it potentially won't work for api compare token:host format.

It had already bitten me when I was testing a Write permissioned endpoint. Even though we don't have any automated tests for those endpoints yet.

I don't understand your point. The changes already work for api compare, and others. This is a cherry-pick from my branch that requires write access.

@ruseinov
Copy link
Contributor

ruseinov commented Apr 23, 2024

Here's an example of api compare usage with specified token.

forest-tool api compare "/Users/romanuseinov/Library/Application Support/com.ChainSafe.Forest/calibnet/0.17.2/car_db/1713525012514.forest.car.zst" --filter=SyncSub --forest "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXSwiZXhwIjoxNzE4NzE1NDA1fQ.iYPmOk-dytEbtdH7EmEE1tad83rvUqUgGkwKlD7VaO4:/ip4/127.0.0.1/tcp/2345/http"

This will fail miserably, because Bearer prefix is required. Wouldn't it be logical to prepend Bearer prefix as opposed to having to manually specify it?

@LesnyRumcajs
Copy link
Member Author

Here's an example of api compare usage with specified token.

forest-tool api compare "/Users/romanuseinov/Library/Application Support/com.ChainSafe.Forest/calibnet/0.17.2/car_db/1713525012514.forest.car.zst" --filter=SyncSub --forest "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXSwiZXhwIjoxNzE4NzE1NDA1fQ.iYPmOk-dytEbtdH7EmEE1tad83rvUqUgGkwKlD7VaO4:/ip4/127.0.0.1/tcp/2345/http"

This will fail miserably, because Bearer prefix is required.

And the Bearer prefix is added in client.rs, thus satisfying the requirement.

@ruseinov
Copy link
Contributor

Here's an example of api compare usage with specified token.
forest-tool api compare "/Users/romanuseinov/Library/Application Support/com.ChainSafe.Forest/calibnet/0.17.2/car_db/1713525012514.forest.car.zst" --filter=SyncSub --forest "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXSwiZXhwIjoxNzE4NzE1NDA1fQ.iYPmOk-dytEbtdH7EmEE1tad83rvUqUgGkwKlD7VaO4:/ip4/127.0.0.1/tcp/2345/http"
This will fail miserably, because Bearer prefix is required.

And the Bearer prefix is added in client.rs, thus satisfying the requirement.

My bad, I somehow managed to miss this change.

@ruseinov ruseinov self-requested a review April 23, 2024 14:38
@ruseinov ruseinov added this pull request to the merge queue Apr 23, 2024
Merged via the queue into main with commit 34027aa Apr 23, 2024
30 checks passed
@ruseinov ruseinov deleted the jwt-bearer branch April 23, 2024 14:53
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

Successfully merging this pull request may close these issues.

None yet

3 participants