Deutsche Zope User Group
Gast 3 Benutzer online
DZUG-News

Zope 2.7 in einem chroot()-environment unter GNU/Linux installieren.

diese schritte beschreiben die installation unter Gentoo Linux 1.4 fuer ppc. entsprechend koennen sich unter anderen distributionen abhaengigkeiten und verzeichnisnamen abweichend verhalten. diese anleitung richtet sich an personen, die mit der administration eines unixoiden systems vertraut sind und somit sich selbst ihren teil denken, wenn etwas nicht so vorgefunden wird, wie beschrieben.

Voraussetzungen

folgende dinge, werden fuer diese schritte vorausgesetzt:

  • Zope 2.7 installiert (inkl. python 2.3)
  • root account auf dem entsprechenden rechner

Datensammlung

grundlage der installation ist das verzeichnis:

  /var/Zope

dieses directory wird die neue root fuer Zope.

System

in seinem laufenden system legt man den user zope in der gruppe zope an. dieser user wird verwendet, um dann die Zope instanz unter dieser UID laufen zu lassen - sie muss also entsprechend an die lokalen voraussetzungen angepasst werden. wird im folgenden von kopieren gesprochen ist ein cp -a gemeint, der die rechte und user/group informationen auf das kopierte file anwendet.

folgende verzeichnisse werden in dem chroot-environment angelegt als root:

   etc
   bin
   var
   usr
   usr/bin
   usr/lib
   opt

in das neue etc kopiert man aus etc folgende dateien:

   passwd
   groups
   ld.so.conf

aus passwd loescht man alle eintraege bis auf root und zope; das selbe macht man mit groups.

in das neue bin kopiert man aus bin folgende dateien:

   sh
   ldconfig

in libraries werden das neue lib kopiert man folgende dateien:

   ld
   libc
   libcrypt
   libdl
   libm
   libnss_files
   libpthread
   libutil
   libz

das bedeutet, die entsprechend aktuelle library wird kopiert sowie die entsprechenden symlinks runter auf die allgemeinen versionen.

fuer python wird dann noch bei gcc3 systemen das verzeichnis /usr/lib/gcc-lib umkopiert. hier muss man gegebenenfalls die kopierten dateien auf das notwendigste beschraenken. z.b. also nur:

   /usr/lib/gcc-lib/powerpc-unknown-linux-gnu/3.2.3

bis auf dieses verzeichnis loescht man nun aus der neuen etc/ld.so.conf alle directories raus.

Python

nach usr/bin geht:

   /usr/bin/python2.3

es wird dananch ein symlink auf diese datei gelegt mit dem namen python.

nach usr/lib kommt:

   /usr/lib/libpython2.3.so  
   /usr/lib/libpython2.3.so.1.0  
   /usr/lib/python2.3

danach kann man einen chroot auf das "neue" system machen und dort einmal:

   ldconfig

danach kann man etc/ld.so.conf und bin/ldconfig aus dem chroot directory loeschen.

Zope

das ganze installierte zope wird von z.b. /opt/Zope-2.7 nach opt in das chroot environment kopiert. man legt nun unter var/zope eine neue instanz an. in dem generierten zope.conf setzt man bei allen ports, auf denen zope listenen soll diese auf 0.0.0.0:port - also z.b.:

   
     address 0.0.0.0:8080
   

will man direkt den command line chroot verwenden, muss den effective-user setzen - und zwar auf zope; weiter unten ist beschrieben, wie man auch direkt zope mit dem user zope starten kann.

sowohl in der zope.conf als auch in runzope muss man nun alle verzeichnisse so anpassen, dass sie absolut sind wenn zope im chroot laeuft. das heisst alle /var/Zope entfernen.

Check

hat alles soweit geklappt, sollte die hierarchie etwa so aussehen:

   opt
   opt/Zope-2.7
   opt/Zope-2.7/...
   usr
   usr/bin
   usr/bin/python2.3
   usr/bin/python
   usr/lib
   usr/lib/python2.3
   usr/lib/python2.3/...
   usr/lib/gcc-lib
   usr/lib/gcc-lib/powerpc-unknown-linux-gnu
   usr/lib/gcc-lib/powerpc-unknown-linux-gnu/3.2.3
   usr/lib/gcc-lib/powerpc-unknown-linux-gnu/3.2.3/...
   usr/lib/libpython2.3.so
   usr/lib/libpython2.3.so.1.0
   bin
   bin/sh
   var
   var/zope
   var/zope/Extensions
   var/zope/bin
   var/zope/bin/zopectl
   var/zope/bin/runzope
   var/zope/bin/zopeservice.py
   var/zope/var
   var/zope/var/Data.fs.tmp
   var/zope/var/Data.fs
   var/zope/var/Data.fs.lock
   var/zope/var/Data.fs.index
   var/zope/var/Z2.pid
   var/zope/var/Z2.lock
   var/zope/import
   var/zope/etc
   var/zope/etc/zope.conf
   var/zope/Products
   var/zope/log
   var/zope/log/Z2.log
   var/zope/log/event.log
   lib
   lib/libc-2.3.2.so
   lib/libutil.so.1
   lib/libnss_files-2.3.2.so
   lib/libz.so
   lib/libdl.so.2
   lib/libutil-2.3.2.so
   lib/libpthread.so.0
   lib/libz.so.1
   lib/libpthread-0.10.so
   lib/libnss_files.so.2
   lib/libc.so.6
   lib/libm.so.6
   lib/libcrypt.so.1
   lib/ld-2.3.2.so
   lib/ld.so.1
   lib/libcrypt-2.3.2.so
   lib/libm-2.3.2.so
   lib/libdl-2.3.2.so
   lib/libz.so.1.2.1
   etc
   etc/ld.so.cache
   etc/passwd
   etc/group

Start

sollte jetzt alles passen kann man das zope per chroot befehl starten:

  chroot /var/Zope /var/zope/bin/runzope

fehlen noch libraries, findet man diese am einfachten mit dem befehl ldd auf dem entsprechenden binary.

zum ablegen der root privilegien bereits zum starten des prozesses kann folgedes programm dienen (der chroot und setuid auf zope wird darin ausgefuehrt und somit verliert dieser und alle kind prozesse sofort die root privilegien:

  chrootsu /var/Zope zope /var/zope/bin/runzope

Makefile:

        chrootsu:chrootsu.c
                $(CC) -Wall -Werror -pedantic -ansi -D_BSD_SOURCE -o $@ $<

chrootsu.c:

        /*
         * Copyright (C) 2004 Christoph Frick 
         * All rights reserved.
         * 
         * Redistribution and use in source and binary forms, with or without
         * modification, are permitted provided that the following conditions are met:

         * 1. Redistributions of source code must retain the above copyright notice,
         *    this list of conditions and the following disclaimer.
         * 2. Redistributions in binary form must reproduce the above copyright notice,
         *    this list of conditions and the following disclaimer in the documentation
         *    and/or other materials provided with the distribution.
         * 3. Neither the name of the project nor the names of its contributors may be
         *    used to endorse or promote products derived from this software without
         *    specific prior written permission.
         * 
         * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND ANY
         * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
         * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
         * DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
         * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
         * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
         * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
         */

        #include 
        #include 
        #include 
        #include 
        #include 
        #include 

        static void usage(char*);

        int
        main(argc, argv) 
                int argc;
                char **argv;
        {
                struct stat st;
                struct passwd *pwd;

                if (getuid()!=0) {
                        usage("only root can do that");
                }

                if (argc!=4) {
                        usage("wrong amount of params");
                }

                if (stat(argv[1], &st)==-1) {
                        perror("stat");
                        usage("failed to stat new root");
                }

                if (!S_ISDIR(st.st_mode)) {
                        usage(" have to be a directory");
                }

                if ((pwd=getpwnam(argv[2]))==NULL) { 
                        usage("failed to get user by name");
                }

                if (chroot(argv[1])==-1) {
                        perror("chroot");
                        usage("failed to chroot to new root");
                }

                if (setuid(pwd->pw_uid)==-1) {
                        perror("setuid");
                        usage("failed to switch to user id");
                }

                if (stat(argv[3], &st)==-1) {
                        perror("stat");
                        usage("failed to stat command");
                }

                if (!S_ISREG(st.st_mode)) {
                        usage(" must be a file");
                }

                if (execl(argv[3],NULL)==-1) {
                        perror("execl");
                        usage("failed to execl command");
                }

                return 0;
        }

        void
        usage(message)
                char *message;
        {
                if (message!=NULL) {
                        fprintf(stderr, "ERROR: %s\n", message);
                }
                fprintf(stderr, "usage: suchroot   \n\n");
                exit(1);
        }

Geschrieben von cfrick . Letzte �nderung 24.02.2004 20:51.