My specific need is the following:
A script of usuario1 has to be able to be executed by any user of group1 (that I know how to do), but when it is executed it has to have the permissions of user1.
It would be something equivalent to the concept of postgres to create a function with security definer .
It may be necessary the intervention of a sudoer for that configuration, that seems reasonable to me. (I know there may be some error in the commands, that I fix later, the question is only about delegating permissions)
Possible use cases:
1) controlled access to resources:
cat recibir_mensaje.sh
echo "$DATE - $1" >> /home/usuario1/mensajes-recibidos.log
Thus, the usuario1 could allow to add messages in the file mensajes-recibidos.log in a controlled manner without the need to allow the writing in the file if the script recibir_mensaje could be run with permissions of usuario1 execute it usuario2
2) controlled delegation of administrative tasks:
Imagine the user subadmin2 to which we want to allow you to create users that belong to group gr_comun . Nothing more than that. We could have a script:
cat crear_usuario_comun.sh
adduser $1
adduser $1 gr_comun
that this script runs with root permissions but does not give subadmin sudo permission but only permission to execute crear_usuario_comun.sh