Hasura v2 select permissions, enforced on your Ecto reads.
Authzura reads the permission metadata of a Hasura v2 project from
hdb_catalog and applies it to your Ecto queries: row filters, columns,
limits, root fields and relationship preloads. It is read-only and deny by
default: anything it cannot enforce is refused, never approximated. There are
no migrations, because Authzura only reads Hasura's metadata and never writes
to your database.
Add authzura to your dependencies in mix.exs:
def deps do
[
{:authzura, "~> 0.1"},
# Only for Authzura.JWT
{:jose, "~> 1.11"}
]
endThen fetch dependencies:
mix deps.getchildren = [
MyApp.Repo,
{Authzura,
[name: MyApp.Authz, repo: MyApp.Repo] ++ Application.get_env(:my_app, MyApp.Authz, [])}
]{:ok, session} =
Authzura.Session.new(
%{"x-hasura-user-id" => "42", "x-hasura-org-id" => "1"},
allowed_roles: ["user", "editor"],
default_role: "user"
)import Ecto.Query
alias MyApp.Article
{:ok, query} =
Article
|> where([a], a.status == "draft")
|> Authzura.scope(session, instance: MyApp.Authz)
rows = MyApp.Repo.all(query)Scoping must be the last step. Prefer all/3 and one/3, which run the read
for you and can preload Hasura relationships:
alias MyApp.Article
{:ok, articles} =
Authzura.all(Article, session,
instance: MyApp.Authz,
columns: [:id, :title],
preload: [:author, comments: [columns: [:id, :body]]]
)alias MyApp.Article
request = %{"columns" => ["id", "title"], "filter" => %{"status" => %{"_eq" => "draft"}}}
{:ok, input_rows} = Authzura.all_input(Article, session, request, instance: MyApp.Authz)- Configuration: options, polling and freshness, reload, status, split repos, telemetry
- Querying: sessions and JWT,
all,oneandscope, untrusted input, preloads, errors - Security: deny by default, unsupported features, side channels, input limits, Hasura compatibility
- Compatibility: property, differential and benchmark evidence against Hasura
mix authzura.check: validate your metadata in CI- HexDocs for the API reference
For PostgREST-style APIs, see PgRest, from the same author.
docker compose up -d postgres
mix test
mix qualityThe test database is built from priv/test_migrations by mix test; Authzura
adds no tables to your application. Every Elixir example in this README and
the guides is run by test/readme_examples_test.exs.
The PgRest examples run by default using the pinned GitHub test dependency; see Using with PgRest.
The opt-in mix authzura.check host-project test: mix test --only host_app.
The opt-in Hasura parity suite: Running parity tests.
Before tagging a release:
mix qualityandmix testpass, andmix docshas no warnings.- Run
mix authzura.checkagainst at least one large real-world Hasura v2 metadata set (hundreds of tables). - Record the result in the release notes as counts only (tables, select permissions, denials, warnings), never any metadata.
- Never commit third-party metadata to this repository.
MIT. See LICENSE.