Allegiance by Timothy Zahn
Young Imperial agent Mara Jade is on a mission to root out corruption in the Empire's middle levels, even as a squad of stormtroopers on the same planet deserts and sets out to uphold justice on its own terms. Before long, Mara, the rogue stormtroopers, and the heroes of the Rebellion will see their paths converge - despite the fact that Mara and Luke Skywalker won't meet face-to-face until almost eight years later! In the process, each person will have to contemplate what "allegiance" means to them.

Buy from Amazon!

Story continued in Choices of One

This is a classic era book from the Legends timeline. It will likely be contradicted by newer books (if so, just think of it as an alternate universe).