1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/website/docs/reference/deploy/securing-unleash.md

59 lines
2.2 KiB
Markdown
Raw Normal View History

---
title: Securing Unleash
---
**If you are still using Unleash v3 you need to follow the [securing-unleash-v3](./securing-unleash-v3)**
2021-02-26 07:49:31 +01:00
> This guide is only relevant if you are using Unleash Open-Source. The Enterprise edition does already ship with multiple SSO options, such as SAML 2.0, OpenID Connect.
2021-08-05 14:00:30 +02:00
Unleash Open-Source v4 comes with username/password authentication out of the box. In addition Unleash v4 also comes with API token support, to make it easy to handle access tokens for Client SDKs and programmatic access to the Unleash APIs.
### Password requirements {#password-requirements}
Unleash requires a strong password.
- minimum 10 characters long
- contains at least one uppercase letter
- contains at least one number
- contains at least one special character (symbol)
2018-11-22 11:20:28 +01:00
### Implementing Custom Authentication {#implementing-custom-authentication}
2021-08-05 14:00:30 +02:00
If you do not wish to use the built-in username/password authentication you can add a customAuthHandler
2018-11-22 11:20:28 +01:00
To secure the Admin API, you have to tell Unleash that you are using a custom admin authentication and implement your authentication logic as a preHook.
```javascript
const unleash = require('unleash-server');
const myCustomAdminAuth = require('./auth-hook');
2018-11-22 11:20:28 +01:00
unleash
.start({
databaseUrl: 'postgres://unleash_user:passord@localhost:5432/unleash',
authentication: {
type: 'custom',
customAuthHandler: myCustomAdminAuth,
},
2018-11-22 11:20:28 +01:00
})
2021-08-05 14:00:30 +02:00
.then((unleash) => {
2018-11-22 11:20:28 +01:00
console.log(
`Unleash started on http://localhost:${unleash.app.get('port')}`,
);
});
```
2018-11-22 11:20:28 +01:00
Additionally, you can trigger the admin interface to prompt the user to sign in by configuring your middleware to return a `401` status on protected routes. The response body must contain a `message` and a `path` used to redirect the user to the proper login route.
```json
{
2018-11-22 11:20:28 +01:00
"message": "You must be logged in to use Unleash",
"path": "/custom/login"
}
```
2019-03-05 09:26:34 +01:00
Examples of custom authentication hooks:
2018-11-22 11:20:28 +01:00
- [securing-google-auth](https://github.com/Unleash/unleash-examples/tree/main/v4/securing-google-auth)
- [securing-basic-auth](https://github.com/Unleash/unleash-examples/tree/main/v4/securing-basic-auth)
- [securing-keycloak-auth](https://github.com/Unleash/unleash-examples/tree/main/v4/securing-keycloak-auth)