-
Notifications
You must be signed in to change notification settings - Fork 29
Use community.crypto for the certificates role #441
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| --- | ||
| - name: 'Install openssl' | ||
| - name: 'Install crypto dependencies' | ||
| ansible.builtin.package: | ||
| name: openssl | ||
| name: | ||
| - python3-cryptography | ||
| state: present | ||
|
|
||
| - name: 'Create certs directory' | ||
|
|
@@ -22,31 +23,6 @@ | |
| state: directory | ||
| mode: '0755' | ||
|
|
||
| - name: 'Deploy configuration file' | ||
| ansible.builtin.template: | ||
| src: openssl.cnf.j2 | ||
| dest: "{{ certificates_ca_directory }}/openssl.cnf" | ||
| owner: root | ||
| group: root | ||
| mode: '0644' | ||
|
|
||
| - name: 'Create index file' | ||
| ansible.builtin.file: | ||
| path: "{{ certificates_ca_directory }}/index.txt" | ||
| state: touch | ||
| owner: root | ||
| group: root | ||
| mode: '0644' | ||
|
|
||
| - name: 'Ensure serial starting number' | ||
| ansible.builtin.template: | ||
| src: serial.j2 | ||
| dest: "{{ certificates_ca_directory }}/serial" | ||
| force: false | ||
| owner: root | ||
| group: root | ||
| mode: '0644' | ||
|
|
||
| - name: 'Create CA key password file' | ||
| ansible.builtin.copy: | ||
| content: "{{ certificates_ca_password }}" | ||
|
|
@@ -56,17 +32,38 @@ | |
| mode: '0600' | ||
| no_log: true | ||
|
|
||
| - name: 'Creating CA certificate and key' | ||
| ansible.builtin.command: > | ||
| openssl req -new | ||
| -x509 | ||
| -nodes | ||
| -extensions v3_ca | ||
| -days 7300 | ||
| -config "{{ certificates_ca_directory }}/openssl.cnf" | ||
| -subj "/CN=Foreman Self-signed CA" | ||
| -keyout "{{ certificates_ca_directory_keys }}/ca.key" | ||
| -out "{{ certificates_ca_directory_certs }}/ca.crt" | ||
| -passout "file:{{ certificates_ca_directory_keys }}/ca.pwd" | ||
| args: | ||
| creates: "{{ certificates_ca_directory_certs }}/ca.crt" | ||
| - name: 'Create CA private key' | ||
| community.crypto.openssl_privatekey: | ||
| path: "{{ certificates_ca_directory_keys }}/ca.key" | ||
| type: "{{ certificates_algorithm_type }}" | ||
| size: "{{ certificates_algorithm_size }}" | ||
| passphrase: "{{ certificates_ca_password }}" | ||
| owner: root | ||
| group: root | ||
| mode: '0600' | ||
|
|
||
| - name: 'Create CA certificate signing request' | ||
| community.crypto.openssl_csr: | ||
| path: "{{ certificates_ca_directory_requests }}/ca.csr" | ||
| privatekey_path: "{{ certificates_ca_directory_keys }}/ca.key" | ||
| privatekey_passphrase: "{{ certificates_ca_password }}" | ||
| common_name: "Foreman Self-signed CA" | ||
| use_common_name_for_san: false | ||
| basic_constraints: | ||
| - 'CA:TRUE' | ||
| basic_constraints_critical: true | ||
| key_usage: | ||
| - keyCertSign | ||
| - cRLSign | ||
| - digitalSignature | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding this helped, but now I am confused, the old OpenSSL config doesn't add that to the CA cert…
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked the original
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. But this is the CA.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for comparison, this is what gets generated by the various implementations we have old openssl code: your ansible code: old katello-certs-tools: why is key usage marked critical for your code?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aha, I think that's what fooling us here. we need digital signature, but without the usage being marked as critical, this is actually not enforced by the consumer.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yepp, just tried it out, dropping now, I'd argue that setting @ehelms opinions? should we aim at bug-for-bug compatibility with katello-certs-tools or rather not? (I'd prefer not)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think aiming to be "correct" for the new certificate generation code is the way to go. What I worry about is, what happens to installer-based certificates that are inherited and continue to be managed (see #421). Will this try and trigger a regeneration of the CA?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The modules might, yes. We talked about a related issue yesterday that people should not get the CA regenerated when e.g. the expiration date changes (it is currently relative to the date the execution happens) and ended up saying that for CA-changing operations we'd require an explicit flag (something like "allow CA changes") so that the CA won't change once generated unless explicitly requested.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, docs say "not valid after" is "not used to determine whether an existing certificate should be regenerated. ", cool. |
||
| key_usage_critical: true | ||
|
stejskalleos marked this conversation as resolved.
|
||
| create_subject_key_identifier: true | ||
|
|
||
| - name: 'Create self-signed CA certificate' | ||
| community.crypto.x509_certificate: | ||
| path: "{{ certificates_ca_directory_certs }}/ca.crt" | ||
| csr_path: "{{ certificates_ca_directory_requests }}/ca.csr" | ||
| privatekey_path: "{{ certificates_ca_directory_keys }}/ca.key" | ||
| privatekey_passphrase: "{{ certificates_ca_password }}" | ||
| provider: selfsigned | ||
| selfsigned_not_after: "+7300d" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,66 +1,61 @@ | ||
| --- | ||
| - name: 'Create server key' | ||
| ansible.builtin.command: > | ||
| openssl genrsa | ||
| -out "{{ certificates_ca_directory_keys }}/{{ certificates_hostname }}.key" | ||
| 4096 | ||
| args: | ||
| creates: "{{ certificates_ca_directory_keys }}/{{ certificates_hostname }}.key" | ||
| - name: 'Create server private key' | ||
| community.crypto.openssl_privatekey: | ||
| path: "{{ certificates_ca_directory_keys }}/{{ certificates_hostname }}.key" | ||
| type: "{{ certificates_algorithm_type }}" | ||
| size: "{{ certificates_algorithm_size }}" | ||
| mode: '0600' | ||
|
|
||
| - name: 'Creating server signing request' | ||
| ansible.builtin.command: > | ||
| openssl req | ||
| -new | ||
| -config "{{ certificates_ca_directory }}/openssl.cnf" | ||
| -key "{{ certificates_ca_directory_keys }}/{{ certificates_hostname }}.key" | ||
| -subj "/CN={{ certificates_hostname }}" | ||
| -addext "subjectAltName = DNS:{{ certificates_hostname }}{% for cname in certificates_cnames %},DNS:{{ cname }}{% endfor %}" | ||
| -out "{{ certificates_ca_directory_requests }}/{{ certificates_hostname }}.csr" | ||
| args: | ||
| creates: "{{ certificates_ca_directory_requests }}/{{ certificates_hostname }}.csr" | ||
| - name: 'Create server CSR' | ||
| community.crypto.openssl_csr: | ||
| path: "{{ certificates_ca_directory_requests }}/{{ certificates_hostname }}.csr" | ||
| privatekey_path: "{{ certificates_ca_directory_keys }}/{{ certificates_hostname }}.key" | ||
| common_name: "{{ certificates_hostname }}" | ||
| subject_alt_name: "{{ _certificates_desired_server_sans }}" | ||
| key_usage: | ||
| - digitalSignature | ||
| - keyEncipherment | ||
| extended_key_usage: | ||
| - serverAuth | ||
|
stejskalleos marked this conversation as resolved.
|
||
| vars: | ||
| _certificates_desired_server_sans: "{{ (([certificates_hostname] + certificates_cnames) | map('regex_replace', '^', 'DNS:') | list) }}" | ||
|
|
||
| - name: 'Sign server signing request' | ||
| ansible.builtin.command: > | ||
| openssl ca | ||
| -create_serial | ||
| -batch | ||
| -extensions ssl_server | ||
| -config "{{ certificates_ca_directory }}/openssl.cnf" | ||
| -passin "file:{{ certificates_ca_directory_keys }}/ca.pwd" | ||
| -in "{{ certificates_ca_directory_requests }}/{{ certificates_hostname }}.csr" | ||
| -out "{{ certificates_ca_directory_certs }}/{{ certificates_hostname }}.crt" | ||
| args: | ||
| creates: "{{ certificates_ca_directory_certs }}/{{ certificates_hostname }}.crt" | ||
| - name: 'Sign server certificate' | ||
| community.crypto.x509_certificate: | ||
| path: "{{ certificates_ca_directory_certs }}/{{ certificates_hostname }}.crt" | ||
| csr_path: "{{ certificates_ca_directory_requests }}/{{ certificates_hostname }}.csr" | ||
| provider: ownca | ||
| ownca_path: "{{ certificates_ca_directory_certs }}/ca.crt" | ||
| ownca_privatekey_path: "{{ certificates_ca_directory_keys }}/ca.key" | ||
| ownca_privatekey_passphrase: "{{ certificates_ca_password }}" | ||
| ownca_not_after: "+7300d" | ||
|
|
||
| - name: 'Create client key' | ||
| ansible.builtin.command: > | ||
| openssl genrsa | ||
| -out "{{ certificates_ca_directory_keys }}/{{ certificates_hostname }}-client.key" | ||
| 4096 | ||
| args: | ||
| creates: "{{ certificates_ca_directory_keys }}/{{ certificates_hostname }}-client.key" | ||
| - name: 'Create client private key' | ||
| community.crypto.openssl_privatekey: | ||
| path: "{{ certificates_ca_directory_keys }}/{{ certificates_hostname }}-client.key" | ||
| type: "{{ certificates_algorithm_type }}" | ||
| size: "{{ certificates_algorithm_size }}" | ||
| mode: '0600' | ||
|
|
||
| - name: 'Creating client signing request' | ||
| ansible.builtin.command: > | ||
| openssl req | ||
| -new | ||
| -config "{{ certificates_ca_directory }}/openssl.cnf" | ||
| -key "{{ certificates_ca_directory_keys }}/{{ certificates_hostname }}-client.key" | ||
| -addext "subjectAltName = DNS:{{ certificates_hostname }}" | ||
| -subj "/CN={{ certificates_hostname }}" | ||
| -out "{{ certificates_ca_directory_requests }}/{{ certificates_hostname }}-client.csr" | ||
| args: | ||
| creates: "{{ certificates_ca_directory_requests }}/{{ certificates_hostname }}-client.csr" | ||
| - name: 'Create client CSR' | ||
| community.crypto.openssl_csr: | ||
| path: "{{ certificates_ca_directory_requests }}/{{ certificates_hostname }}-client.csr" | ||
| privatekey_path: "{{ certificates_ca_directory_keys }}/{{ certificates_hostname }}-client.key" | ||
| common_name: "{{ certificates_hostname }}" | ||
| subject_alt_name: | ||
| - "DNS:{{ certificates_hostname }}" | ||
| key_usage: | ||
| - digitalSignature | ||
| - keyEncipherment | ||
| extended_key_usage: | ||
| - clientAuth | ||
|
|
||
| - name: 'Sign client signing request' | ||
| ansible.builtin.command: > | ||
| openssl ca | ||
| -create_serial | ||
| -batch | ||
| -extensions ssl_client | ||
| -config "{{ certificates_ca_directory }}/openssl.cnf" | ||
| -passin "file:{{ certificates_ca_directory_keys }}/ca.pwd" | ||
| -in "{{ certificates_ca_directory_requests }}/{{ certificates_hostname }}-client.csr" | ||
| -out "{{ certificates_ca_directory_certs }}/{{ certificates_hostname }}-client.crt" | ||
| args: | ||
| creates: "{{ certificates_ca_directory_certs }}/{{ certificates_hostname }}-client.crt" | ||
| - name: 'Sign client certificate' | ||
| community.crypto.x509_certificate: | ||
| path: "{{ certificates_ca_directory_certs }}/{{ certificates_hostname }}-client.crt" | ||
| csr_path: "{{ certificates_ca_directory_requests }}/{{ certificates_hostname }}-client.csr" | ||
| provider: ownca | ||
| ownca_path: "{{ certificates_ca_directory_certs }}/ca.crt" | ||
| ownca_privatekey_path: "{{ certificates_ca_directory_keys }}/ca.key" | ||
| ownca_privatekey_passphrase: "{{ certificates_ca_password }}" | ||
| ownca_not_after: "+7300d" | ||
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.