I understand that it's bad practice, in fact very dangerous to allow arbitrary execution of code without fully validating it and so on.
True.
But say you are tasked to write a small app that allows one to add vhosts to an apache configuration.
Unrelated to the first point. Totally unrelated. Indeed, why is the first point even in there?
Adding vhosts is a simple script. You simply write the script and get it to work. It requires extraordinary privileges. But it's not "arbitrary execution of code". And it will be "fully validatated" (Whatever that means. You write it. You validate it.)
This is not a good choice for a "web app". Nor is it a good choice for a daemon. Indeed, it's really hard to see the connection between "add vhosts to an apache configuration" and "web applications that control daemons."
It's just a script that just updates a file. Nothing special. It requires privileges, so only a select few people can run it. Nothing special there either. Use sudo
.
Do you have your code execute with full privileges,
Obviously. The script can't update the vhosts without some privileges.
Unless by "your code" you don't mean the script that updates the vhosts. If you mean something else, like a web page which allows someone to runt he script which updates the vhosts. In which case, you've conflated the script with the web app that runs the script.
do you write future variables into a database and have a cron job (with full privileges) execute a script that pulls the vars from the database and throws them into a template config file, etc.
Sure. People do that. It seems terribly complex.
Use celery
instead of rolling your own background processor. http://ask.github.com/celery/getting-started/introduction.html