加固 - 操作系统推荐
一般加固指南在主要加固文档中有概述。
你可以配置底层操作系统以提高整体安全性。在极狐GitLab私有化部署等受控环境中,这需要额外的步骤,事实上在某些部署中是必须的。FedRAMP 就是这样一种部署的例子。
SSH 配置
SSH 客户端配置
对于客户端访问(无论是访问极狐GitLab 实例还是底层操作系统),这里有一些 SSH 密钥生成的建议。第一个是典型的 SSH 密钥:
shellssh-keygen -a 64 -t ed25519 -f ~/.ssh/id_ed25519 -C "ED25519 Key"
对于符合 FIPS 的 SSH 密钥,使用以下命令:
shellssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -C "RSA FIPS-compliant Key"
SSH 服务器配置
在操作系统级别,如果你允许 SSH 访问(通常通过 OpenSSH),这里是 sshd_config 文件的配置选项示例(确切位置可能因操作系统而异,但通常在 /etc/ssh/sshd_config):
shell1# 2# Example sshd config file. This supports public key authentication and 3# turns off several potential security risk areas 4# 5PubkeyAuthentication yes 6PasswordAuthentication yes 7UsePAM yes 8UseDNS no 9AllowTcpForwarding no 10X11Forwarding no 11PrintMotd no 12PermitTunnel no 13PermitRootLogin no 14 15# Allow client to pass locale environment variables 16AcceptEnv LANG LC_* 17 18# Change default of 120 seconds to 60 19LoginGraceTime 60 20 21# override default of no subsystems 22Subsystem sftp /usr/lib/openssh/sftp-server 23 24# Protocol adjustments, these would be needed/recommended in a FIPS or 25# FedRAMP deployment, and use only strong and proven algorithm choices 26Protocol 2 27Ciphers aes128-ctr,aes192-ctr,aes256-ctr 28HostKeyAlgorithms ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521 29KexAlgorithms ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521 30Macs hmac-sha2-256,hmac-sha2-512 31
防火墙规则
对于防火墙规则,只需要开放 TCP 端口 80 和 443 以进行基本使用。默认情况下,5050 端口为远程访问容器注册表而开放,但在加固环境中,这通常会存在于不同的主机上,在某些环境中则根本不开放。因此,建议仅使用端口 80 和 443,且端口 80 仅用于重定向到 443。
对于如 FedRAMP 等真正加固或隔离的环境,你应调整防火墙规则,以限制所有端口,除了访问它的那些网络。例如,如果 IP 地址是 192.168.1.2,且所有授权客户端也在 192.168.1.0/24 上,限制对端口 80 和 443 的访问仅限于 192.168.1.0/24(作为一种安全限制),即使访问已在其他地方通过另一个防火墙进行了限制。
理想情况下,如果你正在安装一个极狐GitLab私有化部署实例,你应该在安装开始之前实施防火墙规则,将访问限制在管理员和安装人员,并且在实例安装和正确加固后才为用户添加额外的 IP 地址范围。
使用 iptables 或 ufw 是可接受的,以实施和执行基于每个主机的端口 80 和 443 访问,否则通过 GCP Google Compute 或 AWS Security Groups 使用云端防火墙规则应强制执行此操作。所有其他端口应被阻止,或至少限制为特定范围。有关端口的更多信息,请参见软件包默认值。
防火墙扩展
可能会启用各种需要外部访问的服务(例如 Sidekiq),并需要打开网络访问。将这些类型的服务限制为特定的 IP 地址或特定的 C 类网络。作为分层和额外的预防措施,在可能的情况下,将这些额外服务限制为极狐GitLab 中的特定节点或子网络。
内核调整
可以通过编辑 /etc/sysctl.conf 或 /etc/sysctl.d/ 中的文件之一来进行内核调整。内核调整不能完全消除攻击的威胁,但增加了一层额外的安全性。以下注释解释了这些调整的一些优势。
shell1## Kernel tweaks for sysctl.conf ## 2## 3## The following help mitigate out of bounds, null pointer dereference, heap and 4## buffer overflow bugs, use-after-free etc from being exploited. It does not 100% 5## fix the issues, but seriously hampers exploitation. 6## 7# Default is 65536, 4096 helps mitigate memory issues used in exploitation 8vm.mmap_min_addr=4096 9# Default is 0, randomize virtual address space in memory, makes vuln exploitation 10# harder 11kernel.randomize_va_space=2 12# Restrict kernel pointer access (for example, cat /proc/kallsyms) for exploit assistance 13kernel.kptr_restrict=2 14# Restrict verbose kernel errors in dmesg 15kernel.dmesg_restrict=1 16# Restrict eBPF 17kernel.unprivileged_bpf_disabled=1 18net.core.bpf_jit_harden=2 19# Prevent common use-after-free exploits 20vm.unprivileged_userfaultfd=0 21# Mitigation CVE-2024-1086 by preventing unprivileged users from creating namespaces 22kernel.unprivileged_userns_clone=0 23 24## Networking tweaks ## 25## 26## Prevent common attacks at the IP stack layer 27## 28# Prevent SYNFLOOD denial of service attacks 29net.ipv4.tcp_syncookies=1 30# Prevent time wait assassination attacks 31net.ipv4.tcp_rfc1337=1 32# IP spoofing/source routing protection 33net.ipv4.conf.all.rp_filter=1 34net.ipv4.conf.default.rp_filter=1 35net.ipv6.conf.all.accept_ra=0 36net.ipv6.conf.default.accept_ra=0 37net.ipv4.conf.all.accept_source_route=0 38net.ipv4.conf.default.accept_source_route=0 39net.ipv6.conf.all.accept_source_route=0 40net.ipv6.conf.default.accept_source_route=0 41# IP redirection protection 42net.ipv4.conf.all.accept_redirects=0 43net.ipv4.conf.default.accept_redirects=0 44net.ipv4.conf.all.secure_redirects=0 45net.ipv4.conf.default.secure_redirects=0 46net.ipv6.conf.all.accept_redirects=0 47net.ipv6.conf.default.accept_redirects=0 48net.ipv4.conf.all.send_redirects=0 49net.ipv4.conf.default.send_redirects=0