Skip to content

VPC and VPC Subnet deletion needs to check for network interfaces #738

Closed

Description

@bnaecker

See this for the original context.

Currently, we delete VPCs and VPC Subnets (and maybe other container-like resources) without checking for anything still being inside them. We should perform that check, using the omicron_nexus::db::update_and_check tooling to verify there are no non-soft-deleted VPC Subnets when we delete a VPC, or Network Interfaces when we delete a VPC Subnet.

Activity

  1. bnaecker commented on Jun 16, 2022

    @bnaecker
    CollaboratorAuthor

    I ran into this again while working on a PR to solve #1134. In Nexus::instance_create_network_interface, we first lookup the VPC and VPC Subnet before adding a new interface for an instance. I've updated the internals of the query to check that the instance exists and is stopped without a window for a TOCTOU, but this isn't sufficient. The VPC and VPC Subnet both could be removed after they're fetched, but before we insert the interface for the instance.

    The solution is really to add additional parent-child relationships, via the DatastoreCollection trait. The VPC already has VpcRouters as children, but also needs the VpcSubnet. The VpcSubnet meanwhile needs the NetworkInterface as its own children. This addresses the other side of this issue: concurrently inserting a child while the parent is being deleted.

    The deletion side is still racy. But rather than using update_and_check, as I suggested in the original issue description, we can instead follow the patttern used when deleting other resources:

    • Fetch the parent collection, most notably its rcgen
    • Fetch any children, and fail the request if we find one
    • Delete the parent, conditional on that rcgen not having changed. If we update zero rows, it's assumed to have changed and we fail the request.
  2. bnaecker commented on Jun 16, 2022

    @bnaecker
    CollaboratorAuthor

    One complication here is that when deleting an interface, we need to fetch its parent, VpcSubnet, so that we can make deletion conditional on its rcgen being the same. We don't currently do that, so we've got another trip to the DB. Not the end of the world, but we may want to revisit the question of whether network interfaces are children of the VPC Subnet or the Instance. Neither is exactly right, since they're an association between the two.

  3. bnaecker commented on Jul 26, 2022

    @bnaecker
    CollaboratorAuthor

    Closed by #1483

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