[命令] Rocky Linux 8 & RHEL 8 命令 update-crypto-policies

内容一:update-crypto-policies 参数的意义

1) DEFAULT 不严格的安全等级,可以让系统使用 TLSv1.2
2) FUTURE 严格的安全等级,只能让系统使用 TLSv1.2 不能使用 TLSv1.3

内容二:显示当前的 update-crypto-policies 参数

# update-crypto-policies --show
DEFAULT

(补充:从这里可以看出目前的 update-crypto-policies 参数是 DEFAULT)

内容三:设置 update-crypto-policies 参数

# update-crypto-policies --set=FUTURE

(补充:这里以将 update-crypto-policies 参数设置为 FUTURE 为例)

[排错] 解决 Linux 执行 curl 命令时报错 “curl: (35) error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure”

报错代码:

curl: (35) error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure

分析:

Rocky Linux 8 & RHEL 8 已经默认废弃 TLSv1.2
可以使用 TLSv1.3 替代 TLSv1.2 或者将 update-crypto-policies 参数设置为 DEFAULT 以解决此报错

解决方法:

步骤一:显示当前的 update-crypto-policies 参数

# update-crypto-policies --show
FUTURE

(补充:从这里可以看出目前的 update-crypto-policies 参数是 FUTURE)

步骤二:将 update-crypto-policies 参数设置为 DEFAULT

# update-crypto-policies --set=DEFAULT

(补充:这里以将 update-crypto-policies 参数设置为 DEFAULT 为例)

[步骤] Linux SSL 证书的生成 (Let’s Encrypt certbot 版)

步骤目录:

步骤一:将要申请 Let’s Encrypt SSL 的域名解析到要进行操作的服务器 IP 地址上

步骤二:安装 certbot

步骤三:使用 certbot 生成 Let’s Encrypt SSL 证书

步骤四:显示已经生成的 Let’s Encrypt SSL 证书

步骤五:延期 Let’s Encrypt SSL 证书
5.1 显示 Let’s Encrypt SSL 证书的延期策略
5.2 手动延期 Let’s Encrypt SSL 证书
5.3 自动延期 Let’s Encrypt SSL 证书

步骤六:Let’s Encrypt SSL 证书的生成限制

具体的操作步骤:

步骤一:将要申请 Let’s Encrypt SSL 的域名解析到要进行操作的服务器 IP 地址上

(步骤略)

步骤二:安装 certbot

# yum -y install certbot

(补充:这里以在 Fedora 35 上安装 certbot 为例)

步骤三:使用 certbot 生成 Let’s Encrypt SSL 证书

# certbot certonly --email mingyu.zhu@eternalcenter.com -n --agree-tos --webroot -w /usr/share/nginx/html/ -d eternalcenter.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Requesting a certificate for eternalcenter.com
Performing the following challenges:
http-01 challenge for eternalcenter.com
Using the webroot path /usr/share/nginx/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/eternalcenter.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/eternalcenter.com/privkey.pem
   Your certificate will expire on 2022-03-20. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again. To non-interactively renew *all* of your
   certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le


补充:这里以
1) 使用 mingyu.zhu@eternalcenter.com 邮箱
2) 以非交互式的方式
3) 通过给 /usr/share/nginx/html/ 网站目录里添加验证文件进行验证
4) 给 eternalcenter.com 域名
申请 Let’s Encrypt SSL 证书为例

步骤四:显示已经生成的 Let’s Encrypt SSL 证书

# certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: eternalcenter.com
    Serial Number: 3e8cdb74a1abfbf3d535ec1c3f8cb3e4e4c
    Key Type: RSA
    Domains: eternalcenter.com
    Expiry Date: 2022-03-20 13:48:48+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/eternalcenter.com/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/eternalcenter.com/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


补充:
1) /etc/letsencrypt/live/eternalcenter.com/fullchain.pem 是公钥
2) /etc/letsencrypt/live/eternalcenter.com/privkey.pem 是私钥

步骤五:延期 Let’s Encrypt SSL 证书
5.1 显示 Let’s Encrypt SSL 证书的延期策略

# cat /etc/letsencrypt/renewal/eternalcenter.com.conf 
# renew_before_expiry = 30 days
version = 1.20.0
archive_dir = /etc/letsencrypt/archive/eternalcenter.com
cert = /etc/letsencrypt/live/eternalcenter.com/cert.pem
privkey = /etc/letsencrypt/live/eternalcenter.com/privkey.pem
chain = /etc/letsencrypt/live/eternalcenter.com/chain.pem
fullchain = /etc/letsencrypt/live/eternalcenter.com/fullchain.pem

(补充:可以看出 Let’s Encrypt SSL 证书是在过期前 30 天才能更新)

5.2 手动延期 Let’s Encrypt SSL 证书

# /usr/bin/certbot renew

(补充:这里以延期 Let’s Encrypt SSL 证书为例)

5.3 自动延期 Let’s Encrypt SSL 证书

# crontab -e

添加以下内容:

......
0 0 */30 * * /usr/bin/certbot renew

(补充:这里以每过 30 天的 0 时 0 分延期 Let’s Encrypt SSL 证书为例)

步骤六:Let’s Encrypt SSL 证书的生成限制

1) 一个域名申请次数不能超过 5 次/周
2) 允许申请失败次数不能超过 5 次/时
3) 属于同一个顶级域名的二级域名申请次数不能超过 20 次/周
4) 申请请求频率不能超过 20 次/秒
5) 一个 IP 地址创建用户个数不能超过 10 个/3 小时
6) 一个用户最多 pending 审核的数不能超过 300 个

[步骤] SELinux 的启用 (openSUSE & SLE 版) (不建议)

软件准备:

在 SELinuxProject 的官网上下载 SELinux 策略 UseRefpolicy:

https://github.com/SELinuxProject/refpolicy/wiki/UseRefpolicy

注意:

1) 如果使用此文的方法将 openSUSE & SLE 的 SELinux 设置为 Enforcing 则系统将无法设置 IP 地址
2) 如果使用此文的方法开启了 SELinux 并且将所有的布尔(boolean)值开启,则系统将无法关机,开启所有布尔值的方法:# for i in semanage boolean -l | awk '{print $1}'; do echo $i;setsebool -P $i 1; done

正文:

步骤目录:

步骤一:安装 SELinux 组件

步骤二:安装 SELinux 策略
2.1 解压包含 SELinux 策略的压缩包
2.2 将 SELinux 策略移动到 SELinux 配置文件的位置
2.3 进入到和 SELinux 策略相同目录下
2.4 显示 SELinux 策略的安装手册
2.5 创建 SELinux 策略的配置文件
2.6 创建 SELinux 策略
2.7 编译 SELinux 策略
2.8 安装 SELinux 策略

步骤三:配置 SELinux 配置文件
3.1 在 SELinux 配置文件中将 SELinux 设置为 Permissive 状态
3.2 在系统内核中禁止使用 AppArmor 使用 SELinux 并且将 SELinux 状态设置为 Permissive
3.2.1 设置 grub 文件
3.2.2 让刚刚设置的 grub 文件生效
3.3 刷新系统内所有文件的标签

步骤四:重启系统让 SELinux 生效

具体的操作步骤:

步骤一:安装 SELinux 组件

# zypper in libselinux1 libsemanage1 libsepol-devel libsepol1 libselinux-devel mcstrans libselinux1-32bit policycoreutils checkpolicy libsemanage-devel setools-tcl setools-libs setools-java setools-devel setools-console selinux-tools python3-policycoreutils python3-selinux python3-semanage python3-setools restorecond

步骤二:安装 SELinux 策略
2.1 解压包含 SELinux 策略的压缩包

# tar -xvf refpolicy-2.20210203.tar.bz2

(补充:这里以解压 refpolicy-2.20210203.tar.bz2 压缩包为例)

2.2 将 SELinux 策略移动到 SELinux 配置文件的位置

# mv refpolicy /etc/selinux/

2.3 进入到和 SELinux 策略相同目录下

# cd /etc/selinux/refpolicy/

2.4 显示 SELinux 策略的安装手册

# cat INSTALL

2.5 创建 SELinux 策略的配置文件

# make conf

2.6 创建 SELinux 策略

# make policy

2.7 编译 SELinux 策略

# make install

2.8 安装 SELinux 策略

# make load

步骤三:配置 SELinux 配置文件
3.1 在 SELinux 配置文件中将 SELinux 设置为 Permissive 状态

# vim /etc/selinux/config

创建以下内容:

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=refpolicy

3.2 在系统内核中禁止使用 AppArmor 使用 SELinux 并且将 SELinux 状态设置为 Permissive
3.2.1 设置 grub 文件

# vim /etc/default/grub

在这一行里:

GRUB_CMDLINE_LINUX_DEFAULT="......"
添加以下内容:
GRUB_CMDLINE_LINUX_DEFAULT="...... security=selinux selinux=1 enforcing=0"

3.2.2 让刚刚设置的 grub 文件生效

# grub2-mkconfig -o /boot/grub2/grub.cfg

3.3 刷新系统内所有文件的标签

# restorecon -Rp /

步骤四:重启系统让 SELinux 生效

# reboot

参考文献:

https://documentation.suse.com/sles/15-SP2/html/SLES-all/cha-selinux.html

[内容] Linux SELinux 状态的设置

内容目录:

内容一:SELinux 的状态

内容二:永久切换 SELinux 状态
2.1 将 SELinux 永久切换至 Disabled 状态
2.1.1 修改 SELinux 配置文件
2.1.2 重启系统
2.1.3 显示 SELinux 状态
2.2 将 SELinux 永久切换至 Permissive 状态
2.2.1 修改 SELinux 配置文件
2.2.2 重启系统
2.2.3 显示 SELinux 状态
2.3 将 SELinux 永久切换至 Enforcing 状态
2.3.1 修改 SELinux 配置文件
2.3.2 重启系统
2.3.3 显示 SELinux 状态

内容三:临时切换 SELinux 状态
3.1 临时切换到 Permissive 状态
3.1.1 临时切换到 Permissive 状态
3.1.2 显示 SELinux 状态
3.2 临时切换到 Enforcing 状态
3.2.1 临时切换到 Enforcing 状态
3.2.2 显示 SELinux 状态

具体的内容:

内容一:SELinux 的状态

1) Disabled:完全关闭 SELinux
2) Permissive:即使违反了策略也依旧可以执行,但是违反策略的记录会被记录在日志中
3) Enforcing:如果违反了策略就不能之行

内容二:永久切换 SELinux 状态
2.1 将 SELinux 永久切换至 Disabled 状态
2.1.1 修改 SELinux 配置文件

# vim /etc/selinux/config

将以下内容:

......
SELINUX=......
......

修改为:

......
SELINUX=disabled
......

2.1.2 重启系统

# reboot

2.1.3 显示 SELinux 状态

# getenforce 
Disabled

2.2 将 SELinux 永久切换至 Permissive 状态
2.2.1 修改 SELinux 配置文件

# vim /etc/selinux/config

将以下内容:

......
SELINUX=......
......

修改为:

......
SELINUX=permissive
......

2.2.2 重启系统

# reboot

2.2.3 显示 SELinux 状态

# getenforce 
Permissive

2.3 将 SELinux 永久切换至 Enforcing 状态
2.3.1 修改 SELinux 配置文件

# vim /etc/selinux/config

将以下内容:

......
SELINUX=......
......

修改为:

......
SELINUX=enforcing
......

2.3.2 重启系统

# reboot

2.3.3 显示 SELinux 状态

# getenforce 
Enforcing

内容三:临时切换 SELinux 状态
3.1 临时切换到 Permissive 状态
3.1.1 临时切换到 Permissive 状态

# setenfoce 0


注意:
1) 系统重启后失效
2) 只能从 Enforcing 状态切换到 Permissive 状态

3.1.2 显示 SELinux 状态

# getenforce 
Permissive

3.2 临时切换到 Enforcing 状态
3.2.1 临时切换到 Enforcing 状态

# setenfoce 1


注意:
1) 系统重启后失效
2) 只能从 Permissive 状态切换到 Enforcing 状态

3.2.2 显示 SELinux 状态

# getenforce 
Enforcing