Back to Checks
claude

Claude API key lifetime is within the documented maximum

apikey_lifetime_within_maximum
Service: apikeySeverity: medium
OfficialVerifiedPrivate
Categories:gen-aisecretsidentity-access
Resource Type:ClaudeApiKey

API key lifetimes are bounded. A multi-year expiry satisfies the letter of a rotation policy while leaving the key useful to an attacker for its whole life.

Prowler logoProwlerprowler-provider-claude

Risk

A multi-year expiry satisfies the letter of a rotation policy while leaving the key useful to an attacker for its whole life.

Run this check with Prowler

Run in Prowler Cloud
Run
prowler claude --checks apikey_lifetime_within_maximum

Recommendation

Shorten key lifetimes to the rotation period your policy actually requires.

Remediation

Other

1Shorten key lifetimes to the rotation period your policy actually requires.

Check Code

from prowler.lib.check.models import Check

from prowler_provider_claude.lib.dates import days_between
from prowler_provider_claude.lib.report import CheckReportClaude
from prowler_provider_claude.services.apikey.apikey_client import apikey_client


class apikey_lifetime_within_maximum(Check):
    """API key lifetimes are bounded."""

    def execute(self) -> list[CheckReportClaude]:
        maximum = apikey_client.audit_config.get("claude_max_key_lifetime_days", 365)
        findings = []
        for key in [
            k for k in apikey_client.api_keys if k.status == "active" and k.expires_at
        ]:
            lifetime = days_between(key.created_at, key.expires_at)
            if lifetime is None:
                continue
            report = CheckReportClaude(metadata=self.metadata(), resource=key)
            if lifetime <= maximum:
                report.status = "PASS"
                report.status_extended = (
                    f"API key {key.name} has a lifetime of {lifetime} day(s), within the "
                    f"documented maximum of {maximum}."
                )
            else:
                report.status = "FAIL"
                report.status_extended = (
                    f"API key {key.name} has a lifetime of {lifetime} day(s), longer than the "
                    f"documented maximum of {maximum}."
                )
            findings.append(report)
        return findings