Skip to content

Commit 0edbe81

Browse files
committed
oidc view names
1 parent ef9e253 commit 0edbe81

2 files changed

Lines changed: 62 additions & 17 deletions

File tree

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ obp-api/src/main/scala/code/api/v3_0_0/custom/
2525
/obp-api2/
2626
/.java-version
2727
.scannerwork
28+
29+
# Marketing diagram generation outputs
30+
marketing_diagram_generation/outputs/*

‎obp-api/src/main/scripts/sql/create_oidc_user_and_views.sql‎

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ ALTER USER :OIDC_USER CONNECTION LIMIT 10;
7777
\echo 'Creating read-only view for OIDC access to authuser...'
7878

7979
-- Drop the view if it already exists
80-
DROP VIEW IF EXISTS v_authuser_oidc CASCADE;
80+
DROP VIEW IF EXISTS v_oidc_users CASCADE;
8181

8282
-- Create a read-only view exposing only necessary authuser fields for OIDC
8383
-- TODO: Consider excluding locked users by joining with mappedbadloginattempt table
8484
-- and checking mbadattemptssinceresetorsuccess against max.bad.login.attempts prop
85-
CREATE VIEW v_authuser_oidc AS
85+
CREATE VIEW v_oidc_users AS
8686
SELECT
8787
id,
8888
username,
@@ -101,9 +101,38 @@ WHERE validated = true -- Only expose validated users to OIDC service
101101
ORDER BY username;
102102

103103
-- Add comment to the view for documentation
104-
COMMENT ON VIEW v_authuser_oidc IS 'Read-only view of authuser table for OIDC service access. Only includes validated users. WARNING: Includes password hash and salt for OIDC credential verification - ensure secure access.';
104+
COMMENT ON VIEW v_oidc_users IS 'Read-only view of authuser table for OIDC service access. Only includes validated users and excludes sensitive fields like password hashes. WARNING: Includes password hash and salt for OIDC credential verification - ensure secure access.';
105105

106-
\echo 'OIDC authuser view created successfully.'
106+
\echo 'OIDC users view created successfully.'
107+
108+
-- =============================================================================
109+
-- 3b. Create read-only view for consumer table (OIDC clients)
110+
-- =============================================================================
111+
\echo 'Creating read-only view for OIDC access to consumers...'
112+
113+
-- Drop the view if it already exists
114+
DROP VIEW IF EXISTS v_oidc_clients CASCADE;
115+
116+
-- Create a read-only view exposing necessary consumer fields for OIDC
117+
-- Note: Some OIDC-specific fields like grant_types and scopes may not exist in current schema
118+
-- TODO: Add grant_types and scopes fields to consumer table if needed for full OIDC compliance
119+
CREATE VIEW v_oidc_clients AS
120+
SELECT
121+
COALESCE(consumerid, id::varchar) as client_id, -- Use consumerId if available, otherwise id
122+
secret as client_secret,
123+
redirecturl as redirect_uris,
124+
'authorization_code,refresh_token' as grant_types, -- Default OIDC grant types
125+
'openid,profile,email' as scopes, -- Default OIDC scopes
126+
name as client_name,
127+
createdat as created_at
128+
FROM consumer
129+
WHERE isactive = true -- Only expose active consumers to OIDC service
130+
ORDER BY client_name;
131+
132+
-- Add comment to the view for documentation
133+
COMMENT ON VIEW v_oidc_clients IS 'Read-only view of consumer table for OIDC service access. Only includes active consumers. Note: grant_types and scopes are hardcoded defaults - consider adding these fields to consumer table for full OIDC compliance.';
134+
135+
\echo 'OIDC clients view created successfully.'
107136

108137
-- =============================================================================
109138
-- 4. Grant appropriate permissions to OIDC user
@@ -116,16 +145,18 @@ GRANT CONNECT ON DATABASE :DB_NAME TO :OIDC_USER;
116145
-- Grant USAGE on the public schema (or specific schema where authuser exists)
117146
GRANT USAGE ON SCHEMA public TO :OIDC_USER;
118147

119-
-- Grant SELECT permission on the OIDC view only
120-
GRANT SELECT ON v_authuser_oidc TO :OIDC_USER;
148+
-- Grant SELECT permission on the OIDC views
149+
GRANT SELECT ON v_oidc_users TO :OIDC_USER;
150+
GRANT SELECT ON v_oidc_clients TO :OIDC_USER;
121151

122152
-- Explicitly revoke any other permissions to ensure read-only access
123153
REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM :OIDC_USER;
124154
REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM :OIDC_USER;
125155
REVOKE ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public FROM :OIDC_USER;
126156

127-
-- Grant SELECT on the view again (in case it was revoked above)
128-
GRANT SELECT ON v_authuser_oidc TO :OIDC_USER;
157+
-- Grant SELECT on the views again (in case they were revoked above)
158+
GRANT SELECT ON v_oidc_users TO :OIDC_USER;
159+
GRANT SELECT ON v_oidc_clients TO :OIDC_USER;
129160

130161
\echo 'Permissions granted successfully.'
131162

@@ -153,15 +184,23 @@ SELECT 'User exists: ' || CASE WHEN EXISTS (
153184
SELECT 1 FROM pg_user WHERE usename = :'OIDC_USER'
154185
) THEN 'YES' ELSE 'NO' END AS user_check;
155186

156-
-- Check if view exists and has data
157-
SELECT 'View exists and accessible: ' || CASE WHEN EXISTS (
187+
-- Check if views exist and have data
188+
SELECT 'Users view exists: ' || CASE WHEN EXISTS (
158189
SELECT 1 FROM information_schema.views
159-
WHERE table_name = 'v_authuser_oidc' AND table_schema = 'public'
160-
) THEN 'YES' ELSE 'NO' END AS view_check;
190+
WHERE table_name = 'v_oidc_users' AND table_schema = 'public'
191+
) THEN 'YES' ELSE 'NO' END AS users_view_check;
161192

162-
-- Show row count in the view (if accessible)
193+
SELECT 'Clients view exists: ' || CASE WHEN EXISTS (
194+
SELECT 1 FROM information_schema.views
195+
WHERE table_name = 'v_oidc_clients' AND table_schema = 'public'
196+
) THEN 'YES' ELSE 'NO' END AS clients_view_check;
197+
198+
-- Show row counts in the views (if accessible)
163199
SELECT 'Validated users count: ' || COUNT(*) AS user_count
164-
FROM v_authuser_oidc;
200+
FROM v_oidc_users;
201+
202+
SELECT 'Active clients count: ' || COUNT(*) AS client_count
203+
FROM v_oidc_clients;
165204

166205
-- Display the permissions granted to OIDC user
167206
SELECT
@@ -188,11 +227,12 @@ ORDER BY table_schema, table_name;
188227
\echo 'Username: ' :OIDC_USER
189228
\echo 'Password: [REDACTED - check script variables]'
190229
\echo ''
191-
\echo 'Available view: v_authuser_oidc'
230+
\echo 'Available views: v_oidc_users, v_oidc_clients'
192231
\echo 'Permissions: SELECT only (read-only access)'
193232
\echo ''
194-
\echo 'Test connection command:'
195-
\echo 'psql -h ' :DB_HOST ' -p ' :DB_PORT ' -d ' :DB_NAME ' -U ' :OIDC_USER ' -c "SELECT COUNT(*) FROM v_authuser_oidc;"'
233+
\echo 'Test connection commands:'
234+
\echo 'psql -h ' :DB_HOST ' -p ' :DB_PORT ' -d ' :DB_NAME ' -U ' :OIDC_USER ' -c "SELECT COUNT(*) FROM v_oidc_users;"'
235+
\echo 'psql -h ' :DB_HOST ' -p ' :DB_PORT ' -d ' :DB_NAME ' -U ' :OIDC_USER ' -c "SELECT COUNT(*) FROM v_oidc_clients;"'
196236
\echo ''
197237
\echo '====================================================================='
198238
\echo '⚠️ CRITICAL SECURITY WARNINGS ⚠️'
@@ -228,7 +268,9 @@ ORDER BY table_schema, table_name;
228268
\echo ''
229269
\echo 'BASIC INFO:'
230270
\echo '- The OIDC user has read-only access to validated authuser records only'
271+
\echo '- The OIDC user has read-only access to active client records only'
231272
\echo '- Connection limit is set to 10 concurrent connections'
273+
\echo '- Client view uses hardcoded grant_types and scopes (consider adding to schema)'
232274

233275
\echo ''
234276
\echo '====================================================================='

0 commit comments

Comments
 (0)