Skip to content

nuobit/mssql-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

mssql-auth

A minimal CLI proxy and Python library for Microsoft SQL Server queries. Its only job is to inject credentials so they never appear in command history or scripts.

Install

pip install git+https://github.com/NuoBiT/mssql-auth.git

Update:

pip install --upgrade git+https://github.com/NuoBiT/mssql-auth.git

Uninstall:

pip uninstall mssql-auth

CLI usage

mssql-auth --profile <name> '<SQL query>'
    │               │             │
    │               │             └─ SQL query string
    │               └─ profile name → reads ~/.config/mssql-auth/<name>.conf
    └─ connects, executes, returns JSON

Examples

# Simple query
mssql-auth --profile myserver 'SELECT TOP 10 * FROM Customers'

# Filtered query
mssql-auth --profile myserver "SELECT Name, Code FROM Items WHERE Active = 1"

Output is a JSON array of objects (one per row), printed to stdout. Errors go to stderr.

Library usage

from mssql_auth.client import connect

with connect(profile="myserver") as conn:
    cursor = conn.cursor(as_dict=True)
    cursor.execute("SELECT TOP 10 * FROM Customers")
    rows = cursor.fetchall()

The connect context manager returns a standard pymssql connection with credentials injected from the profile. Use it exactly like any pymssql connection.

Configure a profile

One file per server, chmod 600:

mkdir -p ~/.config/mssql-auth
chmod 700 ~/.config/mssql-auth

cat > ~/.config/mssql-auth/myserver.conf << 'CONF'
[mssql]
server=192.168.1.100
port=1433
database=my_database
user=sa
password=your-password
CONF

chmod 600 ~/.config/mssql-auth/myserver.conf

The port key is optional and defaults to 1433.

The tool refuses to run if the config directory or files are accessible by group or others (like ssh does with ~/.ssh/).

Security model

Data Leaves your machine?
MSSQL credentials No — read locally from ~/.config/
SQL queries Yes — sent to MSSQL server
Query results Yes — returned from MSSQL server

The wrapper is like psql reading ~/.pgpass — credentials stay local, only the queries go over the wire.

Prerequisites

  • python3 >= 3.8
  • pymssql (installed automatically as a dependency)

About

Minimal CLI proxy and library for MSSQL queries — injects credentials transparently

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages