<p>I have a GKE app that uses kubernetes serviceaccounts linked to google service accounts for api authorizations in-app.</p>
<p>Up until now, to test these locally, I had two versions of my images- one with and one without a test-keyfile.json copied into them for authorization. (The production images used the serviceaccount for authorization, the test environment would ignore the serviceaccounts and instead look for a keyfile which gets copied in during the image build.)</p>
<p>I was wondering if there was a way to merge the images into one, and have both prod/test use the Kubernetes serviceaccount for authorization. On production, use GKE's workload identity, and in testing, use a keyfile(s) linked with or injected into a Kubernetes serviceaccount.</p>
<p>Is such a thing possible? Is there a better method for emulating GKE workload identity on a local test environment?</p>

Ral
<p>I do not know a way of emulating workload identity on a non-Google Kubernetes cluster, but you could change your app to read the auth credentials from a volume/file or the metadata server, depending on the environment setting. See <a href="http://%20https://cloud.google.com/community/tutorials/gke-workload-id-clientserver" rel="nofollow noreferrer">this article</a> (and particularly the <a href="https://github.com/GoogleCloudPlatform/community/blob/master/tutorials/gke-workload-id-clientserver/client/main.go#L31" rel="nofollow noreferrer">code linked there</a>) for an example of how to authenticate using local credentials or Google SA depending on environmental variables.The article also shows how to use Pod overlays to keep the prod vs dev changes separate from the bulk of the configuration.</p>
