Nooonapewno
Nooonapewno

Reputation: 23

How to set Basic Auth for Google Cloud Scheduler

I want to schedule an HTTP request with the usage of the Cloud scheduler. My service deployed on k8s is using basic auth. How to add such kind of authorization to the job? Does it require to specify this authorization inside the service account? I yes- then how? Should I use the OIDC token as the OAuth seems to be not a proper one? Lots of gratefulness for any answer from you. Wish you a good day anyway :)

Upvotes: 2

Views: 1801

Answers (2)

johan.gant
johan.gant

Reputation: 33

I found myself getting confused between curl and the format that gcloud CLI requires; there's a tiny difference in the header that's easy to miss: the colon (:) after the 'Authorization' keyword needs be an equals character (=) for glcoud headers. For example:

  • curl: curl -H "Authorization: Basic base-64-encoded-string"
  • gcloud CLI: gcloud scheduler jobs create http AJobIdYouProvide --project="your-project-id" --schedule="* * * * *" --description="Job description" --time-zone="Europe/London" --headers="Authorization=Basic base-64-econded-string" --http-method=GET --uri="https://example.com

It's in the documentation (https://cloud.google.com/sdk/gcloud/reference/scheduler/jobs/create/http#--headers) but can be easily missed and without it your scheduled job will only report back as failed with an Unauthorized response code.

Upvotes: 0

guillaume blaquiere
guillaume blaquiere

Reputation: 75715

Basic Auth is simply a login:password base64 encoded in the header of the request. But, Cloud Scheduler doesn't propose to fill it on the UI.

However, if you use the gcloud CLI, you can do this

gcloud scheduler jobs create http --headers=Authorization="Basic <login:password base64 encoded> ...

You can have a look to the other parameters. You have retry policies which are also super great and not available on the UI.

Upvotes: 5

Related Questions