Skip to content

KMS Bad Key error when using existing Blob context to overwrite object. #502

@frankyn

Description

@frankyn

A Bad Key error can occur when trying to overwrite an existing object when metadata with local metadata.

For example:

// Write an empty object with a kmsKeyName.
Blob blob = storage.create(blobInfo, Storage.BlobTargetOption.kmsKeyName(kmsKeyName))

// Using blob that already has metadata received from Storage API to create a writer.
WriteChannel writer = blob.writer();

// The following will error with the following error:
// {
//    "message": "Bad Cloud KMS crypto key: projects/project-id/locations/us/keyRings/lab1/cryptoKeys/annie-test-key/cryptoKeyVersions/1",
//    "domain": "global",
//     "reason": "invalid"
// }
writer.write(ByteBuffer.wrap(content, 0, content.length));

The recommended change is if kmsKeyName is defined in object metadata is to remove it the resource id contains:

/cryptoKeyVersions/..

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/java-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions