I need to unit test some bash scripts, I have setup a debian squeeze in a chroot. From command line I can use chroot /directory my-command, ou schroot -d / -u root my-command, but I need to run theses commands from a PHPUnit test, runned by Apache (user www-data). With schroot I have this error

E: No controlling terminal E: Authentication failed: Authentication failure

with sudo chroot I have

sudo: no tty present and no askpass program specified

Better idea than me?

link|improve this question

Solution high security inside : www-data ALL=(ALL:ALL) NOPASSWD: ALL in /etc/sudoers, and it run... I am not happy! ;-) – Cédric Girard Dec 7 '11 at 14:38
Try to use www-data ALL=(ALL) NOPASSWD: /path/to/your/PHPUnit-script.sh – Mircea Vutcovici Dec 7 '11 at 14:40
Right, your is better (smaller security hole) than mine :-D – Cédric Girard Dec 7 '11 at 14:47
feedback

1 Answer

up vote 1 down vote accepted

chroot most be run as root. So you have to split your script in two, one that is doing the unit test (myapp-unit-test.sh) and one that will be run as root (myapp-unit-test-chroot.sh).

In /etc/sudoers add:

www-data ALL=(ALL) NOPASSWD:/path/to/myapp-unit-test-chroot.sh

In myapp-unit-test-chroot.sh do something like:

chroot /new/root sudo -u test-user /path/to/myapp-unit-test.sh

In this way you will limit the part that is running as root.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.