MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

Ansible-Lockdown/UBUNTU22-CIS 深度技术分析

项目背景与痛点

在当今的安全领域,CIS(Center for Internet Security)基准已经成为业内一种不可或缺的安全标准。CIS 基准提供了针对多种操作系统和应用程序的安全配置指南,以帮助组织实现和维护安全的环境。对于 Ubuntu 22.04 这样的操作系统,CIS 基准不仅有助于增强系统的安全性,还能确保遵守法规和合规性要求。

然而,手动部署和维护这些安全配置既耗时又容易出错,特别是在大规模环境中。为了解决这个问题,ansible-lockdown/UBUNTU22-CIS 项目应运而生。该项目利用 Ansible 实现了自动化的 CIS 基准合规修复,通过提供明确的执行策略和自动化脚本,确保了高效且一致的安全配置。

核心技术揭秘

该项目的核心技术在于 Ansible 的剧本和任务集的设计与实现。从架构层面看,Ansible 剧本在这其中起着连接自动化流程与系统配置的关键作用。自动化流程涉及的任务包括系统配置项的检查与调整,如防火墙规则、文件权限设置、日志监控及审计等。

以下是该项目的大致架构图:

graph TD A[执行 Ansible Playbook] --> B{"系统配置检查"} B -->|"合规"| C[记录符合项] B -->|"不合规"| D[执行修复任务] D --> E[回滚失败配置] D --> F[记录变更] D --> G[通知管理员]
  • Playbook 负责定义整个自动化流程。
  • 系统配置检查会对各个配置项进行逐一审视,判断是否符合 CIS 基准。
  • 对于不合规的配置项,会触发相应的修复任务。任务完成后,系统会记录变更和通知管理员,且对执行失败的配置项进行回滚。

功能亮点与差异

ansible-lockdown/UBUNTU22-CIS 这个项目展示了鲜明的功能亮点:

  • 一致性:自动化的脚本确保不同机器环境的配置一致性。
  • 可维护性:基于 YAML 的剧本易于阅读和维护。
  • 便携性:适配性高,可以在多个 Ubuntu 22.04 环境中无缝部署。
  • 实时监控与合规验证:执行前后都对系统进行合规检查,确保配置正确。

相比于其他类似的自动化合规工具,该项目最大的差异在于它的简洁性和强大的扩展性。许多竞争对手往往依赖于复杂的配置项,难以完全兼顾所有场景。相比之下,ansible-lockdown/UBUNTU22-CIS 项目简单明了,配置项明确,易于新手上手。

应用场景与落地建议

在生产环境中使用这个项目时,开发者需要注意以下几个方面:

  1. 严格的权限管理:确保 Playbook 仅在受信任的环境中执行,避免在不安全的机器上执行。
  2. 监控与日志记录:详细记录执行过程和任何配置变更,确保系统的操作可追溯。
  3. 环境隔离:考虑到可能存在的业务中断,在大面积部署之前,应先在隔离的环境测试验证。

这种自动化合规工具特别适合那些希望提高安全性、减少系统管理负担的企业。无论是中小型网站、服务器托管,还是大型企业后端服务,都需要这种自动化工具的支持。

综合评价

在优缺点方面,ansible-lockdown/UBUNTU22-CIS 具有以下几点:

  • 优点:项目具有极高的自动化水平与一致性,使得系统安全配置可以快速且方便地实现。剧本的可读性和维护性在同类项目中是相对突出的。
  • 缺点:由于其高度依赖于 Ansible,如果服务节点中有不支持它的环境,则需要开展额外的适配工作。此外,复杂的配置任务仍然可能增加调试的难度。

总体而言,该开源工具为实现 Ubuntu 22.04 的 CIS 基准自动化配置提供了坚强的助力,特别适合那些对于系统安全性有高要求的企业及开发者。

关于

GitHub 原始描述(英文)

Automated CIS Benchmark Compliance Remediation for Ubuntu 22 with Ansible

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

语言占比

Jinja
Shell
YAML

README

UBUNTU 22 CIS

Configure a UBUNTU 22 machine to be CIS compliant

Based on CIS Ubuntu Linux 22.04 LTS Benchmark v3.0.0


Public Repository

Org Stars Stars Forks Followers X URL Discord Badge

License

Lint & Pre-Commit Tools

YamlLint Ansible-Lint

Community Release Information

Release Branch Release Tag Main Release Date Benchmark Version Main Benchmark Version Devel

Main Pipeline Status

Devel Pipeline Status

Devel Commits Open Issues Closed Issues Pull Requests


Subscriber Release Information

Private Release Branch Private Benchmark Version

Private Remediate Pipeline

Private Pull Requests Private Closed Issues


Looking for support?

Lockdown Enterprise

Ansible support

Community

On our Discord Server to ask questions, discuss features, or just chat with other Ansible-Lockdown users

Contributing

Bug reports and feature requests are welcome from everyone, please raise an issue.

Pull requests are accepted from approved contributors only. To be onboarded, join the Discord Server and request contributor access. See CONTRIBUTING.md for the full process.


Caution(s)

This role will make changes to the system which may have unintended consequences. This is not an auditing tool but rather a remediation tool to be used after an audit has been conducted.

  • Testing is the most important thing you can do.

  • Check Mode is not guaranteed! The role will complete in check mode without errors, but it is not supported and should be used with caution.

  • This role was developed against a clean install of the Operating System. If you are implementing to an existing system please review this role for any site specific changes that are needed.

  • To use release version please point to main branch and relevant release for the cis benchmark you wish to work with.

  • Did we mention testing??


Coming From A Previous Release

CIS release always contains changes, it is highly recommended to review the new references and available variables. This has changed significantly since the ansible-lockdown initial release. This is now compatible with python3 if it is found to be the default interpreter. This does come with pre-requisites which it configures the system accordingly.

Further details can be seen in the Changelog


Matching a security Level for CIS

It is possible to only run level 1 or level 2 controls for CIS. This is managed using tags:

  • level1-server
  • level1-workstation
  • level2-server
  • level2-workstation

The controls found in defaults/main.yml also need to reflect this as they control the testing that takes place if you are using the audit component.


Requirements

General:

  • Basic knowledge of Ansible, below are some links to the Ansible documentation to help get started if you are unfamiliar with Ansible

  • Main Ansible documentation page

  • Ansible Getting Started

  • Tower User Guide

  • Ansible Community Info

  • Functioning Ansible and/or Tower Installed, configured, and running. This includes all of the base Ansible/Tower configurations, needed packages installed, and infrastructure setup.

  • Please read through the tasks in this role to gain an understanding of what each control is doing. Some of the tasks are disruptive and can have unintended consequences in a live production system. Also familiarize yourself with the variables in the defaults/main.yml file.

Technical Dependencies:

UBUNTU 22.04

  • Access to download or add the goss binary and content to the system if using auditing (other options are available on how to get the content to the system.)
  • Python3.10+
  • Ansible 2.16+
  • python3-apt

Auditing

This can be turned on or off within the defaults/main.yml file with the variable run_audit. The value is false by default, please refer to the wiki for more details. The defaults file also populates the goss checks to check only the controls that have been enabled in the ansible role.

This is a much quicker, very lightweight, checking (where possible) config compliance and live/running settings.

A new form of auditing has been developed, by using a small (16MB) go binary called goss along with the relevant configurations to check. Without the need for infrastructure or other tooling. This audit will not only check the config has the correct setting but aims to capture if it is running with that configuration also trying to remove false positives in the process.

Refer to UBUNTU22-CIS-Audit.

Example Audit Summary

This is based on a vagrant image with selections enabled. e.g. No Gui or firewall. Note: More tests are run during audit as we check config and running state.


ok: [default] => {
 "msg": [
 "The pre remediation results are: ['Total Duration: 5.454s', 'Count: 338, Failed: 47, Skipped: 5'].",
 "The post remediation results are: ['Total Duration: 5.007s', 'Count: 338, Failed: 46, Skipped: 5'].",
 "Full breakdown can be found in /var/tmp",
 ""
 ]
}

PLAY RECAP *******************************************************************************************************************************************
default : ok=270 changed=23 unreachable=0 failed=0 skipped=140 rescued=0 ignored=0

Documentation

Role Variables

This role is designed that the end user should not have to edit the tasks themselves. All customizing should be done via the defaults/main.yml file or with extra vars within the project, job, workflow, etc.

Tags

There are many tags available for added control precision. Each control has its own set of tags noting what level, what OS element it relates to, whether it’s a patch or audit, and the rule number. Additionally, NIST references follow a specific conversion format for consistency and clarity.

Conversion Format for NIST References:

  1. Standard Prefix:
  • All references are prefixed with “NIST”.
  1. Standard Types:
  • “800-53” references are formatted as NIST800-53.
  • “800-53r5” references are formatted as NIST800-53R5 (with ‘R’ capitalized).
  • “800-171” references are formatted as NIST800-171.
  1. Details:
  • Section and subsection numbers use periods (.) for numeric separators.
  • Parenthetical elements are separated by underscores (_), e.g., IA-5(1)(d) becomes IA-5_1_d.
  • Subsection letters (e.g., “b”) are appended with an underscore. Below is an example of the tag section from a control within this role. Using this example if you set your run to skip all controls with the tag services, this task will be skipped. The opposite can also happen where you run only controls tagged with services.
 tags:
 - level1-server
 - level1-workstation
 - scored
 - avahi
 - services
 - patch
 - rule_2.2.4

Community Contribution

We encourage you (the community) to contribute to this role. Please read the rules below.

  • Your work is done in your own individual branch. Make sure to Signed-off-by and GPG sign all commits you intend to merge.
  • All community Pull Requests are pulled into the devel branch
  • Pull Requests into devel will confirm your commits have a GPG signature, Signed-off-by, and a functional test before being approved
  • Once your changes are merged and a more detailed review is complete, an authorized member will merge your changes into the main branch for a new release

Pipeline Testing

uses:

  • ansible-core 2.16
  • ansible collections - pulls in the latest version based on requirements file
  • runs the audit using the devel branch
  • This is an automated test that occurs on pull requests into devel
  • self-hosted runners using OpenTofu

Known Issues

Some cloud provider repositories may not support GPG key validation (rule_1.2.1.1, rule_1.2.1.2) which may cause issues during the playbook run.

Local Testing

example

molecule test -s default
molecule converge -s wsl -- --check
molecule verify -s localhost

local testing uses:

  • ansible-core
  • molecule 4.0.1
  • molecule-docker 2.0.0
  • molecule-podman 2.0.2
  • molecule-vagrant 1.0.0
  • molecule-azure 0.5.0

Credits and Thanks

Massive thanks to the fantastic community and all its members.

This includes a huge thanks and credit to the original authors and maintainers.

Mark Bolwell, George Nalen, Steve Williams, Fred Witty

评论

暂无评论