Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Role to create and install with custom certificates #247

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions playbooks/custom_certificates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- hosts: all
roles:
Copy link
Member

@stbenjam stbenjam Sep 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be become: true here?

fatal: [centos7-katello-nightly]: FAILED! => {"changed": false, "failed": true, "msg": "There was an issue creating /root/custom_certificates as requested: [Errno 13] Permission denied: '/root/custom_certificates'", "path": "/root/custom_certificates/certs", "state": "absent"}

- custom_certificates
6 changes: 6 additions & 0 deletions playbooks/roles/custom_certificates/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
custom_certificates_ca_directory: /root/custom_certificates
custom_certificates_ca_directory_keys: "{{ custom_certificates_ca_directory }}/private"
custom_certificates_ca_directory_certs: "{{ custom_certificates_ca_directory }}/certs"
custom_certificates_ca_directory_requests: "{{ custom_certificates_ca_directory }}/requests"
custom_certificates_server: "{{ ansible_fqdn }}"
98 changes: 98 additions & 0 deletions playbooks/roles/custom_certificates/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
- name: 'Install openssl'
yum:
name: openssl
state: present

- name: 'Create certs directory'
file:
path: "{{ custom_certificates_ca_directory_certs }}"
state: directory
mode: 0755

- name: 'Create keys directory'
file:
path: "{{ custom_certificates_ca_directory_keys }}"
state: directory
mode: 0755

- name: 'Create requests directory'
file:
path: "{{ custom_certificates_ca_directory_requests }}"
state: directory
mode: 0755

- name: 'Deploy configuration file'
template:
src: openssl.cnf.j2
dest: "{{ custom_certificates_ca_directory }}/openssl.cnf"
owner: root
group: root
mode: 0644

- name: 'Create index file'
file:
path: "{{ custom_certificates_ca_directory }}/index.txt"
state: touch
owner: root
group: root
mode: 0644

- name: 'Ensure serial starting number'
template:
src: serial.j2
dest: "{{ custom_certificates_ca_directory }}/serial"
force: no
owner: root
group: root
mode: 0644

- name: 'Creating CA certificate and key'
command: >
openssl req -new
-x509
-nodes
-extensions v3_ca
-config "{{ custom_certificates_ca_directory }}/openssl.cnf"
-keyout "{{ custom_certificates_ca_directory_keys }}/custom_ca.key"
-out "{{ custom_certificates_ca_directory_certs }}/custom_ca.crt"
args:
creates: "{{ custom_certificates_ca_directory_certs }}/custom_ca.crt"

- name: 'Create server key'
command: >
openssl genrsa
-out "{{ custom_certificates_ca_directory_keys }}/{{ custom_certificates_server }}.key"
args:
creates: "{{ custom_certificates_ca_directory_keys }}/{{ custom_certificates_server }}.key"

- name: 'Create server signing request'
command: >
openssl req
-new
-config "{{ custom_certificates_ca_directory }}/openssl.cnf"
-key "{{ custom_certificates_ca_directory_keys }}/{{ custom_certificates_server }}.key"
-out "{{ custom_certificates_ca_directory_requests }}/{{ custom_certificates_server }}.csr"
args:
creates: "{{ custom_certificates_ca_directory_requests }}/{{ custom_certificates_server }}.csr"

- name: 'Create server certificate'
command: >
openssl ca
-create_serial
-batch
-extensions ssl_server
-config "{{ custom_certificates_ca_directory }}/openssl.cnf"
-in "{{ custom_certificates_ca_directory_requests }}/{{ custom_certificates_server }}.csr"
-out "{{ custom_certificates_ca_directory_certs }}/{{ custom_certificates_server }}.crt"
args:
creates: "{{ custom_certificates_ca_directory_certs }}/{{ custom_certificates_server }}.crt"

- name: 'Run installer with custom certificates'
command: >
foreman-installer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add --disable-system-checks

--scenario katello
--certs-server-cert "{{ custom_certificates_ca_directory_certs }}/{{ custom_certificates_server }}.crt"
--certs-server-cert-req "{{ custom_certificates_ca_directory_requests }}/{{ custom_certificates_server }}.csr"
--certs-server-key "{{ custom_certificates_ca_directory_keys }}/{{ custom_certificates_server }}.key"
--certs-server-ca-cert "{{ custom_certificates_ca_directory_certs }}/custom_ca.crt"
77 changes: 77 additions & 0 deletions playbooks/roles/custom_certificates/templates/openssl.cnf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# {{ ansible_managed }}
#
#---------------------------------------------------------------------------
# OpenSSL configuration file.

dir = {{ custom_certificates_ca_directory }}

[ ca ]
default_ca = CA_default
x509_extensions = v3_ca

[ CA_default ]
serial = $dir/serial
database = $dir/index.txt
new_certs_dir = $dir/certs
private_key = $dir/private/custom_ca.key
certificate = $dir/certs/custom_ca.crt
default_md = sha256
default_days = 7300

preserve = no
email_in_dn = no
policy = policy_match
nameopt = default_ca
certopt = default_ca

unique_subject = no
copy_extensions = none

[ policy_match ]
countryName = match
stateOrProvinceName = match
organizationName = match
organizationalUnitName = optional
commonName = supplied
emailAddress = optional

[ req ]
default_bits = 2048
default_keyfile = privkey.pem
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no

[ req_distinguished_name ]
countryName = US
stateOrProvinceName = NC
localityName = Raleigh
organizationName = Foreman
commonName = {{ ansible_fqdn }}

[ v3_ca ]
basicConstraints = CA:TRUE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer:always
nsCertType = sslCA
keyUsage = cRLSign, keyCertSign
extendedKeyUsage = serverAuth, clientAuth

[ v3_req ]
basicConstraints = CA:FALSE
subjectKeyIdentifier = hash
extendedKeyUsage = serverAuth, clientAuth

[ ssl_server ]
basicConstraints = CA:FALSE
nsCertType = server
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, nsSGC, msSGC
nsComment = "OpenSSL Certificate for SSL Web Server"

[ ssl_client ]
basicConstraints = CA:FALSE
nsCertType = client
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = clientAuth
nsComment = "OpenSSL Certificate for SSL Client"
1 change: 1 addition & 0 deletions playbooks/roles/custom_certificates/templates/serial.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1000