Motivation
To extend support for Authentication with Identity providers that publish JWKs (required for signing JWT) at URL (JWKUrl).
User Impact
Users will now be able to Authenticate with many more Identity Providers such as Firebase and OneGraph.
Implementation
Introduction
As defined by IETF, JSON Web Key (JWK) is a JSON data structure that represents a cryptographic key used for signing/encryption. Below is an example JWK :
{
"alg": "RS256",
"e": "AQAB",
"n": "zk8r6zAVEktzfzrjVbpiWU_rhAs5mFcMrwcT4dVO_bDIw1gViVGk74O5RJMP6MGqHryNigIIvUhVKLYmyqYwk3JGD9whPXfS8RIPsqE3Y2_BtvbXx5yJdAECr_slKvDPfGfrVVcO_8QPw-03JP0WmkFRCBr6yLS7rNgCuZqUr2JQ-aYIxO2PCy64GoxOrgcqtDiVQ8ZluhJoUEGDC4GrDMQLxFNQ9xoj1rQm5L4_-2rIn0BoeI5Ox6n0a1CTjqGNW4PQkRVb_q2wpNzJzwGlqAE0vPsbfvePrwf4MPohnPKu7N6is9sntkltBNq2bFonaOw1t8Jksiz93hwpdFtPbQ",
"kty": "RSA",
"kid": "49ad9bc5e8e44793a2109b56e361a23b41880875",
"use": "sig"
}
JWKUrl hosts multiple such JWKs which are used in the verification of the JWT.
Implemention Details
Support for the JWKUrl
field in Dgraph.Authorization
JSON in the GraphQL Schema. Now it will look like
{
VerificationKey: "",
Header: "",
Namespace: "",
Algo: "",
JWKURL: "",
Audience: ""
}
Users will be allowed to give only one of JWKURL
or (VerificationKey, Algo)
and not both.
- If
(VerificationKey, Algo)
is provided then the GraphQL server will verify JWT against thisVerificationKey
- If
JWKURL
is provided then Server will fetch all the JWKs and verify the token against one of the JWK based on thekid
of JWK.
Some Identity Providers (Firebase) share the JWKs among multiple tenants. In this case, it is required for the user to provide the proper value of Audience
in Dgraph.Authorization JSON. Failing to do so might be a major security risk.
Handling Rotating Keys
Some Identity Providers rotate the keys periodically, for this the GraphQL server will check the max-age
or other similar directives in the Cache-Control
Header or Expires
headers in the response from the JWKURL when it fetches the Keys for the first time( When the Sever Starts or Schema Gets Updated) . On the basis of it, set up a goroutine to periodically fetch the keys from the JWKURL.
However, if the GraphQL server is unable to parse a valid value from these Headers or the Headers are not present altogether, then it will not re-fetch the keys.
Any Schema Update which changes the Dgraph.Authorization
JSON should also re-trigger the fetching of the keys from the JWKURL.