Skip to content

[PLUGIN-1945] Skip bucket creation if exist (copy/move action)#1596

Open
psainics wants to merge 6 commits intodata-integrations:developfrom
cloudsufi:gcs_action_skip_bucket_creation
Open

[PLUGIN-1945] Skip bucket creation if exist (copy/move action)#1596
psainics wants to merge 6 commits intodata-integrations:developfrom
cloudsufi:gcs_action_skip_bucket_creation

Conversation

@psainics
Copy link
Contributor

@psainics psainics commented Feb 18, 2026

Skip bucket creation if exist (copy/move action)

Jira : PLUGIN-1945

Description

if the user does not have storage.buckets.create the flow fails with 403 error, bucket creation should be skipped if the bucket already exists.


Code change

  • Modified StorageClient.java

@psainics psainics self-assigned this Feb 18, 2026
@psainics psainics added enhancement New feature or request build Trigger unit test build labels Feb 18, 2026
*/
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

- Add try-catch around bucket existence check to handle permission errors
- Log warning messages for 403 Forbidden and other unexpected errors
- Fallback to bucket creation when existence check fails
- Separate bucket check and creation into distinct try-catch blocks
} catch (StorageException e) {
// do not throw error if unable to access bucket for backward compatibility.
LOG.warn("Getting unexpected error code {}: {} when checking if bucket {} exists. Attempting to create bucket.",
e.getCode(), e.getMessage(), path.getBucket());
Copy link
Contributor

Choose a reason for hiding this comment

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

please also add the exception in the log.

LOG.warn(....., e);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Trigger unit test build enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments