I'm working on integrating Cloud Tasks into my application, and would like to create tasks for my own endpoint that requires authorization. However, I'm not sure how to go about it.
According to the documentation for the Go Cloud Tasks library I'm using:
type HttpRequest_OidcToken struct {
// If specified, an
// [OIDC](https://developers.google.com/identity/protocols/OpenIDConnect)
// token will be generated and attached as an `Authorization` header in the
// HTTP request.
//
// This type of authorization can be used for many scenarios, including
// calling Cloud Run, or endpoints where you intend to validate the token
// yourself.
OidcToken *OidcToken `protobuf:"bytes,6,opt,name=oidc_token,json=oidcToken,proto3,oneof"`
}
However, based on my understanding of OIDC, it's used for authentication, not authorization, and thus is not what I need.
So, my question is, how should I go about protecting my endpoint? I'd like only the service account used by the task queue to be able to access it. Is verifying the ID token and making sure the email is that of my service account sufficient for this purpose? Thanks!
This should be enough as it is the recommended practice in GCP's documentation:
For additional security, you can consider using IAM conditions in your endpoint.
On the other hand, if you are providing your own endpoint, you may refer to this documentation - Providing your own HTTP Target task handlers