Security ownership map

From seaworld008/Commonly-used-high-value-skills · View interactive version

Security ownership map is an AI agent skill from the GitHub repository seaworld008/Commonly-used-high-value-skills. Use when assessing security ownership from git history: who owns sensitive code, bus factor, CODEOWNERS drift, and co-change risk hotspots.

How to use this skill

Skill file

Security Ownership Map

Overview

Build a bipartite graph of people and files from git history, then compute ownership risk and export graph artifacts for Neo4j/Gephi. Also build a file co-change graph (Jaccard similarity on shared commits) to cluster files by how they move together while ignoring large, noisy commits.

Requirements

If NetworkX is missing and installation in the selected Python environment is authorized:

pip install networkx

Run the examples from the loaded skill directory. Set TARGET_REPO to the absolute path of the repository being analyzed and MAP_OUT to the authorized absolute output directory. Use the same output directory for subsequent queries.

Workflow

  1. Scope the repo and time window (optional --since/--until).
  2. Decide sensitivity rules (use defaults or provide a CSV config).
  3. Build the ownership map with scripts/run_ownership_map.py (co-change graph is on by default; use --cochange-max-files to ignore supernode commits).
  4. Communities are computed by default; graphml output is optional (--graphml).
  5. Query the outputs with scripts/query_ownership.py for bounded JSON slices.
  6. Persist and visualize (see references/neo4j-import.md).

By default, the co-change graph ignores common “glue” files (lockfiles, .github/*, editor config) so clusters reflect actual code movement instead of shared infra edits. Override with --cochange-exclude or --no-default-cochange-excludes. Dependabot commits are excluded by default; override with --no-default-author-excludes or add patterns via --author-exclude-regex.

If you want to exclude Linux build glue like Kbuild from co-change clustering, pass:

python scripts/run_ownership_map.py \
  --repo /path/to/linux \
  --out "$MAP_OUT" \
  --cochange-exclude "**/Kbuild"

Quick start

Build the map for the target repository:

python scripts/run_ownership_map.py \
  --repo "$TARGET_REPO" \
  --out "$MAP_OUT" \
  --since "12 months ago" \
  --emit-commits

Defaults: author identity, author date, and merge commits excluded. Use --identity committer, --date-field committer, or --include-merges if needed.

Example (override co-change excludes):

python scripts/run_ownership_map.py \
  --repo "$TARGET_REPO" \
  --out "$MAP_OUT" \
  --cochange-exclude "**/Cargo.lock" \
  --cochange-exclude "**/.github/**" \
  --no-default-cochange-excludes

Communities are computed by default. To disable:

python scripts/run_ownership_map.py \
  --repo "$TARGET_REPO" \
  --out "$MAP_OUT" \
  --no-communities

Sensitivity rules

By default, the script flags common auth/crypto/secret paths. Override by providing a CSV file:

# pattern,tag,weight
**/auth/**,auth,1.0
**/crypto/**,crypto,1.0
**/*.pem,secrets,1.0

Use it with --sensitive-config path/to/sensitive.csv.

Output artifacts

ownership-map-out/ contains:

people.csv includes timezone detection based on author commit offsets: primary_tz_offset, primary_tz_minutes, and timezone_offsets.

LLM query helper

Use scripts/query_ownership.py to return small, JSON-bounded slices without loading the full graph into context.

Examples:

python scripts/query_ownership.py --data-dir "$MAP_OUT" people --limit 10
python scripts/query_ownership.py --data-dir "$MAP_OUT" files --tag auth --bus-factor-max 1
python scripts/query_ownership.py --data-dir "$MAP_OUT" person --person alice@corp --limit 10
python scripts/query_ownership.py --data-dir "$MAP_OUT" file --file crypto/tls
python scripts/query_ownership.py --data-dir "$MAP_OUT" cochange --file crypto/tls --limit 10
python scripts/query_ownership.py --data-dir "$MAP_OUT" summary --section orphaned_sensitive_code
python scripts/query_ownership.py --data-dir "$MAP_OUT" community --id 3

Use --community-top-owners 5 (default) to control how many maintainers are stored per community.

Basic security queries

Run these to answer common security ownership questions with bounded output:

# Orphaned sensitive code (stale + low bus factor)
python scripts/query_ownership.py --data-dir "$MAP_OUT" summary --section orphaned_sensitive_code

# Hidden owners for sensitive tags
python scripts/query_ownership.py --data-dir "$MAP_OUT" summary --section hidden_owners

# Sensitive hotspots with low bus factor
python scripts/query_ownership.py --data-dir "$MAP_OUT" summary --section bus_factor_hotspots

# Auth/crypto files with bus factor <= 1
python scripts/query_ownership.py --data-dir "$MAP_OUT" files --tag auth --bus-factor-max 1
python scripts/query_ownership.py --data-dir "$MAP_OUT" files --tag crypto --bus-factor-max 1

# Who is touching sensitive code the most
python scripts/query_ownership.py --data-dir "$MAP_OUT" people --sort sensitive_touches --limit 10

# Co-change neighbors (cluster hints for ownership drift)
python scripts/query_ownership.py --data-dir "$MAP_OUT" cochange --file path/to/file --min-jaccard 0.05 --limit 20

# Community maintainers (for a cluster)
python scripts/query_ownership.py --data-dir "$MAP_OUT" community --id 3

# Monthly maintainers for the community containing a file
python scripts/community_maintainers.py \
  --data-dir "$MAP_OUT" \
  --file network/card.c \
  --since 2025-01-01 \
  --top 5

# Quarterly buckets instead of monthly
python scripts/community_maintainers.py \
  --data-dir "$MAP_OUT" \
  --file network/card.c \
  --since 2025-01-01 \
  --bucket quarter \
  --top 5

Notes:

Summary format (default)

Use this structure, add fields if needed:

{
  "orphaned_sensitive_code": [
    {
      "path": "crypto/tls/handshake.rs",
      "last_security_touch": "2023-03-12T18:10:04+00:00",
      "bus_factor": 1
    }
  ],
  "hidden_owners": [
    {
      "person": "alice@corp",
      "controls": "63% of auth code"
    }
  ]
}

Graph persistence

Use references/neo4j-import.md when you need to load the CSVs into Neo4j. It includes constraints, import Cypher, and visualization tips.

Notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.