# Critical Environment Variables for Secure OpenStack MCP Server Connections

> Discover the five critical environment variables for secure OpenStack MCP server connections. Learn what's needed for encrypted, authenticated access to OpenStack Keystone.

- Repository: [JungJungIn/mcp-openstack-ops](https://github.com/call518/mcp-openstack-ops)
- Tags: best-practices
- Published: 2026-02-26

---

**The MCP OpenStack server requires five mandatory environment variables—`OS_PROJECT_NAME`, `OS_USERNAME`, `OS_PASSWORD`, `OS_AUTH_HOST`, and `OS_AUTH_PORT`—plus `OS_AUTH_PROTOCOL=https` and optionally `OS_CACERT` to establish encrypted, authenticated connections to OpenStack Keystone.**

The `call518/mcp-openstack-ops` repository implements a Model Context Protocol (MCP) server that proxies operations to OpenStack clouds. To establish a secure connection, the server relies entirely on environment variables parsed during initialization in [`src/mcp_openstack_ops/connection.py`](https://github.com/call518/mcp-openstack-ops/blob/main/src/mcp_openstack_ops/connection.py).

## Required Environment Variables for OpenStack Authentication

The `get_openstack_connection()` function (lines 44‑46) enforces a minimal set of required variables. If any are missing, the server aborts with a `Missing required OpenStack environment variables` error.

### Core Authentication Credentials

- **`OS_USERNAME`**: The Keystone username for authentication.
- **`OS_PASSWORD`**: The corresponding password credential.

These values are passed directly to the OpenStack SDK's `connection.Connection` constructor.

### Project Scoping

- **`OS_PROJECT_NAME`**: Scopes every operation to a specific tenant. The server uses this to validate resource ownership via `conn.auth.get('project_id')` and the `validate_resource_ownership()` helper (lines 78‑129). Without this variable, the server refuses to start.

### Keystone Endpoint Configuration

- **`OS_AUTH_HOST`**: Hostname or IP address of the Keystone server.
- **`OS_AUTH_PORT`**: Port on which Keystone listens (typically 5000).

These construct the `auth_url` parameter as `{protocol}://{host}:{port}`.

## Security-Critical Variables for TLS Encryption

Beyond authentication, two additional variables control transport-layer security. According to the source code analysis, these are critical for production deployments.

### Enabling HTTPS with OS_AUTH_PROTOCOL

- **`OS_AUTH_PROTOCOL`**: Set to `https` to enforce TLS encryption. When omitted, the default is `http` (insecure). This is read at line 57 and validated at lines 57‑63.

### Certificate Verification with OS_CACERT

- **`OS_CACERT`**: Path to a CA certificate file. When `OS_AUTH_PROTOCOL=https` and this variable is present, the client verifies the server's certificate. If absent while using HTTPS, SSL verification is disabled and a warning is emitted (lines 68‑76). For secure connections, always provide a valid CA bundle.

## Optional Service Endpoint Overrides

The MCP server can reach individual OpenStack services through configurable ports. These are read at lines 81‑89 and inserted into endpoint URLs passed to the SDK:

- `OS_COMPUTE_PORT` (default 8774)
- `OS_NETWORK_PORT` (default 9696)
- `OS_VOLUME_PORT` (default 8776)
- `OS_IMAGE_PORT` (default 9292)
- `OS_PLACEMENT_PORT` (default 8780)
- `OS_HEAT_STACK_PORT` (default 8004)

These variables are not required for basic connectivity but become essential in non-standard deployments using custom ports.

## Configuration Examples

### Minimal Secure .env Configuration

Create a `.env` file based on the repository's `.env.example`:

```text

# Required authentication

OS_PROJECT_NAME=myproject
OS_USERNAME=admin
OS_PASSWORD=SuperSecret123
OS_AUTH_HOST=openstack.example.com
OS_AUTH_PORT=5000

# Security-critical TLS settings

OS_AUTH_PROTOCOL=https
OS_CACERT=/etc/ssl/certs/openstack-ca.pem

```

The repository provides this template at `.env.example` (lines 27‑57).

### Python Connection Implementation

The following mirrors the internal logic of `get_openstack_connection()`:

```python
import os
from pathlib import Path
from dotenv import load_dotenv
from openstack import connection

# Load environment variables

load_dotenv(Path.cwd() / ".env")

# Construct secure connection

conn = connection.Connection(
    auth_url=f"{os.getenv('OS_AUTH_PROTOCOL', 'http')}://{os.getenv('OS_AUTH_HOST')}:{os.getenv('OS_AUTH_PORT')}",
    verify=os.getenv('OS_CACERT') if os.getenv('OS_CACERT') else (os.getenv('OS_AUTH_PROTOCOL') == 'https'),
    project_name=os.getenv('OS_PROJECT_NAME'),
    username=os.getenv('OS_USERNAME'),
    password=os.getenv('OS_PASSWORD'),
    user_domain_name=os.getenv('OS_USER_DOMAIN_NAME', 'Default'),
    project_domain_name=os.getenv('OS_PROJECT_DOMAIN_NAME', 'Default'),
    region_name=os.getenv('OS_REGION_NAME', 'RegionOne'),
    identity_api_version=os.getenv('OS_IDENTITY_API_VERSION', '3'),
    interface="internal",
    compute_endpoint=f"{os.getenv('OS_AUTH_PROTOCOL', 'http')}://{os.getenv('OS_AUTH_HOST')}:{os.getenv('OS_COMPUTE_PORT', '8774')}/v2.1",
    network_endpoint=f"{os.getenv('OS_AUTH_PROTOCOL', 'http')}://{os.getenv('OS_AUTH_HOST')}:{os.getenv('OS_NETWORK_PORT', '9696')}/v2.0",
    volume_endpoint=f"{os.getenv('OS_AUTH_PROTOCOL', 'http')}://{os.getenv('OS_AUTH_HOST')}:{os.getenv('OS_VOLUME_PORT', '8776')}/v3",
    image_endpoint=f"{os.getenv('OS_AUTH_PROTOCOL', 'http')}://{os.getenv('OS_AUTH_HOST')}:{os.getenv('OS_IMAGE_PORT', '9292')}/v2",
    placement_endpoint=f"{os.getenv('OS_AUTH_PROTOCOL', 'http')}://{os.getenv('OS_AUTH_HOST')}:{os.getenv('OS_PLACEMENT_PORT', '8780')}",
    heat_stack_endpoint=f"{os.getenv('OS_AUTH_PROTOCOL', 'http')}://{os.getenv('OS_AUTH_HOST')}:{os.getenv('OS_HEAT_STACK_PORT', '8004')}/v1",
)

# Verify authentication

token = conn.identity.get_token()
print(f"Authenticated successfully. Token: {token[:20]}...")

```

This implementation demonstrates how the MCP server uses environment variables to establish secure, project-scoped connections to OpenStack services.

## Summary

- **Five mandatory variables** (`OS_PROJECT_NAME`, `OS_USERNAME`, `OS_PASSWORD`, `OS_AUTH_HOST`, `OS_AUTH_PORT`) are required for the MCP server to initialize; missing any causes immediate abort with `Missing required OpenStack environment variables`.
- **TLS encryption** requires `OS_AUTH_PROTOCOL=https` combined with `OS_CACERT` to enable certificate verification and prevent credential exposure; without `OS_CACERT`, SSL verification is disabled when using HTTPS.
- **Project isolation** is enforced through `OS_PROJECT_NAME`, which the server uses to validate resource ownership via `validate_resource_ownership()` in [`src/mcp_openstack_ops/connection.py`](https://github.com/call518/mcp-openstack-ops/blob/main/src/mcp_openstack_ops/connection.py).
- **Service ports** can be customized via optional variables (`OS_COMPUTE_PORT`, `OS_NETWORK_PORT`, etc.) for non-standard deployments, processed at lines 81‑89 of the connection module.

## Frequently Asked Questions

### What happens if OS_PROJECT_NAME is missing?

The MCP server aborts startup with a `Missing required OpenStack environment variables` error. According to the source code in [`src/mcp_openstack_ops/connection.py`](https://github.com/call518/mcp-openstack-ops/blob/main/src/mcp_openstack_ops/connection.py) (lines 44‑46), `OS_PROJECT_NAME` is mandatory because the server uses it to scope all operations and validate resource ownership through the `validate_resource_ownership()` helper (lines 78‑129).

### Is OS_CACERT required when using HTTPS?

No, but it is strongly recommended for production security. When `OS_AUTH_PROTOCOL=https` is set but `OS_CACERT` is omitted, the MCP server disables SSL verification and emits a warning (lines 68‑76 in [`connection.py`](https://github.com/call518/mcp-openstack-ops/blob/main/connection.py)). This leaves the connection vulnerable to man-in-the-middle attacks. For secure connections, always provide a valid CA certificate path via `OS_CACERT`.

### Can I use HTTP instead of HTTPS?

Yes, but it is insecure and not recommended for production. If `OS_AUTH_PROTOCOL` is unset or explicitly set to `http`, the MCP server constructs an unencrypted `auth_url`. While this works for testing, it exposes credentials in plaintext. The source code defaults to `http` only when the variable is absent (line 57), so explicit configuration of `https` is required for encrypted connections.

### Where are these variables validated in the codebase?

Environment variables are validated in [`src/mcp_openstack_ops/connection.py`](https://github.com/call518/mcp-openstack-ops/blob/main/src/mcp_openstack_ops/connection.py) within the `get_openstack_connection()` function. Required variables are checked at lines 44‑46, protocol validation occurs at lines 57‑63, and TLS verification settings are handled at lines 68‑76. Optional service port variables are processed at lines 81‑89. The `.env.example` file in the repository root provides a documented template for all supported variables.