-
Notifications
You must be signed in to change notification settings - Fork 48
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
Learning of FK-constraint on Postgres fails for non-owner of the relation #1879
Comments
Does that help: https://stackoverflow.com/q/16830740/946850 The file you linked to comes directly from Postgres, with small adaptations: psql -c '\d+ information_schema.constraint_column_usage' |
According to relevant docs, the view generated by the code that serves as basis for this query is defined such that
Given my current understanding, this does not mean that the offending |
@krlmlr Any update here? I believe there is a mismatch in semantics. Calling You are using query code, which is specifically restricted to tables that are owned by the current user (as explicitly stated in the docs). In a setting where the |
We found the code that needs adoption. Would you like to take a stab, do you need help? |
We also need a reprex. |
The reprex, as requested. I'm sorry for the delay. General set up: CREATE DATABASE fk_vis_reprex;
CREATE USER fk_vis_owner WITH PASSWORD 'pwd123';
CREATE USER fk_vis_reader WITH PASSWORD 'pwd345';
GRANT CONNECT, TEMPORARY, CREATE ON DATABASE fk_vis_reprex TO fk_vis_owner;
GRANT CONNECT, TEMPORARY ON DATABASE fk_vis_reprex TO fk_vis_reader; then, with a connection of our user CREATE SCHEMA fk_vis;
GRANT USAGE ON SCHEMA fk_vis TO fk_vis_reader;
ALTER DEFAULT PRIVILEGES IN SCHEMA fk_vis GRANT SELECT ON TABLES TO fk_vis_reader;
CREATE TABLE fk_vis.item (
item INT GENERATED ALWAYS AS IDENTITY,
name VARCHAR(255) NOT NULL,
PRIMARY KEY(item)
);
CREATE TABLE fk_vis.customer (
customer INT GENERATED ALWAYS AS IDENTITY,
name VARCHAR(255) NOT NULL,
PRIMARY KEY(customer)
);
CREATE TABLE fk_vis.sale (
sale INT GENERATED ALWAYS AS IDENTITY,
item INT,
customer INT,
PRIMARY KEY(sale),
CONSTRAINT fk_item
FOREIGN KEY(item)
REFERENCES fk_vis.item(item),
CONSTRAINT fk_customer
FOREIGN KEY(customer)
REFERENCES fk_vis.customer(customer)
); With this,
From what I understand, there is no restriction for getting this information as the "reader" user (as SELECT conrelid::regclass AS table_name,
conname AS foreign_key,
pg_get_constraintdef(oid)
FROM pg_constraint
WHERE contype = 'f'
AND connamespace = 'fk_vis'::regnamespace
ORDER BY conrelid::regclass::text, contype DESC;
#> table_name | foreign_key | pg_get_constraintdef
#> -------------+-------------+-------------------------------------------------------------
#> fk_vis.sale | fk_item | FOREIGN KEY (item) REFERENCES fk_vis.item(item)
#> fk_vis.sale | fk_customer | FOREIGN KEY (customer) REFERENCES fk_vis.customer(customer) |
Just ran into the same issue. My (PG)SQL knowledge is very limited, but I noticed that NocoDB suffers from the same issue and its proposed solution might serve as inspiration here (see the PGSQL query changes). |
@krlmlr Could you maybe comment on
dm/R/postgres.R
Line 53 in 64449a5
This requires the role issuing the query to have
USAGE
privileges for the role that owns the relation for the corresponding FK-constraint to be picked up bydm_meta_raw()
. Admittedly, I'm fairly new to the topic of DB access privileges, but this seems unnecessarily restrictive. Couldn't you easily find yourself in the situation where the user/role owning theses objects is much more capable than the user/role trying to "learn" them?The text was updated successfully, but these errors were encountered: