Google APIs
Jump to navigation
Jump to search
Access Control
- Authenication
- Principal: entity/identity that can be granted access to a resource. Two types
- User accounts are managed as Google Accounts and are for a developer, admin or other person interacting with Google Cloud
- Service accounts are managed by IAM and are non-human users. For applications needing access to App Engine or Compute Engine instances
- Applications
- Google Cloud APIs only accept requests from registered applications. Application credentials are required in the form of
- API keys
- OAuth 2.0 client credentials, or
- service account keys
Service Accounts
- special type of Google account intended to represent a non-human user that needs to authenticate and be authorized to access data in Google APIs.
- Your application assumes the identity of the service account to call Google APIs, so that the users aren't directly involved.
- What resources? What permissions? Where (local or in cloud)?
- Service accounts are both
- a resource, that can grant roles to other users to access or manage the service account, and
- an identity, which can grant a role to a service account and allow it to access a resource
- E.g.: app running on Compute Engine should only have access to create objects in Cloud Storage: grant it Storage Object Creator role
- Over time, service accounts can accumulate. Name them well. Disable them often. Names should be unique for best performance
Permissioning Use Cases
- as usual, grant minimum set of permissions per service account. (The default service accounts for Compute and App Engine are especially liberal/dangerous.)
- Attaching service accounts to resources:
- Permissions:
iam.serviceAccounts.actAs
- Permissions:
- Directly impersonating a service account:
- Permissions:
iam.serviceAccounts.getAccessToken, .signBlob, .signJwt, .implicitDelegation - Roles:
roles/iam.serviceAccountTokenCreator
- Permissions:
- Once permissions are granted, a user or service can impersonate the identity of a service account if
- the user gets short-term credentials for the service account using the
.getAccessToken()method - user get artifacts signed by Google-managed private key of the service account using the
iam.serviceAccounts.signBlobpermission and calling either thesignBlob()orsignJwtmethods - user may impersonate account without retrieving a credential. Only supported for
generateAccessToken()method
- Generating OpenID Connect (OIDC) ID tokens:
- Permissions:
iam.serviceAccounts.getOpenIdToken - Roles:
iam.serviceAccount.TokenCreator
- Permissions:
- Generating external private keys
- Permissions:
iam.serviceAccountKeys.create - Roles:
roles/editor, roles/iam.serviceAccountAdmin
- Permissions:
- [math]\displaystyle{ \implies }[/math]
gcloud auth activate-service-account
- [math]\displaystyle{ \implies }[/math]
Managing Service Account Keys
- Two types of service account keys:
- Google Cloud-managed keys: cannot be downloaded; kept for maximum of 2 weeks and rotated by Google
- User-managed keys: created, downloadable and managed by users. Cannot be used after deletion from the service account
- Use the IAM service account API to rotate service account keys:
serviceAccount.keys.create(), .delete(), .list()
SDK
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-332.0.0-linux-x86_64.tar.gz tar xvzf google-cloud-sdk-332.0.0-linux-x86_64.tar.gz ./google-cloud-sdk/install.sh # initialize ./google-cloud-sdk/bin/gcloud init # update gcloud components update
[File: google-sdk-comps.png]