Tornando um Servidor de Arquivos e Impressoras Samba mais seguro

Modos de Segurança do Samba

There are two security levels available to the Common Internet Filesystem (CIFS) network protocol user-level and share-level. Samba's security mode implementation allows more flexibility, providing four ways of implementing user-level security and one way to implement share-level:

  • security = user: requires clients to supply a username and password to connect to shares. Samba user accounts are separate from system accounts, but the libpam-smbpass package will sync system users and passwords with the Samba user database.

  • security = domain: this mode allows the Samba server to appear to Windows™ clients as a Primary Domain Controller (PDC), Backup Domain Controller (BDC), or a Domain Member Server (DMS). See the section called “Samba como um Controlador de Domínio” for further information.

  • security = ADS: allows the Samba server to join an Active Directory™ domain as a native member. See the section called “Integração do Samba com o Active Directory” for details.

  • security = server: this mode is left over from before Samba could become a member server, and, due to some security issues, should not be used. See the Server Types and Security Modes section of the Samba guide for more details.

  • security = share: permite que clientes se conectem a compartilhamentos sem informar um usuário e senha.

The preferred security mode depends on the environment and what the Samba server needs to accomplish.

Security = User

This section will reconfigure the Samba file and print server, from the section called “Servidor de arquivos samba” and the Print Server, to require authentication.

First, install the libpam-smbpass package, which will sync the system users to the Samba user database:

sudo apt-get install libpam-smbpass

Note

If the Samba Server task was chosen during installation, libpam-smbpass is already installed.

Edit /etc/samba/smb.conf, and in the [share] section change:

guest ok = no

Finally, restart Samba for the new settings to take effect:

sudo /etc/init.d/samba restart

Agora, ao tentar conectar aos diretórios os impressoras compartilhadas, será solicitado um nome de usuário e senha.

Note

Para mapear uma unidade de rede para o compartilhamento, Reconectar no Logon deve ser marcado, o que exigirá o nome de usuário e senha para entrar apenas uma vez; pelo menos até que se altere a senha.

Segurança de compartilhamento

Existem várias opções disponíveis para aumentar a segurança para cada diretório compartilhado. Usando o exemplo [share], esta seção irá mostrar algumas opções comuns.

Grupos

Grupos define uma coleção de computadores ou usuários que tem um nível de acesso comum a recursos de rede específicos e oferece um nível de granularidade no controle do acesso a tais recursos. Por exemplo, se um grupo qa é definido e contém os usuários freda, danika, e rob, e um segundo grupo support é definido e consiste dos usuários danika, jeremy, e vincent,e certos recursos de rede são configurados para permitir o acesso pelo grupo qa vai posteriormente permitir o acesso para freda, danika, e rob, mas não jeremy ou vincent. Uma vez que o usuário danika pertence a ambos os grupos qa e support, ela será capaz de acessar os recursos configurados para acesso por ambos os grupos, contudo, os outros usuários terão acesso a recursos explicitamente permitidos ao grupo de que fazem parte.

By default, Samba looks for the local system groups defined in /etc/group to determine which users belong to which groups. For more information on adding and removing users from groups, see Basics.

When defining groups in the Samba configuration file, /etc/samba/smb.conf, the recognized syntax is to preface the group name with an "@" symbol. For example, to define a group named sysadmin in a certain section of the /etc/samba/smb.conf, the group name would be entered as @sysadmin.

Permissões de arquivo

File permissions define the explicit rights a computer or user has to a particular directory, file, or set of files. Such permissions may be defined by editing the /etc/samba/smb.conf file and specifying the explicit permissions of a defined file share.

For example, for a defined Samba share called share and the need to give read-only permissions to the group of users known as qa, while allowing write permissions to the share by the group called sysadmin and the user named vincent, then the /etc/samba/smb.conf file could be edited to add the following entries under the [share] entry:

read list = @qa
write list = @sysadmin, vincent

Another possible Samba permission is to declare administrative permissions to a particular shared resource. Users having administrative permissions may read, write, or modify any information contained in the resource where they have been given explicit administrative permissions.

For example, to give the user melissa administrative permissions to the share example, the /etc/samba/smb.conf file would be edited to add the following line under the [share] entry:

admin users = melissa

After editing /etc/samba/smb.conf, restart Samba for the changes to take effect:

sudo /etc/init.d/samba restart

Note

For the read list and write list to work, the Samba security mode must not be set to security = share.

Now that Samba has been configured to limit which groups have access to the shared directory, the filesystem permissions need to be updated.

Traditional Linux™ file permissions do not map well to Windows NT™ Access Control Lists (ACLs). Fortunately POSIX ACLs are available on Kubuntu™ servers providing more fine-grained control. For example, to enable ACLs on srv an ext3 filesystem, edit /etc/fstab and add the ACL option:

UUID=66bcdd2e-8861-4fb0-b7e4-e61c569fe17d /srv  ext3    noatime,relatime,acl 0 
    1

Então remonte a partição:

sudo mount -v -o remount /srv

Note

The above example assumes srv is on a separate partition. If srv — or wherever the share path is configured — is part of the / partition, a reboot may be required.

To match the Samba configuration above, the sysadmin group will be given read, write, and execute permissions to /srv/samba/share, the qa group will be given read and execute permissions, and the files will be owned by the username melissa. Enter the following in a terminal:

sudo chown -R melissa /srv/samba/share/
sudo chgrp -R sysadmin /srv/samba/share/
sudo setfacl -R -m g:qa:rx /srv/samba/share/

Note

The setfacl command above gives execute permissions to all files in the /srv/samba/share directory, which may or may not be desirable.

A Windows™ client will show that the new file permissions are implemented. See the ACL and setfacl man pages for more information on POSIX ACLs.

Perfil Samba AppArmor

Kubuntu™ comes with the AppArmor security module, which provides mandatory access controls. The default AppArmor profile for Samba will need to be adapted to the proper configuration. For more details on using AppArmor, please refer to the official Ubuntu™ documentation.

There are default AppArmor profiles for /usr/sbin/smbd and /usr/sbin/nmbd, the Samba daemon binaries, as part of the apparmor-profiles packages. To install the package from a terminal prompt, enter:

sudo apt-get install apparmor-profiles

Note

Este pacote contém perfis para diversos outros binários.

By default, the profiles for smbd and nmbd are in complain mode, allowing Samba to work without modifying the profile, and only logging errors. To place the smbd profile into enforce mode and have Samba work as expected, the profile will need to be modified to reflect any directories that are shared.

Edit /etc/apparmor.d/usr.sbin.smbd, adding information for [share] from the file server example:

/srv/samba/share/ r,
/srv/samba/share/** rwkix,

Agora coloque o perfil em modo forçado e recarregue-o:

sudo aa-enforce /usr/sbin/smbd
cat /etc/apparmor.d/usr.sbin.smbd | sudo apparmor_parser -r

It is now possible to read, write, and execute files in the shared directory as normal, and the smbd binary will have access to only the configured files and directories. Be sure to add entries for each directory that Samba is configured to share. Any errors will be logged to /var/log/syslog.

Recursos