Relationships are able to cross tenants with attribute strategy

Đang mở
#192 3 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
elixir, postgresql
Lĩnh vực
databases

Hướng nghiên cứu

Bắt đầu bằng cách chạy hai bài kiểm tra quan hệ giữa các tenant được giới thiệu trong commit d8f62872e94bb8e7e115d7e24ec715142ffe4142, sau đó so sánh hành vi với thay đổi trong 0adec1d1634387367bb818e40711e34ceb8cb3e4. Đọc hướng dẫn của Ecto về foreign key trong môi trường multi-tenancy và theo dõi quá trình tạo migration liên quan. Công việc được xem là hoàn tất khi các quan hệ bằng primary key từ chối các insert giữa các tenant ở cấp cơ sở dữ liệu mà không làm hỏng trường hợp được xử lý trong #144.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Elixir
Star
191
Fork
186
Merge trung bình
16 giờ 4 phút
Pull request đã merge (30 ngày)
17

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ash-project/ash_postgres

Tất cả issue của ash-project/ash_postgres

Issue tương tự

Thêm issue về Elixir

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.