Skip to main content

Snowflake Key Pair Rotation Tool for Hevo Data destinations

Project description

Snowflake Key Pair Rotation Tool

Python 3.8+ License: MIT

Automates Snowflake key-pair authentication setup and rotation with Hevo Data destinations.

Installation

From GitHub (Recommended)

pip install git+https://github.com/Legolasan/sf_rotation.git

From Source

git clone https://github.com/Legolasan/sf_rotation.git
cd sf_rotation
pip install .

Development Mode

git clone https://github.com/Legolasan/sf_rotation.git
cd sf_rotation
pip install -e .

Configuration

  1. Create a config file based on the example:
mkdir -p config
curl -o config/config.yaml https://raw.githubusercontent.com/Legolasan/sf_rotation/main/config/config.yaml.example
  1. Edit config/config.yaml with your credentials:
  • Snowflake account URL, admin credentials, target user
  • Hevo API credentials and destination details
  • Key encryption preferences

Usage

Command Line Interface

After installation, the sf-rotation command is available:

# Initial setup
sf-rotation setup --config config/config.yaml

# Key rotation
sf-rotation rotate --config config/config.yaml

# With encrypted private key
sf-rotation setup --config config/config.yaml --encrypted

As Python Module

python -m sf_rotation setup --config config/config.yaml
python -m sf_rotation rotate --config config/config.yaml

Programmatic Usage

from sf_rotation import KeyGenerator, SnowflakeClient, HevoClient

# Generate keys
generator = KeyGenerator(output_directory="./keys")
private_key_path, public_key_path = generator.generate_key_pair(
    key_name="rsa_key",
    encrypted=False
)

# Connect to Snowflake
sf_client = SnowflakeClient(
    account_url="your_account.snowflakecomputing.com",
    username="admin",
    password="password"
)

# Set public key for user
public_key = generator.read_public_key(public_key_path)
formatted_key = generator.format_public_key_for_snowflake(public_key)
sf_client.set_rsa_public_key("target_user", formatted_key)

# Create Hevo destination
hevo = HevoClient(
    base_url="https://us.hevodata.com",
    username="hevo_user",
    password="hevo_pass"
)
private_key = generator.read_private_key(private_key_path)
hevo.create_destination(
    name="my_snowflake",
    account_url="your_account.snowflakecomputing.com",
    warehouse="WAREHOUSE",
    database_name="DATABASE",
    database_user="target_user",
    private_key=private_key
)

Features

  • Generate RSA 2048-bit key pairs (encrypted or non-encrypted)
  • Configure Snowflake users with RSA public keys
  • Create/update Hevo Data destinations with key-pair authentication
  • Seamless key rotation with automatic backup
  • CLI and programmatic interfaces

Process Flow

Setup Mode

  1. Generate RSA key pair
  2. Connect to Snowflake (username/password)
  3. Set RSA_PUBLIC_KEY for target user
  4. Create Hevo destination with private key
  5. Save destination ID

Rotate Mode

  1. Backup existing keys
  2. Generate new key pair
  3. Set RSA_PUBLIC_KEY_2 in Snowflake
  4. Update Hevo destination with new private key
  5. Unset old RSA_PUBLIC_KEY

Project Structure

sf_rotation/
├── src/sf_rotation/
│   ├── __init__.py           # Package exports
│   ├── main.py               # CLI entry point
│   ├── key_generator.py      # OpenSSL key generation
│   ├── snowflake_client.py   # Snowflake connection/key management
│   ├── hevo_client.py        # Hevo API client
│   └── utils.py              # Helper functions
├── config/
│   └── config.yaml.example   # Configuration template
├── pyproject.toml            # Package configuration
├── README.md
└── WORKFLOW.md               # Detailed workflow documentation

Requirements

  • Python 3.8+
  • OpenSSL (for key generation)
  • Snowflake account with admin access
  • Hevo Data account with API access

Security Notes

  • Private keys are stored with 600 permissions
  • Keys directory is gitignored
  • Config files with credentials are gitignored
  • Passphrase prompted at runtime (not stored in config)

License

MIT License - see LICENSE file for details.

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

sf_rotation-1.0.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

sf_rotation-1.0.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file sf_rotation-1.0.0.tar.gz.

File metadata

  • Download URL: sf_rotation-1.0.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for sf_rotation-1.0.0.tar.gz
Algorithm Hash digest
SHA256 07340d7baba7b8b20fc7eab39ac8daa5d90387d3f71c3e46c470278073d71ebd
MD5 0d3ed0052f3b02faa67c0619d032cb59
BLAKE2b-256 79f0a3dd09a69b2ff149b67a2dd3fd374da25871995adb1553d1ab69625c4a31

See more details on using hashes here.

File details

Details for the file sf_rotation-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sf_rotation-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for sf_rotation-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 482aba8fb2d3a4b1e016e7531be745550360f6cff23dfe0605acf2e218f48801
MD5 824c2583976b7e4d5277ad97da26fddc
BLAKE2b-256 7be8a10756bac2f832841aaecc2bbc45716a2d196d5e4b1ac6200c01950c914f

See more details on using hashes here.

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