Relationships are able to cross tenants with attribute strategy
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start by running the two cross-tenant relationship tests introduced in commit d8f62872e94bb8e7e115d7e24ec715142ffe4142, then compare the behavior with the change in 0adec1d1634387367bb818e40711e34ceb8cb3e4. Read the Ecto multi-tenancy foreign-key guidance and trace the migration generation involved. Done means primary-key relationships reject cross-tenant inserts at the database level without breaking the case addressed by #144.
Written by the indexing model from the issue text.
Description
Describe the bug
Ash Postgres currently allows relating two resources from two different tenants when using attribute strategy and referencing the primary key of the other resource.
To Reproduce
Here is a commit that adds two tests that manage cross-tenant relationships.
The one that references the primary key is able to add a cross-tenant relationship, the other correctly fails (with a rather cryptic error message though, so I'm not sure if it's actually failing for the right reason).
Expected behavior
I would expect cross-tenant relationship not to be possible
Runtime
- Elixir version: 1.15.4
- Erlang version: 26.0.2
- OS: Debian Testing
- Ash Postgres version:
main
Additional context
The Ecto guide covers this usecase by adding composite foreign keys to disallow inserting cross-tenant associations.
This is what happens for relationships referencing non-primary key attributes, and it was happening also for primary key attributes before 0adec1d1634387367bb818e40711e34ceb8cb3e4.
That commit was made to fix the error shown in #144, but I think that the fix shouldn't have been dropping the composite foreign key, but rather adding the extra [:id, :org_id] unique index in the migration generator (should this be added for all multitenant-attribute resources or just as soon as their primary key gets referenced for the first time?), as is also shown in the Ecto guide.
Of course the cross-tenant relationship is correctly filtered out when reading the resource so it can't be retrieved, but I think it would be better to disallow its creation completely at the database level given there's the possibility to do so.
- Dominant language
- Elixir
- Stars
- 191
- Forks
- 186
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 17
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ash-project/ash_postgres
-
Temporal: an update or destroy as of an instant doesn't carry into later versionsPossibly taken @hoanle0126 claimed this 14 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
ash-project/ash_postgres#915 · 1 comment ·
Maintainers usually reply within 1 day
-
has_create_action?/1 excludes manual creates, making the #49 nullability fix inert on AshEvents resourcesMay be free again @Mckay-Hinds claimed this 19 days ago, and no pull request is open. Open
Difficulty 3/5 1-2 days Newbie friendliness 76/100
ash-project/ash_postgres#851 · 9 comments ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ash-project/ash_postgres#650 · 6 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ash-project/ash_postgres#642 · 5 comments ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 40/100
ash-project/ash_postgres#628 · 1 comment ·
Maintainers usually reply within 1 day
All issues in ash-project/ash_postgres
Similar issues
-
Flaky testOpendette technique
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
etalab/transport-site#5701 ·
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
@swmansion/popcorn: published .d.ts files lack extensions on relative imports, breaking moduleResolution node16/nodenextPossibly taken @Huyvux12 claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
software-mansion/popcorn#929 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
intellij-elixir/intellij-elixir#4705 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
phoenixframework/phoenix#6908 · 1 comment ·
Maintainers usually reply within 1 day