Skip to content

Enable Authentication for Google Sheet Connector Using Delegated User Credentials #25746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Raghav-Modani
Copy link
Contributor

Description

This change lets the Google Sheets connector to authenticate by using delegated user credentials instead of raw service-account identity (which lives outside the domain). By supplying a “delegated user” email address, the connector will:

  1. Obtain domain-wide delegated credentials for that user
  2. Build a Sheets client under the user’s identity

Since the domain of google service account is different from the organization's Google workspace domain, this change allows to share the google sheets only within the Google workspace domain of the organization.

Additional context and related issues

  1. New Config option: gsheets.delegated-user-email
  2. Auth Flow Update: If gsheets.delegated-user-email is set, we load the service-account key, request the delegated credentials for that user, and build the Sheets client with those credentials.
  3. Backward compatibility: Falls back to plain service-account authentication when no delegated user email is provided.

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x ) Release notes are required, with the following suggested text:

## Google Sheets Connector
* Add support for authentication using delegated user credentials using the `gsheets.delegated-user-email` config property. 

Copy link

cla-bot bot commented May 7, 2025

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Raghav Modani.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@github-actions github-actions bot added docs google-sheets Google Sheets connector labels May 7, 2025
@ConfigDescription("Delegated user email to impersonate the service account")
public SheetsConfig setDelegatedUserEmail(String delegatedUserEmail)
{
this.delegatedUserEmail = Optional.ofNullable(delegatedUserEmail);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We don't have to set nullable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder.

@@ -290,9 +292,12 @@ private static Credential getCredentials(SheetsConfig sheetsConfig)
throw new TrinoException(SHEETS_BAD_CREDENTIALS_ERROR, "No sheets credentials were provided");
}

private static Credential credentialFromStream(InputStream inputStream)
private static Credential credentialFromStream(InputStream inputStream, SheetsConfig sheetsConfig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of passing config we could pass the delegatedUserEmail right ?

Copy link

cla-bot bot commented May 7, 2025

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Raghav Modani.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@Raghav-Modani Raghav-Modani force-pushed the gsheets-connector/add-authentication-options branch from c31b73c to f034351 Compare May 8, 2025 05:56
@cla-bot cla-bot bot added the cla-signed label May 8, 2025
@github-actions github-actions bot added iceberg Iceberg connector delta-lake Delta Lake connector labels May 8, 2025
@ebyhr

This comment was marked as resolved.

@Raghav-Modani Raghav-Modani force-pushed the gsheets-connector/add-authentication-options branch from eae1cf7 to f034351 Compare May 8, 2025 06:25
@Raghav-Modani Raghav-Modani requested review from ebyhr and Praveen2112 May 8, 2025 07:03
@Raghav-Modani
Copy link
Contributor Author

@ebyhr @Praveen2112 Please review this PR and let me know if any changes are required. Thanks!

@Raghav-Modani Raghav-Modani marked this pull request as draft May 9, 2025 12:50
@Raghav-Modani
Copy link
Contributor Author

@Praveen2112 @ebyhr looks like the maven-checks 25-ea is failing consistently. Apart from it, could you please review the latest commits and suggest any changes required?

Copy link
Member

@Praveen2112 Praveen2112 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there is any manual test or validation that this email-id is being used ? Like a manual screenshot based on the history of the sheet ? @ebyhr Any alternatives we could use ?

@Praveen2112
Copy link
Member

@Raghav-Modani Btw please squash the commit into 1.

@Raghav-Modani Raghav-Modani force-pushed the gsheets-connector/add-authentication-options branch from 5618e39 to 70dbec2 Compare May 13, 2025 06:09
@Raghav-Modani Raghav-Modani marked this pull request as ready for review May 13, 2025 06:14
@Raghav-Modani
Copy link
Contributor Author

@Raghav-Modani Btw please squash the commit into 1.

Its done. Please review. @Praveen2112 @ebyhr

Copy link
Member

@Praveen2112 Praveen2112 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can we have a maual test or somesort of a screenshot to ensure the delegated user email is being used.

@Raghav-Modani
Copy link
Contributor Author

LGTM. Can we have a maual test or somesort of a screenshot to ensure the delegated user email is being used.

Definitely, I will attach some screenshot on the working of this config property here shortly.

| `gsheets.data-cache-ttl` | How long to cache spreadsheet data or metadata, defaults to `5m` |
| `gsheets.connection-timeout` | Timeout when connection to Google Sheets API, defaults to `20s` |
| `gsheets.read-timeout` | Timeout when reading from Google Sheets API, defaults to `20s` |
| `gsheets.write-timeout` | Timeout when writing to Google Sheets API, defaults to `20s` |
Copy link
Member

@ebyhr ebyhr May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Raghav-Modani Can you send follow-up PR to change these properties to list-table?

@Raghav-Modani
Copy link
Contributor Author

Screenshots ensuring the delegated user email property is working as expected

  1. Set the gsheets.delegated-user-email property in the configuration file of the connector as shown:
SS1
  1. Share the metadata-mapping sheet with the delegated-user-email, no need to share this with the service account's email-id.
SS2
  1. Also, share the sheets, which are to be queried, with the same delegated-user-email.
SS3
  1. Now, query the sheets. Results are shown below:
    image

@Raghav-Modani Raghav-Modani force-pushed the gsheets-connector/add-authentication-options branch from 70dbec2 to cebfe61 Compare May 14, 2025 12:15
@Raghav-Modani
Copy link
Contributor Author

Hey @Praveen2112 , I have attached the screenshots, please check.

@Raghav-Modani
Copy link
Contributor Author

Hey @Praveen2112 @ebyhr , let me know if there are any issues. If not, can we please merge this PR?
Thanks!

@ebyhr
Copy link
Member

ebyhr commented May 15, 2025

The commit title is too long. Please follow https://trino.io/development/process#pull-request-and-commit-guidelines-

Limit the subject line to 50 characters.

@Raghav-Modani Raghav-Modani force-pushed the gsheets-connector/add-authentication-options branch from cebfe61 to ef5d065 Compare May 15, 2025 14:38
@Raghav-Modani
Copy link
Contributor Author

The commit title is too long. Please follow https://trino.io/development/process#pull-request-and-commit-guidelines-

Limit the subject line to 50 characters.

Hey @ebyhr , changed the commit title and the message body to adhere to the guidelines. I hope this works now. Let me know any other issues to be taken care of?

@ebyhr
Copy link
Member

ebyhr commented May 15, 2025

@Raghav-Modani Please wrap the commit body at 72 characters. https://trino.io/development/process#pull-request-and-commit-guidelines-

@Raghav-Modani Raghav-Modani force-pushed the gsheets-connector/add-authentication-options branch from ef5d065 to 184dee9 Compare May 16, 2025 07:23
@Raghav-Modani
Copy link
Contributor Author

Hey @ebyhr , changed the commit message body. Please check now.

@Raghav-Modani
Copy link
Contributor Author

@ebyhr @Praveen2112 can we merge it now?

@Raghav-Modani
Copy link
Contributor Author

@Praveen2112 @ebyhr are there any other requirements to be fulfilled to get this PR merged? If not, can we please get this merged? Thanks!

@bhargav2427
Copy link

bhargav2427 commented May 21, 2025

@ebyhr @Praveen2112 Could you please check this Pull Request, we are waiting for this.

Copy link
Member

@Praveen2112 Praveen2112 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Raghav-Modani Can you please squash the changes into 1 ?

Enable impersonation of service accounts in Sheets connector.
@Raghav-Modani Raghav-Modani force-pushed the gsheets-connector/add-authentication-options branch from 204e140 to ab7eb9d Compare May 21, 2025 15:04
@Raghav-Modani
Copy link
Contributor Author

@Praveen2112 squashed all the commits into 1.

@ebyhr ebyhr merged commit e0bb9fe into trinodb:master May 21, 2025
18 checks passed
@github-actions github-actions bot added this to the 476 milestone May 21, 2025
@Raghav-Modani Raghav-Modani deleted the gsheets-connector/add-authentication-options branch May 22, 2025 05:10
@Raghav-Modani
Copy link
Contributor Author

Thanks @ebyhr @Praveen2112 for merging this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed delta-lake Delta Lake connector docs google-sheets Google Sheets connector iceberg Iceberg connector
Development

Successfully merging this pull request may close these issues.

4 participants