GCP: サービスアカウントとOAuth Token の用途の違い
GCPの認証方法には、APIキー、OAuth、サービスアカウントの3種類ある
APIキー、OAuthクライアントID、サービスアカウントキーの違い:Google APIs - 無粋な日々に
3種の違いがまとまっている
重要な点は、OAuthはユーザに紐づく、APIキーは匿名、サービスアカウントは独自のサービスアカウントとして認識される
アプリからGCPを操作したい場合は、なるべくサービスアカウントが望ましい
OAuthでユーザに紐付けると、権限が大きくなりがち
ChatGPTにもまとめたもらった
ChatGPT.icon
Google Cloud Platform (GCP) provides various methods for authentication and authorization to ensure secure access to its resources and services. Two commonly used methods are Service Accounts and OAuth tokens, which serve different purposes and use cases. Here's an overview of the differences between them:
Service Accounts:
Purpose: Service accounts are used for server-to-server or application-to-service communication, allowing an application or a GCP resource to interact with other GCP services without the need for a user to be directly involved.
Scope: A service account is associated with a specific GCP project and has its own set of permissions and roles, which determine what actions the service account can perform.
Credentials: Service accounts use JSON Web Tokens (JWT) or PKCS12-encoded X.509 certificates as credentials for authentication. When using a JWT, a signed JSON Web Token is generated, which includes the service account email, private key, and required scopes.
Use cases: Service accounts are ideal for applications that run in the background, automated tasks, or server-to-server interactions where user consent is not required.
OAuth tokens:
Purpose: OAuth tokens are used for user-to-service communication, allowing a user to grant an application access to their data or services on their behalf without sharing their login credentials.
Scope: OAuth tokens are associated with a specific user and have a set of scopes that define the level of access the application has to the user's data or services.
Credentials: OAuth tokens use an access token and a refresh token for authentication. The access token is a short-lived token used to access the user's data, while the refresh token is a long-lived token used to obtain new access tokens when the current access token expires.
Use cases: OAuth tokens are ideal for applications where user consent is required, such as web or mobile apps that need to access user-specific data or services.
In summary, service accounts are used for non-interactive, server-to-server communication within a GCP project, while OAuth tokens are used for interactive, user-to-service communication where user consent is required. The choice between using a service account or OAuth token depends on the specific needs and use cases of the application or service being developed.