Elastic Gmail connector reference
editElastic Gmail connector reference
editThe Elastic GMail connector is a connector for GMail.
Elastic managed connector reference
editView Elastic managed connector reference
Availability and prerequisites
editThis connector is available as a managed connector (managed service) in Elastic Cloud.
This connector is compatible with Elastic versions 8.13.0+.
To use this connector, satisfy all managed connector requirements.
Create a Gmail connector
editUse the UI
editTo create a new Gmail connector:
- In the Kibana UI, navigate to the Search → Content → Connectors page from the main menu, or use the global search field.
- Follow the instructions to create a new native Gmail connector.
For additional operations, see Connectors UI in Kibana.
Use the API
editYou can use the Elasticsearch Create connector API to create a new native Gmail connector.
For example:
resp = client.connector.put( connector_id="my-{service-name-stub}-connector", index_name="my-elasticsearch-index", name="Content synced from {service-name}", service_type="{service-name-stub}", is_native=True, ) print(resp)
const response = await client.connector.put({ connector_id: "my-{service-name-stub}-connector", index_name: "my-elasticsearch-index", name: "Content synced from {service-name}", service_type: "{service-name-stub}", is_native: true, }); console.log(response);
PUT _connector/my-gmail-connector { "index_name": "my-elasticsearch-index", "name": "Content synced from Gmail", "service_type": "gmail", "is_native": true }
You’ll also need to create an API key for the connector to use.
The user needs the cluster privileges manage_api_key
, manage_connector
and write_connector_secrets
to generate API keys programmatically.
To create an API key for the connector:
-
Run the following command, replacing values where indicated. Note the
id
andencoded
return values from the response:resp = client.security.create_api_key( name="my-connector-api-key", role_descriptors={ "my-connector-connector-role": { "cluster": [ "monitor", "manage_connector" ], "indices": [ { "names": [ "my-index_name", ".search-acl-filter-my-index_name", ".elastic-connectors*" ], "privileges": [ "all" ], "allow_restricted_indices": False } ] } }, ) print(resp)
const response = await client.security.createApiKey({ name: "my-connector-api-key", role_descriptors: { "my-connector-connector-role": { cluster: ["monitor", "manage_connector"], indices: [ { names: [ "my-index_name", ".search-acl-filter-my-index_name", ".elastic-connectors*", ], privileges: ["all"], allow_restricted_indices: false, }, ], }, }, }); console.log(response);
POST /_security/api_key { "name": "my-connector-api-key", "role_descriptors": { "my-connector-connector-role": { "cluster": [ "monitor", "manage_connector" ], "indices": [ { "names": [ "my-index_name", ".search-acl-filter-my-index_name", ".elastic-connectors*" ], "privileges": [ "all" ], "allow_restricted_indices": false } ] } } }
-
Use the
encoded
value to store a connector secret, and note theid
return value from this response:resp = client.connector.secret_post( body={ "value": "encoded_api_key" }, ) print(resp)
const response = await client.connector.secretPost({ body: { value: "encoded_api_key", }, }); console.log(response);
POST _connector/_secret { "value": "encoded_api_key" }
-
Use the API key
id
and the connector secretid
to update the connector:resp = client.connector.update_api_key_id( connector_id="my_connector_id>", api_key_id="API key_id", api_key_secret_id="secret_id", ) print(resp)
const response = await client.connector.updateApiKeyId({ connector_id: "my_connector_id>", api_key_id: "API key_id", api_key_secret_id: "secret_id", }); console.log(response);
PUT /_connector/my_connector_id>/_api_key_id { "api_key_id": "API key_id", "api_key_secret_id": "secret_id" }
Refer to the Elasticsearch API documentation for details of all available Connector APIs.
Usage
editTo use this connector as a managed connector in Elastic Cloud, use the Connectors workflow in the Kibana UI.
To create a new Gmail connector:
- Navigate to Search → Connectors page in the Kibana UI.
- Select the New Native Connector button.
- Select the Gmail connector.
For additional operations, see Connectors UI in Kibana.
Connector authentication prerequisites
editBefore 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
.
- Create a Google Cloud Project. Give your project a name, change the project ID and click the Create button.
-
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. -
Create a Service Account. In the
APIs & Services
section, click onCredentials
and click onCreate 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. ClickDone
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
-
-
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 theAdd key
drop-down menu, then selectCreate 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.
-
In the Cloud Console, go to
-
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.
-
Configuration
editThe 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 Console
→Account
and copy the value underCustomer Id
. - Include spam and trash emails
- Toggle to fetch spam and trash emails. Also works with document level security (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.
-
Full syncs will fetch access control lists for each document and store them in the
Documents and syncs
editThe connector will fetch all messages of all users the service account has access to.
Sync types
editFull syncs are supported by default for all connectors.
This connector also supports incremental syncs.
Sync rules
editBasic 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
editDocument 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.
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.
Known issues
editThere are currently no known issues for this connector.
Troubleshooting
editSee Troubleshooting.
Security
editSee Security.
Framework and source
editThis connector is built in Python with the Elastic connector framework.
View the source code for this connector (branch 8.17, compatible with Elastic 8.17).
Self-managed connector reference
editView self-managed connector reference
Availability and prerequisites
editThis connector is available as a self-managed 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.
Create a Gmail connector
editUse the UI
editTo create a new Gmail connector:
- In the Kibana UI, navigate to the Search → Content → Connectors page from the main menu, or use the global search field.
- Follow the instructions to create a new Gmail self-managed connector.
Use the API
editYou can use the Elasticsearch Create connector API to create a new self-managed Gmail self-managed connector.
For example:
resp = client.connector.put( connector_id="my-{service-name-stub}-connector", index_name="my-elasticsearch-index", name="Content synced from {service-name}", service_type="{service-name-stub}", ) print(resp)
const response = await client.connector.put({ connector_id: "my-{service-name-stub}-connector", index_name: "my-elasticsearch-index", name: "Content synced from {service-name}", service_type: "{service-name-stub}", }); console.log(response);
PUT _connector/my-gmail-connector { "index_name": "my-elasticsearch-index", "name": "Content synced from Gmail", "service_type": "gmail" }
You’ll also need to create an API key for the connector to use.
The user needs the cluster privileges manage_api_key
, manage_connector
and write_connector_secrets
to generate API keys programmatically.
To create an API key for the connector:
-
Run the following command, replacing values where indicated. Note the
encoded
return values from the response:resp = client.security.create_api_key( name="connector_name-connector-api-key", role_descriptors={ "connector_name-connector-role": { "cluster": [ "monitor", "manage_connector" ], "indices": [ { "names": [ "index_name", ".search-acl-filter-index_name", ".elastic-connectors*" ], "privileges": [ "all" ], "allow_restricted_indices": False } ] } }, ) print(resp)
const response = await client.security.createApiKey({ name: "connector_name-connector-api-key", role_descriptors: { "connector_name-connector-role": { cluster: ["monitor", "manage_connector"], indices: [ { names: [ "index_name", ".search-acl-filter-index_name", ".elastic-connectors*", ], privileges: ["all"], allow_restricted_indices: false, }, ], }, }, }); console.log(response);
POST /_security/api_key { "name": "connector_name-connector-api-key", "role_descriptors": { "connector_name-connector-role": { "cluster": [ "monitor", "manage_connector" ], "indices": [ { "names": [ "index_name", ".search-acl-filter-index_name", ".elastic-connectors*" ], "privileges": [ "all" ], "allow_restricted_indices": false } ] } } }
-
Update your
config.yml
file with the API keyencoded
value.
Refer to the Elasticsearch API documentation for details of all available Connector APIs.
Usage
editTo use this connector as a self-managed connector, use the Connector workflow in the Kibana UI.
For additional operations, see Connectors UI in Kibana.
Connector authentication prerequisites
editBefore 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
.
- Create a Google Cloud Project. Give your project a name, change the project ID and click the Create button.
-
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. -
Create a Service Account. In the
APIs & Services
section, click onCredentials
and click onCreate 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. ClickDone
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
-
-
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 theAdd key
drop-down menu, then selectCreate 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.
-
In the Cloud Console, go to
-
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.
-
Configuration
editWhen using the self-managed connector workflow, initially these fields will use the default configuration set in the connector source code.
These are set in the get_default_configuration
function definition.
These configurable fields will be rendered with their respective labels in the Kibana UI. Once connected, you’ll be able to update these values in Kibana.
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 Console
→Account
and copy the value underCustomer 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.
-
Full syncs will fetch access control lists for each document and store them in the
Deployment using Docker
editYou can deploy the Gmail connector as a self-managed connector using Docker. Follow these instructions.
Step 1: Download sample configuration file
Download the sample configuration file. You can either download it manually or run the following command:
curl https://raw.githubusercontent.com/elastic/connectors/main/config.yml.example --output ~/connectors-config/config.yml
Remember to update the --output
argument value if your directory name is different, or you want to use a different config file name.
Step 2: Update the configuration file for your self-managed connector
Update the configuration file with the following settings to match your environment:
-
elasticsearch.host
-
elasticsearch.api_key
-
connectors
If you’re running the connector service against a Dockerized version of Elasticsearch and Kibana, your config file will look like this:
# When connecting to your cloud deployment you should edit the host value elasticsearch.host: http://host.docker.internal:9200 elasticsearch.api_key: <ELASTICSEARCH_API_KEY> connectors: - connector_id: <CONNECTOR_ID_FROM_KIBANA> service_type: gmail api_key: <CONNECTOR_API_KEY_FROM_KIBANA> # Optional. If not provided, the connector will use the elasticsearch.api_key instead
Using the elasticsearch.api_key
is the recommended authentication method. However, you can also use elasticsearch.username
and elasticsearch.password
to authenticate with your Elasticsearch instance.
Note: You can change other default configurations by simply uncommenting specific settings in the configuration file and modifying their values.
Step 3: Run the Docker image
Run the Docker image with the Connector Service using the following command:
docker run \ -v ~/connectors-config:/config \ --network "elastic" \ --tty \ --rm \ docker.elastic.co/enterprise-search/elastic-connectors:8.17.0.0 \ /app/bin/elastic-ingest \ -c /config/config.yml
Refer to DOCKER.md
in the elastic/connectors
repo for more details.
Find all available Docker images in the official registry.
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.
Documents and syncs
editThe connector will fetch all messages of all users the service account has access to.
Sync types
editFull syncs are supported by default for all connectors.
This connector also supports incremental syncs.
Sync rules
editBasic 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
editDocument 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.
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.
Known issues
editThere are currently no known issues for this connector.
Troubleshooting
editSee Troubleshooting.
Security
editSee Security.
Framework and source
editThis connector is built in Python with the Elastic connector framework.
View the source code for this connector (branch 8.17, compatible with Elastic 8.17).