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:
- cnspec installed on your workstation
- An Ollama instance you are authorized to scan, reachable over HTTP or HTTPS
- An Ollama API token, if you scan Ollama Cloud
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 ollamaTo connect to an instance on another host, pass its address with --host:
cnspec shell ollama --host http://ollama.lunalectric.com:11434You 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 ollamaVerify the connection by asking for the server version:
cnspec> ollama { host version }Connection options
| Option | Description |
|---|---|
--host | Ollama host address. Defaults to OLLAMA_HOST, or http://localhost:11434 |
--token | Ollama 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:11434When 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 == trueEnsure the API rejects unauthenticated reads and writes
cnspec> ollama.authenticationRequired == true
cnspec> ollama.writeAuthenticationRequired == trueEnsure the API does not accept requests from any web origin
cnspec> ollama.corsAllowsAnyOrigin != trueEnsure only approved model families are installed
cnspec> ollama.models.all(family.in(["llama", "gemma", "qwen2"]))Learn more
-
To learn more about how the MQL query language works, read Write Effective MQL.
-
To learn about all the Ollama resources and properties you can query, read the Mondoo Ollama Resource Pack Reference.