Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/io/cdap/plugin/gcp/gcs/StorageClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public void mapMetaDataForAllBlobs(String path, Consumer<Map<String, String>> fu
*/
public void createBucketIfNotExists(GCSPath path, @Nullable String location, @Nullable CryptoKeyName cmekKeyName) {
try {
if (storage.get(path.getBucket()) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This adds an additional permission storage.buckets.get, do we do storage.get anywhere else?

I wonder if we should do storage.list instead which we do already later on?

Copy link
Contributor

Choose a reason for hiding this comment

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

or may be we could just ignore 403 with storage.get and move forward for backward compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

storage.buckets.get permission is required for this plugin to work, we use it to traverse the bucket in function pairTraverse.

Copy link
Contributor

Choose a reason for hiding this comment

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

pairTraverse function might be only getting called in GCS Move / Copy plugin but StorageClient is used in all other GCS plugins as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As of now createBucketIfNotExists is only being used in gcs copy/move action.

From gcs docs it looks like list permission is for listing all buckets in a project, much slower than get, and less secure.

Let me know what do you think.

Copy link
Contributor

@itsankit-google itsankit-google Feb 18, 2026

Choose a reason for hiding this comment

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

As I mentioned in the reply, we can use storage.get but just ignore 403 with storage.get and move forward for backward compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

// Skip bucket creation if bucket already exists.
try {
  if (storage.get(path.getBucket()) != null) {
    LOG.info("Bucket {} already exists, skipping creation.", path.getBucket());
    return;
  }
} catch (StorageException e) {
  int errorCode = e.getCode();
  if (errorCode == 403) {
    LOG.warn(
        "Getting 403 Forbidden: {} You may not have permission to access bucket {}. Attempting to create bucket.",
        e.getMessage(), path.getUri());
  } else {
    LOG.warn("Getting unexpected error code {}: {} when checking if bucket {} exists. Attempting to create bucket.",
        errorCode, e.getMessage(), path.getBucket());
  }
}
// Fallback to bucket creations when get returns null or throws exception.
// ... Old Flow

LOG.info("Bucket {} already exists, skipping creation.", path.getBucket());
return;
}
GCPUtils.createBucket(storage, path.getBucket(), location, cmekKeyName);
LOG.info("Bucket {} has been created successfully", path.getBucket());
} catch (StorageException e) {
Expand Down
Loading