Skip to main content

Command line utility to tunnel a PostgreSQL connection

Project description

========
Gotthard
========
Gotthard is a command line tool to simplify connecting to a PostgreSQL instance via a bastion_ host.
This tool is created in the context of zalando-stups_, however it could be used without it.

.. contents::
:local:
:depth: 2

Installation
============

.. code-block:: bash

$ sudo pip3 install --upgrade gotthard

Configuration
=============
Gotthard does not have its own configuration. It uses the `piu configuration`_ file.

Usage
=====
Gotthard can provide help with the commands itself:

.. code-block:: bash

$ gotthard --help

Gotthard can run in two basic modes: in the foreground and in the background.

When running in the background, gotthard establishes a tunnel and keeps the tunnel running in the background.

.. code-block:: bash

$ gotthard shipping.logistics.db.example.com

When running in the foreground, the tunnel is established and the command you specify is executed.
Once your command finishes, the tunnel is closed. If you need to pass options to the command, you
will have to add the ``--`` to signify that the following options should not be interpreted by gotthard.

.. code-block:: bash

$ gotthard shipping.logistics.db.example.com psql
$ gotthard shipping.logistics.db.example.com -- psql -U myusername

Stups: Requesting access to odd
-------------------------------
When using even & odd, the command will only succeed if you have been granted access to the odd host you are
trying to connect to. You can request access manually, but you can also have gotthard take care of this. When
specifying a reason, gotthard will actually execute a ``piu request-access`` for you.

.. code-block:: bash

$ gotthard shipping.logistics.db.example.com --reason="Investigating INCIDENT-123" psql

Connecting to a local Spilo
---------------------------
If you want to connect to a Spilo_ that is running in the same network as your odd-host, you can use
the name of the Spilo appliance to connect.
This does however require you to be logged in to your AWS account, as we need to query your account.

.. code-block:: bash

$ gotthard shippinglogistics psql

How does it actually work
================
The way Gotthard works is by setting up an ssh tunnel to the bastion host.
It chooses the local port specified a free local port to tunnel the requests to remote side to port 5432.

When running in the background, it's task is done: It will report back the details of the tunnel.

When running in the foregroed, Gotthard will export the PostgreSQL related `Environment Variables`_ to the process
it needs to run. Most PostgreSQL client tools will use these environment variables to connect, most of your python or
perl scripts should adhere to these variables as well.

.. code-block:: bash

$ gotthard shippinglogistics env | grep PG
PGUSER=username
PGHOST=localhost
PGDATABASE=postgres
PGPORT=52296
PGSSLMODE=require

Examples
========

Export a database
-----------------

.. code-block:: bash

$ gotthard shipping.logistics.db.example.com --reason="FEATURE-123" -- pg_dump -d fancydb -Fc -f fancydb.dump

Get the size of an RDS database
-------------------------------

.. code-block:: bash

$ query="SELECT pg_database_size(CURRENT_CATALOG)"
$ gotthard example.us-west-2.rds.amazonaws.com -- psql -U rds_admin -d featuredb -c "$query"

Duplicate a Spilo database to your machine
------------------------------------------
This actually requires you to have replication privileges.

.. code-block:: bash

$ gotthard shippinglogistics -- pg_basebackup -D /postgres/mydata



.. _bastion: https://en.wikipedia.org/wiki/Bastion_host
.. _zalando-stups: https://github.com/zalando-stups
.. _piu configuration: http://stups.readthedocs.io/en/latest/components/piu.html#how-to-configure
.. _Spilo: https://github.com/zalando/spilo
.. _Environment variables: https://www.postgresql.org/docs/current/static/libpq-envars.html

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

gotthard-0.9.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

gotthard-0.9-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file gotthard-0.9.tar.gz.

File metadata

  • Download URL: gotthard-0.9.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for gotthard-0.9.tar.gz
Algorithm Hash digest
SHA256 5c11d5b361421c47bb6156ee5413394545d7fbeecfd6d3138aa416ef32b2b755
MD5 1c0f3ae4114f95f492f23281e4ae9628
BLAKE2b-256 3b9d9c2c63034ed7b4b8268e3830b2281fa6d26f72f25e2529c24eb22b886e09

See more details on using hashes here.

Provenance

File details

Details for the file gotthard-0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for gotthard-0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 2f4357d5f7f7b17dd325e0e97af900c248af4f09af03db7d0d89dd04f3156351
MD5 77f872e6e47858f5f94a688d46d1ee58
BLAKE2b-256 250da5a68c8efd6ad02c4165899ce7306fab55d2bd65621b5b64bf6bba25fae4

See more details on using hashes here.

Provenance

Supported by

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