We've been using the Google Directory API to get the profile of our users, on an internal app. When we authenticate, we've been using a json keyfile for a service and the google-auth-library
JWT
class. The service account has Domain Wide Delegation to use this endpoint. Thus, the access token needs to have it's subject
set to a workspace admin.
const jwt = new JWT({
email: key.client_email,
key: key.private_key,
subject: '<admin-email-address>',
scopes: 'https://www.googleapis.com/auth/admin.directory.user.readonly',
})
const accessToken = await jwt.getAccessToken()
Our organisation is trying to shift away from using keyfiles for service accounts, and move towards GKE Workload Identity. We can authenticate using application default credentials, setting the subject in clientOptions
.
const auth = new GoogleAuth({
scopes: 'https://www.googleapis.com/auth/admin.directory.user.readonly',
clientOptions: {
subject: '<admin-email-address>'
}
})
const accessToken = await auth.getAccessToken()
However, the access token created doesn't have the subject set. This means the token can't access the Directory API.
Is there a way to create a token that could, using Workload Identity?