Skip to content

store: hub_approvals.access_group has no foreign key to access_groups #3

Closed

Description

@TudorAndrei

Problem

The column hub_approvals.access_group names an access group, but it has no foreign key to access_groups(name):

  • crates/aether-store/migrations/node/012_hub_approvals.sql: access_group TEXT NOT NULL DEFAULT 'friends'
  • crates/aether-store/migrations/node/011_access_groups.sql: access_group_members.group_name has REFERENCES access_groups(name) ON DELETE CASCADE

Thus the store accepts an approval for a group that does not exist. The store also lets a person delete a group while an open approval names it (NodeStore::delete_access_group in crates/aether-store/src/access_groups.rs).

Effect

The error comes late and in the wrong place. When the hub delivers the answer to an invite or a request, hub_sync gives approval.access_group to HostStep::Sign (crates/aether/src/hub_sync.rs), and the node then joins the person to that group. add_access_group_member returns StoreError::NotFound, and the join fails during sync, long after the person deleted the group or after a wrong name was written.

Decision needed

A foreign key changes behaviour, so it needs a rule for a deleted group. Possible rules:

  1. ON DELETE RESTRICT: a group with an open approval cannot be deleted. The admin page and MCP must show why, and must name the open approvals.
  2. ON DELETE CASCADE: deleting a group also deletes its open approvals. The node then does not sign a grant when the hub answers.
  3. Move to the default group: deleting a group moves its open approvals to friends. This needs a trigger or an explicit update in delete_access_group, because ON DELETE SET DEFAULT only works if friends always exists.

Work

  • Choose the rule.
  • Add a migration that rebuilds hub_approvals with the foreign key (SQLite cannot add a foreign key to an existing table). Existing rows that name a missing group need a rule too: drop them or move them to friends.
  • Make put_hub_approval reject a missing group with a clear error.
  • Add store tests for: an approval for a missing group, and the delete of a group with an open approval.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions