-
Notifications
You must be signed in to change notification settings - Fork 25
Generate certificate bundle #90
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
Open
ehelms
wants to merge
1
commit into
theforeman:master
Choose a base branch
from
ehelms:generate-certificate-bundle
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| - name: Generate a certificate bundle for a hostname | ||
| hosts: | ||
| - quadlet | ||
| become: true | ||
| vars_files: | ||
| - "../../vars/defaults.yml" | ||
| vars: | ||
| certificates_ca: false | ||
| certificates_hostnames: | ||
| - "{{ hostname }}" | ||
| roles: | ||
| - role: certificates | ||
| when: "certificate_source == 'default'" | ||
| - role: certificate_bundle | ||
| vars: | ||
| certificate_bundle_hostname: "{{ hostname }}" | ||
| certificate_bundle_ca_certificate: "{{ certificates_ca_directory }}/certs/ca.crt" | ||
| certificate_bundle_server_certificate: "{{ certificates_ca_directory }}/certs/{{ hostname }}.crt" | ||
| certificate_bundle_server_key: "{{ certificates_ca_directory }}/private/{{ hostname }}.key" | ||
| certificate_bundle_client_certificate: "{{ certificates_ca_directory }}/certs/{{ hostname }}-client.crt" | ||
| certificate_bundle_client_key: "{{ certificates_ca_directory }}/private/{{ hostname }}-client.key" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| help: | | ||
| Generate a certificate bundle | ||
|
|
||
| variables: | ||
| hostname: | ||
| parameter: hostname | ||
| help: Hostname to generate a certificate bundle for that will be the common name. | ||
|
|
||
| include: | ||
| - _certificate_source | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| certificate_bundle_output_directory: /root |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| --- | ||
| - name: Create temporary directory | ||
| ansible.builtin.tempfile: | ||
| state: directory | ||
| suffix: certificate-build | ||
| register: certificate_bundle_build_directory | ||
|
|
||
| - name: Create directory structure | ||
| ansible.builtin.file: | ||
| state: directory | ||
| path: "{{ certificate_bundle_build_directory.path }}/ssl-build/{{ certificate_bundle_hostname }}" | ||
| mode: '0755' | ||
|
|
||
| - name: Copy CA certificate | ||
| ansible.builtin.copy: | ||
| src: "{{ certificate_bundle_ca_certificate }}" | ||
| dest: "{{ certificate_bundle_build_directory.path }}/ssl-build/{{ item }}" | ||
| remote_src: true | ||
| mode: '0444' | ||
| loop: | ||
| - katello-server-ca.crt | ||
| - katello-default-ca.crt | ||
|
|
||
| - name: Copy server certificate | ||
| ansible.builtin.copy: | ||
| src: "{{ certificate_bundle_server_certificate }}" | ||
| dest: "{{ certificate_bundle_build_directory.path }}/ssl-build/{{ certificate_bundle_hostname }}/{{ certificate_bundle_hostname }}-{{ item }}" | ||
| remote_src: true | ||
| mode: '0444' | ||
| loop: | ||
| - apache.crt | ||
| - foreman-proxy.crt | ||
|
|
||
| - name: Copy server key | ||
| ansible.builtin.copy: | ||
| src: "{{ certificate_bundle_server_key }}" | ||
| dest: "{{ certificate_bundle_build_directory.path }}/ssl-build/{{ certificate_bundle_hostname }}/{{ certificate_bundle_hostname }}-{{ item }}" | ||
| remote_src: true | ||
| mode: '0440' | ||
| loop: | ||
| - apache.key | ||
| - foreman-proxy.key | ||
|
|
||
| - name: Copy client certificate | ||
| ansible.builtin.copy: | ||
| src: "{{ certificate_bundle_client_certificate }}" | ||
| dest: "{{ certificate_bundle_build_directory.path }}/ssl-build/{{ certificate_bundle_hostname }}/{{ certificate_bundle_hostname }}-{{ item }}" | ||
| remote_src: true | ||
| mode: '0444' | ||
| loop: | ||
| - foreman-proxy-client.crt | ||
| - puppet-client.crt | ||
|
|
||
| - name: Copy client key | ||
| ansible.builtin.copy: | ||
| src: "{{ certificate_bundle_client_key }}" | ||
| dest: "{{ certificate_bundle_build_directory.path }}/ssl-build/{{ certificate_bundle_hostname }}/{{ certificate_bundle_hostname }}-{{ item }}" | ||
| remote_src: true | ||
| mode: '0440' | ||
| loop: | ||
| - foreman-proxy-client.key | ||
| - puppet-client.key | ||
|
|
||
| - name: Create tarball | ||
| community.general.archive: | ||
| path: "{{ certificate_bundle_build_directory.path }}/ssl-build" | ||
| dest: "{{ certificate_bundle_output_directory }}/{{ certificate_bundle_hostname }}.tar.gz" | ||
| mode: '0640' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| HOSTNAME = 'proxy.example.com' | ||
| TARBALL = f'/root/{HOSTNAME}.tar.gz' | ||
|
|
||
| EXPECTED_CA_FILES = [ | ||
| 'ssl-build/katello-server-ca.crt', | ||
| 'ssl-build/katello-default-ca.crt', | ||
| ] | ||
|
|
||
| EXPECTED_SERVER_FILES = [ | ||
| f'ssl-build/{HOSTNAME}/{HOSTNAME}-apache.crt', | ||
| f'ssl-build/{HOSTNAME}/{HOSTNAME}-apache.key', | ||
| f'ssl-build/{HOSTNAME}/{HOSTNAME}-foreman-proxy.crt', | ||
| f'ssl-build/{HOSTNAME}/{HOSTNAME}-foreman-proxy.key', | ||
| ] | ||
|
|
||
| EXPECTED_CLIENT_FILES = [ | ||
| f'ssl-build/{HOSTNAME}/{HOSTNAME}-foreman-proxy-client.crt', | ||
| f'ssl-build/{HOSTNAME}/{HOSTNAME}-foreman-proxy-client.key', | ||
| f'ssl-build/{HOSTNAME}/{HOSTNAME}-puppet-client.crt', | ||
| f'ssl-build/{HOSTNAME}/{HOSTNAME}-puppet-client.key', | ||
| ] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def tarball_members(server): | ||
| result = server.run(f'tar tzf {TARBALL}') | ||
| assert result.succeeded, f'Tarball {TARBALL} not found. Run foremanctl certificate-bundle {HOSTNAME} before tests.' | ||
| return result.stdout.strip().splitlines() | ||
|
|
||
|
|
||
| def test_tarball_created(server): | ||
| assert server.file(TARBALL).exists | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("expected_file", EXPECTED_CA_FILES) | ||
| def test_tarball_contains_ca_certificate(tarball_members, expected_file): | ||
| assert expected_file in tarball_members | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("expected_file", EXPECTED_SERVER_FILES) | ||
| def test_tarball_contains_server_certificate(tarball_members, expected_file): | ||
| assert expected_file in tarball_members | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("expected_file", EXPECTED_CLIENT_FILES) | ||
| def test_tarball_contains_client_certificate(tarball_members, expected_file): | ||
| assert expected_file in tarball_members | ||
|
|
||
|
|
||
| def test_server_certs_are_identical(server): | ||
| apache = server.run(f'tar xzf {TARBALL} -O ssl-build/{HOSTNAME}/{HOSTNAME}-apache.crt') | ||
| proxy = server.run(f'tar xzf {TARBALL} -O ssl-build/{HOSTNAME}/{HOSTNAME}-foreman-proxy.crt') | ||
| assert apache.stdout == proxy.stdout | ||
|
|
||
|
|
||
| def test_client_certs_are_identical(server): | ||
| proxy_client = server.run(f'tar xzf {TARBALL} -O ssl-build/{HOSTNAME}/{HOSTNAME}-foreman-proxy-client.crt') | ||
| puppet_client = server.run(f'tar xzf {TARBALL} -O ssl-build/{HOSTNAME}/{HOSTNAME}-puppet-client.crt') | ||
| assert proxy_client.stdout == puppet_client.stdout | ||
|
|
||
|
|
||
| def test_ca_certs_are_identical(server): | ||
| server_ca = server.run(f'tar xzf {TARBALL} -O ssl-build/katello-server-ca.crt') | ||
| default_ca = server.run(f'tar xzf {TARBALL} -O ssl-build/katello-default-ca.crt') | ||
| assert server_ca.stdout == default_ca.stdout |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.