Workspaces

API key rules

With API key rules, you can enforce API key rotation across a workspace by setting a maximum permitted age for keys. Keys older than the specified age are invalidated for authentication, and can be automatically rotated.

Users and service accounts have different risk profiles and operational needs. With Cloudsmith, you can configure separate API key rules for each.

Note

API key rules are available for Ultra and Enterprise plans.

Note

API key rules are disabled by default.

How it works

Workspace owners and managers can configure separate API key rules for users and service accounts via the Cloudsmith web app, API, or Terraform provider.

Each rule applies to either user accounts or service accounts and has the following configurable settings:

SettingDescription
Max age (hours)The maximum permitted age of an account's API key. The minimum value this can be set to is 24.
Auto-rotateSet to On to automatically rotate API keys that exceed the maximum age specified by the rule. This rotates API keys of all accounts (member, manager, owner, and service) that violate the rule, except for collaborators.

Important

Automatically rotating all API keys may take up to 60 minutes.

Once a rule is enabled, permission is revoked for any API key older than the specified maximum age. This applies to all accounts of that type associated with the workspace. If an account attempts to use an API key that violates the rules, they receive a Permission denied error message.

To regain access, users should update their API key by clicking the Rotate API key icon on the API settings page. For service accounts, manually rotate the service API key to get a replacement, then update any automation that uses it.

Members of multiple workspaces

If a user or service account is a member of multiple workspaces, their permissions are revoked only for the workspace where the API key rules are enforced and their API key violates the rules. Their permissions in all other workspaces are unaffected.

However, if the account is a member of a workspace which also has Auto-rotate enabled for a rule, their API key is rotated across all of their workspaces.

Notifications

When an API key is approaching the maximum age configured, the user or service account creator receives a notification at least 24 hours in advance. This notification is sent via email and also appears as a notification when they log into the application.

Additionally, users receive an email and UI notification when their API key has expired.

If the API rules are enabled with Auto-rotate, users also receive an email notification when their API key has been rotated. This email includes details about the user who initiated the rotation.

For service accounts, the creator of the service account receives an email notification informing them of the upcoming expiration of the service's API key. The email also provides a URL that the user can use to rotate the API key. Additionally, when the creator logs into the application's user interface, they receive a warning message.

If a service account has been created by another service account, no email notification is sent for an upcoming API key expiration. In this scenario, with API key rules enabled, you can use the Get a list of all services within a workspace REST API call to retrieve your services, and find each respective key expiry in the key_expires_at field.

Audit logs

All actions and notifications related to API key rules are recorded in the audit logs.

Audit log entries for service account API key rules have an Object value of service-policy. Entries for user account API key rules have Object: user-policy.

If a user or service account is a member of multiple workspaces, the user who enforces an API key rotation is only visible as the initiator within the workspace where they hold the ownership role. In other workspaces where the user is a member, the API key rotation action is still recorded in the audit logs, but the user who enforced the rotation is obscured and the action is listed as a "Rotated API key" rather than an "Enforced API key rotation."

Configure API key rules via the web app

In the Cloudsmith web app, go to the workspace Settings tab and click API key rules.

Enable API key rules

  1. Click the toggle for a rule to set it to Enabled.
  2. Configure the Max age and Auto-rotate settings.
  3. Click Update rules to save your changes.

Disable API key rules

To disable an API key rule, click the toggle for the rule you want to disable and then click Update rules to save your changes.

Once disabled, restrictions to API keys that previously violated the rules are lifted and these keys become operational again.

Rotate API keys immediately

API key rotation

Rotating an API key is irreversible.

To immediately rotate all API keys that exceed the maximum age specified, enable Auto-rotate and click Rotate keys now for the relevant rule.

Configure API key rules via the API

You can configure and manage API key rules for a workspace by using the following endpoints:

Configure API key rules via the Terraform provider

You can configure and manage API key rules for a workspace by using the cloudsmith_api_key_rule resource in the Cloudsmith Terraform provider.

For usage details, see cloudsmith_api_key_rule (Resource) in the Terraform registry documentation.