MIT License

技术解读

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

“ansible-lockdown/UBUNTU24-CIS”:自动化强制实施 CIS 安全基准则

项目背景与痛点

在现代 IT 环境中,Linux 系统的安全性是重中之重。为了降低系统被攻击的风险,组织机构通常会遵循网络安全行业标准,比如 Center for Internet Security (CIS) 安全基准则。对于 Ubuntu 24 这样的最新版本,手动实施这些标准可能导致费时且易出错的问题。而“ansible-lockdown/UBUNTU24-CIS”这款自动化工具,专门针对 Ubuntu 24 系统,通过 Ansible 作为一种配置管理与自动化工具,为这个版本提供了自动实施 CIS 基准作用,目的是让运维团队能够以高效且一致的方式实施安全最佳实践,从而使系统更加安全。

核心技术揭秘

“ansible-lockdown/UBUNTU24-CIS”的核心在于利用 Ansible 的强大自动化能力来实施 CIS 安全基准则。项目采用了 Ansible playbook 来定义执行任务,每个 playbook 都包含了具体实施 CIS 基准要求的多个任务。以下是一个简化的架构图,展示了 playbooks 如何被触发,以及执行过程中的主要步骤。

graph TD A[用户触发运行] --> B[Total/Ubuntu24] B --> C[Based/Ubuntu24] C --> D[任务细化] D --> E{"被执行的操作?"} E -->|"硬编码规则应用"| F[基于规则的操作] E -->|"角色执行"| G[策略角色执行] F --> H[规则执行] G --> H[规则执行] H --> I{"规则结果?"} I -->|"成功"| J[执行下一条规则] I -->|"失败"| K[记录错误] J -->|循环| H K -->|异常处理| L[异常处理] L -->|返回| H

功能亮点与差异

“ansible-lockdown/UBUNTU24-CIS”项目的一个显著亮点在于其高度的灵活性和自定义能力。用户可以根据实际需求选择性地执行某些规则,而无需改变整个流程。相比其他同类工具,该项目更为全面,覆盖了 CIS 基准中几乎所有的安全准则,而且通过 Ansible 的强大模块化插件体系,使得扩展新的规则和策略变得更加容易。同时,源代码的开放性使得每一个细节尽在开发者掌握之中。

应用场景与落地建议

在生产环境中应用“ansible-lockdown/UBUNTU24-CIS”需要确保 Ansible 客户端已正确安装并配置。在进行 CIS 安全准则实施前,建议针对环境的真实需求进行需求分析,挑选适合自身安全策略的基准实施子集。此外,建议在正式应用前,在隔离环境中进行充分测试。该工具适合于需要定期且动态实施最新安全标准的环境中。

综合评价

“ansible-lockdown/UBUNTU24-CIS”提供的是一种高度自动化、模块化且易于扩展的方法来实施 CIS 安全准则,为运维人员提供了便利。相对的缺点是,由于其基于 Ansible 的 Playbook 模式,新用户可能需要一定的 Ansible 学习成本。不过,考虑到其带来的企业级安全提升,这个代价显然是可以接受的。总的来说,对于期望简化并自动化 CIS 安全准则实施的 Ubuntu 24 系统,这是一个不可或缺的工具。

README

UBUNTU 24 CIS

Configure a UBUNTU 24 machine to be CIS compliant

Based on CIS UBUNTU Benchmark v1.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


🚨 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 have changed significantly since 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 control found in defaults main also need to reflect this as this 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

  • 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 24 - Other versions are not supported.

  • 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.12+
  • 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 (12MB) 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 UBUNTU24-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": [
        "msg": [
        "The pre remediation audit results are: Count: 763, Failed: 234, Skipped: 4, Duration: 9.741s",
        "The post remediation audit results are: Count: 763, Failed: 19, Skipped: 4, Duration: 12.725s",
        "Full breakdown can be found in /opt",
        ""
    ]
}

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

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

评论

暂无评论