AI

Secure Ollama instances with cnspec

Scan Ollama instances for exposure, authentication, and model inventory with cnspec.

Scan an Ollama instance to find out who can reach it and what it serves. cnspec queries the Ollama API to inventory the installed and running models, and it checks the instance for exposure: whether the connection is encrypted, whether the API is reachable beyond the local machine, whether unauthenticated callers can read or write models, and whether any web page can reach the instance through a visitor's browser.

cnspec works against both a local Ollama server and Ollama Cloud.

Ollama 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 Ollama instance with cnspec, you must have:

Only scan Ollama instances you are authorized to assess. The scan sends HTTP requests to the instance.

Connect to an Ollama instance

Without any flags, cnspec connects to Ollama at http://localhost:11434. To test access to a local instance, open a cnspec shell:

cnspec shell ollama

To connect to an instance on another host, pass its address with --host:

cnspec shell ollama --host http://ollama.lunalectric.com:11434

You can also set the OLLAMA_HOST environment variable to omit the --host flag.

To authenticate against a cloud-hosted Ollama instance, pass an API token with --token, or set the OLLAMA_API_TOKEN environment variable:

export OLLAMA_API_TOKEN='YOUR_API_TOKEN'
cnspec shell ollama

Verify the connection by asking for the server version:

cnspec> ollama { host version }

Connection options

OptionDescription
--hostOllama host address. Defaults to OLLAMA_HOST, or http://localhost:11434
--tokenOllama API token for cloud authentication. Defaults to the OLLAMA_API_TOKEN value

Scan an Ollama instance

To scan an Ollama instance:

cnspec scan ollama --host http://ollama.lunalectric.com:11434

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.

You can write your own policies to check your Ollama instances against the controls that matter to your organization.

Explore an Ollama instance

Run cnspec shell ollama --host http://ollama.lunalectric.com:11434 to open the interactive shell.

Review the exposure summary

cnspec> ollama {
    version
    tls
    isLocal
    authenticationRequired
    writeAuthenticationRequired
    corsAllowsAnyOrigin
    dnsRebindingProtected
    cloudEnabled
}

List installed models

cnspec> ollama.models { name family parameterSize quantizationLevel license }

List models loaded in memory

cnspec> ollama.runningModels { name sizeVram expiresAt }

Example security checks

Ensure the connection uses TLS

cnspec> ollama.tls == true

Ensure the API rejects unauthenticated reads and writes

cnspec> ollama.authenticationRequired == true
cnspec> ollama.writeAuthenticationRequired == true

Ensure the API does not accept requests from any web origin

cnspec> ollama.corsAllowsAnyOrigin != true

Ensure only approved model families are installed

cnspec> ollama.models.all(family.in(["llama", "gemma", "qwen2"]))

Learn more

On this page