Skip to content

google-cloud-storage: Cannot create signed url with ImpersonatedCredentials #5043

@salrashid123

Description

@salrashid123

a Storage client using ImpersonatedCredentials does not support creation of SignedURL.

In the sample below thatuses impersonated credentials,

ServiceAccountCredentials sourceCredentials = ServiceAccountCredentials
			     .fromStream(new FileInputStream("/path/to/svc.json"));
sourceCredentials = (ServiceAccountCredentials) sourceCredentials
		 .createScoped(Arrays.asList("https://www.googleapis.com/auth/iam"));
	
 ImpersonatedCredentials targetCredentials = 
                       ImpersonatedCredentials.create(sourceCredentials,
			     "impersonated-account@projectB.iam.gserviceaccount.com", null,
			     Arrays.asList("https://www.googleapis.com/auth/devstorage.read_only"), 300);

Storage storage_service = StorageOptions.newBuilder()
    .setCredentials(targetCredentials)
    .build().getService();

String BUCKET_NAME1= "fabled-ray-104117";
String BLOB_NAME1 = "signed_url_file.txt";

BlobInfo BLOB_INFO1 = BlobInfo.newBuilder(BUCKET_NAME1, BLOB_NAME1).build();

URL url =
	storage_service.signUrl(
            BLOB_INFO1,
            14,
            TimeUnit.MINUTES,
	    Storage.SignUrlOption.httpMethod(HttpMethod.GET), 
	    Storage.SignUrlOption.withV4Signature());
System.out.println(url);

the error is "Signing key was not provided and could not be derived"


one solution is to just implement ServiceAccountSigner in ImpersonatedCredentials

public class ImpersonatedCredentials extends GoogleCredentials implements ServiceAccountSigner

Here is a working sample that successfully impersonates and produces a signed url:

https://gist.github.com/salrashid123/394f1dfee4d7b16049acc6cca772dd43
(see line 145)

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions