Search code examples
google-cloud-platformgoogle-apigoogle-cloud-iam

Identify Google API Key given client_id + client_secret


I work in an ecosystem with a million Google projects, services, and accounts. I have a Google Calendar API client_id and client_secret, and I'd like to upgrade the billing on that API account.

Is there a way for me to search for the API credentials and update the billing given just the client_id and client_secret? We're getting rate limited and would like to upgrade the billing to get these events shipped.


Solution

  • The Client ID contains the project number, which will be the first set of numbers up to the hyphen.

    Example:

    889131808289-j4ebh96l7ltnnblk14jc7v7r06kf03rl.apps.googleusercontent.com
    

    The project number is 889131808289.

    Use the command gcloud projects describe PROJECT_NUMBER to get details on the project.

    Example:

    gcloud projects describe 889131808289
    

    Output:

    createTime: '2018-10-13T04:30:17.002Z'
    labels:
      firebase: enabled
    lifecycleState: ACTIVE
    name: Development
    parent:
      id: '834075312893'
      type: folder
    projectId: development-304587
    projectNumber: '889131808289'
    

    Note: For security, the secrets above are not valid values.

    Once you have the Project ID, you can then match the project to the corresponding billing account by a manual process. You can also use the Google Cloud Console GUI to easily look up the billing account for a project link and link.

    When I have a large number of billing accounts and projects, I create a table manually listing all billing accounts and their projects. A simple Python program can parse the JSON and create a searchable table:

    gcloud billing accounts list --format=json
    
    gcloud billing projects list --billing-account=0101A4-9F1278-8A34FF --format=json
    

    The correct IAM roles to access this level of project and billing information are required on your IAM principal.

    For more information:

    gcloud projects describe

    gcloud billing projects

    Find a Cloud Billing Account ID

    Check if billing is enabled on a project