lunes, 4 de abril de 2016

LINUX-CENTOS-LAB-ACL vs chmod,chown. ejercicios

En el siguiente lab de ejercicios, vamos a analizar un par de requests, donde intentaremos dar solución aplicando ACL y chmod + chgrp + chown como alternativa. De esta forma podremos apreciar en mejor medida ambos utilitarios.

Req. 1: Create a directory named /common. Allow john and davis to share documents in the /common directory using a group called team. Both of them can read, write and remove documents from the other in this directory but any user not member of the group can’t.



en común:
[root@localhost ~]# mkdir /common
[root@localhost ~]# ls -ltr / | grep common
drwxr-xr-x    2 root root  4096 abr  2 16:38 common
[root@localhost ~]# 
[root@localhost ~]# cat /etc/passwd | egrep "davis|john"
john:x:2000:2000::/home/john:/bin/bash
davis:x:3000:10502::/home/davis:/bin/bash
[root@localhost ~]# 


Sol 1: ACL

Se crea el group "team" y se incorpora a los users john y davis

[root@localhost ~]# /usr/sbin/groupadd team
[root@localhost ~]# cat /etc/group | grep team
team:x:10503:
[root@localhost ~]#

Se añade los usuario john y davis al group team
[root@localhost ~]# id john
uid=2000(john) gid=2000(john) groups=2000(john)
[root@localhost ~]# id davis
uid=3000(davis) gid=10502(davis) groups=10502(davis)
[root@localhost ~]# /usr/sbin/usermod -aG 10503 john
[root@localhost ~]# id john
uid=2000(john) gid=2000(john) groups=2000(john),10503(team)
[root@localhost ~]# /usr/sbin/usermod -aG 10503 davis
[root@localhost ~]# id davis
uid=3000(davis) gid=10502(davis) groups=10502(davis),10503(team)
[root@localhost ~]# groups john davis
john : john team
davis : davis team
[root@localhost ~]# cat /etc/group | grep team
team:x:10503:john,davis
[root@localhost ~]# 

Verificar si está implementado ACL en la partición correspondiente al directorio /common
[root@localhost ~]# ls -ltr / | grep common
drwxr-xr-x    2 root root  4096 abr  2 16:38 common
[root@localhost ~]# df -h /
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  7,3G  1,9G  5,1G  27% /
[root@localhost ~]# tune2fs -l /dev/mapper/centos-root | grep -i acl 
Default mount options:    user_xattr acl
[root@localhost ~]# 

Verificación de status ACL en el directorio.
[root@localhost ~]# getfacl /common/
getfacl: Removing leading '/' from absolute path names
# file: common/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
[root@localhost ~]# 

Aplicación y Verificación de reglas ACL en el directorio
[root@localhost ~]# setfacl -dRm g:10503:rwx /common
[root@localhost ~]# getfacl /common/
getfacl: Removing leading '/' from absolute path names
# file: common/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:group::r-x
default:group:team:rwx
default:mask::rwx
default:other::r-x
[root@localhost ~]# 

Sol 2: implementacion con chgrp + chmod

[root@localhost ~]# ls -ltr / | grep common
drwxr-xr-x    2 root root  4096 abr  4 21:32 common
[root@localhost ~]# 

[root@localhost ~]# cat /etc/group | grep team
team:x:10503:john,davis
[root@localhost ~]# 

Aplicar cambio de group owner y privileges 
[root@localhost ~]# /usr/bin/chgrp -R team /common
[root@localhost ~]# ls -ltr / | grep common
drwxr-xr-x    2 root team  4096 abr  4 21:32 common
[root@localhost ~]# /usr/bin/chmod -R 775 /common 
[root@localhost ~]# ls -ltr / | grep common
drwxrwxr-x    2 root team  4096 abr  4 21:32 common
[root@localhost ~]# 

Crear un archivo y verificar:
[davis@localhost common]$ touch /common/otro.davis.txt
[davis@localhost common]$ ls -ltr /common/
total 4
-rwxrwxr-x+ 1 root  team  6 Apr  4 21:33 davis.txt
-rw-rw-r--  1 davis davis 0 Apr  4 21:40 otro.davis.txt
[davis@localhost common]$ 


Deacuerdo al ejemplo es posible obtener el mismo resultado deseado con ambos métodos, salvo algunas ecepciones.
al terminar este lab me quedan las siguientes interrogantes:
¿ qué pasa si tengo más users dentro del group "team" y  cómo limito para que sólo 2 users de un group tenga acceso ?

En ese caso tendría que usar ACL con permiso a cada uno de los users.
En chmod + chgrp no sería posible implementarlo en el caso de ser este el nuevo escenario.


Req. 2: grant execute on script exec_date.sh to user davis
En El siguiente requerimiento, solicita que el script exec_date.sh el cual el user root es owner, pueda ser ejecutado por el user davis.

Observando los privileges que tiene el script actualmente:
[root@localhost common]# ls -ltr exec_date.sh 
-rwxr--r-- 1 root root 13 abr  6 20:56 exec_date.sh
[root@localhost common]# getfacl /common/exec_date.sh 
getfacl: Removing leading '/' from absolute path names
# file: common/exec_date.sh
# owner: root
# group: root
user::rwx
group::r--
other::r--
[root@localhost common]# 

Al intentar ejecutar el script por el user davis, el sistema no lo permite.  
[davis@localhost ~]$ /common/exec_date.sh
-bash: /common/exec_date.sh: Permission denied
[davis@localhost ~]$ 

PAra otorgar privileges de read,write,exec sobre el script, se requiere obtener el uid del user davis.
[root@localhost common]# cat /etc/passwd | grep davis
davis:x:3000:10502::/home/davis:/bin/bash
[root@localhost common]# id davis
uid=3000(davis) gid=10502(davis) groups=10502(davis),10503(team)
[root@localhost common]# 

Se aplica el otrogamiento de permisos al user davis
[root@localhost common]# setfacl -m u:3000:rwx /common/exec_date.sh 
[root@localhost common]# getfacl /common/exec_date.sh 
getfacl: Removing leading '/' from absolute path names
# file: common/exec_date.sh
# owner: root
# group: root
user::rwx
user:davis:rwx
group::r--
mask::rwx
other::r--
[root@localhost common]# 

Desde ahora el user davis ya puede ejecutar el script. 
[davis@localhost ~]$ /common/exec_date.sh
20165904/06/16
[davis@localhost ~]$ 


No hay comentarios:

Publicar un comentario