We use Cloud Endpoints in the Google Cloud for service-to-service authentication in applications deployed to the Google Kubernetes Engine.
We have an Extensible Service Proxy sidecar in front of all of our applications, with a Swagger (OpenApi) 2.0 YAML descriptor specifying which endpoints can be accessed by which other services.
Every service has its own Service Account, and it's straightforward to create the necessary security definition:
securityDefinitions:
service-foo:
authorizationUrl: ""
flow: "implicit"
type: "oauth2"
x-google-issuer: "[email protected]"
x-google-jwks_uri: "https://www.googleapis.com/robot/v1/metadata/x509/service-foo-my-gcloud-project.iam.gserviceaccount.com"
This works well for service-to-service communication in GKE.
But during development, sometimes we want to send requests to these service from our development machines. And with this setup, we need to have access to a raw Service Account key to generate the JWT token, which is inconvenient, and also raises security concerns.
It would be very nice if we could create a security definition with which a developer could access a service using not a Service Account, but their own Google Account.
I tried to create a JWT token using the gcloud
CLI with the following command:
$ gcloud auth print-identity-token
This prints a valid JWT token, where the Audience is 32555940559.apps.googleusercontent.com
, and the token has an email
field with my own Google account email address.
I tried creating a security definition for this, I tried the following.
my-dev-account:
authorizationUrl: ""
flow: "implicit"
type: "oauth2"
x-google-issuer: "https://accounts.google.com"
x-google-jwks_uri: "https://www.googleapis.com/oauth2/v3/certs"
x-google-audiences: "32555940559.apps.googleusercontent.com"
And this technically works, the ESP allows the request go through with the JWT token produced by gcloud auth print-identity-token
. But the problem is that this doesn't limit access to my own account in any way, because 32555940559.apps.googleusercontent.com
is the Client ID of the GCloud SDK itself, so anyone with a Google account would have access.
Is it maybe possible to specify in the security definition that the email
field should be limited to a certain value?
Or am I completely on the wrong track, but is there another way to allow ESP access for a developer Google account?
gcloud
), distribute it, have your developers authenticate using it and have it generate suitably-scoped JWTs? There's alsooauth2l
but I think that doesn't give you what you want ootb. – DazWilkin