In the " old days "

before you installed a truck cap you would apply one to two layers of truck cap tape on the truck side rails and the front . This tape was maybe 1/8 to 3/16 thick and self adhesive on one side . I always liked installing two layers with the second layer overlapping the first layer at the seams . The tape performs several jobs , one it makes water intrusion difficult and two it provides a barrier for the top and the truck to " move " without rubbing against each other . That rubbing is the action that slowly sands away at the paint/primer and allows rust to start .
In your case go ahead and pull the cap off the truck , do whatever you are going to do to stop/clean up the rust and finish the repair . Then reinstall the cap using the cap tape .