Loading

Elastic Gmail connector reference

The Elastic GMail connector is a connector for GMail.

Important

As of Elastic 9.0, managed connectors on Elastic Cloud Hosted are no longer available. All connectors must be self-managed.

This connector is available as a self-managed connector from the Elastic connector framework.

This self-managed connector is compatible with Elastic versions 8.10.0+.

To use this connector, satisfy all self-managed connector requirements.

To create a new Gmail connector:

  1. In the Kibana UI, navigate to the Search → Content → Connectors page from the main menu, or use the global search field.
  2. Follow the instructions to create a new Gmail self-managed connector.

You can use the Elasticsearch Create connector API to create a new self-managed Gmail self-managed connector.

For example:

 PUT _connector/my-gmail-connector {
  "index_name": "my-elasticsearch-index",
  "name": "Content synced from Gmail",
  "service_type": "gmail"
}

Refer to the Elasticsearch API documentation for details of all available Connector APIs.

To use this connector as a self-managed connector, use the Connector workflow in the Kibana UI.

For additional operations, see Connectors UI in Kibana.

Before syncing any data from GMail, you need to create a service account with appropriate access to the GMail and the Google Directory API, which is part of the Google Admin SDK API. You also need to enable domain-wide delegation to impersonate the users you’re fetching messages from.

To get started, log into Google Cloud Platform and go to the Console.

  1. Create a Google Cloud Project. Give your project a name, change the project ID and click the Create button.

  2. Enable Google APIs. Choose APIs & Services from the left menu and click on Enable APIs and Services. You need to enable GMail API and the Google Admin SDK API.

  3. Create a Service Account. In the APIs & Services section, click on Credentials and click on Create credentials to create a service account. Give your service account a name and a service account ID. This is like an email address and will be used to identify your service account in the future. Click Done to finish creating the service account.

    Your service account needs to have access to at least the following scope:

    • https://www.googleapis.com/auth/gmail.readonly
  4. Create a Key File.

    • In the Cloud Console, go to IAM and Admin > Service accounts page.
    • Click the email address of the service account that you want to create a key for.
    • Click the Keys tab. Click the Add key drop-down menu, then select Create new key.
    • Select JSON as the Key type and then click Create. This will download a JSON file that will contain the service account credentials.
  5. Google Workspace domain-wide delegation of authority.

    To access user data like messages on a Google Workspace domain, the service account that you created needs to be granted access by a super administrator for the domain. You can follow the official documentation to perform Google Workspace domain-wide delegation of authority.

    You need to grant the following OAuth Scopes to your service account:

    • https://www.googleapis.com/auth/admin.directory.user.readonly

    This step allows the connector to access user data and their group memberships in your Google Workspace organization.

The following configuration fields are required:

GMail service account JSON
The service account credentials generated from Google Cloud Platform (JSON string). Refer to the Google Cloud documentation for more information.
Google Workspace admin email
Google Workspace admin email. Required to enable document level security (DLS). A service account with delegated authority can impersonate an admin user with permissions to access Google Workspace user data and their group memberships. Refer to the Google Cloud documentation for more information.
Google customer id
Google customer id. Required to fetch messages and to enable document level security (DLS). Go to Google Workspace Admin ConsoleAccount and copy the value under Customer Id.
Include spam and trash emails
Toggle to fetch spam and trash emails. Also works with DLS.
Enable document level security

Toggle to enable document level security (DLS. DLS is supported for the GMail connector. When enabled:

  • Full syncs will fetch access control lists for each document and store them in the _allow_access_control field.
  • Access control syncs will fetch users' access control lists and store them in a separate index.

You can deploy the Gmail connector as a self-managed connector using Docker. Follow these instructions.

Refer to DOCKER.md in the elastic/connectors repo for more details.

Find all available Docker images in the official registry.

Tip

We also have a quickstart self-managed option using Docker Compose, so you can spin up all required services at once: Elasticsearch, Kibana, and the connectors service. Refer to this README in the elastic/connectors repo for more information.

The connector will fetch all messages of all users the service account has access to.

Full syncs are supported by default for all connectors.

This connector also supports incremental syncs.

Basic sync rules are identical for all connectors and are available by default.

Advanced sync rules are available for this connector. The connector supports the GMail advanced search syntax under the messages field.

For example:

{
  "messages": [
    "before:2021/10/10",
    "from:amy"
  ]
}

Document level security (DLS) enables you to restrict access to documents based on a user’s permissions. Refer to configuration on this page for how to enable DLS for this connector.

Note

Refer to DLS in Search Applications to learn how to ingest data from a connector with DLS enabled, when building a search application. The example uses SharePoint Online as the data source, but the same steps apply to every connector.

There are currently no known issues for this connector.

See Troubleshooting.

See Security.

This connector is built in Python with the Elastic connector framework.

View the source code for this connector (branch main, compatible with Elastic 9.0).