# Enforce single sign-on

Require the people at a connection's verified domains to sign in through your identity provider instead of with a password.

**Important:**
Enforcing a connection also turns console passwords off for every IAM user of your organization
(see [Give an IAM user console access](give-a-user-console-access.md)).

## Prerequisites

- Permission for `iam:UpdateSsoConnection`. To open the **Single sign-on** page in the console,
  `iam:ListSsoConnections`.
- Single sign-on works: sign in through the connection once before you enforce it (see Result for
  why).
- The connection is on, which needs a verified domain (see [Verify a domain](verify-a-domain.md)).

## Enforce the connection

**Console**
1. Open **IAM**, then choose **Single sign-on**.
2. On the connection's card, choose **Enforce**. The card shows **Enforced**.

To stop, choose **Stop enforcing**.

**CLI**
```sh
dcloud iam sso-connections update connection-id --enforced
```

**API**
```http
PATCH /iam/api/sso-connections/connection-id
{ "enforced": true }
```

**Terraform**
Set `enforced = true` (with `enabled = true`) on the `dcloud_iam_sso_connection` resource.

## Result

For every address at the connection's verified domains:

- the sign-in page shows no password field: it says that the connection signs the organization in,
  and offers **Continue with SSO**. A password is refused with 403
  `Your organization signs in with single sign-on. Use "Continue with SSO" instead of a password.`;
- no password-reset code is sent, and a reset is refused;
- registering an account with a password, or accepting an invitation with a new password, is
  refused with the same message.

The organization's owner can still sign in with a password, so a broken identity provider
configuration can be repaired: on the sign-in page, under **Continue with SSO**, choose
**Organization owner? Sign in with your password**, then enter the password and choose **Sign in**.
The link is shown to everyone at the domain, so it does not reveal who the owner is; anyone else
who uses it is refused with the message above. Turning the connection off also stops enforcing it.

IAM users who sign in with a user name and a password are refused as well, with
`Your organization signs in with single sign-on, so IAM-user console passwords are off. Ask your administrator.`
IAM users who are signed in lose their session at their next request, and no IAM user can be given
a console password while a connection is enforced.

## If it is refused

- 400 `Turn the connection on before enforcing it.` The console does not send the request for a
  connection that is off; it says `Cannot change enforcement: turn the connection on first.`

## Related

- [Single sign-on](single-sign-on.md) · [Set the password policy](set-the-password-policy.md)
- `iam.sso-connections.update` · `dcloud iam sso-connections update` · `dcloud_iam_sso_connection`
