

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 主题 2：通过安全管线管理不可变基础设施
<a name="theme-2"></a>

**涵盖八大要点策略**  
应用程序控制、修补应用程序、修补操作系统

对于不可变的基础架构，您必须保护部署管道以进行系统更改。 AWS 杰出工程师Colm MacCárthaigh在2022年re: Invent会议上的 “[零权限操作：在不访问数据的情况下运行服务”（YouTube视频）演示](https://www.youtube.com/watch?v=kNbNWxVQP4w)中解释了这一原则。 AWS 

通过限制对配置 AWS 资源的直接访问，您可以要求通过经批准的、安全的自动化管道来部署或更改所有资源。通常，您可以创建 [AWS Identity and Access Management （IAM）](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)策略以允许用户仅访问托管部署管线的账户。您还可以配置 IAM 策略，以允许有限数量的用户进行[紧急访问](https://docs.aws.amazon.com/whitepapers/latest/organizing-your-aws-environment/break-glass-access.html)。为防止手动更改，您可以使用安全组阻止对服务器的 SSH 和 Windows 远程桌面协议（RDP）访问。[会话管理器](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html)是一项功能 AWS Systems Manager，可以提供对实例的访问权限，而无需打开入站端口或维护堡垒主机。

亚马逊机器映像（AMI）和容器映像必须安全且可重复构建。对于 Amazon EC2 实例，您可以使用 [EC2 Image Builder](https://docs.aws.amazon.com/imagebuilder/latest/userguide/what-is-image-builder.html) 来构建 AMIs 具有内置安全功能（例如实例发现、应用程序控制和日志记录）的实例。有关应用程序控制的更多信息，请参阅 ACSC 网站上的[实现应用程序控制](https://www.cyber.gov.au/resources-business-and-government/maintaining-devices-and-systems/system-hardening-and-administration/system-hardening/implementing-application-control)。您也可以使用 Image Builder 来构建容器映像，且可以使用 [Amazon Elastic Container Registry（Amazon ECR）](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html)跨账户共享这些映像。中央安全团队可以批准构建这些镜像 AMIs 和容器镜像的自动流程，以便应用程序团队批准使用生成的任何 AMI 或容器映像。

必须使用 [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 或 [AWS Cloud Development Kit (AWS CDK)](https://docs.aws.amazon.com/cdk/v2/guide/home.html) 等服务在基础设施即代码（IaC）中定义应用程序。代码分析工具 AWS CloudFormation Guard，例如 cfn-nag 或 cdk-nag，可以根据您批准的管道中的安全最佳实践自动测试代码。

与[主题 1：使用托管服务](theme-1.md)一样，Amazon Inspector 可以报告您 AWS 账户中的漏洞。集中的云和安全团队可以使用此信息，来验证应用程序团队是否满足安全性和合规性要求。

要监控和报告合规性，请持续审查 IAM 资源和日志。使用 AWS Config 规则确保只使用经批准 AMIs 的资源，并确保将 Amazon Inspector 配置为扫描 Amazon ECR 资源中是否存在漏洞。

## Well-Architecte AWS d Framework 中的相关最佳实践
<a name="theme-2-best-practices"></a>
+ [OPS05-BP04 使用构建和部署管理系统](https://docs.aws.amazon.com/wellarchitected/latest/operational-excellence-pillar/ops_dev_integ_build_mgmt_sys.html)
+ [REL08-使用不可变基础架构进行BP04 部署](https://docs.aws.amazon.com/wellarchitected/latest/framework/rel_tracking_change_management_immutable_infrastructure.html)
+ [SEC06-BP03 减少手动管理和交互式访问](https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/sec_protect_compute_reduce_manual_management.html)

## 实现此主题
<a name="theme-2-implementation"></a>

### 实施 AMI 和容器构建管线
<a name="t2-ami-pipelines"></a>
+ [使用 EC2 Image Builder](https://docs.aws.amazon.com/imagebuilder/latest/userguide/start-build-image-pipeline.html) 并将以下内容构建到您的 AMIs：
  + [AWS Systems Manager 代理（SSM 代理）](https://docs.aws.amazon.com/systems-manager/latest/userguide/manually-install-ssm-agent-linux.html)，用于实例发现和管理
  + [用于应用程序控制的安全工具，例如[安全增强型 Linux (SELinux) (GitHub)](https://github.com/SELinuxProject)、[文件访问策略守护程序 (fapolicyd) (GitHub)](https://github.com/linux-application-whitelisting/fapolicyd/blob/main/README.md) 或 OpenSCAP](https://www.open-scap.org/)
  + [Amazon A CloudWatch gent](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-on-EC2-Instance.html)，用于记录
+ 对于所有 EC2 实例，请在[实例配置文件或 Systems Manager 用于访问实例的 IAM 角色](https://docs.aws.amazon.com/systems-manager/latest/userguide/setup-instance-permissions.html)中包含 `CloudWatchAgentServerPolicy` 和 `AmazonSSMManagedInstanceCore` 策略。
+ [ AMIs 与整个组织共享](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/share-amis-with-organizations-and-OUs.html)
+ [共享 EC2 Image Builder 资源](https://docs.aws.amazon.com/imagebuilder/latest/userguide/manage-shared-resources.html)
+ [确保应用团队参考的是最新的 AMIs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-custom-resources-lambda-lookup-amiids.html)
+ [使用您的 AMI 管线进行补丁管理](https://docs.aws.amazon.com/imagebuilder/latest/userguide/security-patch-management.html)
+ 实施容器构建管线：
  + [使用 EC2 Image Builder 控制台向导创建容器映像管线](https://docs.aws.amazon.com/imagebuilder/latest/userguide/start-build-container-pipeline.html)
  + [使用 Amazon ECR 作为来源，为您的容器镜像构建持续交付渠道](https://aws.amazon.com/blogs/devops/build-a-continuous-delivery-pipeline-for-your-container-images-with-amazon-ecr-as-source/)（AWS 博客文章）
+ [通过多账户和多区域架构在组织中共享 ECR 容器映像](https://aws.amazon.com/blogs/containers/amazon-ecr-in-multi-account-and-multi-region-architectures/)

### 实施安全的应用程序构建管线
<a name="t2-secure-pipelines"></a>
+ 为 IaC 实施构建管道，例如使用 [EC2 Image Builder 和 AWS CodePipeline](https://aws.amazon.com/blogs/mt/create-immutable-servers-using-ec2-image-builder-aws-codepipeline/)（AWS 博客文章）
+ 在 CI/CD 管道中使用代码分析工具 [AWS CloudFormation Guard](https://docs.aws.amazon.com/cfn-guard/latest/ug/what-is-guard.html)，例如 [cfn-nag](https://github.com/stelligent/cfn_nag) (GitHub) 或 [cdk-nag](https://github.com/cdklabs/cdk-nag) (GitHub)，来帮助检测违反最佳实践的行为，例如：
  + 过于宽松的 IAM 策略，例如使用通配符的策略
  + 过于宽松的安全组规则，例如使用通配符或允许 SSH 访问的规则
  + 未启用的访问日志
  + 未启用的加密
  + 密码文本
+ [在管道中实现扫描工具](https://aws.amazon.com/blogs/devops/building-end-to-end-aws-devsecops-ci-cd-pipeline-with-open-source-sca-sast-and-dast-tools/)（AWS 博客文章）
+ [AWS Identity and Access Management Access Analyzer 在管道中使用](https://aws.amazon.com/blogs/security/validate-iam-policies-in-cloudformation-templates-using-iam-access-analyzer/)（AWS 博客文章）来验证 CloudFormation 模板中定义的 IAM 策略
+ 配置 [IAM 策略](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#:~:text=IAM%20policies%20define%20permissions%20for,CLI%2C%20or%20the%20AWS%20API.)和[服务控制策略](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html)，以获得使用管线或对其进行任何修改的最低权限访问权限

### 实施漏洞扫描
<a name="t2-vulnerability-scanning"></a>
+ [在您组织的所有账户中启用 Amazon Inspector](https://docs.aws.amazon.com/inspector/latest/user/designating-admin.html)
+ 使用 Amazon Inspector AMIs 在你的 AMI 构建管道中进行扫描：
  + [在 EC2 Image Builder 中管理 AMI 的生命周期](https://github.com/aws-samples/ec2-imagebuilder-ami-lifecycle) () GitHub
+ [使用 Amazon Inspector 为 Amazon ECR 存储库配置增强扫描](https://docs.aws.amazon.com/inspector/latest/user/scanning-ecr.html#configure-ecr)
+ [构建漏洞管理程序，对安全调查发现进行分类和修复](https://docs.aws.amazon.com/prescriptive-guidance/latest/vulnerability-management/)

## 监控此主题
<a name="theme-2-monitoring"></a>

### 持续监控 IAM 和日志
<a name="t2-monitor"></a>
+ 定期查看您的 IAM 策略，以确保：
  + 只有部署管线可以直接访问资源
  + 只有经批准的服务才能直接访问数据
  + 用户没有直接访问资源或数据的权限。
+ 监控 AWS CloudTrail 日志以确认用户正在通过管道修改资源，而不是直接修改资源或访问数据
+ 定期查看 IAM 访问权限分析器调查发现
+ 设置提醒，以便在 AWS 账户 的根用户凭证被使用时通知您。

### 实施以下 AWS Config 规则
<a name="t2-config"></a>
+ `APPROVED_AMIS_BY_ID`
+ `APPROVED_AMIS_BY_TAG`
+ `ECR_PRIVATE_IMAGE_SCANNING_ENABLED`