Skip to content

[backend] feat(multi-tenancy): add default tenant migration and foreign keys (#3505)#4979

Merged
damgouj merged 5 commits into
release/currentfrom
issue/3505_tenant_context_and_fk
Feb 25, 2026
Merged

[backend] feat(multi-tenancy): add default tenant migration and foreign keys (#3505)#4979
damgouj merged 5 commits into
release/currentfrom
issue/3505_tenant_context_and_fk

Conversation

@damgouj
Copy link
Copy Markdown
Member

@damgouj damgouj commented Feb 19, 2026

Proposed changes

  • Add default tenant migration and foreign keys

Testing Instructions

  1. OpenAEV must work as before

Related issues

  • 3505

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

@damgouj damgouj self-assigned this Feb 19, 2026
@damgouj damgouj added the filigran team use to identify PR from the Filigran team label Feb 19, 2026
@damgouj damgouj changed the title [backend] feat(multi_tenancy): add default tenant migration and foreign keys (#3505) [backend] feat(multi-tenancy): add default tenant migration and foreign keys (#3505) Feb 19, 2026
@damgouj damgouj marked this pull request as draft February 19, 2026 11:04
@damgouj damgouj force-pushed the issue/3505_tenant_context_and_fk branch from 0455196 to 4f1acae Compare February 19, 2026 13:07
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.48%. Comparing base (d870bf5) to head (ba174ba).
⚠️ Report is 2 commits behind head on release/current.

Additional details and impacted files
@@                  Coverage Diff                  @@
##             release/current    #4979      +/-   ##
=====================================================
+ Coverage              56.44%   56.48%   +0.03%     
- Complexity              4577     4582       +5     
=====================================================
  Files                   1007     1008       +1     
  Lines                  30172    30190      +18     
  Branches                2228     2229       +1     
=====================================================
+ Hits                   17032    17052      +20     
+ Misses                 12166    12164       -2     
  Partials                 974      974              

☔ 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.

@damgouj damgouj marked this pull request as ready for review February 19, 2026 13:37
@damgouj damgouj force-pushed the issue/3505_tenant_context_and_fk branch from ce04a49 to 10fc241 Compare February 23, 2026 10:13
// Add default tenant
statement.execute(addDefaultTenant.replace(DEFAULT_TENANT_ID, DEFAULT_TENANT_UUID));
// Add deleted_at in tenants for soft delete
statement.execute("ALTER TABLE tenants ADD tenant_deleted_at TIMESTAMP WITH TIME ZONE;");
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: Should it be included in the bean ?


try (Statement statement = context.getConnection().createStatement()) {
// Add default tenant
statement.execute(addDefaultTenant.replace(DEFAULT_TENANT_ID, DEFAULT_TENANT_UUID));
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.

nitpick: Seems a lot easier to read with String.format

  statement.execute(String.format("""
      INSERT INTO tenants(tenant_id, tenant_name, tenant_description)
      VALUES ('%s', 'First default tenant auto created to rename', 'First default tenant auto created to rename');
      """, DEFAULT_TENANT_UUID));

Comment on lines +19 to +20
"agents",
"asset_agent_jobs",
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: Since an agent is linked to a asset, do we need to add the tenant link here ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Seen together and with JB, yes we need :)

"custom_dashboards",
"datapacks",
"documents",
"executors",
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: Why not adding tenant on domains like attack pattern and kill chain phases ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pending Denise's answer

"groups",
"import_mappers",
"injectors",
"injectors_contracts",
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: Why ? an injector contracts is linked direclty to an injector.

"injects",
"kill_chain_phases",
"lessons_templates",
"organizations",
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: Mitigation ? Seams to be used by OpenCTI

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Add tenant id and create issue to delete the code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

"injects",
"kill_chain_phases",
"lessons_templates",
"organizations",
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.

nitpick: I have the feeling that notification_rules should include a tenant field so that we can list them in the future when we build the notification center. To be confirmed.

@damgouj damgouj force-pushed the issue/3505_tenant_context_and_fk branch from bfe30eb to ba174ba Compare February 24, 2026 14:40
@damgouj damgouj requested a review from RomuDeuxfois February 24, 2026 14:55
@damgouj damgouj merged commit 370cf7b into release/current Feb 25, 2026
13 checks passed
@damgouj damgouj deleted the issue/3505_tenant_context_and_fk branch February 25, 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.

2 participants