Difference between revisions of "Google Workspace Integration"

[checked revision][unchecked revision]
(31 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:Synchronizing User Accounts with Google Apps}}
+
{{DISPLAYTITLE:Synchronizing User Accounts with G Suite}}
{{Directory Services Preamble|Google Apps account}}
+
{{Directory Services Preamble|G Suite account}}
  
== Prepare the Google Apps account ==
+
<p class=msnote>Please note that on December 16th 2019 [https://go.mailstore.com/?lang=en&target=gsuite-lsa-restriction Google announced] to limit access to G Suite for less secure apps in the future. This includes any MailStore Server version prior to 13, which therefore will no longer be able to authenticate users against G Suite when trying to log into MailStore Server.
In order to synchronize accounts information from Google Apps, MailStore Server requires a service account which has been granted permission to access the Google Apps account. This same service account is later used for archiving email from Google Apps.
 
  
=== Creating a Project ===
+
In MailStore Server 13, support for modern authentication methods via OAuth 2.0 & OpenID Connect as per Google's recommendation was introduced. Although MailStore Server 13 still comes with support for IMAP-based authentication, this document only covers the setup using modern authentication methods as required by Google in the future.</p>
Before MailStore is able to connect to Google Apps accounts a project has to be created. In Google's terminology, a project is the collection of all settings, credentials and meta data of an application that uses Google Developer APIs or  Google Cloud resources.
 
  
* Go to the [https://console.developers.google.com/ Google Developers Console].
+
== Prerequisites and Recommendations ==
* If prompted, login using a Google Account with administrative rights.
+
* To comply with Google's requirements for ''Authorized redirect URIs'' of  OAuth 2.0 clients, MailStore Server must be accessible via an URI that ends with a public top-level domain. Google uses the list from https://publicsuffix.org for validation.
* Click ''Create project''.
+
* For best user experience, the certificate used by MailStore Server should be trusted by all client and the used Web Browsers. Using a certificate that is signed by an trusted certificate authority or [[Using_Lets_Encrypt_Certificates|using Let's Encrypt certificates]] is highly recommended.
* Name the project e.g. ''MailStore API Access''.
+
 
 +
== Register Project with Google ==
 +
Irregardless of whether own or third-party applications such as MailStore are supposed to interact with a G Suite account through Google APIs, they must be registered as a project with Google first. This is necessary to ensure that access by external applications is limited to a minimum and that each application uses its own set of credentials to authenticate with Google.
 +
 
 +
=== Create New Project ===
 +
To register a project  for MailStore Server with Google, proceed as follows:
 +
 
 +
* Go to the [https://console.developers.google.com Google Developers Console].
 +
* If prompted, login using a Google account of you G Suite organization. Logging in with a user that has admin privileges is highly recommend.
 +
* If no project exists, click ''Create Project'' on the dashboard. Otherwise open the project list by clicking on the project drop-down in the header bar and click ''New project''.
 +
* Type in a meaningful name into the ''Project name'' field, e.g. "MailStore Server".
 +
* Verify that ''Organization'' matches the desired organization and adjust the ''Location'' if needed.
 +
* Click on ''Create''.
 +
 
 +
Once the project has been created, make sure that it is selected in the project drop-down list before proceeding.
 +
 
 +
==== Add API Libraries ====
 +
* Open the ''Navigation menu'' and select ''APIs & Services'' > ''Library''.
 +
* In the ''API Library'', search and enable the following APIs and services:
 +
*: <tt>Admin SDK</tt>
 +
*: <tt>Gmail API</tt>
 +
 
 +
==== Customize Consent Screen ====
 +
* Open the ''Navigation menu'' and select ''APIs & Services'' > ''OAuth consent screen''.
 +
* Under ''User Type'' select ''Internal''.
 +
* Click ''Create''
 +
* Type in a meaningful name into the ''Application name'' field, e.g. "MailStore Server"
 +
* Click ''Save''.
 +
 
 +
=== Create Service Account ===
 +
A service account is required for MailStore Server to authenticate with Google and request authorization to use certain Google APIs to synchronize users and group, and to access user mailboxes. The following steps describe the creation of such a service account.
 +
 
 +
* Open the ''Navigation menu'' and select ''APIs & Services'' > '''Credentials''.
 +
* Click ''+ Create Credentials'' and select ''Service account'' from the drop-down list.
 +
* On the ''Create service account'' page, enter a name for the service account, e.g. "MailStore Server Service".
 +
* Enter a description such as "Service account for MailStore Server to synchronize users and access mailboxes"
 
* Click ''Create''.
 
* Click ''Create''.
* In the sidebar on the left, expand ''APIs & auth''.
+
* The service account does not require permissions on project level, therefore do not select a role.
* Next, click ''APIs''.
+
* Click on ''Continue''.
* Under ''Enabled APIs'', optionally disable the APIs that have been enabled automatically.
+
* Under ''Keys'' click on ''+ Create Key''.
* In the section ''Google Apps APIs'' enable ''Admin SDK'' and ''Gmail API''.
+
* Select ''JSON'' as key type and click ''Create''.
* In the sidebar on the left, select Credentials.
+
* The JSON file will be downloaded automatically. Save the JSON file in a secure location as it allows access to cloud resources of your organization.
* Under the ''OAuth'' heading, select ''Create new Client ID''.
+
* Click ''Close'' and then ''Done''.
* When prompted, select ''Service Account'' and click ''Create Client ID''.
+
* Edit the details of the newly created service account by clicking on the corresponding pencil icon.
* Cancel the download of the ''.json'' file that is now offered. MailStore Server does not need this file.
+
* Click ''Show Domain-wide Delegation''.
* Click on ''Generate new P12 key''.
+
* Tick the ''Enable G Suite Domain-wide Delegation'' box.
* A dialog box appears. To proceed, click ''Okay, got it''.
+
* Click ''Save''.
* Save the P12 file (e.g. <tt>MailStore API Access-e035d2ad4f35.p12</tt>) to an appropriate folder on the MailStore Server. MailStore Server does not require the private key password (i.e. ''notasecret'')
+
 
* Note the ''Client ID'' and ''Email Address'' provided for later use.
+
On the ''Credentials'' page, there should be a service account listed under ''Service Accounts'' with a corresponding client listed under ''OAuth 2.0 Client IDs''.
 +
 
 +
=== Create OAuth 2.0 Client for User Authentication ===
 +
To allow users to log in to MailStore by authenticating with Google using the OpenID Connect mechanism, an OAuth 2.0 Client must be created as described below.
  
=== Grant access to the required APIs ===
+
* Open the ''Navigation menu'' and select ''APIs & Services'' > '''Credentials''.
Once created, grant the project access to the APIs used by MailStore Server's Directory Services module.
+
* Click ''+ Create Credentials'' and select ''OAuth client ID'' from the drop-down list.
 +
* Select ''Web application'' as ''Application type''.
 +
* Enter a ''Name'', e.g. "MailStore Server OpenID Connect".
 +
* Click ''+ Add URI'' under ''Authorized redirect URIs''.
 +
* Enter the URI that is reachable by clients in the ''URIs'' field using the the following scheme:
 +
*:<tt>https://<host>.<domain.tld>[:<port>]/oidc/signin</tt>
 +
* Click ''Create'' to finish.
 +
* Copy the client ID and client secret from the ''Your Client ID'' and ''Your Client Secret'' fields to a safe place and click ''OK''.
  
* Go to your Google Apps domain’s [https://admin.google.com/ Admin console].
+
== Grant Access on G Suite Account to Project ==
* Select ''Security'' from the list of controls. If you don't see ''Security'' listed, select ''More controls'' from the gray bar at the bottom of the page, then select ''Security'' from the list of controls. If you can't see the controls, make sure you're signed in as an administrator for the domain.
+
Once created, grant the new project fine-grained access to your G Suite account by defining the Google APIs it is allowed to use.
* Select ''API reference'' from the list of options.
+
 
* Enable the ''API access'' and save the changes.
+
* Open the [https://admin.google.com/ Google Admin console] and log in with a G Suite domain admin.
* Select ''Advanced settings'' from the list of options. If this section is not visible, click on ''Show more'' first.
+
* Select ''Security'' > ''API controls'' from the menu.
* Select ''Manage API client access'' in the ''Authentication'' section.
+
* Unter ''Domain wide delegation'', click ''Manage domain wide delegation''.
* In the ''Client name'' field enter the service account's ''Client ID'' (e.g. ''1047453716425-4l533u425bp2m3lfp0c23ntf8mghlbmb.apps.googleusercontent.com'').
+
* On the ''Domain-wide delegation'' page, click ''Add new''.
* In the ''One or More API Scopes'' field enter the following scopes:
+
* Enter the ''Client ID'' of the OAuth 2.0 Client that is linked with the service account.
*: <tt><nowiki>https://mail.google.com/, https://www.googleapis.com/auth/admin.directory.group.readonly, https://www.googleapis.com/auth/admin.directory.user.readonly</nowiki></tt>
+
* Under ''OAuth Scope'', add the following scopes:
 +
*: <tt><nowiki>https://mail.google.com/, https://www.googleapis.com/auth/admin.directory.group.readonly, https://www.googleapis.com/auth/admin.directory.user.readonly</nowiki></tt>
 
* Click ''Authorize''.
 
* Click ''Authorize''.
  
== Accessing Directory Service Integration ==
+
== Configure MailStore Server ==
{{Directory Services Accessing Configuration|Google Apps|gapps_sync_01.png}}
+
After the project has been successfully set up on the Google side, MailStore Server can now be configured to synchronize and authenticate users with G Suite.
  
== Connection to Google Apps ==
+
{{Directory Services Accessing Configuration|G Suite|gapps_sync_01.png}}
For synchronization MailStore Server requires information on how to connect to the Google Apps.  
 
  
*'''Service Account'''<br/>The ''email address'' provided by the Google Apps Project (e.g. ''1047453716425-4l533u425bp2m3lfp0c23ntf8mghlbmb@developer.gserviceaccount.com'').
+
==== Connection ====
*'''User Name'''<br/>The ''email address'' of a Google Apps Administrator (e.g. ''[email protected]'').
+
For synchronization MailStore Server requires information on how to connect to the G Suite.
*'''Certificate'''<br/>To import, select the ''P12'' file which was provided for downloading when creating the project.
+
 
 +
* '''Key ID'''<br/>To import the private key, select the JSON file hat has been generated by Google for the service account in the [[#Create_Service_Account|Create Service Account]] step.
 +
* '''Service Account'''<br/>The service account is determined automatically from the JSON file.
 +
* '''User Name'''<br/>The email address of a G Suite Administrator (e.g. [email protected]).
  
 
=== User Database Synchronization ===
 
=== User Database Synchronization ===
After configuring the connection settings as described above, you can specify filter criteria for the Google Apps synchronization in this section.
+
After configuring the connection settings as described above, you can specify filter criteria for the G Suite synchronization in this section.
 +
 
 +
* '''Sync only these groups'''<br/>Choose one or several G Suite groups if you only want their members to be created as MailStore Server users. That way it's possible to exclude certain users from being synchronized to MailStore Server.
 +
 
 +
=== Authentication ===
 +
The authentication settings define how MailStore Server should authenticate users at login, that have been synchronized from G Suite.
  
*'''Sync only these groups'''<br/>Choose one or several Google Apps groups if you only want their members to be created as MailStore Server users. That way it's possible to exclude certain users from being synchronized to MailStore Server.
+
* '''Method'''<br/>Ensure that ''OpenID Connect'' is selected. As mentioned in the introduction, the ''IMAP'' option is only available for backward compatibility.
{{Directory Services Options|Google Apps Account}}
+
* '''Client ID'''<br/>Enter the client ID from the [[#Create_OAuth_2.0_Client_for_User_Authentication|Create_OAuth_2.0 Client…]] step.
{{Directory Services Assign Default Privileges|Google Apps Account}}
+
* '''Client Secret'''<br/>Enter the client secret from the [[#Create_OAuth_2.0_Client_for_User_Authentication|Create_OAuth_2.0 Client…]] step.
{{Directory Services Run Synchronization|Google Apps Account}}
+
* '''Redirect Url'''<br/>Enter the same redirect URI as defined in the [[#Create_OAuth_2.0_Client_for_User_Authentication|Create_OAuth_2.0 Client…]] step .
  
 +
{{Directory Services Options|G Suite Account}}
 +
{{Directory Services Assign Default Privileges|G Suite Account}}
 +
{{Directory Services Run Synchronization|G Suite Account}}
 
[[File:ApplicationIntegration_sync_02.png|450px|center]]
 
[[File:ApplicationIntegration_sync_02.png|450px|center]]
  
{{Directory Services Login with Directory Services Credentials|Google Apps Account|mads_ldapauth_01.png}}
 
  
[[de:Google Apps-Integration]]
+
{{Directory Services Test Authentication}}
[[en:Google Apps Integration]]
+
{{Directory Services Login with Directory Services Credentials|G Suite Account|mads_ldapauth_01.png}}
 +
[[de:G Suite-Integration]]
 +
[[en:G Suite Integration]]

Revision as of 09:28, 3 June 2020

In addition to adding users manually as described in chapter User Management, MailStore Server can synchronize its internal user database with the G Suite account of your organization.

During synchronization, user information, such as user names and email addresses, is copied from the G Suite account into MailStore Server's user database. That way, users can use their G Suite account credentials to also log on to MailStore Server and emails can be assigned to their corresponding user archives automatically, for example. No changes are made to the G Suite account itself by MailStore Server. The scope of the synchronization can be limited through filters.


Please note that on December 16th 2019 Google announced to limit access to G Suite for less secure apps in the future. This includes any MailStore Server version prior to 13, which therefore will no longer be able to authenticate users against G Suite when trying to log into MailStore Server. In MailStore Server 13, support for modern authentication methods via OAuth 2.0 & OpenID Connect as per Google's recommendation was introduced. Although MailStore Server 13 still comes with support for IMAP-based authentication, this document only covers the setup using modern authentication methods as required by Google in the future.

Prerequisites and Recommendations

  • To comply with Google's requirements for Authorized redirect URIs of OAuth 2.0 clients, MailStore Server must be accessible via an URI that ends with a public top-level domain. Google uses the list from https://publicsuffix.org for validation.
  • For best user experience, the certificate used by MailStore Server should be trusted by all client and the used Web Browsers. Using a certificate that is signed by an trusted certificate authority or using Let's Encrypt certificates is highly recommended.

Register Project with Google

Irregardless of whether own or third-party applications such as MailStore are supposed to interact with a G Suite account through Google APIs, they must be registered as a project with Google first. This is necessary to ensure that access by external applications is limited to a minimum and that each application uses its own set of credentials to authenticate with Google.

Create New Project

To register a project for MailStore Server with Google, proceed as follows:

  • Go to the Google Developers Console.
  • If prompted, login using a Google account of you G Suite organization. Logging in with a user that has admin privileges is highly recommend.
  • If no project exists, click Create Project on the dashboard. Otherwise open the project list by clicking on the project drop-down in the header bar and click New project.
  • Type in a meaningful name into the Project name field, e.g. "MailStore Server".
  • Verify that Organization matches the desired organization and adjust the Location if needed.
  • Click on Create.

Once the project has been created, make sure that it is selected in the project drop-down list before proceeding.

Add API Libraries

  • Open the Navigation menu and select APIs & Services > Library.
  • In the API Library, search and enable the following APIs and services:
    Admin SDK
    Gmail API

Customize Consent Screen

  • Open the Navigation menu and select APIs & Services > OAuth consent screen.
  • Under User Type select Internal.
  • Click Create
  • Type in a meaningful name into the Application name field, e.g. "MailStore Server"
  • Click Save.

Create Service Account

A service account is required for MailStore Server to authenticate with Google and request authorization to use certain Google APIs to synchronize users and group, and to access user mailboxes. The following steps describe the creation of such a service account.

  • Open the Navigation menu and select APIs & Services > 'Credentials.
  • Click + Create Credentials and select Service account from the drop-down list.
  • On the Create service account page, enter a name for the service account, e.g. "MailStore Server Service".
  • Enter a description such as "Service account for MailStore Server to synchronize users and access mailboxes"
  • Click Create.
  • The service account does not require permissions on project level, therefore do not select a role.
  • Click on Continue.
  • Under Keys click on + Create Key.
  • Select JSON as key type and click Create.
  • The JSON file will be downloaded automatically. Save the JSON file in a secure location as it allows access to cloud resources of your organization.
  • Click Close and then Done.
  • Edit the details of the newly created service account by clicking on the corresponding pencil icon.
  • Click Show Domain-wide Delegation.
  • Tick the Enable G Suite Domain-wide Delegation box.
  • Click Save.

On the Credentials page, there should be a service account listed under Service Accounts with a corresponding client listed under OAuth 2.0 Client IDs.

Create OAuth 2.0 Client for User Authentication

To allow users to log in to MailStore by authenticating with Google using the OpenID Connect mechanism, an OAuth 2.0 Client must be created as described below.

  • Open the Navigation menu and select APIs & Services > 'Credentials.
  • Click + Create Credentials and select OAuth client ID from the drop-down list.
  • Select Web application as Application type.
  • Enter a Name, e.g. "MailStore Server OpenID Connect".
  • Click + Add URI under Authorized redirect URIs.
  • Enter the URI that is reachable by clients in the URIs field using the the following scheme:
    https://<host>.<domain.tld>[:<port>]/oidc/signin
  • Click Create to finish.
  • Copy the client ID and client secret from the Your Client ID and Your Client Secret fields to a safe place and click OK.

Grant Access on G Suite Account to Project

Once created, grant the new project fine-grained access to your G Suite account by defining the Google APIs it is allowed to use.

  • Open the Google Admin console and log in with a G Suite domain admin.
  • Select Security > API controls from the menu.
  • Unter Domain wide delegation, click Manage domain wide delegation.
  • On the Domain-wide delegation page, click Add new.
  • Enter the Client ID of the OAuth 2.0 Client that is linked with the service account.
  • Under OAuth Scope, add the following scopes:
    https://mail.google.com/, https://www.googleapis.com/auth/admin.directory.group.readonly, https://www.googleapis.com/auth/admin.directory.user.readonly
  • Click Authorize.

Configure MailStore Server

After the project has been successfully set up on the Google side, MailStore Server can now be configured to synchronize and authenticate users with G Suite.

  • Log on to MailStore Client as a MailStore Server administrator.
  • Click on Administrative Tools > Users and Archives > Directory Services.
  • In the Integration section, change the directory service type to G Suite.
Gapps sync 01.png


Connection

For synchronization MailStore Server requires information on how to connect to the G Suite.

  • Key ID
    To import the private key, select the JSON file hat has been generated by Google for the service account in the Create Service Account step.
  • Service Account
    The service account is determined automatically from the JSON file.
  • User Name
    The email address of a G Suite Administrator (e.g. [email protected]).

User Database Synchronization

After configuring the connection settings as described above, you can specify filter criteria for the G Suite synchronization in this section.

  • Sync only these groups
    Choose one or several G Suite groups if you only want their members to be created as MailStore Server users. That way it's possible to exclude certain users from being synchronized to MailStore Server.

Authentication

The authentication settings define how MailStore Server should authenticate users at login, that have been synchronized from G Suite.

Options

  • Automatically delete users in MailStore Server
    Here you can choose whether users that have been deleted in the G Suite Account will also be deleted in the MailStore Server user database by the synchronization. Users will also be deleted if they fall out of scope of the configured settings.
    Only MailStore Server users that have their authentication method set to Directory Services will be deleted.
    If the archive folder of such a user already contains archived emails, only the user entry but not its archive folder will be deleted in MailStore Server.

Assigning Default Privileges

By default, users that have been synchronized to MailStore Server from G Suite Account have the privilege to log on to MailStore Server as well as read access to their own user archive.
You can configure those default privileges before synchronization, for example, to assign the privilege Archive E-mail to all new users. To do this, click on Default Privileges...
More information on managing user privileges and their effects is available in the chapter Users, Folders and Settings which also has details on editing existing privileges.

Running Directory Services Synchronization

Click on Test Settings to check synchronization configuration and the results returned by the G Suite Account without any changes to the MailStore Server user database being actually committed.

To finally run the synchronization, click on Synchronize now. The results are shown with any changes committed to the MailStore Server user database.

ApplicationIntegration sync 02.png


You can test the authentication for a user by first selecting him from the list and then clicking on the button on the lower left. You will now be asked for that user's password. Upon clicking OK you'll receive a message whether the authentication has been successful.

Login with G Suite Account Credentials

After synchronization MailStore users can log on to MailStore Server with their G Suite Account username and G Suite Account password.