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

Refactor authentication middleware to include project_id in request tracing #12

Merged
merged 2 commits into from
Jul 25, 2023

Conversation

MohamedBassem
Copy link
Contributor

@MohamedBassem MohamedBassem commented Jul 24, 2023

Refactor authentication middleware to include project_id in request tracing

Change the main authentication middleware to be a top level middleware that
injects the authentication status into the request extensions. The per route
middleware can then just read the AuthenticationStatus and take decisions based
on it. This change allows us to capture the project id in the request tracing
which wasn't possible before because it get invoked just before the request handlers
(due to how middleware ordering works).

The main change in behavior here is that the middleware will be invoked regardless of
whether the route requires authentication or not. This is ok, unless the customer passes
malformed auth headers in which case the request would currently fail with BadRequest
while it would have succeeded before. Note, that we currently don't have any unauthenticated
endpoints, so no "real" change in behavior here.


Stack created with Sapling. Best reviewed with ReviewStack.

AhmedSoliman
AhmedSoliman previously approved these changes Jul 25, 2023
Copy link
Contributor

@AhmedSoliman AhmedSoliman left a comment

Choose a reason for hiding this comment

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

Very cool change 🔥

1. Allow passing --project-id to any subcommand instead of only admin commands.
2. A stricter secret api key matching using regex. Only matching with the prefix was too aggressive matching stuff like "_task_something".
3. Add IP addresses to request tracing
…racing

Change the main authentication middleware to be a top level middleware that
injects the authentication status into the request extensions. The per route
middleware can then just read the AuthenticationStatus and take decisions based
on it. This change allows us to capture the project id in the request tracing
which wasn't possible before because it get invoked just before the request handlers
(due to how middleware ordering works).


The main change in behavior here is that the middleware will be invoked regardless of
whether the route requires authentication or not. This is ok, unless the customer passes
malformed auth headers in which case the request would currently fail with `BadRequest`
while it would have succeeded before. Note, that we currently don't have any unauthenticated
endpoints, so no "real" change in behavior here.
@MohamedBassem MohamedBassem merged commit 398a076 into main Jul 25, 2023
3 checks passed
@MohamedBassem MohamedBassem deleted the pr12 branch July 25, 2023 13:28
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.

2 participants