Skip to content

Add Authorization for Measurement Creation #652

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

pyropy
Copy link
Contributor

@pyropy pyropy commented Jun 24, 2025

This pull request introduces a new authorization mechanism for the createMeasurement API endpoint by requiring a checkerToken. Additionally, it updates the test suite to validate this new functionality thoroughly. The changes enhance security and ensure unauthorized or invalid requests are properly handled.

API Updates:

  • Added a checkerToken parameter to the handler function and updated the createMeasurement function to check for valid authorization headers before measurement creation. Unauthorized requests now return a 403 Unauthorized response. (api/index.js, [1] [2] [3]
  • Updated the createHandler function to include the checkerToken parameter when initializing the handler. (api/index.js, api/index.jsL459-R472)

Test Suite Enhancements:

  • Added VALID_CHECKER_TOKEN to test constants and updated all relevant test cases to include the authorization header with the valid token when making POST requests to /measurements. (api/test/test.js, [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]
  • Added new test cases to ensure unauthorized requests (missing or invalid tokens) are rejected with a 403 Unauthorized response, and no measurements are created in the database. (api/test/test.js, api/test/test.jsR427-R466)
  • Verified that valid requests with the correct checkerToken are processed successfully, returning the expected responses. (api/test/test.js, api/test/test.jsL642-R680)

Related https://github.com/CheckerNetwork/spark-0k-checker/pull/12

Closes #653

@pyropy pyropy marked this pull request as ready for review June 24, 2025 12:04
@pyropy pyropy changed the title Authorize measurement creation Add Authorization for Measurement Creation Jun 24, 2025
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

NOICE!

api/bin/spark.js Outdated
Comment on lines 27 to 28
// TODO:
assert(CHECKER_TOKEN, 'CHECKER_TOKEN is required')
Copy link
Member

Choose a reason for hiding this comment

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

What is this TODO for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I've left TODO to add adittional context why is the CHECKER_TOKEN required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a small comment 03b5110. Let me know if you think I should add more context.

@pyropy
Copy link
Contributor Author

pyropy commented Jun 24, 2025

  • I think we need to first ship a new spark-0k-checker version that sets the access token, before we can land & ship this. Correct?

Yes, that would be correct.

Indeed we could revert both. I propose that we revert only chore: Remove domain redirect #647 as https://github.com/CheckerNetwork/spark-0k-checker/pull/12 contains changes that will make sure that spark-0k nodes post their measurements to the public API.

@bajtos
Copy link
Member

bajtos commented Jun 24, 2025

I propose that we revert only chore: Remove domain redirect #647

SGTM 👍🏻

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

LGTM 👏🏻

Co-authored-by: Julian Gruber <[email protected]>
@pyropy pyropy added this to FilCDN Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Add Authorization for Measurement Creation
4 participants