-
Notifications
You must be signed in to change notification settings - Fork 31
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
Auth Token feature #1952
Auth Token feature #1952
Conversation
dd6925e
to
636d6ac
Compare
636d6ac
to
b0ed068
Compare
This feature is now ready for review |
Hey Luis, sorry for delay! I am planning to review this one by today/tomorrow.. I'll come back to you asap 🚀 |
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.
Hey again,
Here a first round of review, overall looks good and looks working. I tried the use case where I try to upload a new run and it looks working using the generated API key.
curl -s --url-query "test=optaplanner-jmh-benchmarks-8x" -X POST -H "content-type: application/json" -H 'X-Horreum-API-Key: <MY_KEY>' 'http://localhost:8080/api/run/data' -d @/tmp/op-run.json
There are still a couple of comments:
- @barreiro could you please rebase this on top of
master
? those changes shouldn't affect this feature but just to be sure. - Return error msg when the API Key validation failed, I tried to run the same upload command with either a fake key or a revoked one and in both cases no error is returned to the user even if the request failed.
Here an example:
If don't send any auth token, the rest will return a generic error msg:
$ curl -s --url-query "test=optaplanner-jmh-benchmarks-8x" --url-query "owner=optaplanner-team" --url-query "start=2024-07-09T09:45:38" --url-query "stop=2024-07-09T09:45:38" -X POST -H "content-type: application/json" 'http://localhost:8080/api/run/data' -d @/tmp/op-run.json
Cannot upload to test optaplanner-jmh-benchmarks-8x%
and in the logs I see (in DEBUG)
DEBUG [io.hyp.too.hor.svc.TestServiceImpl] (executor-thread-1) Failed to retrieve test optaplanner-jmh-benchmarks-8x as this user ( = []) is not uploader for optaplanner-team and token null does not match
If I send, instead, a revoked token:
$ curl -s --url-query "test=optaplanner-jmh-benchmarks-8x" --url-query "owner=optaplanner-team" --url-query "start=2024-07-09T09:45:38" --url-query "stop=2024-07-09T09:45:38" -X POST -H "content-type: application/json" -H 'X-Horreum-API-Key: HUSR_0A1CE383_38D9_4AFB_B094_99B0D6D6BE73' 'http://localhost:8080/api/run/data' -d @/tmp/op-run.json
there is no response at all and no logs as well, I think it could be very useful to return at least an error msg, even a generic "cannot upload to test ..."
I would suggest to show just the button when there is no API keys set similarly to what we are doing in other places - or showing a message like "No API keys set" and below the button (that's actually just a minor).
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.
@barreiro this looks great!
For this PR, we need user docs adding
For future PR's i think we need to open issues to;
- add global management of keys at admin level
- remove "tokens" and "machine accounts" features
horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/internal/services/UserService.java
Outdated
Show resolved
Hide resolved
horreum-backend/src/main/java/io/hyperfoil/tools/horreum/entity/user/UserApiKey.java
Show resolved
Hide resolved
horreum-backend/src/main/java/io/hyperfoil/tools/horreum/entity/user/UserApiKey.java
Outdated
Show resolved
Hide resolved
horreum-backend/src/main/java/io/hyperfoil/tools/horreum/entity/user/UserApiKey.java
Outdated
Show resolved
Hide resolved
horreum-backend/src/main/java/io/hyperfoil/tools/horreum/entity/user/UserApiKey.java
Outdated
Show resolved
Hide resolved
horreum-backend/src/main/java/io/hyperfoil/tools/horreum/server/ApiKeyIdentityProvider.java
Show resolved
Hide resolved
horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/UserServiceImpl.java
Outdated
Show resolved
Hide resolved
horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/UserServiceImpl.java
Outdated
Show resolved
Hide resolved
horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/UserServiceImpl.java
Outdated
Show resolved
Hide resolved
horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/UserServiceImpl.java
Outdated
Show resolved
Hide resolved
👍
This is not possible, unfortunately. The error msg in your example comes from the exception that is thown in the service logic. For authentication failure you get a simple For reference, a better way to deal with this would be to
👍 |
66ec5da
to
bb8d174
Compare
bb8d174
to
57ca5de
Compare
@barreiro we need docs, is there a separate PR for docs? |
as discussed in #1922