We study insolvency cascades in an interbank system when banks are allowed to insure their loans with credit default swaps (CDS) sold by other banks. We show that a CDS market can be designed to rewire the network of interbank exposures in such a way that makes it more resilient to insolvency cascades: A regulator can use information about the topology of the interbank network to devise a systemic surcharge that is added to the CDS spread. CDS contracts are thus effectively taxed according to how much they contribute to increasing systemic risk. We simulate this regulated CDS market using an agent-based model (CRISIS macro-financial model) and we demonstrate that it leads to an interbank system that is more resilient to insolvency cascades.