Debian Codegraph @

doc/opa.md

raw symbols SCIP
1 # Open Policy Agent
2
3 relic can optionally replace its builtin certificate-based authentication with [Open Policy Agent](https://www.openpolicyagent.org/docs/latest/).
4
5 OPA is a flexible policy engine that evaluates centrally-distributed, user-defined rules
6 from a sidecar daemon. relic can use this to make certificate-based auth more dynamic
7 and CI/CD-friendly, to add support for Azure AD and other token-based authentication, or both.
8
9 To enable OPA in relic, set a URL to the policy to evaluate in the server configuration:
10
11 ```yaml
12 server:
13 policyurl: http://127.0.0.1/v1/data/relic
14 ```
15
16 policyurl can point either at a specific package,
17 or at the root of the server to use the default decision.
18
19 relic will provide the following inputs to the policy:
20
21 - token - The Bearer token provided in the `Authorization` header, if provided
22 - fingerprint - Digest of the client's leaf certificate, if provided
23 - path - Path from the URL being accessed
24 - query - Query parameters from the URL being accessed
25
26 The policy may provide the following fields in return:
27
28 - allow - true if the request should proceed
29 - sub - a string describing the subject or user that authenticated
30 - claims - a map of further key-value pairs describing the authenticated user
31 - errors - an array of strings indicating any errors explaining why the request was denied
32 - roles - an array of strings specifying which key roles the user may access
33 - allowed_keys - an array of strings specifying individual named keys the user may access
34
35 A successful request must set `allow`, `sub` and either `roles` or `allowed_keys` depending on the desired auth model.
36
37 A key can be used if the key's name is listed in `allowed_keys`, or there is an intersection between the `roles` response and the `roles` in the key's configuration in the relic server configuration, or both.
38
39 ## Interactive authentication
40
41 A server with OPA enabled may provide metadata that allows the client to interactively
42 authenticate to Azure AD and then provide the resulting token to relic.
43
44 To enable this, first create or update an Azure AD application with the following
45 under the "Authentication" tab:
46
47 - In the "Mobile and desktop applications" box, add `http://localhost` as a permitted Redirect URI.
48 - In the "Advanced settings" box, ensure "Allow public client flows" is enabled
49
50 Then in the relic server configuration add:
51
52 ```yaml
53 server:
54 azuread:
55 authority: https://login.microsoftonline.com/YOUR-TENANT-ID
56 clientid: YOUR-APP-CLIENT-ID
57 ```
58
59 You can find the tenant ID and client ID on the "Overview" tab of your app registration.
60 The full authority URL can be found by clicking the "Endpoints" button at the top
61 and removing everything after the tenant ID from any of the displayed OAuth URLs.
62
63 Finally, to configure a client to use interactive auth run:
64
65 relic remote login -u https://relic.example.com
66
67 ## Verifying OpenID Connect tokens
68
69 To get started with writing a policy that can verify OpenID Connect tokens
70 such as those from interactive command-line login,
71 see [the OPA documentation](https://www.openpolicyagent.org/docs/latest/oauth-oidc/).