Skip to content
Back to skills

Cost Allocation Audit

ASecurity

Find out who owns your cloud spend from the billing export alone, and draft the rules that allocate it. Use this whenever someone says their tagging or labeling is a mess, asks what share of the AWS, GCP or Azure bill is tagged, needs showback or chargeback per team, product or cost center, has a big "untagged" or "unallocated" bucket, wants to map accounts, projects or subscriptions to owners, or is drafting allocation rules (cost categories, virtual tags) and splits for shared clusters, net...

  • 5 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added December 1, 2026
ai-agentspythongobashsqlnodekubernetesawsgcpazuredatabase

Security analysis

A100/100

Pro scans all 11 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add costory-io/finops-skills --skill cost-allocation-audit --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cost Allocation Audit?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cost Allocation Audit
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/costory-io-cost-allocation-audit/badge)](https://www.skillsdirectory.com/skills/costory-io-cost-allocation-audit)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cost-allocation-audit
description: Find out who owns your cloud spend from the billing export alone, and draft the rules that allocate it. Use this whenever someone says their tagging or labeling is a mess, asks what share of the AWS, GCP or Azure bill is tagged, needs showback or chargeback per team, product or cost center, has a big "untagged" or "unallocated" bucket, wants to map accounts, projects or subscriptions to owners, or is drafting allocation rules (cost categories, virtual tags) and splits for shared clusters, networking or platform costs. Works on AWS CUR 2.0 in Athena, the GCP billing export in BigQuery, and FOCUS exports including Azure. Also use it when they paste tag coverage numbers, a list of tag values or a spend-by-account table and ask what it means, even if they never say "allocation".
---

# Cost allocation audit

The bill says what each service cost, not which team caused it. Tags fix part of that, account and project structure fixes most of the rest, and a slice of every bill can never carry a tag and should not count against anyone. Five checks, all on the billing export:

| # | Check | What it finds | How |
|---|-------|---------------|-----|
| 1 | What the bill is made of | Allocatable spend vs charges nobody can tag (the real denominator) | `sql/<source>/01-coverage.sql`, `charge_class` rows |
| 2 | Coverage by spend, per key | Which tag keys actually carry the money | same query, `tag_key` rows |
| 3 | Cheap wins and value drift | Keys close to full coverage, `payments` vs `Payments` vs `payment` | `scripts/allocate.py` on the `02-extract.sql` result |
| 4 | Ownership from structure | Account, project, folder, subscription, resource group names turned into ordered rules | same, then `--rules` |
| 5 | Shared costs | Shared clusters, networking, platform accounts to split later by usage | same |

Output: coverage %, top unallocated spend, a draft rule list (YAML, first match wins) and the residual unallocated amount after the rules.

Everything here is read-only. Activating tags, enabling exports, backfills, tag inheritance and retagging change billing data or resources: propose them, let the user decide and do them.

| Source | Engine | Files | Cost basis |
|--------|--------|-------|------------|
| AWS CUR 2.0 (Data Exports) | Athena | `sql/aws-cur2/` | Amortized, same formula as the AWS cost and usage dashboard `amortized_cost` |
| GCP standard or detailed billing export | BigQuery | `sql/gcp/` | `cost` before credits, credits reported separately |
| AWS FOCUS 1.2 export | Athena | `sql/focus-aws/` | `EffectiveCost` |
| Azure FOCUS export, or any FOCUS CSV | none (CSV) | `scripts/allocate.py --focus` | `EffectiveCost` |

The GCP FOCUS export is not used: it is in preview, has no `Tags` column (labels sit in `x_Labels`, `x_ProjectLabels`, `x_Tags`) and its `ChargeCategory` has no `Purchase` or `Credit`. The native export is richer for this job.

## 1. Set up

Ask for, or discover:
- **Period**: the last full month. The current month is incomplete, and AWS tag activation, Azure tag inheritance and GCP labels only show up from the day they took effect.
- **Table**: CUR 2.0 or FOCUS table in Athena; `gcp_billing_export_v1_<BILLING_ACCOUNT_ID>` (standard) or `gcp_billing_export_resource_v1_<...>` (detailed) in BigQuery; the FOCUS CSV files of an Azure Cost Management export.
- **Owner keys**: which tag keys mean "owner" (team, owner, squad, cost-center...). Do not guess spellings: run check 1 first and read the keys that exist.
- **Structure**: how accounts, projects, folders, subscriptions and resource groups are named, and which ones are known to be shared.
- **Access**: query rights on the billing table (Athena plus read on the export's S3 bucket; BigQuery data viewer on the billing dataset plus job user). The queries scan one month of the export: on Athena they filter on the Data Exports partition `billing_period` (`YYYY-MM`) to bound the scan (delete that line if your table has no such column), and on large exports set a bytes or data-scanned limit.

Before reading any number, know these provider behaviors. They explain most "nobody tags anything" surprises:
- **AWS tags must be activated.** A tag key only appears in CUR (`resource_tags` and `tags` columns) after someone activates it as a cost allocation tag in Billing and Cost Management. Only the management account (or a standalone account) can do that. New keys take up to 24 hours to appear on the page and up to 24 hours more to activate. A key missing from check 2 may be on thousands of resources and simply inactive: check the Cost allocation tags page before blaming engineers.
- **AWS activation applies going forward.** Months before activation stay untagged unless the management account requests a backfill: up to 12 months back, from the first day of a month, one request per 24 hours. A backfill replays the activation status, so values only appear for periods when the tag was actually on the resource. It can also remove a key from history if that key is now inactive.
- **AWS key spelling.** In `resource_tags`, keys are normalized (lowercase with underscores; user-defined `team` becomes `user_team`, as in `resource_tags_user_creator`), and keys that collide after normalization keep only one value. The `tags` column (CUR 2.0 only) is not normalized and prefixes each source: `resourceTags/`, `accountTag/`, `costCategory/`, `userAttribute/`, `iamPrincipal/`. The SQL reads `resource_tags`; if the export only selected `tags`, swap the column and use the prefixed keys (`resourceTags/team`, `accountTag/team`), as documented on the CUR 2.0 Tags column page.
- **AWS account tags.** Tags on accounts in AWS Organizations, once activated as cost allocation tags, apply to all usage of that account, including refunds, credits and charges that cannot be tagged at resource level. One account tag often beats a thousand resource tags.
- **GCP labels are not retroactive**: a label covers usage from the day it was applied. Three sources exist and are reported separately: resource `labels`, `project.labels` (covers every SKU in the project) and `tags` (resource manager tags, can be inherited).
- **Azure tag inheritance** copies subscription and resource group tags (and billing profile, invoice section tags on MCA) onto usage records, not onto resources. It applies to the current month, 8 to 24 hours after enabling. Purchases and resources that do not emit usage at subscription scope do not get them. Some Azure resource types never pass tags to cost data: the "Tag in cost report" column of the tag support page lists them.

## 2. Run

```bash
scripts/render_sql.sh aws-cur2 01 cur_db.cur2 2026-10 > c1.sql      # paste into the Athena console
scripts/render_sql.sh aws-cur2 02 cur_db.cur2 2026-10 user_team,user_owner > c2.sql
# run c2.sql, download the result as extract.csv, then:
python3 scripts/allocate.py extract.csv --keys user_team,user_owner
python3 scripts/allocate.py extract.csv --keys user_team,user_owner --rules rules.yaml

scripts/render_sql.sh gcp 01 prj.billing.gcp_billing_export_resource_v1_XXXX 2026-10
scripts/render_sql.sh gcp 02 prj.billing.gcp_billing_export_resource_v1_XXXX 2026-10 label:team,project_label:team

python3 scripts/allocate.py focus-2026-10.csv --focus --keys team,owner --rules rules.yaml   # Azure FOCUS export
```

`render_sql.sh` only prints SQL. `allocate.py` is stdlib Python and reads a local CSV; it runs nothing against any account. If the user prefers, run the SQL yourself in their console session and read the rows; the interpretation rules below are the same.

## 3. Read the results

### Check 1: the denominator

Coverage = tagged allocatable spend / allocatable spend. These charges are excluded from the denominator because no resource carries them, so no tagging effort can ever cover them:

| Charge | AWS CUR 2.0 `line_item_line_item_type` | GCP export | FOCUS | Why excluded | Where it goes in showback |
|--------|------|-----|-------|--------------|---------------------------|
| Tax | `Tax` | `cost_type = 'tax'` | `ChargeCategory = 'Tax'` | Levied on the invoice, not a resource | Pro rata to allocated spend |
| Credits, refunds | `Credit`, `Refund` | `credits[]` (reported as `excluded:credits`) | `Credit`; refunds are negative rows inside `Usage`/`Purchase` | Contract or support gesture, not usage | The account's owner if account-specific, else pro rata |
| Discounts | `Discount`, `BundledDiscount` | inside `credits[]` | already inside `EffectiveCost` | Contract-level (EDP, private pricing) | Pro rata |
| Commitment fees, unused part | `SavingsPlanRecurringFee`, `RIFee` (only the unused amount survives in the amortized formula); `SavingsPlanUpfrontFee`, `SavingsPlanNegation`, `Fee` with an RI ARN count 0 | fee rows: SKU starting `Commitment v1:` (resource-based), or a row with `subscription.instance_id`, the `Default` consumption model and no CUD credit (spend-based, new model, whose fee SKU names vary; the `FEE_UTILIZATION_OFFSET` credit nets out the used part) | `Purchase` (`EffectiveCost` is 0 for commitments covering future charges), `CommitmentDiscountStatus = 'Unused'` | The used part is already amortized onto the tagged usage lines (`SavingsPlanCoveredUsage`, `DiscountedUsage`). The unused part is a purchasing decision | Whoever buys commitments (FinOps or platform) |
| Support | product code containing `Support` (verify) | rows with no project: support belongs to the billing account | `ServiceName` containing `Support` (verify) | Billing-account level | Pro rata |
| Marketplace | `bill_billing_entity = 'AWS Marketplace'` | `seller_name` set | `PublisherName <> ProviderName` (heuristic, verify) | A subscription billed to an account, rarely resource-tagged | Account rule (check 4) |
| Corrections | | `cost_type` `adjustment`, `rounding_error` | `ChargeClass = 'Correction'` | Belongs to a previous period | Ignore for this month's coverage |

Rules:
- Never divide by the invoice total. It punishes the teams for tax and support. Never divide by line or resource count either: it rewards tagging a thousand cheap things while the three biggest databases stay untagged.
- Use amortized cost. On unblended (billed) cost, instances covered by a Savings Plan or RI look nearly free on the tagged side while the commitment fee sits untagged, so coverage looks worse than it is and moves when commitments are bought.
- Excluded does not mean ignored: show the excluded amounts next to the coverage %, with the "where it goes" column, so the showback still adds up to the invoice.
- Data transfer is NOT excluded by default. Much of it is billed against a resource and inherits its tags (verify on your data: group untagged spend by `line_item_usage_type` containing `DataTransfer`). If a large untagged share remains, route it to a shared networking bucket in check 5 rather than excluding it.
- With AWS split cost allocation data in the export, the parent instance line keeps its full cost and container rows are added. The parent line keeps its full cost and the split rows carry their share in `split_line_item_split_cost` / `split_line_item_unused_cost`, so the SQL sums `line_item_*` cost columns only and does not double count. Per-pod ownership needs the `split_line_item_*` columns, which this audit does not read.

### Check 2: coverage by spend, per key

- Read `pct` (share of allocatable spend) next to `pct_of_lines`. A big gap is the finding: "92% of line items carry `team`, but only 41% of spend" means the expensive things (large databases, data platforms, shared clusters, old accounts) are the untagged ones.
- `pct_of_lines` counts billing line items, not resources. Do not present it as "92% of resources are tagged".
- Several keys can mean the same thing (`team`, `Team`, `owner`, `squad`). Judge them together: pass all of them to `--keys`; the helper prints the "any of" coverage.
- Ignore system keys for ownership (`aws:createdBy`, `goog-k8s-*`, `k8s-*`, `aws:eks:*`) unless you are mapping namespaces to teams in check 5.
- Key absent or tiny on AWS: check activation first (section 1). Activating, and a backfill of up to 12 months, are actions for the management account owner: propose them with the reason, do not perform them.

### Check 3: cheap wins and value drift

- Cheap wins: take the best owner key and list its untagged allocatable spend by account (helper section 4). The remainder usually sits in a handful of accounts or services; tagging those, or covering them with one account rule, moves coverage more than any company-wide tagging campaign.
- Value drift: the helper groups values that differ only by case, separators or a trailing `s` and shows spend per variant. Put the mapping in `aliases:` so this month's showback is right, and propose the fix at the source (tag policies, IaC default tags) so it stops recurring.
- Treat placeholder values (`unknown`, `tbd`, `default`, `none`, `n/a`) and personal names as untagged.
- Retagging fixes the future only. On AWS, a backfill re-applies activation status, it does not invent values for periods when the tag was not on the resource. Say this when someone expects last quarter to be fixed.

### Check 4: ownership from structure

- Most untagged spend sits in accounts, projects or subscriptions with an obvious owner. Draft rules from account names (`payments-prod` -> payments), GCP folder paths (`account_path`), Azure resource groups, AWS account tags.
- Order matters, first match wins. Default order: shared-bucket rules for known shared accounts, then explicit resource tags, then structure rules from most specific to least specific. Shared rules go first because shared clusters often carry a team tag on some resources, and because a name rule could also match them (`shared-gke-pay` must not land on payments, even when tagged `Payments`). If a dedicated single-team account carries stray tags from other teams, move that account's rule above the tag rule and say why in a comment.
- Prefer stable ids over names when you can (account ids, project ids); names get renamed.
- Do not invent owners. `legacy-app-1` or `sandbox-jdoe` with no other signal stays in the residual and becomes a question for the user.
- Check the per-rule table: a rule matching nothing is dead or misspelled; one rule matching most of the bill is probably too broad.
- Residual = allocatable spend that no rule matches. Report it in currency and as % of allocatable, with its top lines.

### Check 5: shared costs

- Typical shared spend: Kubernetes clusters (EKS, GKE, AKS), network hubs (transit gateways, NAT, interconnects, shared VPC host projects), observability, security, CI, data platform accounts used by many teams.
- Route them to `shared:` buckets, not to a team and not to the residual. Splitting them is a separate step with a usage driver: namespaces or pods for clusters, bytes for networking, an agreed key with finance otherwise.
- AWS split cost allocation data (opt-in in Cost Management preferences, plus the export setting) splits EKS, ECS and some networking costs; EKS rows get `aws:eks:namespace` and similar tags, on new records.
- GKE cost allocation adds `k8s-namespace`, `k8s-label/<key>` and similar labels, forward only, no backfill. Idle capacity appears as `kube:unallocated` and node overhead as `kube:system-overhead`: those are the shared cluster's own cost, not a team's.

## 4. The rules file

`references/rules.example.yaml` shows the format. Conditions are case-insensitive regexes searched in the field (anchor with `^`/`$`), all conditions of a rule must match, and each rule sets `team:` (a name, or `'{tag:<key>}'` to take the tag value, skipped when the row lacks that tag) or `shared:`. Fields: `account_id`, `account_name`, `account_path`, `resource_group`, `service`, `tag:<key>` with the key spelled as in the extract (`tag:user_team`, `tag:label:team`). Write regexes in single quotes. No catch-all rule: the residual must stay visible. The helper parses this restricted YAML subset only.

The same ordered list ports to AWS Cost Categories, GCP or Azure allocation features, or a SQL `CASE` in a showback view. Writing them there is a change: propose it, do not apply it.

## 5. Report

```
# Cost allocation audit: <provider(s)>, <month>

## Summary
<coverage by spend of the best owner key, allocatable total, residual after draft rules, the 1-3 actions that move it most>

## What the bill is made of (measured)
| Class | Amount | Share | Handling in showback |

## Coverage by spend (measured)
| Key | Coverage by spend | Share of line items | Note |

## Top unallocated spend (measured)
| Account / project | Name / path | Untagged amount | Top service | Proposed owner or question |

## Draft rules (estimate until owners confirm)
<YAML>
| Owner | Amount | Share of allocatable |
Residual unallocated: <amount> (<%>)

## Before you act
<activation and backfill to request, aliases to fix at source, owners to confirm, shared buckets to split, what the export could not show>
```

Rules for the numbers:
- Label every figure. Measured: coverage, class totals, untagged amounts, straight from the export for the named month. Estimate: anything that depends on draft rules or unconfirmed owners. Forecast: any projection of future coverage. Never call a draft allocation "the" showback.
- Always state the cost basis (amortized or billed) and the month.
- If a check could not run (key inactive, missing permission, export without tags), say which and what would enable it, rather than skipping it silently.

## When you cannot run it yourself

If you have no access to the user's environment, paste the complete, filled-in SQL or command in your answer so the user can run it as is, with their project, period and table names already substituted where known. Do not point the user to this skill's file paths (`sql/...`, `scripts/...`): they usually cannot see them. Then interpret the output they paste back with the rules above.

## Going further

This audit is a snapshot and drifts within weeks: accounts get created and renamed, a team splits in two, a cluster becomes shared, a new key spelling appears. Keeping showback right means maintaining these rules over time, applying them retroactively to past months when ownership changes (a tag backfill only replays activation, not ownership), and running the same rules across cloud, data platform and AI provider bills, most of which have no tags at all. You can build that on the billing exports plus a rules file like this one; tools such as Costory (costory.io), whose team wrote this skill, do it as a product.

Files in this skill

  • SKILL.md18.2 KB
  • references/rules.example.yaml2.1 KB
  • references/sources.md9.7 KB
  • scripts/allocate.py14.5 KB
  • scripts/render_sql.sh1.7 KB
  • sql/aws-cur2/01-coverage.sql3.2 KB
  • sql/aws-cur2/02-extract.sql2.7 KB
  • sql/focus-aws/01-coverage.sql2.2 KB
  • sql/focus-aws/02-extract.sql1.6 KB
  • sql/gcp/01-coverage.sql3.3 KB
  • sql/gcp/02-extract.sql3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.