メモ代わりの小ネタ
とある事情でGoogle CloudでAPIキーはわかるけどその持ち主のプロジェクトが不明という状況が発生して困っていたところ、Twitterにて以下のコマンドでわかると教えてもらいました。
gcloud alpha services api-keys lookup <API_KEY>
Google Cloud CLIをまだインストールしていない人はこちらを参考にインストールしてください。
Install the gcloud CLI | Google Cloud
実行したユーザがアクセス権のあるプロジェクトであれば以下のようなレスポンスが返ってきます。
name: projects/<プロジェクト番号>/locations/global/keys/xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx parent: projects/<プロジェクト番号>/locations/global
権限がないとこんな感じになりますがプロジェクト番号はわかります。
ERROR: (gcloud.alpha.services.api-keys.lookup) PERMISSION_DENIED: Permission 'apikeys.keys.lookup' denied on resource project.
- '@type': type.googleapis.com/google.rpc.PreconditionFailure
violations:
- subject: ?error_code=110002&service=cloudresourcemanager.googleapis.com&permission=serviceusage.apiKeys.getProjectForKey&resource=projects/<プロジェクト番号>
type: googleapis.com
- '@type': type.googleapis.com/google.rpc.ErrorInfo
domain: apikeys.googleapis.com
metadata:
permission: serviceusage.apiKeys.getProjectForKey
resource: projects/<プロジェクト番号>
service: cloudresourcemanager.googleapis.com
reason: AUTH_PERMISSION_DENIED