Query Report: Read-Only User Configuration 

A read-only user in a database has exclusive permissions to read information and execute query reports. This configuration ensures secure querying and blocks access to sensitive data within the application database.

Role Required: Organization Admin, SDAdmin, Users with Create Query Report permission

SQL expertise is required to configure read-only users. 

 

Contents 

 

Configure a Read-Only User in Postgres 

In the scripts, replace values within <> to your preference. 
CREATE USER <username> WITH PASSWORD '<password>';
GRANT CONNECT ON DATABASE <servicedesk_database> TO <username>;
GRANT USAGE ON SCHEMA public TO <username>;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO <username>;
--Sample Query
REVOKE SELECT ON <tableName> TABLE FROM <username>;
REVOKE SELECT ON aaapassword TABLE FROM readonlyuser;
SELECT sdp_revoke_execute_on_functions('public');
 SELECT sdp_revoke_execute_on_functions('<read-only user name>');


To restore revoke privileges for other users, provide execute permissions to all users except public and read-only users. Use this script  to create a grant function.

SELECT usename FROM pg_catalog.pg_user;

Users mentioned in the screenshot are only for reference.
 SELECT sdp_grant_execute_on_functions('<username>'); 
 SELECT pg_sleep(10);
SELECT Distinct(table_name) as "Name" FROM information_schema.tables WHERE lower(table_name) NOT IN (SELECT lower(table_name) from TableDetails) ORDER BY table_name;

 

Configure a Read-Only User in Microsoft SQL database 

 In Microsoft SQL, you cannot configure a read-only user when the database is linked to the application server using Windows authentication. 
CREATE LOGIN <username> WITH PASSWORD '<password>';
CREATE USER <username> FOR LOGIN <username>;
DENY INSERT, UPDATE, DELETE ON SCHEMA :: [dbo] TO <userName>;
REVOKE SELECT ON SCHEMA :: [dbo] FROM <userName>;

 

Microsoft SQL Restricted Table Access 

 Ignore issues regarding a table or object not being found. 
--Sample Query
SELECT * FROM aaapassword;
REVOKE SELECT ON [SchemaName].[TableName] FROM [UserName];
--or
DENY SELECT ON [SchemaName].[TableName] FROM [UserName];
--Sample Query
SELECT * FROM reportmoduleconfiguration;

 

DENY EXECUTE ON <FunctionName> FROM <Read-Only User Name>;    
DENY EXECUTE ON xp_cmdshell FROM rouser
SELECT * FROM ( SELECT DISTINCT(name) as "Name" FROM sys.objects WHERE type_desc = 'SYSTEM_TABLE' OR type_desc = 'INTERNAL_TABLE' OR type_desc = 'USER_TABLE' OR type_desc = 'VIEW' UNION SELECT DISTINCT(name) FROM sys.tables UNION SELECT DISTINCT(name) FROM sysobjects WHERE sysobjects.xtype = 'U' OR sysobjects.xtype = 'S' UNION SELECT DISTINCT(name) FROM sys.system_views UNION SELECT DISTINCT(TABLE_NAME) FROM INFORMATION_SCHEMA.TABLES ) AS t WHERE t.Name NOT IN (SELECT TableDetails.TABLE_NAME FROM TableDetails );

 

Obtain Encrypted Key of the Password

rodatasource.username=<username> 
rodatasource.password=<password> 

 

 

Update Database Flag    

 

Troubleshoot Query Report Failures 

1. Backup failures in bundled Postgres.

If a backup failure occurs due to permission issues, use this script  to restore necessary permissions for the application database users (sdpadmin).

 

2. In Microsoft SQL database, query report fails with the error message "Restricted table(s) found in query."