> For the complete documentation index, see [llms.txt](https://wiki.datadike.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.datadike.com/pam/administration/identities/sso-google-workspace.md). Agents can also search and read this documentation through its [MCP server](https://wiki.datadike.com/~gitbook/mcp).

# Single sign-on with Google Workspace

Let users sign in to the console with their Google Workspace account, through a custom SAML app in the Google Admin console and the SAML2 method here.

## What this is and when to use it

This page connects the console to Google Workspace over SAML 2.0. Google is the identity provider (IdP): it confirms who the person is. The solution is the service provider (SP): it trusts that confirmation and opens the session. Once it is done, the login screen shows a **SAML2** button, and users sign in with their company Google account instead of a local password.

**The order matters.** The service provider metadata that Google needs exists only after the key and certificate are saved here, so the configuration goes back and forth:

1. Generate the service provider key and certificate.
2. Save them on the **SAML2** tab here.
3. Read the Entity ID and the ACS URL from the service provider metadata.
4. Create the app in the Google Admin console with those values, and download Google's metadata.
5. Come back here, paste Google's metadata, and set the attribute map and the advanced settings.
6. Turn on user access in Google, and test.

What travels between the two sides:

| Value                          | Comes from                                                               | Goes to                         |
| ------------------------------ | ------------------------------------------------------------------------ | ------------------------------- |
| Google IdP metadata (XML)      | Google Admin console, **DOWNLOAD METADATA**                              | **IDP Metadata XML** here       |
| ACS URL                        | Service provider metadata here, `Location` of `AssertionConsumerService` | **ACS URL** in Google           |
| Entity ID                      | Service provider metadata here, `entityID`                               | **Entity ID** in Google         |
| SP private key and certificate | You generate them                                                        | Here only                       |
| Attribute names                | **Attribute mapping** in Google                                          | Keys of **User attribute** here |

For how single sign-on behaves in general, see [Single sign-on](https://wiki.datadike.com/pam/administration/identities/sso.md).

## Before you start

* The **SYSADMIN** profile.
* A Google Workspace super administrator account for the Admin console (`admin.google.com`).
* The public address of this installation, for example `https://pam.contoso.example`.
* OpenSSL, on Linux, macOS, or Git Bash on Windows.
* A local administrator login that keeps working without SSO. Do not make SSO the only way in until it has been tested with several users.

## Steps

### 1. Generate the service provider key and certificate

```bash
openssl req -x509 -newkey rsa:2048 -nodes -days 3650 \
  -keyout sp.key -out sp.crt \
  -subj "/O=Contoso/CN=pam.contoso.example"
```

Use the installation's hostname as `CN`. The command writes `sp.key` and `sp.crt`, valid for ten years. Check that both exist with `ls -l sp.key sp.crt`. The private key stays with this installation and is never sent to Google.

{% hint style="info" %}
On Git Bash for Windows, the shell rewrites arguments that start with `/`, which breaks `-subj`. Put `MSYS_NO_PATHCONV=1` in front of the command. Paste with the right mouse button or **Shift+Insert** rather than **Ctrl+V**, which can carry invisible characters.
{% endhint %}

### 2. Save the key and certificate here

1. Open **System settings › Authentication** and select the **SAML2** tab.
2. Turn on **SAML2**.
3. In **SP private key**, enter the contents of `sp.key`.
4. In **SP cert**, enter the contents of `sp.crt`.
5. Click **Save**.

The service provider metadata is available only after this save. Opened before it, it returns an error saying the SP private key or certificate was not found.

### 3. Read the Entity ID and the ACS URL

1. Open the service provider metadata at `https://<your-server>/core/auth/saml2/metadata/`.
2. Copy the `entityID` attribute of the root element. This is the **Entity ID**.
3. Copy the `Location` attribute of the `AssertionConsumerService` element. This is the **ACS URL**, and it ends in `/saml2/callback/`.

Copy both values from the XML of your installation, never from an example. A reverse proxy or an extra path prefix changes them, and an Entity ID that differs by a single character is what produces `Invalid audience` later.

### 4. Create the custom SAML app in Google

Signed in as super administrator, open **Apps › Web and mobile apps › Add app › Add custom SAML app**.

1. Enter an app name, for example `DataDike PAM`, and click **Continue**.
2. On **Google Identity Provider details**, click **DOWNLOAD METADATA** and keep the XML file. Click **Continue**.
3. On **Service provider details**, fill in:

   | Field           | Value                                                    |
   | --------------- | -------------------------------------------------------- |
   | ACS URL         | The `Location` from step 3, ending in `/saml2/callback/` |
   | Entity ID       | The `entityID` from step 3                               |
   | Start URL       | Empty                                                    |
   | Signed response | Ticked                                                   |
   | Name ID format  | `EMAIL`                                                  |
   | Name ID         | **Basic Information › Primary email**                    |
4. On **Attribute mapping**, add these mappings. Without them the assertion carries only the Name ID, no username reaches this side, and sign-in fails.

   | Google Directory attribute | App attribute |
   | -------------------------- | ------------- |
   | Primary email              | `username`    |
   | Primary email              | `email`       |
   | First name                 | `name`        |
5. Click **Finish**.

### 5. Turn on user access in Google

1. Open **Apps › Web and mobile apps** and select the app.
2. Open **User access**, choose **ON for everyone** or turn it on for the organizational unit that should use it, and click **Save**.

Without this, Google refuses the sign-in with `app_not_enabled_for_user`. The change can take a few minutes to propagate.

### 6. Finish the configuration here

Back on the **SAML2** tab:

1. In **IDP Metadata XML**, paste the whole content of the file downloaded in step 4.
2. Leave **IDP Metadata URL** empty. A custom SAML app in Google does not publish a stable metadata URL, and when **IDP Metadata URL** is filled it takes precedence over the XML.
3. In **User attribute**, map the app attributes named in Google to the user fields here:

   ```json
   {
     "username": "username",
     "email": "email",
     "name": "name"
   }
   ```

   For SAML2, the key is the attribute name the IdP sends and the value is the field here. Only `username`, `name`, `email`, `comment`, `phone` and `groups` are read; any other attribute is ignored.
4. In **SP advanced settings**, enter the following. Google signs the assertion, does not encrypt it, and ignores signed authentication requests:

   ```json
   {
     "organization": {
       "en": {
         "name": "DataDike",
         "displayname": "DataDike",
         "url": "https://datadike.com/"
       }
     },
     "strict": true,
     "security": {
       "authnRequestsSigned": false,
       "wantAssertionsSigned": true,
       "wantAssertionsEncrypted": false,
       "wantMessagesSigned": false,
       "wantNameId": true,
       "requestedAuthnContext": false
     }
   }
   ```

   The key under `en` is `url`, not `uri`. The settings are validated against the SAML schema, and a configuration with `uri` is rejected.
5. Tick **Always update user**, so that name and email are refreshed at every sign-in.
6. Decide on **Logout completely**. When it is ticked, signing out here also signs the user out at Google. If people keep Gmail open in the same browser, untick it, or leaving the console also signs them out of Gmail.
7. In **Organization**, choose the organization that new users are created in.
8. Click **Save**.

## What you should see

The login screen shows a **SAML2** button next to the local login form.

## How to verify it worked

1. Confirm the metadata is served with your certificate:

   ```bash
   curl -s https://<your-server>/core/auth/saml2/metadata/
   ```

   The answer must be XML whose `X509Certificate` matches `sp.crt`, not an error page.
2. In a private browser window, open the login page and click **SAML2**. You must be sent to Google, authenticate there, and come back signed in.
3. Open **Users › Users** and find that user. The **Source** column must show SAML2 rather than `Local`, the username must be the email address, and **Email** must be filled.
4. Try an account from an organizational unit without access to the app. Google must refuse it.
5. Sign out, and confirm the behaviour matches your choice for **Logout completely**.

## Common errors

Authentication errors are recorded in the log of the core service of the installation.

| Symptom                                                                               | Cause                                                                                           | Fix                                                                               |
| ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| `Invalid audience` in the log                                                         | The **Entity ID** in Google is not identical to the `entityID` in the service provider metadata | Copy the `entityID` from the metadata of this installation into Google again      |
| Google shows `app_not_enabled_for_user`                                               | **User access** is off for the user's organizational unit, or the change has not propagated yet | Turn access on, save, and wait a few minutes                                      |
| Google accepts the account but sign-in here fails                                     | The **Attribute mapping** in Google was not saved, so no `username` arrives                     | Redo step 4.4 and confirm Google saved the mappings                               |
| The user has no name or email                                                         | The keys in **User attribute** do not match the app attribute names in Google                   | Make the keys identical to the names typed in Google                              |
| The metadata address returns an error about the SP private key or certificate         | The key and certificate were not saved                                                          | Do step 2 and click **Save** first                                                |
| The pasted XML seems to be ignored                                                    | **IDP Metadata URL** is filled, and it takes precedence                                         | Empty **IDP Metadata URL**                                                        |
| **SP advanced settings** is rejected                                                  | The JSON uses `uri` instead of `url`                                                            | Change the key to `url`                                                           |
| A message asks to check whether a user with the same username or email already exists | A local user already holds that email under another username                                    | Align the existing user's username with the Google email, or remove the duplicate |
| Signing out of the console also signs the user out of Gmail                           | **Logout completely** is ticked                                                                 | Untick it                                                                         |
| `-subj` is mangled on Windows                                                         | Git Bash path conversion                                                                        | Prefix the command with `MSYS_NO_PATHCONV=1`                                      |

## Field reference

Values for Google Workspace on the **SAML2** tab:

| Field                | Value for Google Workspace                                           |
| -------------------- | -------------------------------------------------------------------- |
| SAML2                | On                                                                   |
| IDP Metadata URL     | Empty                                                                |
| IDP Metadata XML     | The XML from **DOWNLOAD METADATA**                                   |
| SP private key       | Contents of `sp.key`                                                 |
| SP cert              | Contents of `sp.crt`                                                 |
| SP advanced settings | The JSON in step 6                                                   |
| User attribute       | Map from Google's app attribute names to `username`, `email`, `name` |
| Always update user   | On                                                                   |
| Logout completely    | Off if users keep Gmail open in the same browser                     |
| Organization         | The organization new users are created in                            |

## Related pages

* [Single sign-on](https://wiki.datadike.com/pam/administration/identities/sso.md): methods, service URLs, and attribute mapping
* [Single sign-on with Microsoft Entra ID](https://wiki.datadike.com/pam/administration/identities/sso-entra-id.md): the same result over OIDC
* [Users and groups](https://wiki.datadike.com/pam/administration/identities/users-and-groups.md): the records SSO creates
* [Multi-factor authentication](https://wiki.datadike.com/pam/administration/identities/mfa.md): a second factor here, or delegated to Google
