|
| 1 | +--- |
| 2 | +title: Authentication |
| 3 | +description: How to customize authentication methods for UI login and API |
| 4 | +--- |
| 5 | + |
| 6 | +GitProxy allows setting up various auth methods for both UI users, and the backend API. |
| 7 | + |
| 8 | +### Where to Configure Auth Methods |
| 9 | + |
| 10 | +Auth methods can be configured in [proxy.config.json](/proxy.config.json). The `authentication` array allows setting UI authentication, for user login and management purposes. The `apiAuthentication` array allows setting up an _optional_ authentication layer for extra API security. |
| 11 | + |
| 12 | +### Default Configuration |
| 13 | + |
| 14 | +By default, GitProxy has a **local** UI authentication method enabled. Although not particularly secure, this allows logging in with simple user/password combinations for signup and login. |
| 15 | + |
| 16 | +### Supported Methods |
| 17 | + |
| 18 | +#### UI Auth |
| 19 | + |
| 20 | +Currently, GitProxy supports three differemt methods for user creation and login: |
| 21 | +- Local |
| 22 | +- ActiveDirectory |
| 23 | +- OIDC |
| 24 | + |
| 25 | +Each of these has its own specific config entry with necessary parameters for setting up the method. |
| 26 | + |
| 27 | +#### API Auth |
| 28 | + |
| 29 | +GitProxy also supports protecting API endpoints with extra auth layers. Currently, the only available method is JWT - but this can be easily extended to use your own methods such as GitHub login and more. |
| 30 | + |
| 31 | +### Sample Configuration - UI |
| 32 | + |
| 33 | +#### Active Directory |
| 34 | + |
| 35 | +A default, empty setup for OIDC is already present in [proxy.config.json](/proxy.config.json): |
| 36 | + |
| 37 | +```json |
| 38 | +{ |
| 39 | + "type": "ActiveDirectory", |
| 40 | + "enabled": false, |
| 41 | + "adminGroup": "", |
| 42 | + "userGroup": "", |
| 43 | + "domain": "", |
| 44 | + "adConfig": { |
| 45 | + "url": "", |
| 46 | + "baseDN": "", |
| 47 | + "searchBase": "" |
| 48 | + } |
| 49 | +}, |
| 50 | +``` |
| 51 | + |
| 52 | +#### OIDC |
| 53 | + |
| 54 | +A default, empty setup for OIDC is already present in [proxy.config.json](/proxy.config.json). You can fill this in with your required parameters. Here's an example using Google as a login provider: |
| 55 | + |
| 56 | +```json |
| 57 | +"authentication": [ |
| 58 | + { |
| 59 | + "type": "openidconnect", |
| 60 | + "enabled": true, |
| 61 | + "oidcConfig": { |
| 62 | + "issuer": "https://accounts.google.com", |
| 63 | + "clientID": "<client-id>", |
| 64 | + "clientSecret": "<client-secret>", |
| 65 | + "callbackURL": "http://localhost:8080/api/auth/oidc/callback", |
| 66 | + "scope": "email profile" |
| 67 | + } |
| 68 | + } |
| 69 | +], |
| 70 | +``` |
| 71 | + |
| 72 | +Notice that the `callbackURL` (`<ui-host-url>/api/auth/oidc/callback`) must be set both in your provider and this config file for the flow to work. |
| 73 | + |
| 74 | +### Sample Configuration - API |
| 75 | + |
| 76 | +#### JWT |
| 77 | + |
| 78 | +JWT auth is ideal for using the GitProxy API along with CI tools and automation. It allows verifying credentials and admin permissions to use GitProxy securely in scripts, CI/CD pipelines and more. |
| 79 | + |
| 80 | +You will need an existing OIDC setup to release valid JWT tokens. |
| 81 | + |
| 82 | +**Warning: GitProxy does not provide/release JWT tokens for API validation.** Your service (configured through `jwtConfig`) will have to do this on its own. For example, it could be an app that allows users to log in through Google, and releases a JWT `access_token` with a one hour expiry date. |
| 83 | + |
| 84 | +If the `jwt` auth method is enabled in the config, you'll notice that UI requests are no longer working. This is expected since the endpoints require a valid JWT to proceed. Once the `Bearer: <your-JWT>` authorization header is added, you should be able to access the endpoints as usual. |
| 85 | + |
| 86 | +##### JWT Role Mapping |
| 87 | + |
| 88 | +JWT auth also allows authenticating to specific in-app roles by using JWT `claims`. In the following sample config, Google JWT tokens that contain the following `claim` (`name: "John Doe"`) will be assigned the in-app admin role: |
| 89 | + |
| 90 | +```json |
| 91 | +"apiAuthentication": [ |
| 92 | + { |
| 93 | + "type": "jwt", |
| 94 | + "enabled": true, |
| 95 | + "jwtConfig": { |
| 96 | + "clientID": "<client-id>", |
| 97 | + "authorityURL": "https://accounts.google.com", |
| 98 | + "expectedAudience": "<expected-audience>", |
| 99 | + "roleMapping": { |
| 100 | + "admin": { |
| 101 | + "name": "John Doe" |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | +], |
| 107 | +``` |
| 108 | + |
| 109 | +In other words, your JWT token provider can define an arbitrary `claim` that can be mapped to any app role you want, such as `admin`, or a custom role such as `ci-only`. This allows for granular access control for automation solutions using GitProxy. |
| 110 | + |
| 111 | +Note that if the `expectedAudience` is missing, it will be set to the client ID. |
| 112 | + |
| 113 | +### Adding your own methods |
| 114 | + |
| 115 | +You can add new UI auth methods by extending the [passport.js configuration file](/src/service/passport/local.js) with your desired method. You'll have to define a module and then add it to the `authStrategies` map: |
| 116 | + |
| 117 | +```js |
| 118 | +const local = require('./local'); |
| 119 | +const activeDirectory = require('./activeDirectory'); |
| 120 | +const oidc = require('./oidc'); |
| 121 | + |
| 122 | +const authStrategies = { |
| 123 | + local: local, |
| 124 | + activedirectory: activeDirectory, |
| 125 | + openidconnect: oidc, |
| 126 | +}; |
| 127 | +``` |
| 128 | + |
| 129 | +Check out the files in [src/service/passport](/src/service/passport) for examples on how to define the specific `configure()` functions for each method: |
| 130 | +- [Local](/src/service/passport/local.js) |
| 131 | +- [ActiveDirectory](/src/service/passport/activeDirectory.js) |
| 132 | +- [OIDC](/src/service/passport/oidc.js) |
| 133 | + |
| 134 | +### Questions? |
| 135 | + |
| 136 | +If you have any questions, feel free to [open a discussion](https://github.com/finos/git-proxy/discussions). |
0 commit comments