I think its obvious that Starfleet's Security Division serves on all Starfleet facilities, not just on Starships. Their duties probably extend beyond being muscle, MPs and guards as well. In the TNG episode the Pegasus, Starfleet Security was developing a cloaking device and in the Drumhead the head of the Security Division was the person who effectively shut down Admiral Satie. So it would appear that Security has jurisdiction over intelligence, espionage and matters of National Security. IRL, when my father was in the USAAF he was in the Security Service (now called Air Force Intelligence, Surveillance and Reconnaissance Agency) and he was not an MP. So it's possible that Starfleet Security might have ground forces under it's purview as well.