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

Fix incorrect 200 for a 401 from NMAgent #1799

Merged
merged 5 commits into from
Feb 14, 2023

Conversation

timraymond
Copy link
Member

In scenarios where the subnet token does not match (leading to a 401 from NMAgent), CNS returns a 200 for the PublishStatusCode. This is incorrect, and a 401 should be returned instead. This leads clients of CNS to take incorrect action on, what they believe to be, a successful response.

@timraymond timraymond requested a review from a team as a code owner February 10, 2023 16:51
@timraymond timraymond requested review from rsagasthya and rbtr and removed request for a team February 10, 2023 16:51
@rbtr rbtr enabled auto-merge (squash) February 10, 2023 17:35
@rbtr
Copy link
Contributor

rbtr commented Feb 10, 2023

blocked on lints

@rbtr
Copy link
Contributor

rbtr commented Feb 10, 2023

is this related to #1787?

@smittal22
Copy link
Contributor

smittal22 commented Feb 10, 2023

is this related to #1787?

@rbtr, yes. As CNS is expected to just relay NMA's response (byte64 encoded) back to DNC for any decision making, we shouldn't be handling the error status code in CNA's server-side logic. I have closed my PR with an appropriate comment.
FYI @timraymond , @ashvindeodhar

@timraymond
Copy link
Member Author

Lints cleared. Please review.

rbtr
rbtr previously approved these changes Feb 10, 2023
@smittal22 smittal22 self-requested a review February 10, 2023 18:56
smittal22
smittal22 previously approved these changes Feb 10, 2023
@rbtr rbtr force-pushed the traymond/fix-incorrect-cns-200 branch from 2de29b7 to 02f40b4 Compare February 10, 2023 22:41
@tamilmani1989 tamilmani1989 dismissed stale reviews from smittal22 and rbtr via 02f40b4 February 11, 2023 22:47
@timraymond
Copy link
Member Author

@rbtr approval needed again when you get a chance

@timraymond timraymond requested a review from rbtr February 13, 2023 11:26
rbtr
rbtr previously approved these changes Feb 13, 2023
cns/restserver/api_test.go Show resolved Hide resolved
cns/restserver/api.go Show resolved Hide resolved
In scenarios where the subnet token does not match (leading to a 401
from NMAgent), CNS returns a 200 for the PublishStatusCode. This is
incorrect, and a 401 should be returned instead. This leads clients of
CNS to take incorrect action on, what they believe to be, a successful
response.
It's important that we ensure that PublishResponseBody is, indeed, JSON.
Also, that JSON needs to have an httpStatusCode property with its value
set to the response code returned from NMAgent (in this test case, a
401).
The UnpublishStatusCode was not being set by CNS, which could lead to
misbehavior from clients that expect it to be set appropriately. This
uses the StatusCode provided by the nmagent.Error to propagate the
httpStatusCode.
One of these lints is inappropriate in a test, so it's been silenced
(adding context to the HTTP Request). The other one is marginal, but
easy to fix, so there's now a check for an error from JSON encoding.
@rbtr rbtr removed the request for review from rsagasthya February 14, 2023 16:46
@rbtr rbtr merged commit 48c7a14 into Azure:master Feb 14, 2023
@timraymond timraymond deleted the traymond/fix-incorrect-cns-200 branch February 14, 2023 17:59
rjdenney pushed a commit that referenced this pull request Mar 13, 2023
In scenarios where the subnet token does not match (leading to a 401
from NMAgent), CNS returns a 200 for the PublishStatusCode. This is
incorrect, and a 401 should be returned instead. This leads clients of
CNS to take incorrect action on, what they believe to be, a successful
response.
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.

4 participants