For the complete documentation index, see llms.txt. This page is also available as Markdown.

Using gcloud

This guide covers the same integration as Manual, performed from the command line with the gcloud CLI instead of the Google Cloud console. The resulting service account, external user and IAM roles are identical.

The user performing the integration must have the following roles assigned:

  1. Organisation Administrator on your organisation

  2. Billing Account Administrator on your organisation/billing account

Why this is needed?

Organisation Administrator role is used to create the billing project and to assign the organisation-level IAM roles. Billing Account Administrator role is used to assign the Billing Account Viewer role.

Identities involved

Identity
Where it lives
Purpose

OneLens Reader SA, <service-account-id>@<billing-project-id>.iam.gserviceaccount.com

Created by you, in your billing project

Holds the read-only IAM roles OneLens uses. The address is unique to your environment, since it contains your own billing project ID.

onelens.finops@astuto.ai

Invited into your organisation as an external user

OneLens FinOps team, console login and manual validation

onelens-customer-sa@astuto-prod-mum.iam.gserviceaccount.com

OneLens, in our own environment

Our platform identity. You grant it Service Account Token Creator on your OneLens Reader SA so it can generate short-lived credentials to impersonate it. It receives no other role, and no service account keys are ever shared.

The external user email above is the default. If the OneLens team provided you with a different address during onboarding, use that address in place of onelens.finops@astuto.ai throughout this guide.

Values to collect before you start

Field
Example value

Organisation ID

111111111111

Billing Account ID

XXXXXX-XXXXXX-XXXXXX

Billing Export Project ID

onelens-billing-project

1

Set the environment variables

Before running any commands, set the shell variables below. Every command in this guide references them, so no manual substitution is required. Replace the placeholder values with your own, then run the block once in the shell you will use for the rest of the guide.

SA_EMAIL is derived from SA_ID and your billing project, so it is different for every customer. That derived address is the Service Account email you send to OneLens at the end of this guide.

2

Verify your variables and permissions

Run the check below before making any changes. It confirms that the variables are set and that your user holds the roles required to proceed. Nothing is modified.

Pre-flight check script
3

Create the Billing Project

Create the project that will hold your exported billing data, link it to your billing account, and enable the APIs it needs.

If you already have a project set up to host billing data through BigQuery, skip the project creation above and set BILLING_PROJECT_ID to that project.

4

Enable Detailed Usage Export

Create the dataset that will hold the detailed usage cost export.

The dataset location is set to US so that cost data can be exported retroactively from the start of the previous month during the initial setup. Table expiry is left unset, which keeps your cost history intact indefinitely.

https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables#data-availability

Enabling the export must be completed in the Google Cloud console, it cannot be performed via CLI. Print the billing export URL for your account, then open it in a browser:

  • On the BigQuery export tab, enable Detailed usage cost with the following options:

    • Under Projects, select the billing project (OneLens Billing Project).

    • Under Dataset, select the dataset created above (billing_export).

    • Click Save.

5

Enable CUD Export

This step must be completed in the Google Cloud console, it cannot be performed via CLI. Print the billing export URL for your account, then open it in a browser:

  • On the BigQuery export tab, enable Committed use discounts export with the following options:

    • Under Projects, select the billing project (OneLens Billing Project).

    • Under Linked dataset name, enter a new dataset name: cud_export.

    • Under Location type, select Multi-region.

    • Under Multi-region, select US (multiple regions in the United States).

    • Click Save.

The committed use discounts export writes a cud_subscriptions_export table holding the metadata of every committed use discount purchased in any project linked to this billing account: product, commitment amount, term and consumption model.

6

Create the Service Account

Create the service account in the billing project, then assign the Service Account Token Creator role, allowing the OneLens backend service account and the OneLens external user to impersonate it.

7

Grant Organisation-level roles

Run the following commands to grant all required organisation-level roles to both principals. Granting at the organisation covers every project in it, including projects created later. Each command is idempotent, existing bindings are never overwritten.

Grant roles to External User (onelens.finops@astuto.ai)

Grant roles to OneLens Service Account ($LOCAL_SA)

Create and grant the AI key inventory role (Service Account only)

OneLens reports on the API keys in your organisation, so that keys which can reach Vertex AI or Gemini without a restriction are visible alongside their cost. That needs one permission, apikeys.keys.list, which returns a key's name, display name, API restrictions and creation time.

There is a predefined role for this, API Keys Viewer, and this guide deliberately does not use it. It also contains apikeys.keys.getKeyString, which reads live key strings. The custom role below holds apikeys.keys.list and nothing else, so the key strings in your organisation stay unreachable.

This role is granted to the service account only, not to the external user.

8

Grant Billing project roles

Grant BigQuery access to the billing export project for both principals. The service account additionally needs BigQuery Read Session User for programmatic reads.

9

Grant Billing Account Viewer role

10

Verify access

After completing all steps above, run the following commands to confirm that roles have been applied correctly.

Check Organisation-level roles, External User

Check Organisation-level roles, OneLens Service Account

Check Billing account and Billing project roles

Role summary

The table below lists every IAM role granted, the resource level at which it is applied, the member it is assigned to, and its purpose.

Both = onelens.finops@astuto.ai and the OneLens Reader service account.

Role
Scope
Member
Purpose

roles/resourcemanager.organizationViewer

Organisation

Both

View the organisation, folder and project hierarchy

roles/cloudasset.viewer

Organisation

Both

View the asset inventory across the organisation

roles/browser

Organisation

Both

Browse the resource hierarchy without reading resource data

roles/viewer

Organisation

User only

Read-only console access for FinOps analysis

Service viewer roles*

Organisation

SA only

Read metadata for Compute, GKE, Cloud SQL and other services

roles/bigquery.resourceViewer

Organisation

Both

View BigQuery datasets, tables and jobs

roles/bigquery.metadataViewer

Organisation

Both

Read dataset and table metadata

roles/bigquery.jobUser

Organisation

Both

Run BigQuery jobs and queries

roles/billing.viewer

Billing account

Both

Read billing account costs, invoices and spend data

roles/bigquery.dataViewer

Billing project

Both

Read the data inside the billing export tables

roles/bigquery.readSessionUser

Billing project

SA only

Create read sessions for programmatic data reads

roles/iam.serviceAccountTokenCreator

Your OneLens Reader SA

OneLens backend SA and external user

Impersonate the OneLens Reader service account

onelensAiKeyInventory (custom)

Organisation

SA only

List API key metadata for AI cost reporting

*Service viewer roles are roles/aiplatform.viewer, roles/cloudfunctions.viewer, roles/cloudsql.viewer, roles/compute.viewer, roles/container.viewer, roles/dataflow.viewer, roles/dataproc.viewer, roles/file.viewer, roles/monitoring.viewer, roles/networkmanagement.viewer, roles/recommender.viewer, roles/redis.viewer and roles/serviceusage.serviceUsageViewer.

Revoking access (if required)

Access is fully reversible. The commands below remove every binding this guide created and delete the service account.

Remove Organisation-level access, External User
Remove Organisation-level access, OneLens Service Account
Remove Billing account and Billing project access, and delete the Service Account

Last updated