Google Workspace credentials setup
This page describes how to create the Google Cloud service account and domain-wide delegation that Duplicati uses to back up and restore Google Workspace
Duplicati accesses a Google Workspace domain with a service account that uses domain-wide delegation to act on behalf of the users in the domain. Before you can set up a backup, the service account needs to be created in a Google Cloud project, and a Google Workspace super administrator needs to authorize it in the Google Admin console.
When you are done, you have the two values that Duplicati asks for:
Admin email: The email address of a Google Workspace administrator in the domain. The service account acts as this user to list the users, groups, organizational units and other resources in the domain.
Service account JSON: The JSON key file for the service account.
The same steps apply whether you use the Google Workspace backup source in Duplicati or a managed Google Workspace backup in the Duplicati Console.
Decide on backup and restore credentials
A backup only needs the read-only scopes, while a restore into the domain needs scopes with write access. You can choose between:
One service account for both backup and restore: Simple to set up, but the key stored with the backup can also modify data in the domain.
Separate service accounts: The service account used for the backup is only authorized for the read-only scopes. A second service account with the restore scopes is created, or temporarily authorized, when you need to restore. This is the most secure option.
If you restore into a different domain, the service account with the restore scopes must be authorized in the target domain.
Step 1: Create or choose a Google Cloud project
Sign in to the Google Cloud console with an account in your Google Workspace organization.
Click the project selector at the top of the page, and either choose an existing project or click New project.
If you create a new project, give it a name, such as "Duplicati backup", choose your organization as the location, and click Create.


Make sure the new project is selected in the project selector before continuing.
Step 2: Enable the APIs
Duplicati calls a number of Google APIs, and each one must be enabled in the project.
Go to APIs & Services → Library.
Search for each API in the list below, open it, and click Enable.
Admin SDK API
Users, groups and organizational units
Gmail API
Gmail
Google Drive API
Drive, shared drives and Sites
Google Calendar API
Calendar
People API
Contacts
Google Tasks API
Tasks
Google Keep API
Keep
Google Chat API
Chat
Groups Settings API
Group settings




If you do not want to back up some types of data, you can leave out the APIs for those types, and exclude the types in the backup configuration.
Step 3: Configure the Google Chat API
The Google Chat API refuses requests from a project that does not have a Chat app configured, even when the requests are made on behalf of users. If you back up Google Chat, configure it like this:
Go to APIs & Services → Enabled APIs & services and open Google Chat API.
Go to the Configuration tab.
Under Application info, enter an App name, such as "Duplicati backup", and a Description. The Avatar URL is optional, and must point to a square PNG image if you set it.
Leave the remaining settings at their defaults. Duplicati does not need the app to receive messages, so nobody needs to interact with it.
Click Save at the bottom of the page.


Step 4: Create the service account
Go to IAM & Admin → Service Accounts.
Click Create service account.
Enter a Service account name, such as "duplicati-backup". The Service account ID, and with it the email address of the service account, is filled in from the name. Optionally, enter a description.
The service account does not need any roles in the project, so the optional Permissions and Principals with access steps can be skipped. Click Create and close.


Step 5: Create a JSON key
In the list of service accounts, click the new service account.
Go to the Keys tab.
Click Add key → Create new key.
Choose JSON and click Create.
The JSON key file is downloaded to your computer. This file is the Service account JSON used in Duplicati.




Step 6: Note the client ID of the service account
Go to the Details tab of the service account.
Copy the Unique ID. This is the OAuth 2 client ID of the service account, a number with about 21 digits.
The client ID is also in the JSON key file as client_id.


Step 7: Authorize domain-wide delegation
Sign in to the Google Admin console as a super administrator.
Go to Security → Access and data control → API controls.
Under Domain wide delegation, click Manage domain wide delegation.


In the list of API clients, click Add new.
In Client ID, enter the unique ID of the service account from step 6.
In OAuth scopes (comma-delimited), paste the list of scopes that matches how the service account is used (see below).
Click Authorize.

The service account is now listed among the API clients with the client ID and the authorized scopes. Click View details to see the full list of scopes. In the example below, the domain uses separate service accounts for backup and restore: the first is authorized for the 12 restore scopes, and the second for the 14 backup scopes.

Duplicati requests the read-only scopes when making a backup and the write scopes when restoring, so a service account used for both needs both sets of scopes:
See the API permissions reference for what each scope is used for, and which scopes are needed for each data type. If you leave out a type of data, you can also leave out its scopes.
It usually takes a few minutes before the authorization is active, but in some cases it can take up to 24 hours.
Step 8: Choose the admin email
Duplicati needs the email address of a user in the domain that can read the directory. The service account acts as this user when it lists the users, groups, organizational units and shared drives in the domain.
Use the email address of a super administrator, or of an administrator with an admin role that can read users, groups and organizational units.
Use the email address of a real user in the domain, not the
client_emailof the service account.For restores into the directory, such as restoring users, groups or organizational units, the administrator must also be allowed to create and update those objects.
Step 9: Use the credentials in Duplicati
Enter the admin email and the contents of the JSON key file in Duplicati:
For the Duplicati backup source, follow Configure Google Workspace backup.
For a managed backup, follow Create a managed backup.
Use the test function to check that the credentials work. In the Duplicati Console, the Test permissions function shows which of the required scopes are authorized for the service account, and which are missing.
Troubleshooting
unauthorized_client: Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested
Domain-wide delegation is missing, or a requested scope is not in the authorized list. Check that the client ID matches the service account, and that every scope is listed exactly as above. Wait a few minutes after changes.
invalid_grant: Invalid email or User ID
The admin email is not a user in the domain, or the user is suspended.
invalid_grant: account not found or invalid JWT signature
The JSON key has been deleted or belongs to a different service account. Create a new key and update the backup configuration.
Not Authorized to access this resource/api for the directory
The admin email belongs to a user without admin rights to read the directory. Use a super administrator.
... API has not been used in project ... or it is disabled
Enable the API mentioned in the error message in the Google Cloud project that the service account belongs to.
Google Chat app not found
Configure the Google Chat API as described in step 3.
Key creation is disabled by an organization policy
Make an exception for the iam.disableServiceAccountKeyCreation policy for the project, as described in step 5.
Last updated
Was this helpful?

