Difference between revisions of "Google APIs"
Jump to navigation
Jump to search
(→SDK) |
|||
| (3 intermediate revisions by the same user not shown) | |||
| Line 34: | Line 34: | ||
* Generating OpenID Connect (OIDC) ID tokens: | * Generating OpenID Connect (OIDC) ID tokens: | ||
** Permissions: <code>iam.serviceAccounts.getOpenIdToken</code> | ** Permissions: <code>iam.serviceAccounts.getOpenIdToken</code> | ||
| − | ** Roles: <code>iam.serviceAccount.TokenCreator | + | ** Roles: <code>iam.serviceAccount.TokenCreator</code> |
* Generating external private keys | * Generating external private keys | ||
** Permissions: <code>iam.serviceAccountKeys.create</code> | ** Permissions: <code>iam.serviceAccountKeys.create</code> | ||
| Line 55: | Line 55: | ||
gcloud components update | gcloud components update | ||
| − | [[google-sdk-comps.png]] | + | [[File: google-sdk-comps.png]] |
| + | |||
| + | *You should get a "success" message after running the init command. | ||
| + | * gcloud command-line tool[https://cloud.google.com/sdk/gcloud guide] | ||
| + | * Accessing Services[https://cloud.google.com/sdk/cloudplatform with the gcloud CLI] | ||
| + | * Google's API [https://developers.google.com/api-client-library Client Libraries] | ||
Latest revision as of 17:57, 16 March 2021
Access Control[edit]
- 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[edit]
- 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[edit]
- 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[edit]
- 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[edit]
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
- You should get a "success" message after running the init command.
- gcloud command-line toolguide
- Accessing Serviceswith the gcloud CLI
- Google's API Client Libraries
