Search code examples
javaspring-bootgoogle-cloud-schedulerspring-cloud-gcp

What all the PERMISSION required to call GCP Cloud Scheduler Create Job


I need to create a Job from the Java Code(Spring Boot)

I am using java client library for the Cloud Scheduler, since we dont have Spring boot Integration.

CloudSchedulerClient cloudSchedulerClient = CloudSchedulerClient.create(cloudSchedulerSettings);
JobName name = JobName.of("projectname", "location", "Test");
System.out.println(name.getJob());

above code gives me the job, which i have created using GCP console.

But i also needs to create Job from Code, did it as below

Job build = Job.newBuilder().setName("Chiru").setSchedule("0 1 * * 0")
                .setDescription("From Code")
                .setHttpTarget(HttpTarget.newBuilder()
                        .setUri("http://google.com").build()).build();
        LocationName parent = LocationName.of("project", "location");
        Job response = cloudSchedulerClient.createJob(parent.toString(), build);

This gives me error saying permission denied on the resource

Exception in thread "main" com.google.api.gax.rpc.PermissionDeniedException: io.grpc.StatusRuntimeException: PERMISSION_DENIED: Permission denied on resource project <projectname>.

I am using Service account for the Authentication

ServiceAccountCredentials credentials = ServiceAccountCredentials.fromStream(new FileInputStream("key.json"));
        CloudSchedulerSettings cloudSchedulerSettings =
                CloudSchedulerSettings.newBuilder()
                        .setCredentialsProvider(FixedCredentialsProvider.create(credentials))
                        .build();

Here is the SA account ROLES

Permissions on SA


Solution

  • I contacted GCP Support on this issue. Later we found its because of the wrong project-id i was using