PlaybookLast checked 16 October 2026 with AI-assisted research. Editor: Akshay Dubey.MethodologyCorrections log

API key governance is the practice of finding every API key, personal access token and OAuth client secret, binding each one to the identity it acts as and a named owner, replacing what a platform can issue as short-lived credentials, and limiting, expiring and retiring the rest. Keys are credentials; governance attaches to the identity behind them.

API keys, personal access tokens and OAuth client secrets turn up in code, CI logs and chat messages, and they are often created by hand, outside any provisioning process. This playbook sets out how to bring them under governance: find them, tie each one to an identity and an owner, replace what can be replaced, and limit, expire and retire the rest.

An API key is a credential, not an identity

This site's taxonomy treats an API key as a credential. It proves an identity; it is not one. Every key is held by, and acts as, some identity:

  • an AWS access key authenticates as an IAM user;
  • a GitHub personal access token acts as the GitHub user who created it, within the permissions the token was given;
  • an OAuth client secret proves an OAuth client registered with an authorisation server, typically used with the client credentials grant;
  • a SaaS API key acts as a user, a service account or the whole tenant, depending on the product.

Why it matters: if you inventory keys without the identity behind them, you cannot answer what a leaked key can do, who should approve its rotation, or whether removing it breaks anything. Governance (owner, purpose, review) attaches to the identity. Rotation, expiry and storage attach to the key. One identity can hold several keys, which is normal; several services sharing one key is a reuse problem.

What goes wrong

Two case studies on this site show the pattern from different sides. In the Codecov case, Codecov's post-mortem says an HMAC key for a Google Cloud Storage service account was taken from an intermediate layer of a Docker image and used to alter the Bash Uploader, which then sent the environment of customers' CI jobs, including any keys in it, to a third-party server. In the Snowflake UNC5537 case, Mandiant found that the credentials used had been exposed by infostealer malware, had not been rotated in some cases for years, and that the accounts had no MFA. In both, a static credential stayed valid long after it had left its intended home.

Step 1: Inventory keys by issuer

Keys are issued by platforms, so start from each issuer's own records rather than from scanning alone. Scanning code and logs for exposed secrets is still needed (see secrets management), but it finds leaks, not the full population.

  • AWS. The IAM credential report is a CSV with, for each IAM user, columns such as access_key_1_active, access_key_1_last_rotated and access_key_1_last_used_date. AWS notes that it covers only the first two access keys per user and that ListAccessKeys gives full coverage. A report can be generated at most once every four hours (AWS, Getting credential reports).
  • GitHub. Organisation owners can see and approve fine-grained personal access tokens that request access to the organisation, and can restrict classic tokens (GitHub, Setting a personal access token policy for your organization).
  • Identity providers and authorisation servers. List OAuth clients that use client secrets, with secret creation and expiry dates.
  • SaaS products. Each product that issues API keys has its own admin view. Record which products allow tenant-wide keys.

The cross-platform discovery queries give commands for several of these sources. The script below works on the AWS credential report.

#!/usr/bin/env python3
"""Flag AWS IAM access keys that are old or unused, from an IAM credential report.

Usage:
  aws iam generate-credential-report
  aws iam get-credential-report --query Content --output text | base64 --decode > report.csv
  python3 flag_keys.py report.csv 90
Read-only. Prints one line per active key older than, or unused for, the given number of days.
"""
import csv
import sys
from datetime import datetime, timezone


def parse(value):
    if value in ("", "N/A", "not_supported", "no_information"):
        return None
    return datetime.fromisoformat(value.replace("Z", "+00:00"))


def main(path, max_days):
    now = datetime.now(timezone.utc)
    with open(path, newline="") as fh:
        for row in csv.DictReader(fh):
            for n in ("1", "2"):
                if row.get(f"access_key_{n}_active") != "true":
                    continue
                rotated = parse(row[f"access_key_{n}_last_rotated"])
                used = parse(row[f"access_key_{n}_last_used_date"])
                reasons = []
                if rotated and (now - rotated).days > max_days:
                    reasons.append(f"not rotated for {(now - rotated).days} days")
                if used is None:
                    reasons.append("no recorded use")
                elif (now - used).days > max_days:
                    reasons.append(f"unused for {(now - used).days} days")
                if reasons:
                    print(f"{row['user']}\tkey {n}\t" + "; ".join(reasons))


if __name__ == "__main__":
    main(sys.argv[1], int(sys.argv[2]) if len(sys.argv) > 2 else 90)

Limits of this script. It reads only the first two access keys per IAM user, because that is all the credential report holds. The report can be up to four hours old. It covers IAM users only, not keys issued by other AWS services or by other platforms. It does not say what a key can do; join the output with IAM policy data for that. We have checked it with python3 -m py_compile and on a sample CSV, not against a live account.

Step 2: Bind every key to an identity and an owner

For each key, record the identity it acts as, the system that uses it, where it is stored, and a named human owner. Keys that act as a person's own account deserve a closer look. A classic GitHub token, for example, can reach every repository its user can reach, according to GitHub's token documentation. When automation runs on a person's token, it inherits that person's access and stops working when they leave. In our reading this is a case of OWASP's NHI10, Human Use of NHI, seen from the other side: a human credential doing a machine's job. The fix is a dedicated identity for the automation, such as a GitHub App or a service account, with its own credential.

Step 3: Replace keys where a platform offers short-lived credentials

The cheapest key to govern is the one that no longer exists. AWS's IAM security best practices say to require workloads to use temporary credentials with IAM roles, and, where possible, to rely on temporary credentials instead of long-term access keys. Our GitHub Actions to AWS playbook shows one replacement, and the workload identity federation page explains the general pattern. Keep a list of the keys that cannot be replaced yet, with the reason; that list is your remaining exposure.

Step 4: Narrow what each remaining key can do

  • Prefer GitHub fine-grained tokens, which work for one resource owner and can be limited to selected repositories and permissions. GitHub recommends them over classic tokens, while noting they cannot yet do everything classic tokens can.
  • Give each IAM user that holds an access key only the permissions its workload needs, and use AWS last accessed information to remove permissions that are not used.
  • Where a SaaS product offers scoped keys, issue one key per integration with the smallest scope, not one tenant-wide admin key shared by several systems.

Step 5: Set expiry and rotate by risk

Set a maximum lifetime wherever the issuer supports it. GitHub organisations can set maximum lifetimes for fine-grained and classic tokens; GitHub says fine-grained tokens default to expiring within 366 days, and that non-compliant tokens are blocked from the organisation but not revoked. GitHub also removes personal access tokens that have not been used for a year. AWS recommends updating access keys when needed, for example when an employee leaves, and using last used information to do so safely. For rotation without outages, use the dual-credential pattern in our credential rotation playbook: AWS IAM users can hold two access keys, which allows an overlap.

Step 6: Store keys in one place and watch for leaks

A key that lives in a vault can be rotated by automation and audited when it is read. A key in a config file, a CI variable and a wiki page at once cannot. Move keys into managed secret storage, give each consuming workload its own read path, and turn on secret scanning for code repositories. When a leak is found, treat the key as compromised: revoke it, check the issuer's logs for its use, and only then replace it. Our NHI security operations playbook covers that response.

Step 7: Retire keys that are not used

Use the issuer's last-used data to find keys with no recent use, confirm with the owner, deactivate first, and delete after a waiting period. AWS describes this approach in its best practice to regularly review and remove unused users, roles, permissions, policies and credentials. The decommissioning playbook describes the deactivate, wait, delete sequence.

Mapping to the OWASP NHI Top 10

This is our mapping, not a statement by OWASP.

Risk (OWASP NHI Top 10 (2025))How it shows up for API keysSteps above
NHI2 Secret LeakageKeys in code, images, CI logs or chat1, 6
NHI7 Long-Lived SecretsKeys with no expiry and no rotation3, 5
NHI5 Overprivileged NHITenant-wide or admin keys for narrow tasks4
NHI9 NHI ReuseOne key shared by several services or environments2, 4
NHI10 Human Use of NHIAutomation running on a person's token, or people using service keys2
NHI1 Improper OffboardingKeys left active after the system or owner has gone7

Frequently asked questions

Is an API key a non-human identity?

No. In this site's taxonomy an API key is a credential. It proves an identity, such as an IAM user, a service account or an OAuth client. Governance attaches to that identity; rotation and expiry attach to the key.

How often should API keys be rotated?

There is no single interval that fits every key. AWS recommends temporary credentials where possible and updating long-term keys when needed. In our view, set expiry by risk, rotate high-privilege and widely shared keys more often, and treat any key that cannot expire as an item to replace.

What should we do first with thousands of keys?

Start with the issuers that hold privileged keys, export their own records, and tie each key to an identity and owner. Deactivate keys with no recorded use after confirming with the owner. Replace keys with short-lived credentials where the platform supports it.

How do you rotate an OAuth client secret without downtime?

Add a second credential to the client, move every consumer to it, confirm in sign-in logs that the old one is no longer used, then delete it. Better still, remove the secret: Microsoft's guidance for Entra applications puts managed identities first, then federated credentials, then certificates, and says not to use client secrets. The overlap method is our practice, not a vendor requirement.

Sources

  • OWASP Non-Human Identities Top 10 (2025), owasp.org
  • AWS, Security best practices in IAM, docs.aws.amazon.com
  • AWS, Getting credential reports for your AWS account, docs.aws.amazon.com
  • GitHub, Managing your personal access tokens, docs.github.com
  • GitHub, Setting a personal access token policy for your organization, docs.github.com
  • NIST SP 800-53 Rev. 5, Security and Privacy Controls for Information Systems and Organizations (AC-2, AC-6, IA-5), csrc.nist.gov
  • NHI Governance, Codecov Bash Uploader compromise (2021), case study
  • NHI Governance, Snowflake customer intrusions by UNC5537 (2024), case study

Where a primary URL is not shown, we have not confirmed the figure against the publisher’s own document and say so on the page rather than linking a secondary source that paraphrases it. Paywalled standards (ISO/IEC, AICPA) are cited by clause and not linked. Corrections welcome: report an error.

Disclosure. This reference is free. No vendor pays for coverage, placement, or favourable treatment. HumanAudit Inc., which publishes this site, sells ISO/IEC 42001 documentation and plans NHI governance documentation packs, including an RFP kit that does not name, rank or recommend any vendor; it builds and sells no NHI scanner and no NHI discovery, monitoring or security tool (see About). Links to its offers appear in the header, in the site footer and in one marked box on guide pages; company profiles carry none. See our methodology, sourcing standards and corrections policy.

From the publisher

HumanAudit, which publishes this site, is preparing the NHI Governance pack: an NHI policy, ownership register, lifecycle procedures and one control set mapped, as our interpretation, to PCI DSS v4.0.1, ISO/IEC 27001:2022, NIS2 and DORA. Planned for March 2027; not yet on sale, and no price has been published.

Monthly change log

Know when the NHI landscape changes.

One email a month from this reference: new deals, standards status changes and corrections. No sponsored content. Unsubscribe from any email.

We first email you a link to confirm. Privacy policy.