-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
haproxy.sh: allows certificate deployment to multiple hosts #5180
Open
lgrawet
wants to merge
1
commit into
acmesh-official:dev
Choose a base branch
from
lgrawet:haproxy_cluster
base: dev
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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -43,7 +43,8 @@ | |||||
# needing to reload HAProxy. Default is "no". | ||||||
# | ||||||
# Require the socat binary. DEPLOY_HAPROXY_STATS_SOCKET variable uses the socat | ||||||
# address format. | ||||||
# address format. The certificate can be deployed to a comma separated ',' list | ||||||
# of hosts ("TCP4:10.0.0.1:1999,TCP4:10.0.0.2:1999") | ||||||
# | ||||||
# export DEPLOY_HAPROXY_MASTER_CLI="UNIX:/run/haproxy-master.sock" | ||||||
# | ||||||
|
@@ -193,7 +194,6 @@ haproxy_deploy() { | |||||
_issuer="${_pem}.issuer" | ||||||
_ocsp="${_pem}.ocsp" | ||||||
_reload="${Le_Deploy_haproxy_reload}" | ||||||
_statssock="${Le_Deploy_haproxy_stats_socket}" | ||||||
|
||||||
_info "Deploying PEM file" | ||||||
# Create a temporary PEM file | ||||||
|
@@ -327,62 +327,65 @@ haproxy_deploy() { | |||||
|
||||||
# Update certificate over HAProxy stats socket or master CLI. | ||||||
if _exists socat; then | ||||||
# look for the certificate on the stats socket, to chose between updating or creating one | ||||||
_socat_cert_cmd="echo '${_cmdpfx}show ssl cert' | socat '${_statssock}' - | grep -q '^${_pem}$'" | ||||||
_debug _socat_cert_cmd "${_socat_cert_cmd}" | ||||||
eval "${_socat_cert_cmd}" | ||||||
_ret=$? | ||||||
if [ "${_ret}" != "0" ]; then | ||||||
_newcert="1" | ||||||
_info "Creating new certificate '${_pem}' over HAProxy ${_socketname}." | ||||||
# certificate wasn't found, it's a new one. We should check if the crt-list exists and creates/inserts the certificate. | ||||||
_socat_crtlist_show_cmd="echo '${_cmdpfx}show ssl crt-list' | socat '${_statssock}' - | grep -q '^${Le_Deploy_haproxy_pem_path}$'" | ||||||
_debug _socat_crtlist_show_cmd "${_socat_crtlist_show_cmd}" | ||||||
eval "${_socat_crtlist_show_cmd}" | ||||||
export IFS=',' | ||||||
for _statssock in ${Le_Deploy_haproxy_stats_socket}; do | ||||||
# look for the certificate on the stats socket, to choVse between updating or creating one | ||||||
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.
Suggested change
|
||||||
_socat_cert_cmd="echo '${_cmdpfx}show ssl cert' | socat '${_statssock}' - | grep -q '^${_pem}$'" | ||||||
_debug _socat_cert_cmd "${_socat_cert_cmd}" | ||||||
eval "${_socat_cert_cmd}" | ||||||
_ret=$? | ||||||
if [ "${_ret}" != "0" ]; then | ||||||
_err "Couldn't find '${Le_Deploy_haproxy_pem_path}' in haproxy 'show ssl crt-list'" | ||||||
return "${_ret}" | ||||||
_newcert="1" | ||||||
_info "Creating new certificate '${_pem}' over HAProxy ${_socketname}." | ||||||
# certificate wasn't found, it's a new one. We should check if the crt-list exists and creates/inserts the certificate. | ||||||
_socat_crtlist_show_cmd="echo '${_cmdpfx}show ssl crt-list' | socat '${_statssock}' - | grep -q '^${Le_Deploy_haproxy_pem_path}$'" | ||||||
_debug _socat_crtlist_show_cmd "${_socat_crtlist_show_cmd}" | ||||||
eval "${_socat_crtlist_show_cmd}" | ||||||
_ret=$? | ||||||
if [ "${_ret}" != "0" ]; then | ||||||
_err "Couldn't find '${Le_Deploy_haproxy_pem_path}' in haproxy 'show ssl crt-list'" | ||||||
return "${_ret}" | ||||||
fi | ||||||
# create a new certificate | ||||||
_socat_new_cmd="echo '${_cmdpfx}new ssl cert ${_pem}' | socat '${_statssock}' - | grep -q 'New empty'" | ||||||
_debug _socat_new_cmd "${_socat_new_cmd}" | ||||||
eval "${_socat_new_cmd}" | ||||||
_ret=$? | ||||||
if [ "${_ret}" != "0" ]; then | ||||||
_err "Couldn't create '${_pem}' in haproxy" | ||||||
return "${_ret}" | ||||||
fi | ||||||
else | ||||||
_info "Update existing certificate '${_pem}' over HAProxy ${_socketname}." | ||||||
fi | ||||||
# create a new certificate | ||||||
_socat_new_cmd="echo '${_cmdpfx}new ssl cert ${_pem}' | socat '${_statssock}' - | grep -q 'New empty'" | ||||||
_debug _socat_new_cmd "${_socat_new_cmd}" | ||||||
eval "${_socat_new_cmd}" | ||||||
_socat_cert_set_cmd="echo -e '${_cmdpfx}set ssl cert ${_pem} <<\n$(cat "${_pem}")\n' | socat '${_statssock}' - | grep -q 'Transaction created'" | ||||||
_debug _socat_cert_set_cmd "${_socat_cert_set_cmd}" | ||||||
eval "${_socat_cert_set_cmd}" | ||||||
_ret=$? | ||||||
if [ "${_ret}" != "0" ]; then | ||||||
_err "Couldn't create '${_pem}' in haproxy" | ||||||
_err "Can't update '${_pem}' in haproxy" | ||||||
return "${_ret}" | ||||||
fi | ||||||
else | ||||||
_info "Update existing certificate '${_pem}' over HAProxy ${_socketname}." | ||||||
fi | ||||||
_socat_cert_set_cmd="echo -e '${_cmdpfx}set ssl cert ${_pem} <<\n$(cat "${_pem}")\n' | socat '${_statssock}' - | grep -q 'Transaction created'" | ||||||
_debug _socat_cert_set_cmd "${_socat_cert_set_cmd}" | ||||||
eval "${_socat_cert_set_cmd}" | ||||||
_ret=$? | ||||||
if [ "${_ret}" != "0" ]; then | ||||||
_err "Can't update '${_pem}' in haproxy" | ||||||
return "${_ret}" | ||||||
fi | ||||||
_socat_cert_commit_cmd="echo '${_cmdpfx}commit ssl cert ${_pem}' | socat '${_statssock}' - | grep -q '^Success!$'" | ||||||
_debug _socat_cert_commit_cmd "${_socat_cert_commit_cmd}" | ||||||
eval "${_socat_cert_commit_cmd}" | ||||||
_ret=$? | ||||||
if [ "${_ret}" != "0" ]; then | ||||||
_err "Can't commit '${_pem}' in haproxy" | ||||||
return ${_ret} | ||||||
fi | ||||||
if [ "${_newcert}" = "1" ]; then | ||||||
# if this is a new certificate, it needs to be inserted into the crt-list` | ||||||
_socat_cert_add_cmd="echo '${_cmdpfx}add ssl crt-list ${Le_Deploy_haproxy_pem_path} ${_pem}' | socat '${_statssock}' - | grep -q 'Success!'" | ||||||
_debug _socat_cert_add_cmd "${_socat_cert_add_cmd}" | ||||||
eval "${_socat_cert_add_cmd}" | ||||||
_socat_cert_commit_cmd="echo '${_cmdpfx}commit ssl cert ${_pem}' | socat '${_statssock}' - | grep -q '^Success!$'" | ||||||
_debug _socat_cert_commit_cmd "${_socat_cert_commit_cmd}" | ||||||
eval "${_socat_cert_commit_cmd}" | ||||||
_ret=$? | ||||||
if [ "${_ret}" != "0" ]; then | ||||||
_err "Can't update '${_pem}' in haproxy" | ||||||
return "${_ret}" | ||||||
_err "Can't commit '${_pem}' in haproxy" | ||||||
return ${_ret} | ||||||
fi | ||||||
fi | ||||||
if [ "${_newcert}" = "1" ]; then | ||||||
# if this is a new certificate, it needs to be inserted into the crt-list` | ||||||
_socat_cert_add_cmd="echo '${_cmdpfx}add ssl crt-list ${Le_Deploy_haproxy_pem_path} ${_pem}' | socat '${_statssock}' - | grep -q 'Success!'" | ||||||
_debug _socat_cert_add_cmd "${_socat_cert_add_cmd}" | ||||||
eval "${_socat_cert_add_cmd}" | ||||||
_ret=$? | ||||||
if [ "${_ret}" != "0" ]; then | ||||||
_err "Can't update '${_pem}' in haproxy" | ||||||
return "${_ret}" | ||||||
fi | ||||||
fi | ||||||
done | ||||||
else | ||||||
_err "'socat' is not available, couldn't update over ${_socketname}" | ||||||
fi | ||||||
|
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.
I don't see any reason to export IFS here.