Skip to main content

Drive CSE Upload

With Google Workspace Client-side encryption (CSE), you can add another layer of encryption to your organization's data — like files and emails — in addition to the default encryption that Google Workspace provides.

For select Google Workspace editions, admins can import sensitive files from third-party storage using Client-side encryption and the Google Drive API, preserving the confidentiality of your data.

In this package we are providing a code sample (in the form of a Python library) to upload files hosted locally to Google Drive as Client-side encrypted (CSE) files.

Disclaimer

This sample is provided only to show how the basic logic can be implemented. It’s not meant to be a production-grade working solution.

Project Prerequisites

Google Cloud

  • Have a Cloud project

  • Have Google Drive API enabled for the project

  • Have a user with an admin rights in that project

  • Have a service-account configured for the project

  • Have the service-account provisioned for Domain Wide Delegation

  • Store the Service Account Private Key File downloaded during the account creation

    Note: The file is only downloaded during creation; you cannot re-download it

Identity Provider (IDP)

  • Have an OAuth Client ID for Desktop
  • Download and store the Client Secret File for the configured OAuth Client Id

Google Admin Console

  • Have CSE configured for the domain
  • Have an IDP configured for the domain
  • Have a KACLS configured for the domain

Key ACL Service (KACLS)

  • The KACLS must support the /privilegedwrap, /privilegedunwrap, and /digest endpoints
  • Have the KACLS configured for the domain allow /privilegedwrap and /privilegedunwrap by the admin user
  • Have the KACLS configured for the domain allow /digest by Google
  • See https://developers.google.com/workspace/cse/reference

Installing this Package

The easiest way to install this package is to get it from PyPi:

pip install drive-cse-upload

This will get this package and all of its dependencies.

Details

If you get this package from GitHub, you'll need to install its dependencies separately.

Python
  • Python 3.10.7 or greater
Tink Cryptographic Library
pip3 install tink>=1.10.0
Google Client Library
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

Running the Example

  • Set these parameters to match your setup

    • SA_KEY_FILE: The Service Account Private Key File
    • CLIENT_SECRET_FILE: The OAuth Client Secret File
    • SAVED_CREDS_FILE: Where to store the IDP Oauth credentials
    • AS_USER: Upload the file as this user (an email-address)
    • INPUT_FILE The file to upload
    • PARENT_ID The parent folder/shared-drive for the uploaded file (optional)

    Note: The first three files listed above contain sensitive information that should be protected. Users must ensure that the files passed-in / created are not readable by anyone but their owner.

$ python example.py \
  --sa-key-file "${SA_KEY_FILE}" \
  --client-secret-file "${CLIENT_SECRET_FILE}" \
  --saved-creds-file "${SAVED_CREDS_FILE}" \
  --as-user "${AS_USER}" \
  "${INPUT_FILE}"

This will upload and validate the file ${INPUT_FILE} to ${AS_USER}'s root MyDrive.

$ python example.py \
  --sa-key-file "${SA_KEY_FILE}" \
  --client-secret-file "${CLIENT_SECRET_FILE}" \
  --saved-creds-file "${SAVED_CREDS_FILE}" \
  --as-user "${AS_USER}" \
  --parent-id "${PARENT_ID}" \
  "${INPUT_FILE}"

This will upload and validate the file ${INPUT_FILE} as a child of the folder or shared-drive designated by ${PARENT_ID}.

As part of the upload process, you'll be prompted to open a browser window with a URL for authenticating with the IDP. Enter the admin user credentials there to continue.

When done, the code will print the name and the id of the newly uploaded file. You can see the file in the Drive web client. To ensure that the file is uploaded correctly, now try the "Download and decrypt" action. This should download the decrypted file to your local host.

Metadata

Release files for drive-cse-upload 2.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drive-cse-upload 2.2.0
File Size Uploaded Provenance Actions
drive_cse_upload-2.2.0.tar.gz 16.1 kB Without provenance Details for drive_cse_upload-2.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for drive-cse-upload 2.2.0
File Interpreter ABI Platform Actions
drive_cse_upload-2.2.0-py3-none-any.whl Python 3 none any Details for drive_cse_upload-2.2.0-py3-none-any.whl

Total release size: 44.4 kB

Release files / drive_cse_upload-2.2.0.tar.gz

Download URL drive_cse_upload-2.2.0.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
79fa0e7680afd0741a1dcaca56f2ac55588f7ab3e37342af088ffa4be1b136a7
BLAKE2b-256 checksum
How to use checksums
89001bca18a98ffbba098ae5bed529a016d0b1e89b7b06fcc573641672b254fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / drive_cse_upload-2.2.0-py3-none-any.whl

Download URL drive_cse_upload-2.2.0-py3-none-any.whl
Size 28.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c5b6e5654b2f8b32f6a99cb6298ffa2965f5a30f8736df0df4caf1476000959
BLAKE2b-256 checksum
How to use checksums
3ec354908677b55cfcef51c322b0b1e1736ff9b0f0be26e2fdc6ac15dbad7a17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Security for drive-cse-upload 2.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page