|
| 1 | +# Proxy Configuration Guide |
| 2 | + |
| 3 | +This guide explains how to configure the Databricks SQL Connector for Python to work with HTTP/HTTPS proxies, including support for Kerberos authentication. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | +- [Basic Proxy Configuration](#basic-proxy-configuration) |
| 7 | +- [Proxy with Basic Authentication](#proxy-with-basic-authentication) |
| 8 | +- [Proxy with Kerberos Authentication](#proxy-with-kerberos-authentication) |
| 9 | +- [Troubleshooting](#troubleshooting) |
| 10 | + |
| 11 | +## Basic Proxy Configuration |
| 12 | + |
| 13 | +The connector automatically detects proxy settings from environment variables: |
| 14 | + |
| 15 | +```bash |
| 16 | +# For HTTPS connections (most common) |
| 17 | +export HTTPS_PROXY=http://proxy.example.com:8080 |
| 18 | + |
| 19 | +# For HTTP connections |
| 20 | +export HTTP_PROXY=http://proxy.example.com:8080 |
| 21 | + |
| 22 | +# Hosts to bypass proxy |
| 23 | +export NO_PROXY=localhost,127.0.0.1,.internal.company.com |
| 24 | +``` |
| 25 | + |
| 26 | +Then connect normally: |
| 27 | + |
| 28 | +```python |
| 29 | +from databricks import sql |
| 30 | + |
| 31 | +connection = sql.connect( |
| 32 | + server_hostname="your-workspace.databricks.com", |
| 33 | + http_path="/sql/1.0/warehouses/your-warehouse", |
| 34 | + access_token="your-token" |
| 35 | +) |
| 36 | +``` |
| 37 | + |
| 38 | +## Proxy with Basic Authentication |
| 39 | + |
| 40 | +For proxies requiring username/password authentication, include credentials in the proxy URL: |
| 41 | + |
| 42 | +```bash |
| 43 | +export HTTPS_PROXY=http://username:password@proxy.example.com:8080 |
| 44 | +``` |
| 45 | + |
| 46 | +## Proxy with Kerberos Authentication |
| 47 | + |
| 48 | +For enterprise environments using Kerberos authentication on proxies: |
| 49 | + |
| 50 | +### Prerequisites |
| 51 | + |
| 52 | +1. Install Kerberos dependencies: |
| 53 | + ```bash |
| 54 | + pip install databricks-sql-connector[kerberos] |
| 55 | + ``` |
| 56 | + |
| 57 | +2. Obtain a valid Kerberos ticket: |
| 58 | + ```bash |
| 59 | + kinit user@EXAMPLE.COM |
| 60 | + ``` |
| 61 | + |
| 62 | +3. Set proxy environment variables (without credentials): |
| 63 | + ```bash |
| 64 | + export HTTPS_PROXY=http://proxy.example.com:8080 |
| 65 | + ``` |
| 66 | + |
| 67 | +### Connection with Kerberos Proxy |
| 68 | + |
| 69 | +```python |
| 70 | +from databricks import sql |
| 71 | + |
| 72 | +connection = sql.connect( |
| 73 | + server_hostname="your-workspace.databricks.com", |
| 74 | + http_path="/sql/1.0/warehouses/your-warehouse", |
| 75 | + access_token="your-databricks-token", |
| 76 | + |
| 77 | + # Enable Kerberos proxy authentication |
| 78 | + _proxy_auth_type="kerberos", |
| 79 | + |
| 80 | + # Optional Kerberos settings |
| 81 | + _proxy_kerberos_service_name="HTTP", # Default: "HTTP" |
| 82 | + _proxy_kerberos_principal="user@EXAMPLE.COM", # Optional: uses default if not set |
| 83 | + _proxy_kerberos_delegate=False, # Enable credential delegation |
| 84 | + _proxy_kerberos_mutual_auth="REQUIRED" # Options: REQUIRED, OPTIONAL, DISABLED |
| 85 | +) |
| 86 | +``` |
| 87 | + |
| 88 | +### Kerberos Configuration Options |
| 89 | + |
| 90 | +| Parameter | Default | Description | |
| 91 | +|-----------|---------|-------------| |
| 92 | +| `_proxy_auth_type` | None | Set to `"kerberos"` to enable Kerberos proxy auth | |
| 93 | +| `_proxy_kerberos_service_name` | `"HTTP"` | Kerberos service name for the proxy | |
| 94 | +| `_proxy_kerberos_principal` | None | Specific principal to use (uses default if not set) | |
| 95 | +| `_proxy_kerberos_delegate` | `False` | Whether to delegate credentials to the proxy | |
| 96 | +| `_proxy_kerberos_mutual_auth` | `"REQUIRED"` | Mutual authentication requirement level | |
| 97 | + |
| 98 | +### Example: Custom Kerberos Settings |
| 99 | + |
| 100 | +```python |
| 101 | +# Using a specific service principal with delegation |
| 102 | +connection = sql.connect( |
| 103 | + server_hostname="your-workspace.databricks.com", |
| 104 | + http_path="/sql/1.0/warehouses/your-warehouse", |
| 105 | + access_token="your-token", |
| 106 | + |
| 107 | + _proxy_auth_type="kerberos", |
| 108 | + _proxy_kerberos_service_name="HTTP", |
| 109 | + _proxy_kerberos_principal="dbuser@CORP.EXAMPLE.COM", |
| 110 | + _proxy_kerberos_delegate=True, # Allow credential delegation |
| 111 | + _proxy_kerberos_mutual_auth="OPTIONAL" # Less strict verification |
| 112 | +) |
| 113 | +``` |
| 114 | + |
| 115 | +## Troubleshooting |
| 116 | + |
| 117 | +### Kerberos Authentication Issues |
| 118 | + |
| 119 | +1. **No Kerberos ticket**: |
| 120 | + ```bash |
| 121 | + # Check if you have a valid ticket |
| 122 | + klist |
| 123 | + |
| 124 | + # If not, obtain one |
| 125 | + kinit user@EXAMPLE.COM |
| 126 | + ``` |
| 127 | + |
| 128 | +2. **Wrong service principal**: |
| 129 | + - Check with your IT team for the correct proxy service principal name |
| 130 | + - It's typically `HTTP@proxy.example.com` but may vary |
| 131 | + |
| 132 | +3. **Import errors**: |
| 133 | + ``` |
| 134 | + ImportError: Kerberos proxy authentication requires 'pykerberos' |
| 135 | + ``` |
| 136 | + Solution: Install with `pip install databricks-sql-connector[kerberos]` |
| 137 | + |
| 138 | +### Proxy Connection Issues |
| 139 | + |
| 140 | +1. **Enable debug logging**: |
| 141 | + ```python |
| 142 | + import logging |
| 143 | + logging.basicConfig(level=logging.DEBUG) |
| 144 | + ``` |
| 145 | + |
| 146 | +2. **Test proxy connectivity**: |
| 147 | + ```bash |
| 148 | + # Test if proxy is reachable |
| 149 | + curl -x http://proxy.example.com:8080 https://www.databricks.com |
| 150 | + ``` |
| 151 | + |
| 152 | +3. **Verify environment variables**: |
| 153 | + ```python |
| 154 | + import os |
| 155 | + print(f"HTTPS_PROXY: {os.environ.get('HTTPS_PROXY')}") |
| 156 | + print(f"NO_PROXY: {os.environ.get('NO_PROXY')}") |
| 157 | + ``` |
| 158 | + |
| 159 | +### Platform-Specific Notes |
| 160 | + |
| 161 | +- **Linux/Mac**: Uses `pykerberos` library |
| 162 | +- **Windows**: Uses `winkerberos` library (automatically selected) |
| 163 | +- **Docker/Containers**: Ensure Kerberos configuration files are mounted |
| 164 | + |
| 165 | +## Security Considerations |
| 166 | + |
| 167 | +1. **Avoid hardcoding credentials** - Use environment variables or secure credential stores |
| 168 | +2. **Use HTTPS connections** - Even through proxies, maintain encrypted connections to Databricks |
| 169 | +3. **Credential delegation** - Only enable `_proxy_kerberos_delegate=True` if required by your proxy |
| 170 | +4. **Mutual authentication** - Keep `_proxy_kerberos_mutual_auth="REQUIRED"` for maximum security |
| 171 | + |
| 172 | +## See Also |
| 173 | + |
| 174 | +- [Kerberos Proxy Example](../examples/kerberos_proxy_auth.py) |
| 175 | +- [Databricks SQL Connector Documentation](https://docs.databricks.com/dev-tools/python-sql-connector.html) |
0 commit comments