Heat 2 Tbsp. oil in a large heavy pot over medium-high. Drain tomatoes, reserving the liquid to use later. Add the tomatoes, red pepper flakes and a pinch of salt to the pot. Stir to combine, then allow to cook, undisturbed, until caramelized and browning in spots, about 5 minutes. Break up tomatoes, scraping bottom of pot, and continue to cook, scraping and stirring occasionally, until tomatoes are caramelized all over, about 5 minutes more. Transfer tomatoes to a plate.
Heat another 2 Tbsp. oil in same pot over medium heat. Add onion, garlic, and a pinch more red pepper flakes, if you like. Cook, stirring often, until vegetables are soft and starting to brown around edges, 8-10 minutes. Stir in vinegar and caramelized tomatoes, scraping up browned bits. Add broth, beans, vinegar, dried herbs, reserved tomato juice and Parmesan rind (if using) to the pot. Bring to a simmer. Cook until flavors meld, about 30–45 minutes. Taste soup and season with salt and pepper, as needed.
Just before serving, stir in spinach and pesto, if using and cook until spinach is just wilted. Serve.
See Cook's Notes for how to start this soup with dried beans instead, as well as other tips for making this soup!