在RHEL 7上为服务配置基于主机和基于用户的安全性

时间:2020-03-21 11:42:57  来源:igfitidea点击:

SSH,HTTP/S,DNS,NFS,SMB和SMTP的安全性。

基于主机的安全性

基于主机的安全性将在应用程序级别而非防火墙上配置。

我们的目标是按以下方式配置访问控制:

  • 允许来自:*。rhce.local(10.8.8.0/24),
  • 拒绝来自:my1337.hacker.local(10.8.9.99/32)。

SSH协议

允许所有用户进行防火墙SSH访问:

# firewall-cmd --permanent --add-service=ssh

打开“ /etc/hosts.deny”并添加以下内容:

sshd:   my1337.hacker.local

打开“ /etc/hosts.allow”并添加以下内容:

sshd:   *.rhce.local

默认情况下,所有内容都是允许的。

# journalctl -xlf
[...]
sshd[3069]: refused connect from my1337.hacker.local (10.8.9.99)

HTTP/HTTPS(Apache)

允许所有防火墙HTTP/S访问:

# firewall-cmd --permanent --add-service={http,https}

将以下内容放入httpd配置文件:

<RequireAll>
  Require host rhce.local
  Require not host my1337.hacker.local
</RequireAll>
# journalctl -xlf
[...]
[authz_core:error] [pid 3057] [client 10.8.9.99:43378] AH01630: client denied by server configuration: /var/www/html/

DNS(未绑定)

允许所有防火墙DNS访问:

# firewall-cmd --permanent --add-service=dns

打开“ /etc/unbound/unbound.conf”并添加以下行:

access-control: 10.8.8.0/24 allow

默认情况下,所有内容均被拒绝。

NFS

允许所有防火墙NFS访问:

# firewall-cmd --permanent --add-service=nfs

打开“/etc/exports”并配置访问权限:

/nfs *.rhce.local(ro)

其他一切都被拒绝。

中小型企业

允许所有防火墙SMB访问:

# firewall-cmd --permanent --add-service=samba

打开“ /etc/samba/smb.conf”并配置主机允许条目:

hosts allow = 10.8.8.

也可以使用主机拒绝列表,但是请注意,如果列表冲突,则允许列表优先。

SMTP(后缀)

允许所有防火墙SMTP访问:

# firewall-cmd --permanent --add-service=smtp

打开“/etc/postfix/access”并添加以下内容:

rhce.local

OK
my1337.hacker.local REJECT

运行步:

# postmap /etc/postfix/access

将以下行添加到'/etc/postfix/main.cf'中:

smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
# journalctl -xlf
[...]
postfix/smtpd[3939]: connect from my1337.hacker.local[10.8.9.99]
postfix/smtpd[3939]: NOQUEUE: reject: RCPT from my1337.hacker.local[10.8.9.99]: 554 5.7.1 <my1337.hacker.local[10.8.9.99]>: Client host rejected: Access denied; from=<Hyman@theitroad> to=<Hyman@theitroad> proto=ESMTP helo=
postfix/smtpd[3939]: disconnect from my1337.hacker.local[10.8.9.99]
[...]
postfix/smtpd[3939]: connect from srv1.rhce.local[10.8.8.71]
postfix/smtpd[3939]: A075621186: client=srv1.rhce.local[10.8.8.71]
postfix/cleanup[3944]: A075621186: message-id=<Hyman@theitroad>
postfix/qmgr[3882]: A075621186: from=<Hyman@theitroad>, size=610, nrcpt=1 (queue active)
postfix/smtpd[3939]: disconnect from srv1.rhce.local[10.8.8.71]
postfix/local[3946]: A075621186: to=<Hyman@theitroad>, relay=local, delay=0.08, delays=0.06/0.01/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
postfix/qmgr[3882]: A075621186: removed

基于用户的安全性

SSH协议

打开“/etc/ssh/sshd_config”并配置以下部分:

AllowUsers sandy
DenyUsers root

不要忘记重启sshd服务。

HTTP/HTTPS(Apache)

打开“ /etc/httpd/conf/httpd.conf”并配置用户身份验证:

<Directory "/var/www/html">
   AuthType Basic
   AuthName "Login Required"
   AuthUserFile "/etc/httpd/conf/htpasswd"
   Require valid-user
</Directory>

我们将需要使用有效用户创建密码文件:

# htpasswd -c /etc/httpd/conf/htpasswd sandy

不要忘记重启httpd服务。

NFS

NFS服务器不需要身份验证,仅实施基于客户端的IP地址或者主机名的访问限制。
使用默认的安全方法sec = sys,NFS服务器将信任客户端发送的所有uid。

Kerberos应该用于证明用户身份。

中小型企业

打开“ /etc/samba/smb.conf”并配置以下部分:

valid users = sandy, alice
write list = alice
read list = sandy

有效用户是应被允许登录此服务的用户列表。

写入列表是被授予对服务的读写访问权限的用户列表。
如果正在连接的用户在此列表中,那么无论设置了“只读”选项如何,都将为他们提供写访问权限。

不要忘记重启smb服务。

SMTP(Postfix)

Postfix的按地址访问控制'/etc/postfix/access':

Hyman@theitroad REJECT