Skip to main content

Audit service-account credentials

The CodeNOW API lists the credentials of the service accounts you manage — CodeNOW API keys, Git HTTPS tokens and Git SSH keys — with their state, expiry and last use. Use it to audit them automatically: which credentials expire soon, which nobody uses any more, which were created outside CodeNOW.

The calls are read-only and return metadata only (names, states, dates, scopes, fingerprints) — never a secret or a token value. Credentials are created, suspended and revoked in the CodeNOW UI, on the service account's KEYS & TOKENS tab.

Before you start​

  • Use an API key of a person who manages the service accounts: an account Owner or Admin (sees every service account), the owner of a service account, or an Admin / Service Account Manager of the owning team. Create it under Profile › KEYS & TOKENS › CodeNOW API keys — see Authentication.
  • A service account's own API key doesn't work for an audit. A service account never manages service accounts, so it sees none of them (404 on its own credentials, an empty search).
  • Keep the API key in an environment variable, for example CODENOW_API_KEY, never in a script.
The API host

The examples use https://api.cloud.codenow.com. Replace it with your installation's API host if it differs.

The calls​

CallReturns
GET /service-accounts/{idOrUsername}/credentialsThe credentials of one service account, identified by its UUID or username (sa-<account>_<name>).
GET /service-account-credentialsThe credentials of every service account you manage, each with its serviceAccount.
GET /service-accountsThe service accounts you manage, with their lifecycle state.

Both credential calls need the headers X-Codenow-Api-Key and Accept: application/vnd.codenow.v1+json. Full reference: List the credentials of a service account, Search the credentials of all managed service accounts.

curl -s https://api.cloud.codenow.com/service-accounts/sa-acme_ci/credentials \
-H "X-Codenow-Api-Key: $CODENOW_API_KEY" \
-H "Accept: application/vnd.codenow.v1+json"

A service account you don't manage — or that doesn't exist — is answered with 404.

Filters​

ParameterValuesDefaultCalls
kindAPI_KEY, GIT_TOKEN, SSH_KEYall kindsboth
stateACTIVE, SUSPENDED, EXPIRED, REVOKEDACTIVE, SUSPENDED, EXPIREDboth
originCODENOW (created through CodeNOW), EXTERNAL (created directly in GitLab)bothsearch
serviceAccountUUIDs or usernamesall you managesearch
expiresWithinDays0–3650—search
unusedForDays0–3650—search
  • Several values: repeat the parameter (kind=API_KEY&kind=GIT_TOKEN) or give one comma-separated value (kind=API_KEY,GIT_TOKEN) — not both in one parameter; mixing them is rejected with 400.
  • Filters combine with AND; several values of one filter match any of them.
  • expiresWithinDays — credentials that expire after now and at most this many days from now. Expired credentials and credentials that never expire are left out.
  • unusedForDays — API keys and HTTPS tokens not used in the last N days, including those never used. GitLab reports no last use for SSH keys, so SSH keys are left out whenever this filter is set.
  • A serviceAccount you don't manage, or that doesn't exist, simply matches nothing.

An invalid value is answered with 400 as application/problem+json, naming the parameter:

{
"type": "https://api.codenow.com/problem/illegal-argument",
"title": "Illegal Argument",
"status": 400,
"detail": "Invalid value 'abc' for unusedForDays."
}

The response​

{
"credentials": [
{
"id": "4182",
"kind": "API_KEY",
"name": "nightly-audit",
"state": "ACTIVE",
"origin": "CODENOW",
"serviceAccount": { "id": "0b6c2f0e-6a43-4c1e-9b7e-2f1d6a0c9e11", "username": "sa-acme_ci", "name": "ci", "state": "ACTIVE" },
"createdAt": "2026-03-02T09:14:00Z",
"createdBy": { "type": "USER", "id": "jnovak" },
"expiresAt": "2027-03-01T00:00:00Z",
"lastUsedAt": "2026-06-30T17:20:00Z"
},
{
"id": "5c0b7e21-44d9-5a3f-9e12-8b6d0f3c7a55",
"kind": "GIT_TOKEN",
"name": "mirror-sync",
"state": "ACTIVE",
"origin": "CODENOW",
"scopes": ["read_repository"],
"serviceAccount": { "id": "9e4a1b77-0c3d-4f62-a8e5-1d7b3c9f0a22", "username": "sa-acme_mirror", "name": "mirror", "state": "ACTIVE" },
"createdAt": "2026-05-20T10:00:00Z",
"expiresAt": "2026-12-01T00:00:00Z"
}
]
}
FieldMeaning
id + kindIdentify a credential; they stay the same across calls, so results can be compared between runs.
stateACTIVE; SUSPENDED (API keys only); EXPIRED; REVOKED (Git credentials only — pass state=REVOKED to see them).
originCODENOW or EXTERNAL. API keys are always CODENOW.
serviceAccountThe service account (id, username, name, state) — in search results only; the per-account call has it once at the top.
scopesGitLab scopes of an HTTPS token, for example read_repository, write_repository, read_api, api.
fingerprint, keyTypeAn SSH key's fingerprint and type, for example ssh-ed25519.
createdAt, createdByWhen and by whom it was created. createdAt may be missing for EXTERNAL credentials.
expiresAtWhen it stops working; omitted when it never expires.
lastUsedAtLast use — see Last use. Omitted when never used; never present for SSH keys.
revokedAt, revokedByWhen and by whom a Git credential was revoked through CodeNOW.
unverifiedtrue when GitLab couldn't be reached and the Git credential is shown as CodeNOW last recorded it.
  • Fields without a value are omitted, not sent as null — test for a missing key.
  • People are ids only: createdBy and revokedBy are {type, id}, where type is USER or SERVICE_ACCOUNT and id is the CodeNOW username, the service account's username, or codenow for the platform. Resolve names yourself if you need them.
  • Sort order: service account name, kind (API_KEY, GIT_TOKEN, SSH_KEY), credential name, id.
  • GET /service-accounts adds each service account's lifecycle state: ACTIVE, DISABLING, DISABLED, ENABLING or DELETING. Only ACTIVE service accounts can authenticate.

Expiry times​

Git tokens and SSH keys, new API keys and new CI keys stop working at 00:00 UTC on their expiry date, so expiresAt is a midnight time such as 2027-03-01T00:00:00Z. API keys created earlier keep the time they were created with and may show an end-of-day time, for example 2026-12-01T22:59:59.999Z. Compare expiresAt as a timestamp, not as a date string.

Last use​

  • API keys: recorded by CodeNOW, precise to about 5 minutes. Use is recorded only since the account 25.0.5 release — older use isn't known. Until N days have passed since that release, unusedForDays=N lists every API key that hasn't been used since the release, including keys used before it.
  • HTTPS tokens: as reported by GitLab; it can lag by a few minutes.
  • SSH keys: GitLab reports no last use, so there is none.

Warnings and the cap​

The response has a warnings array when the result may be incomplete — always check it. It is omitted when there is nothing to report.

codeMeaningWhat to do
GIT_UNAVAILABLEGitLab couldn't be reached for a service account. The call still succeeds: its Git credentials come from CodeNOW's records with unverified: true. The warning names the serviceAccount. When more than 20 service accounts are affected, a single GIT_UNAVAILABLE warning without serviceAccount gives their number instead (the affected credentials still carry unverified: true).Treat the Git part as possibly stale; run the audit again later.
TRUNCATEDMore than 1000 credentials matched. The first 1000 in sort order are returned.Narrow the search — for example by kind or serviceAccount — and call again.
UNKNOWN_CREDENTIALCredentials this API version can't represent were left out; the message gives their number. The audit never shrinks silently.Report it; check the service account in the CodeNOW UI.

There is no paging. Each warning has a human-readable message:

"warnings": [
{
"code": "GIT_UNAVAILABLE",
"serviceAccount": { "id": "0b6c2f0e-6a43-4c1e-9b7e-2f1d6a0c9e11", "username": "sa-acme_ci", "name": "ci", "state": "ACTIVE" },
"message": "GitLab could not be reached; Git credentials are shown as CodeNOW last recorded them."
}
]

Recipes​

API=https://api.cloud.codenow.com # your installation's API host
audit() {
curl -sf "$API/service-account-credentials?$1" \
-H "X-Codenow-Api-Key: $CODENOW_API_KEY" \
-H "Accept: application/vnd.codenow.v1+json"
}

# Credentials that expire within 14 days
audit 'expiresWithinDays=14' |
jq -r '.credentials[] | [.serviceAccount.username, .kind, .name, .expiresAt] | @tsv'

# API keys and HTTPS tokens not used for 90 days (or never)
audit 'unusedForDays=90' |
jq -r '.credentials[] | [.serviceAccount.username, .kind, .name, (.lastUsedAt // "never")] | @tsv'

# Git credentials created outside CodeNOW
audit 'origin=EXTERNAL' |
jq -r '.credentials[] | [.serviceAccount.username, .kind, .name, (.createdAt // "?")] | @tsv'

# Fail the job when the result may be incomplete
audit 'expiresWithinDays=14' | jq -e '(.warnings // []) | length == 0' > /dev/null \
|| { echo "Audit incomplete: check warnings" >&2; exit 1; }

Through the MCP server​

The CodeNOW MCP server offers the same calls as read-only tools, so an AI assistant can run the audit for you:

ToolCall
service_account_credential_listGET /service-accounts/{idOrUsername}/credentials
service_account_credential_searchGET /service-account-credentials (same filters; list values as arrays)
service_account_list / service_account_getGET /service-accounts, GET /service-accounts/{idOrUsername}

Ask, for example: "Which service-account credentials expire within 14 days? Mention any warnings." The tools act with the permissions of the connected user, so connect as someone who manages the service accounts.

Not included​

  • Per-deployment CI tokens — the tokens CodeNOW issues to deployments (the Deployment tokens line on the service account) are not part of the audit.
  • Deleted API keys — a deleted API key is not kept, so it no longer appears. (Revoked Git credentials are kept as REVOKED.)
  • SSH-key last use — GitLab doesn't report it.
  • A credential deleted directly in GitLab drops out of the result; one created through CodeNOW and revoked there shows as REVOKED. EXTERNAL credentials keep stable ids while they exist.