Skip to content

[backend] fix(multi-tenancy): dev env with openaev_owner new user (#0000)#5694

Merged
corinnekrych merged 16 commits intorelease/currentfrom
issue/flyway-migration
May 6, 2026
Merged

[backend] fix(multi-tenancy): dev env with openaev_owner new user (#0000)#5694
corinnekrych merged 16 commits intorelease/currentfrom
issue/flyway-migration

Conversation

@corinnekrych
Copy link
Copy Markdown
Contributor

@corinnekrych corinnekrych commented May 5, 2026

Proposed changes

Flyway migration to use openaev_owner for running migration

To test it, in your application-dev.properties change:

spring.datasource.username=openaev_owner
spring.datasource.password=openaev

Testing Instructions

  1. Step-by-step how to test
  2. Environment or config notes

Related issues

  • Closes #ISSUE-NUMBER

Checklist

  • I consider the submitted work as finished
  • I tested the code for its functionality
  • I wrote test cases for the relevant uses case
  • I added/update the relevant documentation (either on github or on notion)
  • Where necessary I refactored code to improve the overall quality
  • For bug fix -> I implemented a test that covers the bug

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@github-actions github-actions Bot added the filigran team use to identify PR from the Filigran team label May 5, 2026
@corinnekrych corinnekrych changed the title [backend] fix(multi-tenancy): Dev env with openaev_owner new user (#0000) [backend] fix(multi-tenancy): dev env with openaev_owner new user (#0000) May 5, 2026
@corinnekrych corinnekrych marked this pull request as ready for review May 5, 2026 16:34
* openaev_app} that the application adopts at runtime via {@code SET ROLE openaev_app} (configured
* in {@code spring.datasource.hikari.connection-init-sql}). Flyway continues to run as the
* superuser for DDL operations.
* <p>Prerequisites (run by DBA once):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question : Does that mean that we need to provide a clear documentation to the existing users that they need to run this before upgrading ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a pre-requisites

*
* <pre>
* CREATE ROLE openaev_app NOLOGIN NOSUPERUSER;
* GRANT openaev_app TO openaev_owner;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think openaev_owner will be created on most setups by the time this runs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean?
the user is created via the container bootstrap/seed init-db.sql
it works in dev env, tested locally

what i dont know how to fix - I'm stuck on that one - is how to make drone working as it is not using container to run api-test

Comment thread openaev-dev/init-db.sql
CREATE USER openaev_owner WITH PASSWORD 'openaev' NOSUPERUSER CREATEROLE;

-- 3. Grant the app role to the owner (so SET ROLE works at runtime)
GRANT openaev_app TO openaev_owner;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why this grant is necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This grant is necessary to make SET ROLE openaev_app work at runtime.

In PostgreSQL, SET ROLE only works if the current session user is a member of the target role. Without GRANT openaev_app TO openaev_owner, any attempt by the app to do SET ROLE openaev_app would fail with a "permission denied" error.
By granting openaev_app to openaev_owner, the application can switch into the openaev_app role at runtime, which ensures RLS policies are evaluated under the correct role context — enforcing tenant isolation as intended.

openaev_owner owns the tables (required to run DDL/RLS policies), but table ownership bypasses RLS at query time. The application therefore adopts openaev_app via SET ROLE — a non-owner role that RLS policies are enforced on. GRANT openaev_app TO openaev_owner makes that role switch possible.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 40.39%. Comparing base (48d2a7e) to head (8b468aa).

Additional details and impacted files
@@                  Coverage Diff                  @@
##             release/current    #5694      +/-   ##
=====================================================
- Coverage              40.40%   40.39%   -0.01%     
  Complexity              6112     6112              
=====================================================
  Files                   2123     2123              
  Lines                  56997    56989       -8     
  Branches                7230     7229       -1     
=====================================================
- Hits                   23028    23023       -5     
+ Misses                 32613    32611       -2     
+ Partials                1356     1355       -1     
Flag Coverage Δ
backend 64.33% <ø> (+<0.01%) ⬆️
frontend 1.42% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@corinnekrych corinnekrych merged commit d00e1e4 into release/current May 6, 2026
36 of 38 checks passed
@corinnekrych corinnekrych deleted the issue/flyway-migration branch May 6, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

filigran team use to identify PR from the Filigran team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants