30.1. Configuring Secrets for an S3 Storage #
Consider a scenario where the analyst role must be able to read the data from an S3 storage, the etl_user role must be able to write the data to this storage, and other roles cannot have access to this storage.
To configure this scenario:
For example:
SELECT duckdb.create_simple_secret( type := 'S3', key_id := 'AKIAIOSFODNN7EXAMPLE', secret := 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY', endpoint := 'storage.example.ru', region := 'us-east-1' ) ON CONFLICT DO NOTHING;Initialize the metadata catalog.
For example:
SELECT metastore.init(true) ON CONFLICT DO NOTHING;
For example:
SELECT metastore.add_storage('data_storage', 's3://data-bucket/', 's3://data-bucket/tmp/') ON CONFLICT DO NOTHING;Create an analytical table, and then create a view for this table.
For example:
SELECT metastore.add_table('sales_data', 'data_storage', 'public.sales') ON CONFLICT DO NOTHING; SELECT metastore.create_view('sales_data') ON CONFLICT DO NOTHING;Grant privileges on the analytical table:
Grant the
SELECTprivilege to theanalystrole.For example:
GRANT SELECT ON sales_data TO analyst;
Grant the
INSERTprivilege to the role that writes the data to the analytical table.For example:
SELECT metastore.mgrant('INSERT', 'TABLE', 'sales_data', 'etl_user') ON CONFLICT DO NOTHING;
If the analyst role executes the following command:
SELECT * FROM sales_data;
Since the
analystrole is granted theSELECTprivilege on the view, the command is executed.The simple secret is found in the user mapping for the
PUBLICrole.The connection to the S3 storage is established.
If the etl_user role executes the following command:
SELECT metastore.copy_table('sales_data', 'SELECT * FROM staging.sales') ON CONFLICT DO NOTHING;
Since the
etl_userrole is granted theINSERTprivilege on the analytical table, the command is executed.The simple secret is found in the user mapping for the
PUBLICrole.The connection to the S3 storage is established.
If the random_user role attempts to execute the following command:
SELECT * FROM sales_data;
Since the random_user role is not granted any privileges on the view, the command is rejected with an access error.