Cloud Access Keys for AI Agents Need Owners, Monitoring and End Dates

Oct 28, 2026 539 views

Curving geometric 3D abstraction representing cloud infrastructure and non-human credential lifecycles.

The cloud credential risk that’s easiest to miss is the one left behind after its workload disappears. AWS IAM user access keys don’t expire on their own, so a key created for a short lived agent can remain valid after the project, its sponsor and its operational context have all vanished.

That creates a lifecycle gap. People generally trigger an offboarding process when they leave a company; agents don’t trigger one when their task ends. The remedy is to make credentials discoverable, assign them an accountable owner, limit new key creation and verify that retired access has actually stopped working.

OWASP ranks improper offboarding first in its 2025 Top 10 for non-human identities. The priority makes sense: teams can’t retire credentials they don’t know exist. A hypothetical IAM user named research-agent-2, for example, might have an active key created 14 months ago and last used 11 months ago, even though its project has closed.

Speed adds pressure. In September 2026, GreyNoise described an AI orchestrated campaign against PaperCut servers that went from an empty workspace to remote code execution at a real victim in under four hours. After launch, the campaign compromised at least 11 organizations in 26 seconds. The incident wasn’t about abandoned AWS keys, but it illustrates how quickly exposed access can become useful once an attacker gets in. Annual reviews are a poor match for that pace.

Find stale AWS IAM keys with a credential report

CloudQuery can sync AWS IAM credential reports into aws_iam_credential_reports when the table is enabled in the source configuration. Each report includes up to two access key slots per user. The ClickHouse query below selects the latest synced report, expands both slots into separate rows and returns active keys that are at least 90 days old and have gone unused for at least 90 days.

SQL
WITH latest_reports AS (
SELECT
_cq_platform_id,
arn,
`user` AS principal,
access_key1_active,
access_key_1_last_rotated,
access_key_1_last_used_date,
access_key2_active,
access_key_2_last_rotated,
access_key_2_last_used_date
FROM aws_iam_credential_reports
ORDER BY _cq_sync_group_id DESC, _cq_sync_time DESC
LIMIT 1 BY _cq_platform_id
),
keys AS (
SELECT _cq_platform_id, arn, principal,
1 AS key_slot,
access_key1_active AS active,
access_key_1_last_rotated AS created,
access_key_1_last_used_date AS last_used
FROM latest_reports
UNION ALL
SELECT _cq_platform_id, arn, principal,
2 AS key_slot,
access_key2_active AS active,
access_key_2_last_rotated AS created,
access_key_2_last_used_date AS last_used
FROM latest_reports
)
SELECT _cq_platform_id, arn, principal,
key_slot, created, last_used
FROM keys
WHERE principal != '<root_account>'
AND active = true
AND created < now() - INTERVAL 90 DAY
AND (
last_used IS NULL
OR last_used < now() - INTERVAL 90 DAY
)
ORDER BY last_used NULLS FIRST, principal, key_slot;

Column spelling matters: the active fields are named access_key1_active and access_key2_active, while the corresponding date fields include an underscore before the number. CloudQuery Platform tables point to the latest complete snapshot already, so the latest row clause is useful mainly on destinations that retain history. There it can also bring back a user who has since been deleted.

Ninety days is a review trigger, not proof that a key is disposable. Quarterly processes may use credentials infrequently, and a null or placeholder last used date calls for investigation rather than an automatic judgment. The report also can’t identify which agent used an IAM account. Join the results with audit logs and establish a named owner before acting. The query excludes the root account, whose access keys need a separate audit; AWS recommends having none.

For PostgreSQL, quote "user", use interval '90 days' and replace ClickHouse’s LIMIT 1 BY with DISTINCT ON. Here, the ARN identifies each IAM user:

SQL
WITH latest_reports AS (
SELECT DISTINCT ON (arn)
arn, "user" AS principal,
access_key1_active, access_key_1_last_rotated, access_key_1_last_used_date,
access_key2_active, access_key_2_last_rotated, access_key_2_last_used_date
FROM aws_iam_credential_reports
ORDER BY arn, _cq_sync_time DESC
),
keys AS (
SELECT arn, principal, 1 AS key_slot,
access_key1_active AS active,
access_key_1_last_rotated AS created,
access_key_1_last_used_date AS last_used
FROM latest_reports
UNION ALL
SELECT arn, principal, 2 AS key_slot,
access_key2_active AS active,
access_key_2_last_rotated AS created,
access_key_2_last_used_date AS last_used
FROM latest_reports
)
SELECT split_part(arn, ':', 5) AS account_id, arn, principal,
key_slot, created, last_used
FROM keys
WHERE principal <> '<root_account>'
AND active
AND created < now() - interval '90 days'
AND (last_used IS NULL OR last_used < now() - interval '90 days')
ORDER BY last_used NULLS FIRST, principal, key_slot;

That output is a shortlist for review, not a deletion queue. Ask who owns each credential, which workload still depends on it and when access should end. Similar inventory work applies to other clouds: entraid_serviceprincipals holds Microsoft Entra ID credential metadata, while entraid_serviceprincipal_owners records owners. Check identifiers and validity dates, not secret values; Microsoft Graph returns secretText only at creation. In Google Cloud, gcp_iam_service_account_keys can list service account keys when enabled in the sync, but audit logs are needed to understand their use.

Block persistent key creation in deployment plans

Inventory identifies credentials already in circulation. A deployment policy can reduce the number of new long lived keys that enter the system. env zero approval policies run during deployment and destruction, so they can reject selected credential resources in Terraform and OpenTofu plans when env zero governs that deployment.

The scope has limits. The policy won’t catch keys created manually in a console, by an external script or by an env zero task. It also doesn’t revoke the identity used to authenticate a deployment. Cloud native controls, such as an AWS service control policy or Google Cloud’s organization policy for service account keys, and ongoing inventory remain part of the control set.

Assign a policy to an env zero project and its environments inherit it, including subprojects. The example below blocks creation of selected persistent credential types, whether a person or an agent starts the deployment.

package env0
import future.keywords.contains
import future.keywords.every
import future.keywords.if
import future.keywords.in
key_resources := {
"aws_iam_access_key",
"aws_iam_user_login_profile",
"aws_iam_service_specific_credential",
"aws_iam_signing_certificate",
"google_service_account_key",
"azuread_service_principal_password",
"azuread_application_password",
"azuread_service_principal_certificate",
"azuread_application_certificate",
}
# A real Terraform or OpenTofu plan carries format_version, and omits
# resource_changes entirely when there is nothing to change.
tf_plan(p) if {
is_object(p)
p.format_version
}
standard_plan if {
not input.plan.is_run_all
tf_plan(input.plan)
}
run_all_plan if {
input.plan.is_run_all == true
is_object(input.plan.modules)
count(input.plan.modules) > 0
every _, m in input.plan.modules {
tf_plan(m)
}
}
resource_changes := object.get(input.plan, "resource_changes", []) if standard_plan
resource_changes := [rc |
some _, m in input.plan.modules
some rc in object.get(m, "resource_changes", [])
] if run_all_plan
deny contains msg if {
not standard_plan
not run_all_plan
msg := "Unsupported plan format for the credential policy"
}
deny contains msg if {
some rc in resource_changes
key_resources[rc.type]
"create" in rc.change.actions
msg := sprintf("%s: long-lived credential prohibited", [rc.address])
}
allow if count(deny) == 0

The policy accepts standard Terraform or OpenTofu plan data and the module map used by Terragrunt run all. Empty plans may omit resource_changes, so the policy treats that as no changes. Unknown input shapes are denied; attach it only to projects that produce the formats it supports, because a Pulumi, CloudFormation or Kubernetes deployment would also be denied. Replacements count as creation and are caught. The resource list is illustrative, and the policy can’t detect hardcoded secrets or keys minted outside Terraform.

The explicit allow rule lets deployments proceed when no denial applies. Without it, a policy that returns no decision may leave every deployment waiting for human approval. Validate the full env zero input wrapper with key creation, role only plans, replacements, run all, missing plan data and destruction. ENV0_PRINT_POLICY_INPUT=true logs the input, and ENV0_OPA_VERSION pins the OPA version. The policy runs on env zero’s default OPA version, 0.46.1, and on OPA 1.x; its future.keywords imports support both.

Some integrations still need a persistent key. In that case, document the exception with a named owner, workload, least privilege scope, revocation deadline, secure storage, monitoring and approval record. AWS IAM access keys can’t be tagged, so keep ownership on the identity and in the credential inventory.

Where possible, use federation. env zero supports OIDC based deployment authentication, and an AWS role can issue temporary credentials that expire with the session. The role’s permissions and trust relationship still need an owner and review.

Use a finite lifecycle and confirm revocation

AWS IAM user keys have no built in expiration date, so teams need an external mechanism to give them an end point. For Terraform managed credentials, an environment TTL can start a teardown when the workload’s environment expires. Put disposable credentials in the same environment as the resources they serve, then verify that the destroy completed and the key is gone.

A TTL starts a destroy; it doesn’t guarantee one. A failed operation, a locked environment, a manually created key or an identity managed elsewhere can leave access active. TTLs can also be extended or set to infinite, and TTL limits don’t bind administrators. On the env zero Free plan, TTL destruction pauses after an organization exceeds 250 runs in a month, until the monthly count resets at the start of the next month in UTC. A key may therefore outlive its TTL by as much as a month.

Infrastructure teardown also won’t revoke the identity that called the deployment. Review the trust relationship and permission scope for OIDC federation, and rotate persistent tokens through the system that issued them. Terraform managed access keys put secret values in state, so the state backend needs protection.

For keys outside an environment lifecycle, identify the specific key, check its last use and confirm its owner and dependencies before disabling it. The credential report doesn’t include key IDs. AWS CLI commands can retrieve the key ID and last used metadata, then deactivate the key:

Shell
aws iam list-access-keys \
--user-name research-agent-2
aws iam get-access-key-last-used \
--access-key-id &lt;key-id>
aws iam update-access-key \
--user-name research-agent-2 \
--access-key-id &lt;key-id> \
--status Inactive

Deactivation is reversible, but it can disrupt a quarterly process or a disaster recovery job that hasn’t run recently. Observe authentication errors for a period that fits the workload’s schedule, get the owner’s approval and then delete the key under the organization’s change process. Deletion can’t be reversed.

env zero’s Free plan includes custom approval policies and environment TTL, alongside limits of 250 runs per month and 30 active environments. CloudQuery Platform has a free tier, and its CLI can sync data to a team’s own Postgres database. The first operational step is straightforward: sync the credential report, run the query and review the results.

Make credential ownership part of agent operations

A forgotten virtual machine can continue to incur costs. A forgotten credential can continue to grant access. That difference makes credential lifecycle management a distinct part of agent ownership: teams need to know what was issued, who depends on it and who can retire it.

Agents that completed a project last quarter won’t report their old keys. A stale key doesn’t have to be labeled orphaned to pose a risk; it only has to remain valid. Treating inventory, deployment policy and verified revocation as connected operational tasks gives every credential a visible owner and a credible end date.

The post What happens when the agent is long gone, but its access key lives on? appeared first on The New Stack.

Source: Zeen Rachidi · thenewstack.io

Comments

Sign in to comment.
No comments yet. Be the first to comment.

Related Articles

What happens when the agent is long gone, but its access ...