Relationships are able to cross tenants with attribute strategy

Aperta
#192 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
elixir, postgresql
Ambito
databases

Direzione di ricerca

Inizia eseguendo i due test sulle relazioni tra tenant introdotti nel commit d8f62872e94bb8e7e115d7e24ec715142ffe4142, quindi confronta il comportamento con la modifica in 0adec1d1634387367bb818e40711e34ceb8cb3e4. Leggi la guida di Ecto sulle foreign key nel multi-tenancy e traccia la generazione della migration coinvolta. Il lavoro è completo quando le relazioni tramite chiave primaria rifiutano gli insert tra tenant a livello di database senza compromettere il caso affrontato da #144.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

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.

Lingua principale
Elixir
Stelle
191
Fork
186
Merge medio
16h 4m
PR unite (30g)
17

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ash-project/ash_postgres

Tutte le issue di ash-project/ash_postgres

Issue simili

Altre issue su Elixir

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.