一般加固指南在主要加固文档中有概述。

你可以配置底层操作系统以提高整体安全性。在极狐GitLab私有化部署等受控环境中,这需要额外的步骤,事实上在某些部署中是必须的。FedRAMP 就是这样一种部署的例子。

SSH 配置

SSH 客户端配置

对于客户端访问(无论是访问极狐GitLab 实例还是底层操作系统),这里有一些 SSH 密钥生成的建议。第一个是典型的 SSH 密钥:

ssh-keygen -a 64 -t ed25519 -f ~/.ssh/id_ed25519 -C "ED25519 Key"

对于符合 FIPS 的 SSH 密钥,使用以下命令:

ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -C "RSA FIPS-compliant Key"

SSH 服务器配置

在操作系统级别,如果你允许 SSH 访问(通常通过 OpenSSH),这里是 sshd_config 文件的配置选项示例(确切位置可能因操作系统而异,但通常在 /etc/ssh/sshd_config):

#
# Example sshd config file. This supports public key authentication and
# turns off several potential security risk areas
#
PubkeyAuthentication yes
PasswordAuthentication yes
UsePAM yes
UseDNS no
AllowTcpForwarding no
X11Forwarding no
PrintMotd no
PermitTunnel no
PermitRootLogin no

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# Change default of 120 seconds to 60
LoginGraceTime 60

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Protocol adjustments, these would be needed/recommended in a FIPS or
# FedRAMP deployment, and use only strong and proven algorithm choices
Protocol 2
Ciphers aes128-ctr,aes192-ctr,aes256-ctr
HostKeyAlgorithms ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
KexAlgorithms ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
Macs hmac-sha2-256,hmac-sha2-512

防火墙规则

对于防火墙规则,只需要开放 TCP 端口 80443 以进行基本使用。默认情况下,5050 端口为远程访问容器注册表而开放,但在加固环境中,这通常会存在于不同的主机上,在某些环境中则根本不开放。因此,建议仅使用端口 80443,且端口 80 仅用于重定向到 443

对于如 FedRAMP 等真正加固或隔离的环境,你应调整防火墙规则,以限制所有端口,除了访问它的那些网络。例如,如果 IP 地址是 192.168.1.2,且所有授权客户端也在 192.168.1.0/24 上,限制对端口 80443 的访问仅限于 192.168.1.0/24(作为一种安全限制),即使访问已在其他地方通过另一个防火墙进行了限制。

理想情况下,如果你正在安装一个极狐GitLab私有化部署实例,你应该在安装开始之前实施防火墙规则,将访问限制在管理员和安装人员,并且在实例安装和正确加固后才为用户添加额外的 IP 地址范围。

使用 iptablesufw 是可接受的,以实施和执行基于每个主机的端口 80443 访问,否则通过 GCP Google Compute 或 AWS Security Groups 使用云端防火墙规则应强制执行此操作。所有其他端口应被阻止,或至少限制为特定范围。有关端口的更多信息,请参见软件包默认值

防火墙扩展

可能会启用各种需要外部访问的服务(例如 Sidekiq),并需要打开网络访问。将这些类型的服务限制为特定的 IP 地址或特定的 C 类网络。作为分层和额外的预防措施,在可能的情况下,将这些额外服务限制为极狐GitLab 中的特定节点或子网络。

内核调整

可以通过编辑 /etc/sysctl.conf/etc/sysctl.d/ 中的文件之一来进行内核调整。内核调整不能完全消除攻击的威胁,但增加了一层额外的安全性。以下注释解释了这些调整的一些优势。

## Kernel tweaks for sysctl.conf ##
##
## The following help mitigate out of bounds, null pointer dereference, heap and
## buffer overflow bugs, use-after-free etc from being exploited. It does not 100%
## fix the issues, but seriously hampers exploitation.
##
# Default is 65536, 4096 helps mitigate memory issues used in exploitation
vm.mmap_min_addr=4096
# Default is 0, randomize virtual address space in memory, makes vuln exploitation
# harder
kernel.randomize_va_space=2
# Restrict kernel pointer access (for example, cat /proc/kallsyms) for exploit assistance
kernel.kptr_restrict=2
# Restrict verbose kernel errors in dmesg
kernel.dmesg_restrict=1
# Restrict eBPF
kernel.unprivileged_bpf_disabled=1
net.core.bpf_jit_harden=2
# Prevent common use-after-free exploits
vm.unprivileged_userfaultfd=0
# Mitigation CVE-2024-1086 by preventing unprivileged users from creating namespaces
kernel.unprivileged_userns_clone=0

## Networking tweaks ##
##
## Prevent common attacks at the IP stack layer
##
# Prevent SYNFLOOD denial of service attacks
net.ipv4.tcp_syncookies=1
# Prevent time wait assassination attacks
net.ipv4.tcp_rfc1337=1
# IP spoofing/source routing protection
net.ipv4.conf.all.rp_filter=1
net.ipv4.conf.default.rp_filter=1
net.ipv6.conf.all.accept_ra=0
net.ipv6.conf.default.accept_ra=0
net.ipv4.conf.all.accept_source_route=0
net.ipv4.conf.default.accept_source_route=0
net.ipv6.conf.all.accept_source_route=0
net.ipv6.conf.default.accept_source_route=0
# IP redirection protection
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.all.secure_redirects=0
net.ipv4.conf.default.secure_redirects=0
net.ipv6.conf.all.accept_redirects=0
net.ipv6.conf.default.accept_redirects=0
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0