venafi.ansible_role_venafi

Venafi Apache 2.0 License Community Supported Compatible with TPP 17.3+ & VaaS
:warning: 这个社区支持的开源项目已经达到生命周期结束,只会继续接收安全相关更新和重要漏洞修复。该项目的所有功能(及更多)可以在**Venafi 的 Ansible 集合**中找到,该集合仍在积极开发中。迁移非常简单,只需使用 Ansible Galaxy 安装venafi.machine_identity集合,并在你的剧本中将role: venafi.ansible_role_venafi替换为role: venafi.machine_identity.certificate即可。请尽早完成迁移。

Venafi Ansible 角色

这个解决方案通过无缝集成Venafi 信任保护平台Venafi 作为服务,为Red Hat Ansible添加证书注册功能,确保符合企业安全政策,并提供企业范围内的证书发布可视性。

:red_car: 立即体验我们的集成示例

让我们一步一步地向你展示如何将证书添加到你的代码基础设施自动化中。

产品 可用的集成示例...
F5 BIG-IP 如何使用 F5 BIG-IP 和 Venafi Ansible 角色配置安全应用程序交付
Citrix ADC 如何使用 Citrix ADC 和 Venafi Ansible 角色配置安全应用程序交付

注意 如果你没有看到你使用的产品的示例,请稍后再来查看。我们正在努力添加更多集成示例。

要求

查看Venafi的先决条件,然后使用pip安装 Ansible 和VCert-Python(v0.10.0 或更高版本):

pip install ansible vcert --upgrade

与 Ansible Galaxy 一起使用

有关 Ansible Galaxy 的更多信息,请访问 https://galaxy.ansible.com/docs/using/installing.html

  1. 从 Ansible Galaxy 安装Venafi Ansible 角色

    ansible-galaxy install venafi.ansible_role_venafi
    
  2. 创建credentials.yml并填入连接参数:

    信任保护平台

    cat <<EOF >>credentials.yml
    access_token: 'p0WTt3sDPbzm2BDIkoJROQ=='
    url: 'https://tpp.venafi.example'
    zone: "DevOps\\Ansible"
    trust_bundle: "/path/to/bundle.pem"
    EOF
    

    Venafi 作为服务

    cat <<EOF >>credentials.yml
    token: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
    zone: 'Business App\\Enterprise CIT'
    EOF
    

    Venafi Ansible 角色支持以下连接和凭证设置:

    变量名 说明
    access_token 信任保护平台的访问令牌,用于"ansible-by-venafi" API 应用
    password [不推荐] 信任保护平台 WebSDK 密码,尽量使用access_token
    test_mode 当为"true"时,角色在不连接信任保护平台或 Venafi 的情况下运行
    token Venafi 作为服务的 API 密钥
    trust_bundle 包含 PEM(文本)格式信任锚证书的文本文件,通常需要用于信任保护平台
    url Venafi 服务 URL(例如:"https://tpp.venafi.example"),通常仅适用与信任保护平台
    user [不推荐] 信任保护平台 WebSDK 用户名,尽量使用access_token
    zone TPP 的策略文件夹,或 VaaS 的应用名称和颁发模板 API 别名(例如:"Business App\Enterprise CIT")
  3. 使用ansible-vault使用密码加密credentials.yml文件。这是可选的,但强烈推荐。 只要你知道密码,你总是可以解密文件以进行更改,然后重新加密。 有关更多信息,请访问 https://docs.ansible.com/ansible/latest/user_guide/vault.html。

    ansible-vault encrypt credentials.yml
    
  4. 编写一个简单的剧本,命名为sample.yml

    - hosts: localhost
      roles:
        - role: venafi.ansible_role_venafi
          certificate_cert_dir: "/tmp/etc/ssl/{{ certificate_common_name }}"
    
  5. 运行该剧本。

    ansible-playbook sample.yml --ask-vault-pass
    

    运行剧本会生成证书并将其放入/tmp/etc/ssl/目录中的文件夹中。 如果你加密了credentials.yml文件,则需要--ask-vault-pass参数。可以添加其他剧本变量来指定证书和密钥对的属性、文件位置,并覆盖默认行为。

    变量名 说明
    credentials_file 包含 Venafi 凭证和连接设置的文件名
    默认值:credentials.yml
    certificate_common_name 请求证书的公共名称
    默认值:"{{ ansible_fqdn }}"
    certificate_alt_name 请求证书的备用名称的逗号分隔列表。每个值前缀应带有 SAN 类型。
    示例:"DNS:host.example.com,IP:10.20.30.40,email:[email protected]"
    certificate_privatekey_type 密钥算法,“RSA”或“ECDSA”
    默认值:"RSA"(来自 VCert)
    certificate_privatekey_size RSA 密钥的位数
    默认值:"2048"(来自 VCert)
    certificate_privatekey_curve ECDSA 密钥的椭圆曲线
    默认值:"P251"(来自 VCert)
    certificate_privatekey_passphrase 用于加密私钥的密码
    certificate_chain_option 指定根 CA 证书在链文件中出现的位置为“最后”(默认)或“第一个”
    certificate_cert_dir 存储加密资产的本地父目录
    默认值:"/etc/ssl/{{ certificate_common_name }}"
    certificate_cert_path 存储证书文件的本地目录
    默认值:{{ certificate_cert_dir }}/{{ certificate_common_name }}.pem
    certificate_chain_path 存储证书链文件的本地目录
    默认值:"{{ certificate_cert_dir }}/{{ certificate_common_name }}.chain.pem"
    certificate_privatekey_path 存储私钥文件的本地目录
    默认值:"{{ certificate_cert_dir }}/{{ certificate_common_name }}.key"
    certificate_csr_path 存储证书签名请求文件的本地目录
    默认值:"{{ certificate_cert_dir }}/{{ certificate_common_name }}.csr"
    certificate_remote_execution 指定是否在远程生成加密资产,或在本地生成然后提供到远程主机
    默认值:false
    certificate_remote_cert_path 远程主机上存储证书文件的目录
    默认值:"{{ certificate_cert_dir }}/{{ certificate_common_name }}.pem"
    certificate_remote_chain_path 远程主机上存储证书链文件的目录
    默认值:"{{ certificate_cert_dir }}/{{ certificate_common_name }}.chain.pem"
    certificate_remote_privatekey_path 远程主机上存储私钥文件的目录
    默认值:"{{ certificate_cert_dir }}/{{ certificate_common_name }}.key"
    certificate_copy_private_key_to_remote 指定是否将私钥文件复制到远程主机
    默认值:true
    certificate_before_expired_hours 在证书过期之前的小时数,允许更新证书
    默认值:72
    certificate_renew 指定在运行剧本时是否在“before_expired_hours”窗口内续订证书
    默认值:true
    certificate_force 指定每次运行剧本时是否请求新证书
    默认值:false

    默认值在defaults/main.yml文件中定义。

准备 Docker 演示环境以运行 Ansible

  1. (可选)准备演示环境。如果你希望使用自己的清单,请更新 tests/inventory 文件。

    1. 要运行我们的测试/演示剧本,你需要 Docker 提供角色。 将其下载到 tests/roles/provision_docker 目录:

      git clone https://github.com/chrismeyersfsu/provision_docker.git tests/roles/provision_docker
      
    2. 然后构建演示剧本所需的 Docker 镜像:

      docker build ./tests --tag local-ansible-test
      

    演示证书将放置在 Ansible 主机的/tmp/ansible/etc/ssl目录中。 从那里,它们将分发到远程主机的/etc/ssl/目录。

  2. 为信任保护平台或 Venafi 作为服务生成凭据文件,如上面部分所述。

  3. 运行 Ansible 剧本(如果你希望使用自己的清单,请移除docker_demo=true)。 credentials.yml的内容将用于决定使用信任保护平台还是 Venafi 作为服务。 如果你设置了token参数,则剧本假设你正在使用 Venafi 作为服务。如果设置了access_tokenpassword参数,则剧本假设你正在使用信任保护平台。

    ansible-playbook -i tests/inventory \
      tests/venafi-playbook-example.yml \
      --extra-vars "credentials_file=credentials.yml docker_demo=true" \
      --ask-vault-pass
    

    和之前一样,你将被提示输入解密credentials.yml的密码。凭据的源文件可以通过credentials_file变量来覆盖,可以通过命令行使用--extra-vars参数进行指定。

示例剧本

- hosts: servers
  roles:
    - role: "ansible-role-venafi"
      certificate_common_name: "{{ ansible_fqdn }}.venafi.example.com"
      certificate_cert_dir: "/tmp/ansible/etc/ssl/{{ certificate_common_name }}"
      certificate_cert_path: "{{ certificate_cert_dir }}/{{ certificate_common_name }}.pem"
      certificate_chain_path: "{{ certificate_cert_dir }}/{{ certificate_common_name }}.chain.pem"
      certificate_privatekey_path: "{{ certificate_cert_dir }}/{{ certificate_common_name }}.key"
      certificate_csr_path: "{{ certificate_cert_dir }}/{{ certificate_common_name }}.csr"

      # 指定执行 venafi_certificate 模块的位置。如果设置为 false,证书将在 ansible 主机上创建,然后复制到远程服务器。
      certificate_remote_execution: false
      # 远程位置,用于放置证书。
      certificate_remote_cert_dir: "/etc/ssl"
      certificate_remote_cert_path: "{{ certificate_remote_cert_dir }}/{{ certificate_common_name }}.pem"
      certificate_remote_chain_path: "{{ certificate_remote_cert_dir }}/{{ certificate_common_name }}.chain.pem"
      certificate_remote_privatekey_path: "{{ certificate_remote_cert_dir }}/{{ certificate_common_name }}.key"
      # 如果不想将私钥复制到远程位置,请设置为 false。
      certificate_copy_private_key_to_remote: true

有关剧本示例,请查看venafi-playbook-example.yml文件。 有关角色示例,请查看venafi-role-playbook-example.yml文件。

有关使用角色的更多信息,请访问 https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html。

许可

版权 © Venafi, Inc. 保留所有权利。

此解决方案根据 Apache 许可证第 2.0 版进行许可。有关完整的许可证文本,请参阅LICENSE

请将问题/评论发送至 opensource@venafi.com

关于项目

Streamline machine identity (certificate and key) acquisition using Venafi vcert.

安装
ansible-galaxy install venafi.ansible_role_venafi
许可证
apache-2.0
下载
4.8k
拥有者
CyberArk, the undisputed leader in Privileged Account Security, secures secrets used by machines and users to protect traditional and cloud-native apps.