4 ms·
I’ve never used those tools, but I don’t see how you can automate away authorization issues. The GraphQL spec[1] says authorization in the GraphQL layer is fine
by criddell 5y ago
I’ve never used those tools, but I don’t see how you can automate away authorization issues. The GraphQL spec[1] says authorization in the GraphQL layer is fine for prototyping or toy programs, but for a production system it needs to be in the business logic layer.
[1]: https://graphql.org/learn/authorization/ https://graphql.org/learn/authorization/
- gavinray 5y agoIn Hasura, you authenticate externally -- can be custom API endpoint that signs a JWT/auth webhook, or an auth provider like Auth0, Okta, Firebase, Keycloak, etc. Doesn't matter, just have to return some claims values. You can then use these claims values in your authorization (permissions) layer. IE, when a user logs in, you can sign a claim with "X-Hasura-User-ID" = 1, and "X-Hasura-Org-ID" = 5, and then put rules on tables like: > "Role USER can SELECT rows in table 'user' WHEN X-Hasura-User-ID = user.id" > "Role USER can SELECT rows in table 'organization' WHEN X-Hasura-Org-Id = organization.id" There's more depth to it than this, but this is the gist of it.
- pycal 5y agothis is really powerful stuff when working with a CISO “the data itself defines who may access it”
- golergka 5y agoYou just handle this part my your code and leave the rest to Hasura.
- RedShift1 5y agoPostgreSQL and other databases have fine grained authorization controls down to the column level, what more does one need?
- jseban 5y agoYeah this must be one of the most underused features ever. People don't realise that you can solve little bobby tables by just setting the permissions correctly in the database.
- littlecranky67 5y agoYou cannot model every business constraint in DB permissions; Stuff like "If customer X has less than 3 active contracts, new contract activations require sign-off of Manager of at least level Y" etc.
- RedShift1 5y agoThat can absolutely be done via triggers or limit access by using functions for certain operations instead of direct table access
- littlecranky67 5y agoAnd how do you unit test triggers? Yes you can do it in a ton of ways, but you just end up scattering your business layer all over the database, the GraphQL adapter, API gateways etc. The alternative is just to create a dedicated BE service endpoint (in whatever you prefer, REST,HTTP/JSON,SOAP, gRPC etc.), which does the required checks for you. Triggers, functions or whatever you use are just code; yes, that is my pitch: Have your buisness logic in code, ideally in a dedicated BE API endpoint instead in the DB.
- criddell 5y agoThat’s the path I ended up taking. The GraphQL resolvers had no idea idea there was a database. They talked to a layer that understood all the business objects and that sat on top of a layer that understood authorization and only that layer had any connection to the data store.
- necovek 5y agoAre you suggesting that you don't use any constraints (unique, not null...) or defaults in the database either? That's your business logic in the database right there.
- throwanem 5y agoObservability, flexibility (I don't need to push a migration to change auth), SSO integration, and the ability to keep a clean separation between user and "machine" (service, replication, etc) accounts.
- RedShift1 5y agoWhat does observability mean? Can you translate this into a concrete question? As for flexibility, do you mean authentication or authorization? SSO can be done at the SQL server level (MSSQL has it and so does Postgres, don't know about others), but handling the SSO part in your app and using "set role" and passing a user ID for your row level security policies to use is easier to set up and more flexible. Clean separation between user and machine accounts can absolutely be done with MSSQL and Postgres.
- littlecranky67 5y agoI say it over and over again, row/column level permissions are not even close to enough for any larger app. How do you translate access restriction like "user X cannot view more than 10 articles per month" or "customer Y cannot insert any more orders if total outstanding/unpaid amount of invoices in last 30 days succeeds Z" into row/columnlevel permissions? You don't, that's why you have a business layer.
- jseban 5y ago> How do you translate access restriction like "user X cannot view more than 10 articles per month" That's not permissions in the general sense of authorisation, that should just be modelled as any other "business logic". Put that article_limit in the users table and join it in the selects. Edit: or tracking the users article views with timestamps, and making a select aggregate over the month.. > "customer Y cannot insert any more orders if total outstanding/unpaid amount of invoices in last 30 days succeeds Z" insert into orders select from user a inner join invoices b etc.. any kind of limitless complexity here on how you want to limit the orders.
- littlecranky67 5y agoBut if you design a public GraphQL API, you cannot trust the query issuer (Browser or App on the Client). You have to enforce those rules outside of the query. And yes, there is tons of ways to do this outside of GraphQL, which is exactly my point, that row/column permissions alone do not suffice.
- jseban 5y agoOk I get you now, yes you are correct, if you have a public API and you have business constraints that need to be enforced, you have to do this server side. But you can still implement this easily in queries, so for example granting the client only read permissions, plus execution permissions on certain database functions, and inside these functions you can implement the constraints. What I'm trying to say, is that you don't necessarily need any backend "services" java etc, to implement these type of constraints, they can be modelled as any other business logic in the database.