Skip to content

Authentication for metrics and version endpoint #9029

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 1 commit into
base: master
Choose a base branch
from

Conversation

naveenpaul1
Copy link
Contributor

@naveenpaul1 naveenpaul1 commented May 16, 2025

Describe the Problem

Noobaa provides multiple metrics endpoints for customers. The first one is Noobaa management service and the other one is Noobaa endpoint service. In the case of Noobaa management metrics endpoint, Noobaa provides a route to fetch the metrics. And for Noobaa endpoint metrics, metrics can be fetched by loadbalancer IP and port. Anyone with a valid URL can access these metrics endpoints without any kind of authentication.

Explain the Changes

noobaa -core

  1. JWT token will be authenticated Inside metrics_request_handler() and get_version_handler()
  2. JWT token will be verified against signature and role metrics-auth, with the role validation we can make sure other JWT tokens signed using the same secret won’t work.
  3. Invalid auth token will return 403 error

Issues: Fixed #xxx / Gap #xxx

  1. RHSTOR-7202
  2. DFBUGS-1802

Testing Instructions:

containerized deployment

  1. The customer should be able to access the bearer token from the secret metrics-auth-secret, secret can be used for accessing noobaa management and endpoint metrics/version.
JWT_TOKEN=$(oc get secret/{token-secret-name} -n {namespace} -o jsonpath={.data.metrics_token} | base64 -d)    
curl -k -H "Authorization: Bearer ${JWT_TOKEN "https://{endpoint-loadbalancer-ingress-ip}:{endpoint-port}
curl -k -H "Authorization: Bearer ${JWT_TOKEN}" https://$(oc -n {namespace} get route noobaa-mgmt -o jsonpath='{.status.ingress[*].host}/version or metrics endpoints')

Design doc : https://ibm.ent.box.com/notes/1853310270159

  • Doc added/updated
  • Tests added

@naveenpaul1 naveenpaul1 force-pushed the metrics-auth-token branch from fa24a14 to f4993b1 Compare May 21, 2025 06:28
@naveenpaul1 naveenpaul1 requested a review from alphaprinz May 21, 2025 06:39
@naveenpaul1 naveenpaul1 force-pushed the metrics-auth-token branch 2 times, most recently from 6f9df66 to a87519b Compare May 27, 2025 06:56
try {
jwt_utils.authenticate_jwt_token(req);
} catch (err) {
res.writeHead(403, { 'Content-Type': 'text/plain' });
Copy link
Member

@tangledbytes tangledbytes May 28, 2025

Choose a reason for hiding this comment

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

Why text/plain and not application/json if the format is JSON? Same for prometheus reporting.

Copy link
Member

Choose a reason for hiding this comment

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

First this error handling shouldn't be here. as noted below this should be in a function in http_utils.
Second - why are we authenticating the get_version call ??

Copy link
Contributor Author

@naveenpaul1 naveenpaul1 May 28, 2025

Choose a reason for hiding this comment

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

Parent link for this epic: RHSTOR-7202 mentioned that version also needs to be authenticated.

Copy link
Member

Choose a reason for hiding this comment

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

I dont know what is mentioned there and why, but I am afraid that it will fail the callers to this version route as they dont authenticate and just use plain curl. did you check who is calling it in the core and operator code bases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in operator I couldnt find the direct call to version endpoint, in core I could find one reference for version here, Is this code still in use?
Customer concern is about exposing the version, and vulnerabilities associated with it.

Copy link
Member

Choose a reason for hiding this comment

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

we always return the server version as a header - see endpoint_utils.set_noobaa_server_header

is this critical enough to require a change?

Copy link
Member

Choose a reason for hiding this comment

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

We better add a config option that allow us to turn on/off the auth for both metrics and version routes (one config for each because different clients use it)

Copy link
Contributor Author

@naveenpaul1 naveenpaul1 May 29, 2025

Choose a reason for hiding this comment

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

ok, and for metrics and version default value for auth enabled?
config.METRICS_AUTH_ENABLED = true;
config.VERSION_AUTH_ENABLED = true;

try {
jwt_utils.authenticate_jwt_token(req);
} catch (err) {
res.writeHead(403, { 'Content-Type': 'text/plain' });
Copy link
Member

Choose a reason for hiding this comment

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

First this error handling shouldn't be here. as noted below this should be in a function in http_utils.
Second - why are we authenticating the get_version call ??

@naveenpaul1 naveenpaul1 force-pushed the metrics-auth-token branch 2 times, most recently from 41cf84e to 2409ace Compare May 29, 2025 07:27
@naveenpaul1 naveenpaul1 force-pushed the metrics-auth-token branch from 2409ace to 53c677f Compare May 29, 2025 08:57
@naveenpaul1 naveenpaul1 requested a review from guymguym May 29, 2025 09:14
@naveenpaul1 naveenpaul1 force-pushed the metrics-auth-token branch from 53c677f to 5440be0 Compare May 29, 2025 11:27
message: err.message,
}, null, 2);
res.end(reply);
return false;
Copy link
Member

Choose a reason for hiding this comment

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

this is not enough, the caller should check for this return, and the normal path should return true. but i think maybe this is better be thrown instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all the methods ends with res.end() do not send anything back, simply end the method with res.end()
An I tested the flow with this change and its working without any issues

@@ -1118,6 +1118,9 @@ config.DEFAULT_REGION = 'us-east-1';

config.VACCUM_ANALYZER_INTERVAL = 86400000;

config.METRICS_AUTH_ENABLED = true;
config.VERSION_AUTH_ENABLED = true;
Copy link
Member

Choose a reason for hiding this comment

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

i am not sure about the default being true. will that break anything?

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 couldnt find issues during my testing.

@naveenpaul1 naveenpaul1 force-pushed the metrics-auth-token branch from 5440be0 to f84e8d8 Compare May 29, 2025 13:34
@naveenpaul1 naveenpaul1 requested a review from guymguym May 29, 2025 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants