googleapis / googleapis/python-genai

Add CMEK directly in Gemini Batch Job Configuration

Open
#2,622 1 comment 0 reactions 1 assignee Claimed by @Venkaiahbabuneelam View on GitHub
priority: p3 type: feature request
Dominant language
Python
Stars
4k
Forks
1k
Avg merge
2d 11h
Merged PRs (30d)
40

Description

Feature Request
---

I am facing an issue with my company's Org policy that requires a Customer Managed Encryption Key (CMEK) in place to use some features (i.e. Gemini Batch Inference). I'd like a clean way to enter our CMEK directly into the configuration of a batch job `types.CreateBatchJobConfig(...)` similar to the existing _encryption_spec_ parameter in `types.CreateCachedContentConfig(...)` and `types.CreateTuningJobConfig(...)`, which utilize the _kms_key_name_ field in `types.EncryptionSpec(...)`.

Background
---

For a normal `client.models.generate_content(...)` request, you cannot pass CMEK(s) directly, as `GenerateContentConfig` has no _kms_key_name_ / _encryption_spec_ field. Therefore, `client.batches.create(...)` in **google-genai** does not currently expose a CMEK field for Gemini batch jobs.

So this does _not_ work:
```python
genai.types.CreateBatchJobConfig(
display_name="example_job",
dest="gs://bucket/blob_name",
encryption_spec=genai.types.EncryptionSpec(
kms_key_name="projects//locations//keyRings//cryptoKeys/",
)
)
```

And the only alternatives are to:
1. use the Vertex AI batch prediction API surface instead of **google-genai** as Vertex `BatchPredictionJob` supports an encryption spec / encryption key field
2. use `gcloud` command line to enable default CMEK on your existing project resources (i.e. cloud storage buckets) _BEFORE_ you use **google-genai**
```
gcloud storage buckets update gs://YOUR_OUTPUT_BUCKET --default-kms-key=projects/YOUR_PROJECT/locations/YOUR_LOCATION/keyRings/YOUR_KEYRING/cryptoKeys/YOUR_KEY
```
3. Register the CMEK in your current session (i.e. with a **curl** command) (Reference: [Google Docs](https://docs.cloud.google.com/generative-ai-app-builder/docs/cmek#key-registration))

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.