Apache group

Материал из pNp Wiki
Перейти к: навигация, поиск

Конфигурирование Apache. Доступ к содержимому по группам

Предварительные требования

  • Виртуальная машина с двумя сетевыми интерфейсами
  • Установленные пакеты: bash-completion, policycoreutils, policycoreutils-python, policycoreutils-devel, setroubleshoot-server, httpd, httpd-manual, elinks, curl, perl

Конфигурирование ограничений

Ограничение на основе групп

У нас уже имеется ранее созданая директория /content/private и в ней файл index.html. Теперь следует создать еще пару пользователей lisa, и tony, а так же включить их в группу webmasters, а затем, данной группе предоставить доступ к содержимому директории:

[root@vm-01 ~]# htpasswd /etc/httpd/passwd lisa 
New password: 
Re-type new password: 
Adding password for user lisa
[root@vm-01 ~]# htpasswd /etc/httpd/passwd tony
New password: 
Re-type new password: 
Adding password for user tony
[root@vm-01 ~]#

Создадим файл /etc/httpd/group, добавим туда группу, включающую наших пользователей и дадим права на чтение пользователю apache:

[root@vm-01 ~]# echo "webmasters: lisa tony" >> /etc/httpd/group
[root@vm-01 ~]# chown apache:apache /etc/httpd/group
[root@vm-01 ~]# chmod 600 /etc/httpd/group
[root@vm-01 ~]# ls -lahi /etc/httpd/group
716151 -rw-------. 1 apache apache 22 Jan 29 12:44 /etc/httpd/group
[root@vm-01 ~]#

Укажем группу пользователей в файле /etc/httpd/conf.d/vm-01.conf которые имеют доступ к определенной части вебсайта:

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin webmaster@vm-01.example.com
    DocumentRoot "/content"
    ServerName vm-01.example.com
    ServerAlias www.vm-01.example.com
    ErrorLog "/var/log/httpd/vm-01.example.com-error_log"
    CustomLog "/var/log/httpd/vm-01.example.com-access_log" common
    ScriptAlias /cgi-bin/ "/content/dynamic"
	<Directory "/content">
    		AllowOverride None
    		# Allow open access:
    		Require all granted
	</Directory>
	<Directory "/content/private">
		AuthType basic
		AuthName "Private area! Restricted access"
		AuthUserFile "/etc/httpd/passwd"
		AuthGroupFile "/etc/httpd/group"
    		Require group webmasters
	</Directory>
	<Directory "/content/dynamic">
		Options ExecCGI
		AddHandler cgi-script .cgi .pl
		AllowOverride None
		Require all granted
	</Directory>
</VirtualHost>

Приведем файл /content/private/index.html к следующему виду:

This is private directory. Only for webmasters!!!
Mon Jan 29 13:05:55 MSK 2018

Перезапускаем Apache:

[root@vm-01 ~]# systemctl restart httpd
[root@vm-01 ~]# systemctl is-active httpd
active
[root@vm-01 ~]#

Проверка

С виртуальной машины vm-02 обратимся к странице при помощи утилиты curl:

[root@vm-01 ~]# curl -u lisa "http://192.168.1.1/private/"
Enter host password for user 'lisa':
This is private directory. Only for webmasters!!!
Mon Jan 29 13:05:55 MSK 2018
[root@vm-01 ~]# curl -u tony "http://192.168.1.1/private/"
Enter host password for user 'tony':
This is private directory. Only for webmasters!!!
Mon Jan 29 13:05:55 MSK 2018

А вот для пользователя andy доступ будет закрыт:

[root@vm-01 ~]# curl -u andy "http://192.168.1.1/private/"
Enter host password for user 'andy':
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>
[root@vm-01 ~]#

Ссылки

Apache ModAuthGroupfile
RHEL System Administration Guide