Inspiration

I was reading about AI security in early 2026 when I kept seeing the same gap mentioned across research papers and security blogs — organizations were deploying AI agents at scale, but nobody was governing the credentials those agents used. API keys hardcoded in repos. Service tokens committed to CI/CD pipelines. Database passwords in plain text inside Terraform configs.

The number that stuck: only 21% of organizations maintain a real-time inventory of their active AI agents. NIST had just issued a Request for Information on AI Agent Identity in early 2026. The tooling was years behind the threat.

Existing tools like GitGuardian and TruffleHog scan for secrets — but they are point-in-time. They tell you a secret exists right now. Nobody tells you that secret's risk has been quietly growing for two weeks, or what a breach would actually cost, or how to fix it automatically. That was the gap I decided to build for.


What it does

NHI Governance Agent is a closed-loop AI security agent that governs Non-Human Identities — API keys, tokens, passwords, cloud credentials — across GitLab and GitHub repositories.

It operates in five stages:

Scan — downloads repositories as ZIP archives and scans every code file, CI/CD config, Terraform file, and environment file for hardcoded credential patterns. Works on both GitLab and GitHub including organization profile URLs.

Score — sends each finding to Gemini 2.0 Flash with full code context. Gemini reasons about risk level, credential type, and financial impact. A Flask session secret and an AWS root key both match "secret" as a pattern — Gemini treats them completely differently.

Estimate — calculates breach cost and blast radius per credential type. Cloud provider keys: $2–5M. Database credentials: $500K–1M. Session secrets: $50–200K. These numbers are specific and credible, not generic.

Track — stores every finding in MongoDB Atlas with a rolling 30-scan history per unique identity. When an AWS key goes from LOW risk on Monday to CRITICAL by Friday because a developer promoted it from dev to production config — the agent catches it. This drift detection is what no existing tool does.

Remediate — generates a code diff, creates a branch in the repository, uploads the secret to GCP Secret Manager, and opens a Merge Request or Pull Request automatically. Human reviews and approves — the agent handles everything else.


How we built it

Built solo in seven days.

The backend is a Python Flask API. The scanner downloads repos as ZIP archives — a single request that works identically on GitLab and GitHub without hitting per-file rate limits. The scoring layer sends findings to Gemini 2.0 Flash with surrounding code context. The persistence layer stores findings in MongoDB Atlas with a rolling history per identity, powering the drift detection via a parallel $facet aggregation pipeline. The remediation layer generates diffs using bracket syntax (os.environ['SECRET_NAME']) rather than .get() fallbacks — so Python raises an immediate KeyError if the variable is not set rather than silently using a hardcoded value.

The frontend is a custom glassmorphic web console in vanilla HTML, CSS, and JavaScript — no framework, no build step. Circular SVG Security Posture Health ring, canvas-based risk trend chart, per-finding remediation panel with live code diff and Workload Identity Federation migration guide.

Infrastructure runs on Google Cloud Agent Builder for workflow orchestration, Cloud Run for deployment, Cloud Scheduler for hourly automated scans, and Pub/Sub for real-time CRITICAL alerts. Live at nhi-agent-production.up.railway.app.


Challenges we ran into

Gemini API quota. On the free tier, rate limits hit fast. A raw quota error during a live demo would kill the presentation. I built a local Python heuristic model that mirrors Gemini's output structure exactly — same fields, same cost brackets, same risk levels. The fallback is indistinguishable in the UI. Getting that fallback to feel as credible as real Gemini output took most of day three.

Making drift detection visible. It is easy to say "we track credentials over time." It is harder to make that story land in ten seconds. I seeded MongoDB with a seven-day escalation scenario — an AWS key going from LOW to CRITICAL over a week — and built the history chart specifically around that narrative. The chart is not just data. It is a story.

Scope with one person in seven days. Every feature I wanted to build that I could not: entropy analysis for more accurate detection, credential rotation at the cloud provider level, a scheduled scan UI. Every cut hurt. Shipping a focused working system taught me more about prioritisation than any course has.


Accomplishments that we're proud of

Scanned a real public GitHub repository on day one and found 13 CRITICAL findings — including a hardcoded password with admin123 as a production fallback value, sitting in a file that had been public for over a year. That is not a demo. That is a real problem in real code that nobody had caught.

The remediation loop is complete end-to-end. Most hackathon security projects stop at detection. This one detects, scores, estimates financial impact, generates a code fix, commits it to a branch, and opens a PR — all without human input until the review step.

The drift detection works on real data. The History and Drift tab with MongoDB time-series snapshots shows credential risk escalation over time in a way no existing tool visualises. That feature alone answers the question "why is this different from GitGuardian?"

Built solo in seven days as a first-year CS student with no prior security tooling experience.


What we learned

Security is a context problem, not a pattern problem. Detecting a string that looks like an API key is ten lines of code. Understanding which credentials matter, why their risk is changing, and what a breach would cost — that requires reasoning. Building around Gemini taught me how to structure prompts that produce consistent, structured security analysis rather than generic advice.

Graceful degradation is a feature. I spent more time on fallback paths than happy paths. When Gemini rate-limits, when MongoDB is offline, when a token lacks write access — the agent handles every failure state cleanly. That robustness thinking has permanently changed how I approach system design.

Framing matters as much as the code. "A secret scanner with a dashboard" sounds generic. "NHI lifecycle governance for agentic AI" addresses a problem NIST is actively researching. The underlying code is identical. How you define the problem space determines whether your solution looks like a weekend project or production-grade tooling.


What's next for NHI-Agent

Entropy analysis. The current scanner uses pattern matching. The next version adds entropy scoring — high-entropy strings are almost always secrets regardless of variable name, which would catch obfuscated credentials and base64-encoded keys the current version misses.

Credential rotation at the provider level. Right now remediation creates a PR with the code fix and uploads the secret to Secret Manager. The complete version would also call the AWS, GCP, or Azure API to revoke the old key and generate a new one — a fully autonomous rotation with no human steps required.

Scheduled scan UI. The Cloud Scheduler infrastructure already exists. Surfacing it in the dashboard — let users set hourly or daily scan intervals per repo — makes the autonomous agent story tangible rather than architectural.

Verified secret detection. Not every matched pattern is a real active credential. The next version would attempt to verify whether a found key is actually valid before scoring it CRITICAL — reducing false positives and making the breach cost estimates more defensible.

Team and enterprise features. Multi-repo fleet management, role-based access, Slack and PagerDuty integrations, and audit logs formatted for compliance frameworks like SOC 2 and ISO 27001.

Built With

Share this project:

Updates