Skip to main content

SingleStore IAM authentication library for cloud providers

Project description

SingleStore Auth IAM - Python Client Library

A Python client library for getting JWTs from SingleStore's IAM service when running in cloud environments (AWS, GCP, Azure).

Installation

pip install singlestore-auth-iam

Quick Start

import asyncio
from s2iam import get_jwt_database

async def main():
        # Get a JWT for database access
    jwt = await get_jwt_database("your-workspace-group-id")
    print(f"JWT: {jwt}")

    # Or without workspace group ID
    jwt = await get_jwt_database()
    print(f"JWT: {jwt}")

if __name__ == "__main__":
    asyncio.run(main())

For API gateway access:

import asyncio
from s2iam import get_jwt_api

async def main():
    # Get a JWT for API gateway access
    jwt = await get_jwt_api()
    print(f"JWT: {jwt}")

if __name__ == "__main__":
    asyncio.run(main())

That's it! The library automatically detects your cloud environment and gets the appropriate JWT.

Configuration

Environment Variables

  • S2IAM_SERVER_URL: Custom authentication server URL (default: https://auth.singlestore.com)
  • S2IAM_DEBUGGING: Set to "true" to enable debug logging

Supported Environments

The library automatically detects and works in:

  • AWS: EC2 instances, Lambda functions, ECS tasks
  • Google Cloud: Compute Engine, Cloud Functions, Cloud Run
  • Azure: Virtual Machines, Functions, Container Instances

Error Handling

from s2iam import get_jwt_database, CloudProviderNotFound

try:
    jwt = await get_jwt_database("workspace-id")
except CloudProviderNotFound:
    print("Not running in a supported cloud environment")

Configuration

Workspace Group ID

The workspace_group_id parameter is optional for get_jwt_database(). When provided, it scopes the JWT to a specific workspace group. When omitted (or None), the JWT may have broader access depending on your SingleStore configuration.

Environment Variables

  • S2IAM_DEBUGGING: Set to "true" to enable debug logging
  • S2IAM_SERVER_URL: Custom authentication server URL (default: https://auth.singlestore.com)

Provider-Specific Configuration

AWS

  • Uses standard AWS SDK configuration (AWS_REGION, AWS_PROFILE, etc.)
  • Supports IAM roles, EC2 instance profiles, and Lambda execution roles

GCP

  • Uses Application Default Credentials (ADC)
  • Supports service account impersonation via GCE_METADATA_HOST

Azure

  • Uses Azure SDK configuration
  • Supports managed identities and service principals

API Reference

Core Functions

detect_provider(timeout=5.0, logger=None, clients=None)

Automatically detect which cloud provider the application is running on.

Parameters:

  • timeout (float): Detection timeout in seconds
  • logger (Logger): Custom logger instance
  • clients (List[CloudProviderClient]): Custom list of provider clients

Returns: CloudProviderClient

get_jwt(jwt_type, workspace_group_id=None, server_url=None, **kwargs)

Get a JWT from SingleStore's authentication service.

Parameters:

  • jwt_type (JWTType): Type of JWT to request
  • workspace_group_id (str): Workspace group ID
  • server_url (str): Authentication server URL
  • **kwargs: Additional provider-specific parameters

Returns: str (JWT)

Cloud Provider Clients

All provider clients implement the CloudProviderClient interface:

Methods

  • detect(): Test if running on this cloud provider
  • get_type(): Get the provider type
  • assume_role(role_identifier): Assume a different role/identity
  • get_identity_headers(additional_params=None): Get authentication headers

Models

CloudIdentity

Represents verified identity information:

@dataclass
class CloudIdentity:
    provider: CloudProviderType
    identifier: str
    account_id: str
    region: str
    resource_type: str
    additional_claims: Dict[str, str]

CloudProviderType

Enum of supported cloud providers:

  • AWS
  • GCP
  • AZURE

JWTType

Enum of JWT types:

  • DATABASE_ACCESS
  • API_GATEWAY_ACCESS

Error Handling

The library defines several specific exceptions:

  • CloudProviderNotFound: No cloud provider could be detected
  • ProviderNotDetected: Provider not detected, call detect() first
  • ProviderIdentityUnavailable: Provider detected but no identity available
  • AssumeRoleNotSupported: Assume role not supported by provider

Development

Testing

Tests use the Go test server (s2iam_test_server) started with the new --info-file flag for deterministic startup (no stdout JSON parsing). Async tests require pytest-asyncio which is part of the dev extras.

# Install with dev dependencies
pip install -e .[dev]

# Run full test suite (cloud‑dependent tests skip outside cloud VMs)
pytest

# Coverage
pytest --cov=s2iam --cov-report=html

# Example: Just integration tests
pytest -k integration

Manual server run example (atomic startup):

go build -o s2iam_test_server ../go/cmd/s2iam_test_server
tmpfile=$(mktemp)
./s2iam_test_server --port=0 --info-file "$tmpfile" --shutdown-on-stdin-close &
while [ ! -s "$tmpfile" ]; do sleep 0.05; done
jq . "$tmpfile"

Code Quality

# Format
black src tests
isort src tests

# Static checks
flake8 src tests
mypy src

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for your changes
  5. Run the test suite
  6. Submit a pull request

Support

For issues and questions, please use the GitHub Issues page.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

singlestore_auth_iam-0.5.0.tar.gz (40.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

singlestore_auth_iam-0.5.0-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

Details for the file singlestore_auth_iam-0.5.0.tar.gz.

File metadata

  • Download URL: singlestore_auth_iam-0.5.0.tar.gz
  • Upload date:
  • Size: 40.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for singlestore_auth_iam-0.5.0.tar.gz
Algorithm Hash digest
SHA256 bb33fb9297262ccf33a33d8cfcd35fbf19f3ac366f0546a34c2c2afd6f0e1e37
MD5 020cb0d59b029a80066f9dfbc589b589
BLAKE2b-256 7567a3c7bb3b81d6e030c2b5f63d7ca332dec81da55be776f4aed9a2ff0257e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for singlestore_auth_iam-0.5.0.tar.gz:

Publisher: publish-pypi.yml on singlestore-labs/singlestore-auth-iam

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file singlestore_auth_iam-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for singlestore_auth_iam-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3034603ecb8f270b0eee8cf16738652c7fde9c2fc9b06437b4b6c78e37743907
MD5 5160ee646514f535aaf44d89757ecdd7
BLAKE2b-256 752ab13c39d4308ae8ea9756156f3c80f14635a9d5f4e6b795f93560588c8111

See more details on using hashes here.

Provenance

The following attestation bundles were made for singlestore_auth_iam-0.5.0-py3-none-any.whl:

Publisher: publish-pypi.yml on singlestore-labs/singlestore-auth-iam

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page