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

auth: add an endpoint for basic auth diagnosis #28

Merged
merged 1 commit into from
Sep 14, 2020

Conversation

rohanpm
Copy link
Member

@rohanpm rohanpm commented Sep 10, 2020

Let's add a trivial endpoint which can be used to determine whether
the current user is authenticated, along with their roles. Without
this, there is no way to verify directly that the authentication
reverse-proxy is working correctly, or for a user to verify that
they were given the roles they requested, etc.

This also gives the healthcheck and whoami endpoints the same
openapi tag, so that they appear in the API docs together (as both
of them are kind of "meta APIs" relating to the service itself
rather than the exodus CDN.)

Let's add a trivial endpoint which can be used to determine whether
the current user is authenticated, along with their roles. Without
this, there is no way to verify directly that the authentication
reverse-proxy is working correctly, or for a user to verify that
they were given the roles they requested, etc.

This also gives the healthcheck and whoami endpoints the same
openapi tag, so that they appear in the API docs together (as both
of them are kind of "meta APIs" relating to the service itself
rather than the exodus CDN.)
@rohanpm
Copy link
Member Author

rohanpm commented Sep 10, 2020

Travis is acting a bit odd today.



@app.get("/healthcheck")
@app.get("/healthcheck", tags=["service"])
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is unrelated to this PR

Copy link
Member

Choose a reason for hiding this comment

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

Tags could be added in an additional commit, at least.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is related to the PR... the purpose of putting tags on the APIs is to make them appear grouped in some logical way in the docs.

Prior to my change here, there was only one endpoint (/healthcheck) without any tag, so there was nothing to group it with. Now in this change I'm adding one more endpoint which seems to belong in the same group, so I've put the same tag on the old endpoint and my new endpoint to group them.

Copy link
Contributor

Choose a reason for hiding this comment

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

The value of the change is unquestionable. Mixing this effort with another effort is the issue here. The value of keeping PRs small and related to the PR subject+linked issue is for future trouble shooting/debugging.

Copy link
Member

@negillett negillett Sep 14, 2020

Choose a reason for hiding this comment

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

Now in this change I'm adding one more endpoint which seems to belong in the same group, so I've put the same tag on the old endpoint and my new endpoint to group them.

Makes sense to me.
I see that the explanation is also included in the commit message.

Copy link
Member Author

Choose a reason for hiding this comment

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

The value of keeping PRs small and related to the PR subject+linked issue is for future trouble shooting/debugging.

I agree with the principle of keeping PRs small and focused, but I don't think we agree on how to apply that principle. I explained (already in the commit message) how I think this change is related to the purpose of the PR.

@@ -28,3 +28,10 @@ def test_healthcheck():
)
def test_publish(env, expected):
assert gateway.publish(env) == expected


def test_whoami():
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if this test covers all options:
a request without any payload
a request with incorrect payload
a request with correct payload

Copy link
Member

Choose a reason for hiding this comment

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

If I understand whoami correctly, there's only one possible response; it just returns whatever context it's given.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, this test is not aiming to cover those cases, it doesn't work at that level.

This test (and all the other existing tests which directly invoke some endpoint function) have assumed that the FastAPI routing, (de)serialization, dependency injection etc features all work as documented. The test scope can be summarized as "Given that fastapi works correctly, whoami does what it needs to do".

Testing that fastapi works correctly is expected to be covered elsewhere. I think we could have at least a few tests in the repo making use of TestClient https://fastapi.tiangolo.com/tutorial/testing/#using-testclient to help cover that, I don't think all tests should be written that way though.

Taking the example "a request with incorrect payload" - if there is an incorrect value in the auth header, the expected behavior is that the request is rejected before it even reaches the whoami() function, so it can't be covered by this style of test which calls whoami directly. It's instead already tested (in isolation) in tests/auth/test_call_context.py::test_bad_header.

There is no integration test currently which tests the pieces when combined. I looked into it just now and I think it might be better left to a later PR... the reason is that there is still no endpoint which requires authentication yet. This means there's no way for an integration test to realistically cover cases such as "user didn't authenticate where authentication is required" or "user authenticated but is missing needed roles".

@lmilbaum
Copy link
Contributor

Is there an issue this PR can be linked to?

@negillett
Copy link
Member

It seems CI is still acting strange.

@rohanpm rohanpm merged commit ec53e16 into release-engineering:master Sep 14, 2020
@rohanpm rohanpm deleted the whoami branch September 14, 2020 22:41
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.

3 participants