AI

Secure OpenAI organizations with cnspec

Scan OpenAI organizations, projects, and API keys against security best practices with cnspec.

Scan your OpenAI organization to review who has access, how API keys and service accounts are managed, and how uploaded data is governed. cnspec queries the OpenAI API to evaluate organization users and invites, projects and their API keys, service accounts, files, vector stores, and audit log visibility.

OpenAI is one of the AI targets cnspec can assess. For the full list, see the AI infrastructure overview. New to cnspec? Start with the quickstart.

Prerequisites

To scan an OpenAI organization with cnspec, you must have:

Organization resources such as users, invites, audit logs, project API keys, and service accounts require an admin API key.

Connect to OpenAI

Pass an API key with --token. cnspec accepts both project keys and admin keys and detects the key type automatically:

cnspec shell openai --token YOUR_ADMIN_API_KEY

You can also set the OPENAI_API_KEY environment variable to omit the --token flag:

export OPENAI_API_KEY='YOUR_ADMIN_API_KEY'
cnspec shell openai

Some queries need one credential for an object and the other for its governance, such as which projects a fine tuning checkpoint is shared into. To reach them, pass a project key with --token and an admin key with --admin-token (or the OPENAI_ADMIN_KEY environment variable):

cnspec shell openai --token YOUR_PROJECT_API_KEY --admin-token YOUR_ADMIN_API_KEY

Verify the connection by listing your projects:

cnspec> openai.projects { name status }

Connection options

OptionDescription
--tokenOpenAI API key, either a project key (sk-proj-...) or an admin key (sk-admin-...). Defaults to OPENAI_API_KEY
--admin-tokenOpenAI admin API key to use alongside --token. Defaults to OPENAI_ADMIN_KEY
--organizationOpenAI organization ID. Defaults to OPENAI_ORG_ID
--projectOpenAI project ID. Defaults to OPENAI_PROJECT_ID
--base-urlOpenAI API base URL for custom endpoints. Defaults to OPENAI_BASE_URL

Scan an OpenAI organization

To scan your OpenAI organization:

cnspec scan openai --token YOUR_ADMIN_API_KEY

When the scan completes, cnspec prints a pass or fail result for each check and an overall risk score. To output results in other formats such as JSON, JUnit, or SARIF, read Report Results.

Scan with the Mondoo OpenAI Security policy

Mondoo maintains an out of the box Mondoo OpenAI Security policy that checks organization owner count, pending owner invites, service account roles, API keys in archived projects, project API key rotation, vector store expiration, and audit log access. Several of its checks require an admin API key.

Mondoo Platform users: Enable the policy in your space. In the Mondoo App, go to Findings > Policies, search for "OpenAI", and add the policy. All future scans of your OpenAI organization automatically evaluate against it. To learn more, read Manage policies in Mondoo Platform.

Open source users: Pass the policy bundle URL directly to cnspec:

cnspec scan openai --token YOUR_ADMIN_API_KEY \
  --policy-bundle https://raw.githubusercontent.com/mondoohq/cnspec/refs/heads/main/content/mondoo-openai-security.mql.yaml

You can also create your own policies to meet your specific requirements.

Explore an OpenAI organization

Run cnspec shell openai --token YOUR_ADMIN_API_KEY to open the interactive shell.

List organization users and their roles

cnspec> openai.users { name email role }

Review project API keys

cnspec> openai.projects { name apiKeys { name ownerType createdAt lastUsedAt } }

Review project service accounts

cnspec> openai.projects { name serviceAccounts { name role } }

Example security checks

Ensure no more than three organization owners

cnspec> openai.users.where(role == "owner").length <= 3

Ensure no pending invitations grant owner access

cnspec> openai.invites.where(status == "pending" && role == "owner").length == 0

Ensure project service accounts do not hold the owner role

cnspec> openai.projects.all(serviceAccounts.all(role != "owner"))

Ensure archived projects do not retain active API keys

cnspec> openai.projects.where(status == "archived").all(apiKeys.length == 0)

Ensure vector stores have an expiration policy

cnspec> openai.vectorStores.all(expiresAt != empty)

Learn more

On this page