Skip to main content

An OPAL fetch provider to bring authorization state from Postgres DB.

Project description

opal

OPAL Fetcher for Postgres

Check out OPAL main repo here.

What's in this repo?

An OPAL custom fetch provider to bring authorization state from Postgres.

This fetcher is both:

  • A fully functional fetch-provider for Postgres: can be used by OPAL to fetch data from Postgres DB.
  • Serving as an example how to write custom fetch providers for OPAL and how to publish them as pip packages.

How to try this custom fetcher in one command? (Example docker-compose configuration)

You can test this fetcher with the example docker compose file in this repository root. Clone this repo, cd into the cloned repo, and then run:

docker compose up

this docker compose configuration already correctly configures OPAL to load the Postgres Fetch Provider, and correctly configures OPAL_DATA_CONFIG_SOURCES to include an entry that uses this fetcher.

How to use this fetcher in your OPAL Setup

1) Build a custom opal-client Dockerfile

The official docker image only contains the built-in fetch providers. You need to create your own Dockerfile (that is based on the official docker image), that includes this fetcher's pip package.

Your Dockerfile should look like this:

FROM authorizon/opal-client:latest
RUN pip install --no-cache-dir --user opal-fetcher-postgres

2) Build your custom opal-client container

Say your special Dockerfile from step one is called custom_client.Dockerfile.

You must build a customized OPAL container from this Dockerfile, like so:

docker build -t yourcompany/opal-client -f custom_client.Dockerfile .

3) When running OPAL, set OPAL_FETCH_PROVIDER_MODULES

Pass the following environment variable to the OPAL client docker container (comma-separated provider modules):

OPAL_FETCH_PROVIDER_MODULES=opal_common.fetcher.providers,opal_fetcher_postgres.provider

Notice that OPAL receives a list from where to search for fetch providers. The list in our case includes the built-in providers (opal_common.fetcher.providers) and our custom postgres provider.

4) Using the custom provider in your DataSourceEntry objects

Your DataSourceEntry objects (either in OPAL_DATA_CONFIG_SOURCES or in dynamic updates sent via the OPAL publish API) can now include this fetcher's config.

Example value of OPAL_DATA_CONFIG_SOURCES (formatted nicely, but in env var you should pack this to one-line and no-spaces):

{
    "config": {
        "entries": [
            {
                "url": "postgresql://postgres@example_db:5432/postgres",
                "config": {
                    "fetcher": "PostgresFetchProvider",
                    "query": "SELECT * from city;",
                    "connection_params": {
                        "password": "postgres"
                    }
                },
                "topics": [
                    "policy_data"
                ],
                "dst_path": "cities"
            }
        ]
    }
}

Notice how config is an instance of PostgresFetcherConfig (code is in opal_fetcher_postgres/provider.py).

Values for this fetcher config:

  • The url is actually a postgres dsn. You can set the postgres password in the dsn itself if you want.
  • connection_params are optional, if you want to include certain overrides outside the dsn.
  • Your config must include the fetcher key to indicate to OPAL that you use a custom fetcher.
  • Your config must include the query key to indicate what query to run against postgres.

About OPAL (Open Policy Administration Layer)

OPAL is an administration layer for Open Policy Agent (OPA), detecting changes to both policy and policy data in realtime and pushing live updates to your agents.

OPAL brings open-policy up to the speed needed by live applications. As your application state changes (whether it's via your APIs, DBs, git, S3 or 3rd-party SaaS services), OPAL will make sure your services are always in sync with the authorization data and policy they need (and only those they need).

Check out OPAL's main site at OPAL.ac.

simplified

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

opal-fetcher-postgres-0.0.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

opal_fetcher_postgres-0.0.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file opal-fetcher-postgres-0.0.1.tar.gz.

File metadata

  • Download URL: opal-fetcher-postgres-0.0.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.3

File hashes

Hashes for opal-fetcher-postgres-0.0.1.tar.gz
Algorithm Hash digest
SHA256 96058b78b2d66ca46b78eec2a3ca8ba962a70bad0128f60c4d34b53ce77e3362
MD5 24dc80dacc255fd110f6fde25b04e833
BLAKE2b-256 8f54129d45a75da508df9bf8c4388cffaa37a7fa854bdc6a1cd6eeb0e68bdef7

See more details on using hashes here.

File details

Details for the file opal_fetcher_postgres-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: opal_fetcher_postgres-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.3

File hashes

Hashes for opal_fetcher_postgres-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c785f368d562c73855dfcd18f7ee0a5145837219356660472bc28506a8cc57a
MD5 802a068aeeaaa0850c4f80d0c9bba496
BLAKE2b-256 45ed8021392bb7ec09fc8480f5094c495d1fbf24bcc85ed33d28f8511b8068b5

See more details on using hashes here.

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