As Xantec points out in a comment on the question, Section 31 is allegedly an autonomous branch of Starfleet, which derives its authority from the Starfleet Charter:
Sloan: We don't submit reports or ask for approval for specific operations, if that's what you mean. We're an autonomous department.
Bashir: Authorised by whom?
Sloan: Section thirty one was part of the original Starfleet charter.
Star Trek: Deep Space Nine Season 6 Episode 18: "Inquisition"
I say "allegedly" because the information comes from Luther Sloan, a character who is unreliable at best. Sisko confirms later in the episode that Section 31 has some kind of relationship with Starfleet, but we're not sure exactly what it is:
Sisko: There's no record of a Deputy Director Sloan anywhere in Starfleet. And as for Section thirty one, that's a little more complicated. Starfleet Command doesn't acknowledge its existence, but they don't deny it either. They simply said they'd look into it and get back to me.
Bashir: When?
Sisko: They didn't say.
Star Trek: Deep Space Nine Season 6 Episode 18: "Inquisition"
This relationship is further confirmed in a later episode:
Sisko: Officially, Starfleet Command has said that they are appalled at the very notion that an organisation like Section Thirty one might exist, and that they plan to get to the bottom of this entire business.
Bashir: And unofficially?
Sisko: They have quietly pushed the investigation aside, which means either they don't take Section Thirty one seriously or someone at Starfleet Command is protecting them.
Star Trek: Deep Space Nine Season 7 Episode 16: "Inter Arma Enim Silent Leges"
Unfortunately, Section 31 is wrapped up in so many layers of lies and deception that it's hard to know who is telling the truth, and when. About all we can confirm is that Starfleet allies with them at least occasionally, as Admiral Ross does in "Inter Arma Enim Silent Leges":
Bashir: And how long have you worked for Section Thirty One?
Ross: I don't.
Bashir: Oh. Just a temporary alliance, is it?
Ross: Something like that.
Star Trek: Deep Space Nine Season 7 Episode 16: "Inter Arma Enim Silent Leges"