{"id":30091957,"url":"https://github.com/permitio/opal-fetcher-postgres","last_synced_at":"2025-08-09T07:54:45.161Z","repository":{"id":41872049,"uuid":"387850726","full_name":"permitio/opal-fetcher-postgres","owner":"permitio","description":"An OPAL custom data fetcher to bring authorization state from Postgres","archived":false,"fork":false,"pushed_at":"2024-06-07T16:12:23.000Z","size":38,"stargazers_count":23,"open_issues_count":1,"forks_count":22,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-30T01:06:25.414Z","etag":null,"topics":["example"],"latest_commit_sha":null,"homepage":"https://opal.ac","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/permitio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-20T16:24:39.000Z","updated_at":"2025-05-22T20:26:08.000Z","dependencies_parsed_at":"2024-06-07T17:52:53.752Z","dependency_job_id":null,"html_url":"https://github.com/permitio/opal-fetcher-postgres","commit_stats":{"total_commits":18,"total_committers":6,"mean_commits":3.0,"dds":"0.38888888888888884","last_synced_commit":"124bb5cabf6352dcd5eacb7b64ac41c3a3d11b24"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/permitio/opal-fetcher-postgres","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fopal-fetcher-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fopal-fetcher-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fopal-fetcher-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fopal-fetcher-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/permitio","download_url":"https://codeload.github.com/permitio/opal-fetcher-postgres/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fopal-fetcher-postgres/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269548490,"owners_count":24436109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-09T02:00:10.424Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example"],"created_at":"2025-08-09T07:54:44.400Z","updated_at":"2025-08-09T07:54:45.135Z","avatar_url":"https://github.com/permitio.png","language":"Python","readme":"\u003cp  align=\"center\"\u003e\n \u003cimg src=\"https://github.com/permitio/opal/assets/4082578/4e21f85f-30ab-43e2-92de-b82f78888c71\" height=170 alt=\"opal\" border=\"0\" /\u003e\n\u003c/p\u003e\n\u003ch2 align=\"center\"\u003e\nOPAL Fetcher for Postgres\n\u003c/h2\u003e\n\n[Check out OPAL main repo here.](https://github.com/permitio/opal)\n\n### What's in this repo?\nAn OPAL [custom fetch provider](https://docs.opal.ac/tutorials/write_your_own_fetch_provider) to bring authorization state from [Postgres](https://www.postgresql.org/).\n\nThis fetcher is both:\n- **A fully functional fetch-provider for Postgres:** can be used by OPAL to fetch data from Postgres DB.\n- **Serving as an example** how to write custom fetch providers for OPAL and how to publish them as pip packages.\n\n### How to try this custom fetcher in one command? (Example docker-compose configuration)\n\nYou 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:\n```\ndocker compose up\n```\nthis 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.\n\n### ✏️ How to use this fetcher in your OPAL Setup\n\n#### 1) Build a custom opal-client `Dockerfile`\n\nThe 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.\n\nYour `Dockerfile` should look like this:\n```\nFROM permitio/opal-client:latest\nRUN pip install --no-cache-dir --user opal-fetcher-postgres\n```\n\n#### 2) Build your custom opal-client container\nSay your special Dockerfile from step one is called `custom_client.Dockerfile`.\n\nYou must build a customized OPAL container from this Dockerfile, like so:\n```\ndocker build -t yourcompany/opal-client -f custom_client.Dockerfile .\n```\n\n#### 3) When running OPAL, set `OPAL_FETCH_PROVIDER_MODULES`\nPass the following environment variable to the OPAL client docker container (comma-separated provider modules):\n```\nOPAL_FETCH_PROVIDER_MODULES=opal_common.fetcher.providers,opal_fetcher_postgres.provider\n```\nNotice that OPAL receives a list from where to search for fetch providers.\nThe list in our case includes the built-in providers (`opal_common.fetcher.providers`) and our custom postgres provider.\n\n#### 4) Using the custom provider in your DataSourceEntry objects\n\nYour 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.\n\nExample value of `OPAL_DATA_CONFIG_SOURCES` (formatted nicely, but in env var you should pack this to one-line and no-spaces):\n```json\n{\n    \"config\": {\n        \"entries\": [\n            {\n                \"url\": \"postgresql://postgres@example_db:5432/postgres\",\n                \"config\": {\n                    \"fetcher\": \"PostgresFetchProvider\",\n                    \"query\": \"SELECT * from city;\",\n                    \"connection_params\": {\n                        \"password\": \"postgres\"\n                    }\n                },\n                \"topics\": [\n                    \"policy_data\"\n                ],\n                \"dst_path\": \"cities\"\n            }\n        ]\n    }\n}\n```\n\nNotice how `config` is an instance of `PostgresFetcherConfig` (code is in `opal_fetcher_postgres/provider.py`).\n\nValues for this fetcher config:\n* The `url` is actually a postgres dsn. You can set the postgres password in the dsn itself if you want.\n* `connection_params` are optional, if you want to include certain overrides outside the dsn.\n* Your `config` must include the `fetcher` key to indicate to OPAL that you use a custom fetcher.\n* Your `config` must include the `query` key to indicate what query to run against postgres.\n\n### 🚩 Possible User Issues\nWhile trying to send requests to a Postgres data source, you may encounter that the request fails. This can be caused by the format of the config entry URL for which the standard is:\n\n`postgresql://\u003cuser\u003e:\u003cpassword\u003e@\u003chost\u003e/\u003cdb\u003e`\n\nIt might be most common that this request fails due to the password field being incorrectly parsed by the underlying library called `asyncpg`, which is one of the required libraries used within our OPAL custom data fetcher.\n\nIn order to solve the issue, you need to change the data source config entry URL to the format shown below:\n\n`postgresql://\u003chost\u003e/\u003cdb\u003e?user=\u003cuser\u003e\u0026password=\u003cpassword\u003e`\n\n### 📖 About OPAL (Open Policy Administration Layer)\n[OPAL](https://github.com/permitio/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.\n\nOPAL 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).\n\nCheck out OPAL's main site at [OPAL.ac](https://opal.ac).\n\n\u003cimg src=\"https://i.ibb.co/CvmX8rR/simplified-diagram-highlight.png\" alt=\"simplified\" border=\"0\"\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermitio%2Fopal-fetcher-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpermitio%2Fopal-fetcher-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermitio%2Fopal-fetcher-postgres/lists"}