4.01.2013

fix me lucks fs

Lunes 1 de abril, primeros minutos en la oficina y enciendo mi laptop y ... no iniciada mi laptop, algo causó que mi file system de mi rhel 6 falle, mi fs estaba cifrado con LUCKs (con contraseña), así que apoyándome en un live cd SystemRescue:
# cryptsetup luksOpen /dev/md3 securebackup
Nos pedirá la contraseña :
Enter passphrase for /dev/md3
Para leer todos los volúmenes físicos:
# vgscan --mknodes
Tendríamos esta salida:
Reading all physical volumes. This may take a while...
  Found volume group "cryptvg" using metadata type lvm2
Ahora debemos activar el volumen lógico:
# vgchange -ay
Deberíamos tener una salida como :
1 logical volume(s) in volume group "cryptvg" now active
"cryptovg" es solo el nombre del volumen group usado en este ejemplo
Finalmente revisamos nuestro logical volumen a recuperar con lvdisplay:
# lvdisplay
--- Logical volume ---
  LV Name                /dev/cryptvg/lvroot
  VG Name                cryptvg
  LV UUID                g0AghZ-bcv5-n6pP-AQUA-5c32-fQa1-OteSlg
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                600.01 GiB
  Current LE             153602
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     6144
  Block device           253:1
Reparamos nuestro logical volumen (lvm2 y LUCKS) 
# fsck -C -V /dev/cryptvg/mybackup
Podríamos darle también fsck -C -V -y, y es así como solucione mi inconveniente gracias a este post http://www.cyberciti.biz/faq/howto-centos-rhel-fedora-debian-fsck-ext3-on-luks-volume/

the eagle

Romperse el pico y garras para renovarse, muchas gracias Dios por esta didáctica ave.
http://www.youtube.com/watch?v=c4388tMnAnY   
Aqui  PNL Triangulo de los niveles lógicohttp://www.youtube.com/watch?v=_6by5S2LMJc

2.28.2013

sftp/chroot + selinux

Dado que en un ambiente de hosting los webmaster necesitan subir cosas a su web, Nessus sugirió sFTP, ni modo... Debemos activar los booleanos ssh_chroot_rw_homedirs, httpd_enable_homedirs, fenced_can_ssh (no descarto otro que no recuerde ahora..)

El archivo de configuración /etc/ssh/sshd_config lo deje así:


# override default of no subsystems
#Subsystem      sftp    /usr/libexec/openssh/sftp-server
Subsystem       sftp    internal-sftp
Match Group apache

        ChrootDirectory /data/web
        ForceCommand internal-sftp
        AllowTcpForwarding no


Creamos el usuario "webmaster" asignandolo al grupo apache el cual no debería tener shell y en mi caso con un home particular por ejemplo "incoming".

useradd -g apache -d /incoming -s /sbin/nologin  webmaster

Nótese que éste comando crea el directorio /incoming conteniendo:

[root@rusia incoming]# ls -lZa
drwx------. adminer apache system_u:object_r:default_t:s0   .
dr-xr-xr-x. root    root   system_u:object_r:root_t:s0      ..
-rw-r--r--. webmaster apache system_u:object_r:default_t:s0   .bash_logout
-rw-r--r--. webmaster apache system_u:object_r:default_t:s0   .bash_profile
-rw-r--r--. webmaster apache system_u:object_r:default_t:s0   .bashrc
-rw-r--r--. webmaster apache system_u:object_r:default_t:s0   .kshrc


Importante: Al final de todo el proceso y verificar que todo lo requerido funcione eliminé este directoio feo "/incoming" de la raiz y en /etc/passwd editar:
webmaster:x:613:48::/hosting/web1:/sbin/nologin

Luego bajo el directorio "Document Root" donde el webmaster subira sus htmls (en mi caso /hosting/web1/) deberá tener los propietarios y contextos:

/hosting : drwxr-xr-x. root root system_u:object_r:home_root_t:s0
/hosting/web1/  : drwxr-xr-x. root root unconfined_u:object_r:user_home_dir_t:s0
/hosting/web1/public_html : drwxr-xr-x+ wemaster apache unconfined_u:object_r:user_home_dir_t:s0 
/hosting/web1/public_html/* : webmaster apache unconfined_u:object_r:user_home_t:s0

Donde * son los directorios, archivos y cosas html

Finalmente revisar mediante un cliente sftp subiendo un file de nombre piedra.html por ejemplo.
Esta piedra.html tendra el contexto : adminer apache system_u:object_r:user_home_t:s0, el cual es válido e interpretado por apache normalmente.
Este escenario esta basado en http://www.thegeekstuff.com/2012/03/chroot-sftp-setup/ considerando RHEL6 con selinux enforcing.