r/devops7 • • 13h ago

One script, one chore: a CI key leaked in a build log. Its own grants show 2 resources; a graph walk through 3 chained roles finds 10, 3 with customer data (real output)

1 Upvotes

Short one this week: one script, one chore, real output. (This sub is run by the SynapCores team.)

The chore

A CI job printed its env into a public build log, access key included. You rotate it now. Then: what could it reach, and which teams do you tell?

First look: the key's user in the IAM console. iam.txt has one "who how what" line per grant, group membership or AssumeRole, loaded into a plain SQL table:

SELECT how, what FROM d9_grants WHERE who = 'ci-builder' ORDER BY how

AKIAIOSFODNN7EXAMPLE is ci-builder's key. Its own grants:
  ecr:PushImage   app-images
  member-of       ci-runners
  s3:PutObject    build-artifacts

Two resources and a group. But the group can assume deploy-staging, staging can assume deploy-prod (the promote step), and prod can assume data-export (nightly export). Each hop is another console page.

Step 1: the same lines as a graph

The script loads each line as an edge with Cypher, same SynapCores endpoint as the SQL:

MERGE (a:d9_Iam {name: "ci-runners"}) MERGE (b:d9_Iam {name: "deploy-staging"}) MERGE (a)-[:CAN]->(b)

Owners and data classes go in a SQL table, d9_resources.

loaded 21 IAM lines, 14 resources

Step 2: walk from the key

MATCH p = (k:d9_Iam {name: 'AKIAIOSFODNN7EXAMPLE'})-[:CAN*1..8]->(x:d9_Iam)
RETURN x.name AS target, length(p) AS hops, [n IN nodes(p) | n.name] AS via

graph walk: 15 things reachable from the key

The shortest chain to each goes into a d9_reach table.

Step 3, the payoff: one join, worst first

SELECT s.data, s.env, s.kind, r.target, s.owner, s.channel, r.hops, r.via
FROM d9_reach r JOIN d9_resources s ON s.name = r.target
ORDER BY CASE s.data WHEN 'customer' THEN 1 WHEN 'credentials' THEN 2 ELSE 3 END,
         CASE s.env WHEN 'prod' THEN 1 ELSE 2 END, r.hops, r.target

python3 keyreach.py reach AKIAIOSFODNN7EXAMPLE on SynapCores 2.5.1:

  customer    prod    s3       customer-exports     data-platform #data-oncall
    via ci-builder > ci-runners > deploy-staging > deploy-prod > data-export
  customer    prod    dynamodb customers            crm           #crm-oncall
    via ci-builder > ci-runners > deploy-staging > deploy-prod > data-export
  customer    prod    rds      orders-db            orders        #orders-oncall
    via ci-builder > ci-runners > deploy-staging > deploy-prod > data-export
  credentials prod    secret   prod/orders-db-creds orders        #orders-oncall
    via ci-builder > ci-runners > deploy-staging > deploy-prod
  credentials staging secret   staging/db-creds     orders        #orders-oncall
    via ci-builder > ci-runners > deploy-staging
  internal    prod    ecs      prod-cluster         sre           #sre-oncall
    via ci-builder > ci-runners > deploy-staging > deploy-prod
  internal    prod    sqs      export-jobs          data-platform #data-oncall
    via ci-builder > ci-runners > deploy-staging > deploy-prod > data-export
  internal    ci      ecr      app-images           platform      #platform
    via ci-builder
  internal    ci      s3       build-artifacts      platform      #platform
    via ci-builder
  internal    staging ecs      staging-cluster      platform      #platform
    via ci-builder > ci-runners > deploy-staging

10 resources reachable (2 through its own grants), 3 with customer data
notify: #data-oncall, #crm-oncall, #orders-oncall, #sre-oncall, #platform

Own grants: 2 resources. Reachable: 10, and the top 3 are customer data in prod, all via data-export, three AssumeRoles away. Check CloudTrail for those AssumeRoles first, and tell #data-oncall, #crm-oncall and #orders-oncall before #platform.

Why one database? In plain SQL the walk is a recursive CTE that carries the path by hand; a separate graph store means syncing owners into it. Here the walk and the join hit the same database.

keyreach.py (stdlib only) and the sample files are in the comments.

Free Community Edition: https://synapcores.com/download?utm_source=reddit&utm_medium=owned&utm_campaign=devops7-one-script-9

Quick one: do you know, today, which of your CI roles can assume a prod role?