Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate alternatives for table lookups #292

Open
mmd-osm opened this issue Oct 16, 2023 · 7 comments
Open

Evaluate alternatives for table lookups #292

mmd-osm opened this issue Oct 16, 2023 · 7 comments

Comments

@mmd-osm
Copy link
Collaborator

mmd-osm commented Oct 16, 2023

Evaluate if PostgreSQL CREATE FUNCTION could be used for table lookups.

https://www.postgresql.org/docs/current/sql-createfunction.html

(...)
CREATE OR REPLACE FUNCTION lookup(t character varying)
  RETURNS SETOF mytable AS 
  ' SELECT * FROM public.mytable WHERE mytable.t = t; '
LANGUAGE SQL
IMMUTABLE
SECURITY DEFINER
SET search_path = public, pg_temp;
select * from lookup('...');
@mmd-osm mmd-osm added this to the v0.9.0 milestone Oct 16, 2023
@tomhughes
Copy link
Contributor

What on earth would be the point of that? Encapsulating database access in functions is full on enterprise nonsense...

@mmd-osm
Copy link
Collaborator Author

mmd-osm commented Oct 16, 2023

I want to revoke SELECT permissions for the cgimap user on one particular table. With the database function in place, you need to provide the correct lookup value. Otherwise, you have no access to any of the table contents.
Maybe there are other ways to accomplish the same.

@tomhughes
Copy link
Contributor

Surely if you revoke select on the table (and why would you want to do that?) then the function will be no more able to read it than a direct select would. Plus you will need us to create functions on the master database for you!

@tomhughes
Copy link
Contributor

Ah I see that's the point of SECURITY DEFINER to elevate permissions but that then means the function needs to be defined as a different user.

@mmd-osm
Copy link
Collaborator Author

mmd-osm commented Oct 16, 2023

Yes, exactly, that's the point... the db function needs to be created outside of cgimap by another user, and could then be consumed by cgimap instead of directly reading from the table.

@tomhughes
Copy link
Contributor

What table exactly is it that you don't want to be able to read, except that you do because you're going to create a function to read it? Is the goal to limit what columns you can read or something?

@mmd-osm
Copy link
Collaborator Author

mmd-osm commented Oct 16, 2023

The idea was to limit access to oauth_access_tokens. This may seem a bit far fetched at first. However, since tokens are stored in a particular way, we should probably avoid uncontrolled read access that could happen due some programming mistake, or something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants