-
Notifications
You must be signed in to change notification settings - Fork 1
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
Ensure old ssl certs not copied in nginx role #149
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b6ec6fc
Only copy server certs to nginx if hashes different
ruaridhg c5cd597
Merge branch 'main' into 145-ssl-certs-in-nginx
ruaridhg e84e9f2
Copy certs to and from cache depending on expiry
ruaridhg 7016fea
Merge branch 'main' into 145-ssl-certs-in-nginx
ruaridhg 8524d27
Separate ssl_enabled.yml file for nginx
ruaridhg 710dec8
Add test certificate and key to prepare.yml molecule
ruaridhg c85e8ee
Fix prepare.yml
ruaridhg a9d0c00
Remove certs from prepare
ruaridhg 0a7585a
Add selfsigned_not_after varaible for ssl_certificates role
p-j-smith 7c61b68
fix comparision of expiry dates for cache and nginx certs
p-j-smith 2677ba4
Add tasks to copy certs between cache and nginx
p-j-smith 04b5203
Use https in verify stage of molecule tests for nginx role
p-j-smith e79aae6
update tomcat version
p-j-smith 94f469c
make linters happy
p-j-smith 7ba3347
Merge branch 'main' into 145-ssl-certs-in-nginx
p-j-smith 8360757
remove unnecessary double quotes from code block
p-j-smith 8218f16
remove remaining redundant quotes from yaml block in readme
p-j-smith 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 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 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 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 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 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 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
35 changes: 34 additions & 1 deletion
35
roles/nginx/molecule/resources/inventory/group_vars/all.yml
This file contains 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 |
---|---|---|
@@ -1,6 +1,39 @@ | ||
--- | ||
nginx_owner: root | ||
nginx_group: root | ||
|
||
nginx_server_name: molecule.instance.local | ||
nginx_proxy_port: 8000 | ||
nginx_diffie_helman_size_bits: 2048 | ||
nginx_root: /home/ | ||
nginx_use_ssl: false | ||
|
||
nginx_use_ssl: true | ||
nginx_certs_dir: /etc/nginx/ssl | ||
nginx_ssl_cert_file: /etc/nginx/ssl/server.cert | ||
nginx_ssl_key_file: /etc/nginx/ssl/server.key | ||
nginx_server_cert_cache: /etc/ssl/certs/server.cert | ||
nginx_server_key_cache: /etc//ssl/certs/server.key | ||
|
||
nginx_old_ssl_certificate: | ||
owner: "{{ nginx_owner }}" | ||
group: "{{ nginx_group }}" | ||
certificate_directory: /etc/ssl/certs | ||
privatekey_filename: "{{ nginx_server_key_cache }}" | ||
use_pk8: false | ||
csr_filename: /etc/ssl/certs/server.csr" | ||
csr_common_name: "{{ nginx_server_name }}" | ||
certificate_filename: "{{ nginx_server_cert_cache }}" | ||
provider: selfsigned | ||
selfsigned_not_after: +365d | ||
|
||
nginx_new_ssl_certificate: | ||
owner: "{{ nginx_owner }}" | ||
group: "{{ nginx_group }}" | ||
certificate_directory: "{{ nginx_certs_dir }}" | ||
privatekey_filename: "{{ nginx_ssl_key_file }}" | ||
use_pk8: false | ||
csr_filename: "{{ nginx_certs_dir }}/server.csr" | ||
csr_common_name: "{{ nginx_server_name }}" | ||
certificate_filename: "{{ nginx_ssl_cert_file }}" | ||
provider: selfsigned | ||
selfsigned_not_after: +3650d |
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -31,4 +31,4 @@ platforms: | |
- 443 | ||
- 8000 | ||
published_ports: | ||
- 127.0.0.1:8080:80 | ||
- 127.0.0.1:8080:443 |
This file contains 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 @@ | ||
--- | ||
- name: Copy certificate to new location | ||
ansible.builtin.copy: | ||
remote_src: true | ||
src: "{{ item.src }}" | ||
dest: "{{ item.dest }}" | ||
owner: "{{ nginx_owner }}" | ||
group: "{{ nginx_group }}" | ||
mode: "0600" | ||
backup: true # Preserve overwritten certificates and keys for rollback | ||
with_items: "{{ items }}" |
This file contains 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 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,99 @@ | ||
--- | ||
- name: Ensure nginx certs directory exists | ||
ansible.builtin.file: | ||
path: "{{ nginx_certs_dir }}" | ||
owner: "{{ nginx_owner }}" | ||
group: "{{ nginx_group }}" | ||
state: directory | ||
mode: "0700" | ||
|
||
- name: Stat current SSL certificate | ||
ansible.builtin.stat: | ||
path: "{{ nginx_ssl_cert_file }}" | ||
register: current_cert | ||
|
||
- name: Stat cached SSL certificate | ||
ansible.builtin.stat: | ||
path: "{{ nginx_server_cert_cache }}" | ||
register: cached_cert | ||
|
||
- name: Check whether the certs exist | ||
ansible.builtin.debug: | ||
msg: | ||
- "Cached nginx cert exists at {{ nginx_server_cert_cache }}: {{ | ||
cached_cert.stat.exists }}." | ||
- "nginx cert exists at {{ nginx_ssl_cert_file }}: {{ | ||
current_cert.stat.exists }}." | ||
failed_when: (not cached_cert.stat.exists) and (not current_cert.stat.exists) | ||
|
||
- name: Get current SSL certificate info | ||
community.crypto.x509_certificate_info: | ||
path: "{{ nginx_ssl_cert_file }}" | ||
when: current_cert.stat.exists | ||
register: current_cert_info | ||
|
||
- name: Get cached SSL certificate info | ||
community.crypto.x509_certificate_info: | ||
path: "{{ nginx_server_cert_cache }}" | ||
when: cached_cert.stat.exists | ||
register: cached_cert_info | ||
|
||
- name: Copy server certificates from cache if the nginx cert doesn't exist | ||
ansible.builtin.include_tasks: copy_certificates.yml | ||
vars: | ||
items: | ||
- src: "{{ nginx_server_cert_cache }}" | ||
dest: "{{ nginx_ssl_cert_file }}" | ||
- src: "{{ nginx_server_key_cache }}" | ||
dest: "{{ nginx_ssl_key_file }}" | ||
when: | ||
- not current_cert.stat.exists | ||
- cached_cert.stat.exists | ||
|
||
- name: Copy server certificates to cache if the cache cert doesn't exist | ||
ansible.builtin.include_tasks: copy_certificates.yml | ||
vars: | ||
items: | ||
- src: "{{ nginx_ssl_cert_file }}" | ||
dest: "{{ nginx_server_cert_cache }}" | ||
- src: "{{ nginx_ssl_key_file }}" | ||
dest: "{{ nginx_server_key_cache }}" | ||
when: | ||
- current_cert.stat.exists | ||
- not cached_cert.stat.exists | ||
|
||
- name: Copy server certificates from cache if the nginx cert expires sooner | ||
ansible.builtin.include_tasks: copy_certificates.yml | ||
vars: | ||
items: | ||
- src: "{{ nginx_server_cert_cache }}" | ||
dest: "{{ nginx_ssl_cert_file }}" | ||
- src: "{{ nginx_server_key_cache }}" | ||
dest: "{{ nginx_ssl_key_file }}" | ||
when: | ||
- current_cert.stat.exists | ||
- cached_cert.stat.exists | ||
- current_cert_info.not_after | to_datetime('%Y%m%d%H%M%SZ') < | ||
cached_cert_info.not_after | to_datetime('%Y%m%d%H%M%SZ') | ||
|
||
- name: Copy server certificates to cache if the cache cert expires sooner | ||
ansible.builtin.include_tasks: copy_certificates.yml | ||
vars: | ||
items: | ||
- src: "{{ nginx_ssl_cert_file }}" | ||
dest: "{{ nginx_server_cert_cache }}" | ||
- src: "{{ nginx_ssl_key_file }}" | ||
dest: "{{ nginx_server_key_cache }}" | ||
when: | ||
- current_cert.stat.exists | ||
- cached_cert.stat.exists | ||
- current_cert_info.not_after | to_datetime('%Y%m%d%H%M%SZ') > | ||
cached_cert_info.not_after | to_datetime('%Y%m%d%H%M%SZ') | ||
|
||
- name: | ||
Generate Diffie-Hellman (DH) parameters. Number of {{ | ||
nginx_diffie_helman_size_bits }}. | ||
community.crypto.openssl_dhparam: | ||
path: "{{ nginx_dh_params_file }}" | ||
size: "{{ nginx_diffie_helman_size_bits }}" | ||
notify: Reload nginx |
This file contains 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 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 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 |
---|---|---|
|
@@ -7,7 +7,7 @@ java_home: /usr/lib/jvm/jre | |
java_profile_d: /etc/profile.d | ||
|
||
# mirsg.tomcat | ||
tomcat_version: 9.0.82 | ||
tomcat_version: 9.0.97 | ||
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. updated tomcat as 9.0.82 seems to no longer be available for download |
||
tomcat_owner: tomcat | ||
tomcat_group: tomcat | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the default value