venafi.ansible_role_venafi
: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 和 Venafi Ansible 角色配置安全应用程序交付 如何使用 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
从 Ansible Galaxy 安装Venafi Ansible 角色:
ansible-galaxy install venafi.ansible_role_venafi创建
credentials.yml并填入连接参数:信任保护平台:
cat <<EOF >>credentials.yml access_token: 'p0WTt3sDPbzm2BDIkoJROQ==' url: 'https://tpp.venafi.example' zone: "DevOps\\Ansible" trust_bundle: "/path/to/bundle.pem" EOFVenafi 作为服务:
cat <<EOF >>credentials.yml token: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' zone: 'Business App\\Enterprise CIT' EOFVenafi Ansible 角色支持以下连接和凭证设置:
变量名 说明 access_token信任保护平台的访问令牌,用于"ansible-by-venafi" API 应用 password[不推荐] 信任保护平台 WebSDK 密码,尽量使用 access_tokentest_mode当为"true"时,角色在不连接信任保护平台或 Venafi 的情况下运行 tokenVenafi 作为服务的 API 密钥 trust_bundle包含 PEM(文本)格式信任锚证书的文本文件,通常需要用于信任保护平台 urlVenafi 服务 URL(例如:"https://tpp.venafi.example"),通常仅适用与信任保护平台 user[不推荐] 信任保护平台 WebSDK 用户名,尽量使用 access_tokenzoneTPP 的策略文件夹,或 VaaS 的应用名称和颁发模板 API 别名(例如:"Business App\Enterprise CIT") 使用
ansible-vault使用密码加密credentials.yml文件。这是可选的,但强烈推荐。 只要你知道密码,你总是可以解密文件以进行更改,然后重新加密。 有关更多信息,请访问 https://docs.ansible.com/ansible/latest/user_guide/vault.html。ansible-vault encrypt credentials.yml编写一个简单的剧本,命名为
sample.yml。- hosts: localhost roles: - role: venafi.ansible_role_venafi certificate_cert_dir: "/tmp/etc/ssl/{{ certificate_common_name }}"运行该剧本。
ansible-playbook sample.yml --ask-vault-pass运行剧本会生成证书并将其放入/tmp/etc/ssl/目录中的文件夹中。 如果你加密了
credentials.yml文件,则需要--ask-vault-pass参数。可以添加其他剧本变量来指定证书和密钥对的属性、文件位置,并覆盖默认行为。变量名 说明 credentials_file包含 Venafi 凭证和连接设置的文件名
默认值:credentials.ymlcertificate_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_sizeRSA 密钥的位数
默认值:"2048"(来自 VCert)certificate_privatekey_curveECDSA 密钥的椭圆曲线
默认值:"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 }}.pemcertificate_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指定是否在远程生成加密资产,或在本地生成然后提供到远程主机
默认值:falsecertificate_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指定是否将私钥文件复制到远程主机
默认值:truecertificate_before_expired_hours在证书过期之前的小时数,允许更新证书
默认值:72certificate_renew指定在运行剧本时是否在“before_expired_hours”窗口内续订证书
默认值:truecertificate_force指定每次运行剧本时是否请求新证书
默认值:false默认值在defaults/main.yml文件中定义。
准备 Docker 演示环境以运行 Ansible
(可选)准备演示环境。如果你希望使用自己的清单,请更新 tests/inventory 文件。
要运行我们的测试/演示剧本,你需要 Docker 提供角色。 将其下载到
tests/roles/provision_docker目录:git clone https://github.com/chrismeyersfsu/provision_docker.git tests/roles/provision_docker然后构建演示剧本所需的 Docker 镜像:
docker build ./tests --tag local-ansible-test
演示证书将放置在 Ansible 主机的
/tmp/ansible/etc/ssl目录中。 从那里,它们将分发到远程主机的/etc/ssl/目录。为信任保护平台或 Venafi 作为服务生成凭据文件,如上面部分所述。
运行 Ansible 剧本(如果你希望使用自己的清单,请移除
docker_demo=true)。credentials.yml的内容将用于决定使用信任保护平台还是 Venafi 作为服务。 如果你设置了token参数,则剧本假设你正在使用 Venafi 作为服务。如果设置了access_token或password参数,则剧本假设你正在使用信任保护平台。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