USGA says:
17-1. Flagstick Attended, Removed Or Held Up
Before making a stroke from anywhere on the course, the player may have the flagstick attended, removed or held up to indicate the position of the hole.
If the flagstick is not attended, removed or held up before the player makes a stroke, it must not be attended, removed or held up during the stroke or while the player’s ball is in motion if doing so might influence the movement of the ball.
Note 1: If the flagstick is in the hole and anyone stands near it while a stroke is being made, he is deemed to be attending the flagstick.
Note 2: If, prior to the stroke, the flagstick is attended, removed or held up by anyone with the player’s knowledge and he makes no objection, the player is deemed to have authorized it.
Note 3: If anyone attends or holds up the flagstick while a stroke is being made, he is deemed to be attending the flagstick until the ball comes to rest.
(Moving attended, removed or held-up flagstick while ball in motion – see Rule 24-1)