asfquart depends on two services run by ASF Infrastructure: the OAuth provider, for logging users in, and LDAP, for requests that authenticate with a username and password. This page lists the endpoints, what each is used for, and what an application and its users see when one of them cannot be reached.
| Endpoint | Constant | Used for | Contacted by |
|---|---|---|---|
https://oauth.apache.org/auth-oidc | asfquart.generics.OAUTH_URL_INIT | Sending the user to log in | The user's browser |
https://oauth.apache.org/token-oidc | asfquart.generics.OAUTH_URL_CALLBACK | Exchanging the code from the callback for the user's details | asfquart, once per login |
ldaps://ldap-eu.apache.org:636 | asfquart.ldap.DEFAULT_LDAP_URI | Checking a password and looking up project memberships | asfquart, on every request that has an Authorization: Basic header and no session cookie |
asfquart itself contacts nothing else. By default sessions are kept in a cookie, and are not checked against either service once they exist.
An application can add services of its own in two places, and their availability is then the application's to document:
app.sessions, a store for server-side sessions. It is called whenever the session is read for a request that has a session cookie, so a store that uses a database or another service is contacted that often.app.token_handler, which is called whenever the session is read for a request that has an Authorization: Bearer header and no session cookie, and may look the token up wherever it likes.A login is a round trip through the OAuth provider; see OAuth workflows for the steps.
OAUTH_URL_INIT)asfquart redirects the browser here when a login starts. asfquart makes no connection to this endpoint itself, so it cannot tell whether it is available.
If it cannot be reached:
state is no longer accepted after the workflow timeout (15 minutes by default), and the record of it is removed the next time a login starts or a callback arrives. However long the provider is down, no more than 10,000 such records are kept; see Pending logins.OAUTH_URL_CALLBACK)When the browser returns from the provider, asfquart makes one POST request to this endpoint to exchange the code for the user‘s details, with the code in the form body rather than the URL. Redirects aren’t followed. The request is time limited: 10 seconds to connect, 15 seconds between reads, and 30 seconds in total. It is not retried.
| What happens | Response to the user |
|---|---|
| The endpoint cannot be reached, or does not answer in time | 403 OAuth authentication failed. |
The endpoint answers with a status other than 200 | 403 OAuth authentication failed. |
The answer is not a JSON object with a valid uid | 403 OAuth authentication failed. |
In each of these cases:
state of that login has been used up, so the user has to start a new login; reloading the page does not retry the exchange.OAuth code exchange failed: ...) that tells the three rows above apart: the kind of error if the endpoint could not be reached, the status if it was not 200, or which check the answer failed. It does not have the code, the state, or the answer itself.So while the OAuth provider is down, nobody can log in, and everybody who is logged in can carry on until their session expires.
LDAP is used only for requests that carry an Authorization: Basic header, and only when:
Authorization header is then not read at all, even if the session in the cookie turns out to have expired;basic_auth=True (it is off by default); andaioldap extra is installed (asfquart[aioldap]).Without basic_auth=True such a request is answered with 401 Basic authentication is not enabled, and LDAP is not contacted. With it, and without the extra, the app does not start: asfquart.construct() raises a RuntimeError. See HTTP Basic authentication.
For each such request asfquart connects to LDAP as the user, which checks the password, and looks up the projects that the user is a member or owner of. The lookup is cached in memory for an hour per user. The password is checked on every request, cached or not, so the cache saves the lookup but not the connection.
The cache holds the lookups of at most 1,000 users (asfquart.ldap.DEFAULT_LDAP_CACHE_MAX_ENTRIES). Lookups that are more than an hour old are removed whenever somebody authenticates, and when the cache is full the lookup that has gone longest without being used makes way for the newest, so a user who keeps coming back keeps their place. A user whose lookup is gone is not refused: it is made again on their next request. Only a lookup that succeeded is cached, so the cache does not grow with attempts to log in.
| What happens | Response to the user |
|---|---|
| LDAP refuses the username and password | 403 Invalid credentials provided |
| LDAP cannot be reached, fails, or returns nothing | 500 Could not perform LDAP authorization check, please try again later. |
| LDAP does not answer within 30 seconds | The same 500 |
| Ten LDAP checks are already going on | The request waits for one of them to end, within its 30 seconds. If none does, the same 500, without asking LDAP |
| A hundred requests are already waiting for that | The same 500, at once, without asking LDAP |
In every case the reason is in the application's log, and not in the response. See Failed logins for what is logged.
When LDAP cannot be reached:
Authorization: Basic (and so has no session cookie) fails with the 500 above, including those of users whose memberships are cached.asfquart.ldap logger.asfquart.ldap.LDAP_TIMEOUT), which covers checking the password and looking up the memberships. It does not cover a connection that the server leaves unanswered: see When LDAP does not answer the connection.What an LDAP server that has stopped answering does to the application depends on where it stops. The two cases are very different.
This is a server that does not reply when the connection is opened, or that accepts it and then says nothing while the encryption is set up. A host that is down behind a firewall which drops packets looks like this, and so does a server that is overloaded or suspended.
asfpy.aioldap in a thread of its own, but the LDAP library that it uses (bonsai) keeps hold of the Python interpreter while it connects, so no other thread runs, and the one that serves requests is among them.LDAP_TIMEOUT cannot end the wait, because it is counted by the part of the application that is stopped.asfquart.ldap.LDAP_NETWORK_TIMEOUT). After that the request is the 500 above, and the application runs again. Without it there would be no end: in a test with asfpy 0.60, the application was still stopped when the test was ended after 45 seconds.LDAPNETWORK_TIMEOUT=5 into the environment of the process. The LDAP library reads that once, at its first use, and there is no other way to set it that works for the connection. So it is done in asfquart.construct(..., basic_auth=True), when the application starts and before its own code can have used the library. (An application that turns app.basic_auth on afterwards gets it at its first LDAP check, or can call asfquart.ldap.set_network_timeout() itself, as early as it can.) Three things follow:LDAPNETWORK_TIMEOUT set. A value that is already in the environment is left alone.LDAP_NETWORK_TIMEOUT works only before construct() is called.ldapsearch, for instance) get the same timeout.500 one after another, and the other four when their 30 seconds were over, without a connection being tried for them. For as long as the server stays silent and such requests keep arriving, the application is stopped for most of the time.asfquart connects to LDAP for one request at a time. The connection includes the check of the password. The lookup of the memberships that follows is not held back, and those go on side by side.
500, and no connection is made for it.This is a server that sets up the connection, and then does not reply to the password or to the lookup of the memberships.
asfpy.aioldap, and the interpreter is free while it lasts.asfquart.ldap.MAX_LDAP_OPERATIONS). One that a request has given up on still counts until it really ends, and so does one that waits for its turn to connect.500 when its 30 seconds are over, and LDAP is not asked for it. The log says so, at most once a minute.asfquart.ldap.MAX_LDAP_WAITING). They hold nothing in LDAP. A request past those is refused at once with the 500.The endpoints are module-level constants, and are read when they are used. An application can point asfquart at other servers, a test OAuth provider for instance, by assigning to them before the first request:
import asfquart import asfquart.generics asfquart.generics.OAUTH_URL_INIT = "https://oauth.example.org/auth?state=%s&redirect_uri=%s" asfquart.generics.OAUTH_URL_CALLBACK = "https://oauth.example.org/token" app = asfquart.construct("myapp")
OAUTH_URL_INIT takes the state and the callback URL, each as a %s. OAUTH_URL_CALLBACK is just the endpoint - the code is POSTed to it as a form field named code.
Before 0.2.0 OAUTH_URL_CALLBACK took the code as a %s, and a lot of apps set it to the old default, "https://oauth.apache.org/token-oidc?code=%s". That exact value is treated as the new default, so those apps get the POST and can drop the line. Any other value with a %s is still sent as a GET, with a warning logged once - remove the query string to switch to POST, if the endpoint accepts one.