If several clients' ad accounts land in one etlmcp table, never grant a client's login SELECT on that table: it would see every other client's spend. Give each client a view that filters the table on that client's account_id values, create it WITH (security_barrier), and grant the client SELECT on the view alone. Row-level security on the table, or a separate destination table per client, are the two alternatives.
Why a view works
Every row etlmcp writes carries the canonical columns, and two of them identify the ad account: account_id and account_name. A filter on account_id is the reliable one, since an account can be renamed on the platform.
PostgreSQL's CREATE VIEW page says that, by default, a view reads its base tables with the privileges of the view's owner, not of the person querying it. So the client's role needs SELECT on its view and USAGE on the view's schema, and nothing on the etlmcp table. If you set the security_invoker option, that changes: the client would then need SELECT on the table too, which defeats the purpose. Leave it off.
Create the view with security_barrier
A plain filtering view can leak rows it hides. A client can pass a function of its own into a query on the view, and the planner may run that function on rows before the view's filter removes them. The security_barrier option makes PostgreSQL apply the view's conditions first. The CREATE VIEW page says to use it when the view is meant to give row-level security.
CREATE SCHEMA client_acme;
CREATE VIEW client_acme.ad_performance
WITH (security_barrier) AS
SELECT date, network, account_id, account_name,
campaign_id, campaign_name, adgroup_id, adgroup_name,
ad_id, ad_name, impressions, clicks, cost,
conversions, conversion_value, currency
FROM public.ad_performance
WHERE account_id IN ('1234567890', 'act_987654321');
CREATE ROLE acme_bi LOGIN PASSWORD '…';
GRANT USAGE ON SCHEMA client_acme TO acme_bi;
GRANT SELECT ON client_acme.ad_performance TO acme_bi;
Put each client's view in its own schema, so a BI tool that browses schemas shows that client nothing else. Run this as the login etlmcp uses, or as a role that can read the table, because the view's owner is the one whose privileges count.
Columns added later
PostgreSQL fixes a view's column list when you create it. A view written as SELECT * keeps the columns the table had at that moment, and columns added to the table afterwards stay out of it. etlmcp adds columns to its own tables: when a pipeline starts sending a new extra field, the next run adds an extra.-prefixed column with ALTER TABLE. Those columns stay invisible to the client until you recreate the view. CREATE OR REPLACE VIEW lets you add new columns at the end of the list, as long as the existing ones keep their names, order and types. Extra columns keep their dotted names, so quote them in the select list, for example "extra.reach".
Listing the columns by name, as above, is also a choice about what each client sees: a column you leave out never reaches them.
Row-level security instead
You can put the filter on the table itself: ALTER TABLE … ENABLE ROW LEVEL SECURITY, then one CREATE POLICY … FOR SELECT TO <client role> USING (account_id IN (…)) per client, and grant each client SELECT on the table. With row security on, a role sees only rows a policy allows; with no policy for it, it sees none.
Two points matter with etlmcp. First, the table's owner bypasses row security unless you also run ALTER TABLE … FORCE ROW LEVEL SECURITY; etlmcp creates the table with its own login, so that login owns it and keeps full access by default, which its loads need. If you force row security, you must add policies that let that login select, delete and insert its rows, or its runs stop working. Second, superusers and roles with BYPASSRLS always bypass the policies, so never give a client such a role. Views keep the rules in one place per client and leave etlmcp's own access untouched, which is why they are the simpler choice here.
A table per client
The third way is to give each client its own destination. A PostgreSQL destination names one schema and one table, and etlmcp creates that table if it does not exist. Point each client's pipelines at their own table, then grant the client SELECT on that table only. Each run deletes and rewrites only its own pipeline's rows, matched on the _etlmcp_pipeline_id column, within the run's date range, so pipelines sharing a table never overwrite each other either. Destinations count toward your plan's limit, so this suits a handful of clients better than dozens; see pricing.
Checklist
- Filter on
account_id, notaccount_name. - Create each view
WITH (security_barrier)and withoutsecurity_invoker. - Grant the client USAGE on its schema and SELECT on its view, nothing on the etlmcp table.
- Recreate the view when you want new
extra.columns to show. - When you add an ad account for a client, add its ID to that client's view.