Skip to content

New API feature: allow API clients to authenticate via authentication header#1367

Merged
josecelano merged 2 commits into
torrust:developfrom
josecelano:727-remove-api-token-from-logs
Mar 10, 2025
Merged

New API feature: allow API clients to authenticate via authentication header#1367
josecelano merged 2 commits into
torrust:developfrom
josecelano:727-remove-api-token-from-logs

Conversation

@josecelano

@josecelano josecelano commented Mar 10, 2025

Copy link
Copy Markdown
Member

The API allows client authentication via a token parameter in the URL query:

curl http://0.0.0.0:1212/api/v1/stats?token=MyAccessToken | jq

Now it's also possible to do it via an Authentication Header:

curl -H "Authorization: Bearer MyAccessToken" http://0.0.0.0:1212/api/v1/stats | jq

This is to avoid leaking the token in logs, etc.

For now, it's only optional and recommendable. It could be mandatory in future major API versions.

The API client uses by default the Authentication Header. It could be a breaking change if you use the newer client witn an old API that does not support it. However we have not released any crate for the API client yet. And we are still using a different client in the Index.

@josecelano josecelano requested a review from da2ce7 March 10, 2025 11:31
@josecelano josecelano self-assigned this Mar 10, 2025
@josecelano josecelano added Enhancement / Feature Request Something New - Developer - Torrust Improvement Experience API Related to the Tracker API labels Mar 10, 2025
@josecelano josecelano linked an issue Mar 10, 2025 that may be closed by this pull request
@josecelano josecelano force-pushed the 727-remove-api-token-from-logs branch from f3005cc to ccf9880 Compare March 10, 2025 12:02
@josecelano josecelano force-pushed the 727-remove-api-token-from-logs branch from ccf9880 to 3f915a2 Compare March 10, 2025 13:15
@codecov

codecov Bot commented Mar 10, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 82.79570% with 16 lines in your changes missing coverage. Please review.

Project coverage is 81.31%. Comparing base (6a22b1e) to head (34f2f43).
Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
packages/rest-tracker-api-client/src/v1/client.rs 82.14% 10 Missing ⚠️
...rest-tracker-api-server/src/v1/middlewares/auth.rs 83.78% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1367      +/-   ##
===========================================
- Coverage    81.37%   81.31%   -0.06%     
===========================================
  Files          229      229              
  Lines        16448    16519      +71     
  Branches     16448    16519      +71     
===========================================
+ Hits         13385    13433      +48     
- Misses        2821     2840      +19     
- Partials       242      246       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The API allos client authentication via a `token` parameter in the URL
query:

```console
curl http://0.0.0.0:1212/api/v1/stats?token=MyAccessToken | jq
```

Now it's also possible to do it via Authentication Header:

```console
curl -H "Authorization: Bearer MyAccessToken" http://0.0.0.0:1212/api/v1/stats | jq
```

This is to avoid leaking the token in logs, proxies, etc.

For now, it's only optional and recommendable. It could be mandatory in
future major API versions.
@josecelano josecelano force-pushed the 727-remove-api-token-from-logs branch from 3f915a2 to 084beb2 Compare March 10, 2025 13:48
Instead of passing the `token` via GET param.

The server supports both. Since we have not released any version crate for the
client yet we can use the header by deafault which is more secure.
@josecelano

Copy link
Copy Markdown
Member Author

ACK 34f2f43

@josecelano josecelano marked this pull request as ready for review March 10, 2025 16:00
@josecelano josecelano merged commit c04df74 into torrust:develop Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

- Developer - Torrust Improvement Experience API Related to the Tracker API Enhancement / Feature Request Something New

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove API token from logs

1 participant