Rechte zum Schreiben
Hallo, ich versuche über PHP (Apache) eine Datei in einem User-Verzeichnis zu erstellen. Der Webserver läuft ja unter wwwrun.nogroup. Wie kann ich nun über PHP eine Datei in einem Userverzeichnis mit (User/Gruppe) user111.www anlegen/schreiben? Ich weiß, gehört hier vielleicht nicht so recht in diese Liste die Frage, aber im Apache gibt's doch die Möglichkeit der Angabe von User und Group für VirtualHosts. Weiß jemand nen Tipp? Gruß Thorsten Hantke
an T. Hantkes Tastatur wurde am Montag, 10. Juni 2002 19:00 folgendes notiert:
Wie kann ich nun über PHP eine Datei in einem Userverzeichnis mit (User/Gruppe) user111.www anlegen/schreiben?
In php nacher ein chown/chmod, .. ausführen. $PHPDOKU/function.chmod.html $PHPDOKU/function.chown.html Hagen -- rand( 41 ) -> sig 08 Ja, Buckow ist schön, aber doch mit Einschränkung. Es hängt alles davon ab, ob wir Buckow die Gegend oder Buckow die Stadt meinen, allen Respekt vor jener, aber Vorsorge gegen diese. Seine Häuser kleben wie Nester an Abhängen und Hügelkanten, und sein Straßenpflaster, um das Schlimmste vorwegzunehmen, ist lebensgefährlich. Theodor Fontane , Wanderungen durch die Mark Brandenburg http://www.amazon.de/exec/obidos/ASIN/3351031041/buckow/
Hallo Thorsten, hallo Leute, Am Montag, 10. Juni 2002 19:00 schrieb T. Hantke:
ich versuche über PHP (Apache) eine Datei in einem User-Verzeichnis zu erstellen.
Der Webserver läuft ja unter wwwrun.nogroup.
Wie kann ich nun über PHP eine Datei in einem Userverzeichnis mit (User/Gruppe) user111.www anlegen/schreiben?
Ich weiß, gehört hier vielleicht nicht so recht in diese Liste die Frage, aber im Apache gibt's doch die Möglichkeit der Angabe von User und Group für VirtualHosts.
Such mal in der Apache-Doku nach suEXEC. Bei mir liegt das auf http://localhost/manual/suexec.html Wenn ich es richtig verstanden habe, sollte das - in Kombination mit User und Group in den VirtualHost-Definitionen - das gewünschte bewirken. Gruß Christian Boltz PS @Hagen: | int chown ( string filename, mixed user) | | Ändert den Eigentümer der Datei filename in Benutzer user. Nur | der Superuser kann den Eigentümer einer Datei ändern. Dein Apache läuft doch hoffentlich nicht als root, oder? -- Registrierter Linux-Nutzer #239431 Linux - life is too short for reboots.
Christian Boltz wrote:
Am Montag, 10. Juni 2002 19:00 schrieb T. Hantke:
Wie kann ich nun über PHP eine Datei in einem Userverzeichnis mit (User/Gruppe) user111.www anlegen/schreiben?
Such mal in der Apache-Doku nach suEXEC.
Wenn ich es richtig verstanden habe, sollte das - in Kombination mit User und Group in den VirtualHost-Definitionen - das gewünschte bewirken. Dein Apache läuft doch hoffentlich nicht als root, oder?
Wohl wirklich nicht. Wenn er aberr suEXEC benutzt um einen Befehl als preveligierter Benutzer auszufuehren, heisst das unter Linux automatisch das der Apache als root laufen muss. suEXEC ist hier nicht das richtige Mittel, sondern sudo oder su1 oder vergleichbare Programme. Peter
Hallo Peter, hallo Thorsten, hallo Leute, Am Dienstag, 11. Juni 2002 23:38 schrieb Peter Wiersig:
Christian Boltz wrote:
Am Montag, 10. Juni 2002 19:00 schrieb T. Hantke:
Wie kann ich nun über PHP eine Datei in einem Userverzeichnis mit (User/Gruppe) user111.www anlegen/schreiben?
Such mal in der Apache-Doku nach suEXEC.
Wenn ich es richtig verstanden habe, sollte das - in Kombination mit User und Group in den VirtualHost-Definitionen - das gewünschte bewirken. Dein Apache läuft doch hoffentlich nicht als root, oder?
Wohl wirklich nicht. Wenn er aberr suEXEC benutzt um einen Befehl als preveligierter Benutzer auszufuehren, heisst das unter Linux automatisch das der Apache als root laufen muss.
suEXEC ist hier nicht das richtige Mittel, sondern sudo oder su1 oder vergleichbare Programme.
Hmm, habe ich das so falsch verstanden? Also nochmal nachgelesen. IMHO sieht es (immer noch) so aus: ----- Zitat Apache-Manual ----- The suEXEC feature -- introduced in Apache 1.2 -- provides Apache users the ability to run CGI and SSI programs under user IDs different from the user ID of the calling web-server. Normally, when a CGI or SSI program executes, it runs as the same user who is running the web server. ----- Ende Zitat Apache-Manual ----- Also: suexec ist ein Programm (in /sbin), dass den User ändert, unter dem der Apache Scripte (PHP, Perl, ...) ausführt und damit z. B. auch Dateien anlegt. (Dazu muss suexec suid-root gesetzt sein.) Durch suEXEC werden Scripte mit einer in der config festgelegten uid (auf keinen Fall als root) ausgeführt und demzufolge auch vom Script angelegte Dateien unter dieser uid erzeugt. Das dürfte also genau das sein, was Thorsten sucht. Um jetzt der Paranoia -- hilfe, ein suid-bit -- ;-) entgegenzuwirken: Bevor suexec irgendetwas tut, führt es erst einige Überprüfungen durch, insgesamt 20 an der Zahl - siehe z. B. bei installierter Apache-Doku http://localhost/manual/suexec.html Ich beschränke mich auf die wichtigsten Punkte, übernommen aus der genannten Doku (deshalb auf englisch) und jeweils auf die Überschrift gekürzt: - Was the wrapper called with the proper number of arguments? - Is the user executing this wrapper a valid user of this system? - Is this valid user allowed to run the wrapper? - Does the target program have an unsafe hierarchical reference? - Is the target user NOT superuser? - Is the target group NOT the superuser group? - Is the target userid ABOVE the minimum ID number? - Is the target groupid ABOVE the minimum ID number? - Is the directory within the Apache webspace? - Is the directory NOT writable by anyone else? - Is the target program NOT writable by anyone else? - Is the target program NOT setuid or setgid? - Is the target user/group the same as the program's user/group? - Can we successfully clean the process environment to ensure safe operations? Nach all diesen Überprüfungen empfinde ich es als sicherer, mit suexec zu arbeiten, als alle Dateien, die durch Scripte erstellt werden, unter wwwrun anzulegen. Dies gilt besonders, wenn auf dem Server mehrere Virtual Hosts liegen, die von verschiedenen Benutzern genutzt werden, die nicht 100% vertrauenswürdig sind. Würden dabei Dateien als wwwrun angelegt, hätten es andere Nutzer des Webservers relativ leicht, per PHP "fremde" Dateien, die eben als wwwrun angelegt wurden, zu löschen/verändern usw. Gruß Christian Boltz -- Registrierter Linux-Nutzer #239431 Linux - life is too short for reboots.
Christian Boltz wrote:
Am Dienstag, 11. Juni 2002 23:38 schrieb Peter Wiersig:
Christian Boltz wrote:
Am Montag, 10. Juni 2002 19:00 schrieb T. Hantke:
Wie kann ich nun über PHP eine Datei in einem Userverzeichnis mit (User/Gruppe) user111.www anlegen/schreiben?
Such mal in der Apache-Doku nach suEXEC.
Wenn ich es richtig verstanden habe, sollte das - in Kombination mit User und Group in den VirtualHost-Definitionen - das gewünschte bewirken. Dein Apache läuft doch hoffentlich nicht als root, oder?
Wohl wirklich nicht. Wenn er aberr suEXEC benutzt um einen Befehl als preveligierter Benutzer auszufuehren, heisst das unter Linux automatisch das der Apache als root laufen muss.
suEXEC ist hier nicht das richtige Mittel, sondern sudo oder su1 oder vergleichbare Programme.
Hmm, habe ich das so falsch verstanden? Also nochmal nachgelesen.
Durch suEXEC werden Scripte mit einer in der config festgelegten uid (auf keinen Fall als root) ausgeführt und demzufolge auch vom Script angelegte Dateien unter dieser uid erzeugt.
Das dürfte also genau das sein, was Thorsten sucht.
Ja, kann es vielleicht sein. Unter dem Punkt "Using suEXEC" taucht als erster Punkt "Virtual Hosts" auf, was das einzige war das ich im Hinterkopf zu suEXEC gespeichert hatte. Der zweite Punkt "User directories" macht dann das was du vorgehabt hast. Nur will Thorsten wirklich das Skript in jedes public_html ablegen? Und gleich vorweg: SymLinks an dieser Stelle halte ich fuer eine falsche Idee. Wie schuetzt man dieses Skript dann davor, das der Benutzer es aendert? (wenn er auch noch das public_html directory nutzen will) Oder will Thorsten fuer jeden User einen VirtualHost einrichten?
Dies gilt besonders, wenn auf dem Server mehrere Virtual Hosts liegen, die von verschiedenen Benutzern genutzt werden, die nicht 100% vertrauenswürdig sind. Würden dabei Dateien als wwwrun angelegt, hätten es andere Nutzer des Webservers relativ leicht, per PHP "fremde" Dateien, die eben als wwwrun angelegt wurden, zu löschen/verändern usw.
fuer diesen Fall ist suEXEC natuerlich genau das richtige. Verstanden hatte ich folgendes: Thorsten hat den Server team.example.com und 1 PHP-Skript /do/create_dir.php und dieses Skript soll in beliebigen Verzeichnissen eine Datei erstellen, die dann am Ende user123.www gehoeren soll. Christian, zeig mir bitte eine Loesung mit suEXEC. Ich kann danach eine Loesung mit Hilfe von sudo ausarbeiten und dann koennen wir mal vergleichen. Peter
Hallo Peter, hallo Thorsten, hallo Leute, Am Donnerstag, 13. Juni 2002 10:08 schrieb Peter Wiersig:
Christian Boltz wrote:
Am Dienstag, 11. Juni 2002 23:38 schrieb Peter Wiersig:
Christian Boltz wrote:
Am Montag, 10. Juni 2002 19:00 schrieb T. Hantke:
Wie kann ich nun über PHP eine Datei in einem Userverzeichnis mit (User/Gruppe) user111.www anlegen/schreiben?
[suEXEC] sollte - in Kombination mit User und Group in den VirtualHost-Definitionen - das gewünschte bewirken.
suEXEC ist hier nicht das richtige Mittel, sondern sudo oder su1 oder vergleichbare Programme.
Hmm, habe ich das so falsch verstanden? Also nochmal nachgelesen.
Durch suEXEC werden Scripte mit einer in der config festgelegten uid (auf keinen Fall als root) ausgeführt und demzufolge auch vom Script angelegte Dateien unter dieser uid erzeugt.
Das dürfte also genau das sein, was Thorsten sucht.
Ja, kann es vielleicht sein. Unter dem Punkt "Using suEXEC" taucht als erster Punkt "Virtual Hosts" auf, was das einzige war das ich im Hinterkopf zu suEXEC gespeichert hatte.
Der zweite Punkt "User directories" macht dann das was du vorgehabt hast.
Nur will Thorsten wirklich das Skript in jedes public_html ablegen?
----- aus Apache-Doku - suexec.html ----- Using suEXEC [Virtual hosts lasse ich mal aus] User directories: The suEXEC wrapper can also be used to execute CGI programs as the user to which the request is being directed. This is accomplished by using the "~" character prefixing the user ID for whom execution is desired. The only requirement needed for this feature to work is for CGI execution to be enabled for the user and that the script must meet the scrutiny of the security checks above. ----- Ende Zitat ----- Den Absatz "The only requirement..." verstehe ich folgendermaßen: - Der User muss das Recht haben, CGIs (oder PHP) auszuführen - Die Sicherheitsüberprüfungen von suEXEC müssen erfolgreich absolviert werden. Sprich: Das Script muss dem User gehören, niemand sonst darf Schreibrechte darauf haben usw. Mit "the script" ist wohl ein beliebiges (PHP/Perl/...)-Script gemeint, das der User auf seinen Webspace hochlädt. Ich kann mir nicht vorstellen, dass in jedem Userverzeichnis ein bestimmtes Script liegen muss, damit suEXEC funktioniert - wäre wohl auch irgendwo zwischen ungeschickt und dämlich ;-)
Und gleich vorweg: SymLinks an dieser Stelle halte ich fuer eine falsche Idee.
ACK. SymLinks haben IMHO auf einem Webserver nichts zu suchen. (und wenn es unbedingt sein muss, dann bitte nur ifOwnerMatch)
Wie schuetzt man dieses Skript dann davor, das der Benutzer es aendert? (wenn er auch noch das public_html directory nutzen will)
Das wäre dann ja das Risiko des jeweiligen Users, da ja alles, was sein Script "anstellt", unter seiner uid läuft ;-)
Oder will Thorsten fuer jeden User einen VirtualHost einrichten?
Dies gilt besonders, wenn auf dem Server mehrere Virtual Hosts liegen, die von verschiedenen Benutzern genutzt werden, die nicht 100% vertrauenswürdig sind. Würden dabei Dateien als wwwrun angelegt, hätten es andere Nutzer des Webservers relativ leicht, per PHP "fremde" Dateien, die eben als wwwrun angelegt wurden, zu löschen/verändern usw.
fuer diesen Fall ist suEXEC natuerlich genau das richtige.
Verstanden hatte ich folgendes: Thorsten hat den Server
@Thorsten: Vielleicht solltest Du nochmal kurz schreiben, was Du vorhast, das macht die Sache einfacher (mein Kristallkugel-Reiniger ist leider leer ;-)
team.example.com und 1 PHP-Skript /do/create_dir.php und dieses Skript soll in beliebigen Verzeichnissen eine Datei erstellen, die dann am Ende user123.www gehoeren soll.
Hatte ich anders verstanden. Warten wir auf die Antwort von Thorsten...
Christian, zeig mir bitte eine Loesung mit suEXEC. Ich kann danach eine Loesung mit Hilfe von sudo ausarbeiten und dann koennen wir mal vergleichen.
Das sagst Du so einfach... Alles, was ich über suEXEC weiß, habe ich mir aus der Doku zusammengelesen. Im praktischen Einsatz habe ich suEXEC nicht. Das ganze ist wieder mal ein Beispiel, wie man durch Probleme anderer Leute sein Wissen erweitert ;-) Gruß Christian Boltz -- Registrierter Linux-Nutzer #239431 Linux - life is too short for reboots.
participants (4)
-
Christian Boltz
-
Hagen Kuehnel
-
Peter Wiersig
-
T. Hantke