Difference between revisions of "Google APIs"

From Bitnami MediaWiki
Jump to navigation Jump to search
Line 55: Line 55:
 
  gcloud components update
 
  gcloud components update
  
−
[File: google-sdk-comps.png]
+
[[File: google-sdk-comps.png]]

Revision as of 17:49, 16 March 2021

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
  1. API keys
  2. OAuth 2.0 client credentials, or
  3. 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
  • Directly impersonating a service account:
    • Permissions: iam.serviceAccounts.getAccessToken, .signBlob, .signJwt, .implicitDelegation
    • Roles: roles/iam.serviceAccountTokenCreator
  • Once permissions are granted, a user or service can impersonate the identity of a service account if
  1. the user gets short-term credentials for the service account using the .getAccessToken() method
  2. user get artifacts signed by Google-managed private key of the service account using the iam.serviceAccounts.signBlob permission and calling either the signBlob() or signJwt methods
  3. 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
  • Generating external private keys
    • Permissions: iam.serviceAccountKeys.create
    • Roles: roles/editor, roles/iam.serviceAccountAdmin
[math]\displaystyle{ \implies }[/math] gcloud auth activate-service-account

Managing Service Account Keys

  • Two types of service account keys:
  1. Google Cloud-managed keys: cannot be downloaded; kept for maximum of 2 weeks and rotated by Google
  2. 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

Google-sdk-comps.png