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

Allow for response caching when "Authorization" header is part of API backend configuration #281

Closed
GUI opened this issue Sep 10, 2015 · 1 comment

Comments

@GUI
Copy link
Member

GUI commented Sep 10, 2015

While looking into some API caching things today, I discovered that api.data.gov is unable to cache API responses if the API backend is configured to use HTTP basic auth. This issue only crops up when an API backend is being protected by HTTP basic authentication (username/password), and api.data.gov is setup to add that basic auth to each request as it traverses our proxy layer. The basic flow looks something like this:

[ request (no auth header) ] => [ api.data.gov ] => *basic auth header added* => [ caching server ] => [ API backend ]

The problem is that whenever HTTP authentication headers are on a request, HTTP caching servers by default will refuse to cache any responses. This is done for safety reasons because you typically don't want your HTTP cache to cache any authenticated requests & responses, since then subsequent requests would bypass any authentication logic your app may implement. However, our situation is a little different since api.data.gov is acting as the gatekeeper, and this http basic auth isn't something the user is passing in (this is only to establish trust between the api.data.gov servers and the API backend). So in these cases, caching the responses should be perfectly valid and would be consistent with the rest of our APIs.

I think we only have a few API backend setups using this approach, but this is a problem, since this is a perfectly valid way to setup an API backend and yet it effectively disables the entire caching layer (in a pretty non-obvious way).

@GUI GUI self-assigned this Sep 10, 2015
GUI added a commit to NREL/api-umbrella-gatekeeper that referenced this issue Sep 10, 2015
This is part of 18F/api.data.gov#281

The bulk of this will be implemented (with tests) over in the router
project, since that's where the caching stuff lives. But this allows us
to distinguish between authorization headers we add due to api backend
config versus externally sent authorization headers.
GUI added a commit to NREL/api-umbrella-router that referenced this issue Sep 10, 2015
This is part of 18F/api.data.gov#281

This allows for the HTTP cache to work despite Authorization headers
being present if the gatkeeper is what's responsible for adding the
Authorization headers to the request during proxying (since by default,
Authorization headers disables all caching).
@GUI
Copy link
Member Author

GUI commented Sep 10, 2015

This should be fixed and deployed to production. Caching is now allowed for any API backend that sets HTTP Basic auth as part of their proxy config. However, we still disallow caching if the user is sending the HTTP basic auth headers as part of their original request, so these changes should be safe if there are any APIs out there that were also doing doing their own user-facing HTTP basic auth stuff.

@dnesting: Your benchmarks should now be seeing cached responses from api.data.gov. I had to roll out these changes in phases on our servers, so your benchmark results might be slightly in flux between 12:49AM ET - 1:05AM ET. You shouldn't have seen any outages, but please let me know if you happen to have seen anything. However, performance may have degraded slightly as we took servers out of rotation during this time period. Cached results should have started around 12:56AM ET, but things weren't totally settled with all nodes back in action until 1:05AM ET. Hopefully this caching will help out.

@GUI GUI closed this as completed Sep 10, 2015
GUI added a commit to NREL/api-umbrella-router that referenced this issue Sep 18, 2015
This is part of 18F/api.data.gov#281

The associated changes are on the gatekeeper project's
6d2e6574998ff0478481d7ff7f0b327019006e05 commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant