-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
RFC: https_proxy extension: initial commit #8298
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
base: main
Are you sure you want to change the base?
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # squid must be configured to do ssl-bumping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Also a self-signed cert with ca needs to be created | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # the ca needs to be stored as "squid-self-signed.crt" in userpatches/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # to do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # check if https_proxy/HTTPS_PROXY are set and then if cert is available. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # HOST | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # if a cert file is there copy into docker container or host machine and enable it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function post_family_config__prepare_host_for_https_proxy() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -f ${USERPATCHES_PATH}/squid-self-signed.crt ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_alert "Found cert file: ${USERPATCHES_PATH}/squid-self-signed.crt" "${EXTENSION}" "info" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run_host_command_logged mkdir -p /usr/share/ca-certificates/extra/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run_host_command_logged cp ${USERPATCHES_PATH}/squid-self-signed.crt /usr/share/ca-certificates/extra/squid-self-signed.crt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run_host_command_logged echo "extra/squid-self-signed.crt" >> /etc/ca-certificates.conf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run_host_command_logged update-ca-certificates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_alert "Host/Docker prepared for https proxy" "${EXTENSION}" "info" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_alert "Cert file not found" "${EXTENSION}" "error" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+24
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. 🛠️ Refactor suggestion Quote variables and ensure idempotent CA config on host function post_family_config__prepare_host_for_https_proxy() {
- if [ -f ${USERPATCHES_PATH}/squid-self-signed.crt ]; then
- display_alert "Found cert file: ${USERPATCHES_PATH}/squid-self-signed.crt" "${EXTENSION}" "info"
- run_host_command_logged mkdir -p /usr/share/ca-certificates/extra/
- run_host_command_logged cp ${USERPATCHES_PATH}/squid-self-signed.crt /usr/share/ca-certificates/extra/squid-self-signed.crt
- run_host_command_logged echo "extra/squid-self-signed.crt" >> /etc/ca-certificates.conf
- run_host_command_logged update-ca-certificates
+ cert_host="${USERPATCHES_PATH}/squid-self-signed.crt"
+ if [[ -f "$cert_host" ]]; then
+ display_alert "Found cert file: $cert_host" "${EXTENSION}" "info"
+ run_host_command_logged mkdir -p "/usr/share/ca-certificates/extra/"
+ run_host_command_logged cp "$cert_host" "/usr/share/ca-certificates/extra/squid-self-signed.crt"
+ # Append only if not already present
+ if ! grep -Fxq "extra/squid-self-signed.crt" /etc/ca-certificates.conf; then
+ run_host_command_logged bash -c 'echo "extra/squid-self-signed.crt" >> /etc/ca-certificates.conf'
+ fi
+ run_host_command_logged update-ca-certificates
display_alert "Host/Docker prepared for https proxy" "${EXTENSION}" "info"
else
display_alert "Cert file not found" "${EXTENSION}" "error"
exit 1
fi
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # CHROOT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Add cert into chroot before customization so customization won't fail on https downloads | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function pre_customize_image__prepare_https_proxy_inside_chroot() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| display_alert "Found cert file" "${EXTENSION}" "info" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chroot_sdcard mkdir -p /usr/share/ca-certificates/extra/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run_host_command_logged cp ${USERPATCHES_PATH}/squid-self-signed.crt "${SDCARD}"/usr/share/ca-certificates/extra/squid-self-signed.crt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run_host_command_logged echo "extra/squid-self-signed.crt" >> "${SDCARD}"/etc/ca-certificates.conf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chroot_sdcard cat /etc/ca-certificates.conf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chroot_sdcard update-ca-certificates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+28
to
+35
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. 🛠️ Refactor suggestion Unify chroot operations and properly quote paths function pre_customize_image__prepare_https_proxy_inside_chroot() {
- display_alert "Found cert file" "${EXTENSION}" "info"
- chroot_sdcard mkdir -p /usr/share/ca-certificates/extra/
- run_host_command_logged cp ${USERPATCHES_PATH}/squid-self-signed.crt "${SDCARD}"/usr/share/ca-certificates/extra/squid-self-signed.crt
- run_host_command_logged echo "extra/squid-self-signed.crt" >> "${SDCARD}"/etc/ca-certificates.conf
- chroot_sdcard cat /etc/ca-certificates.conf
- chroot_sdcard update-ca-certificates
+ display_alert "Preparing chroot for HTTPS proxy" "${EXTENSION}" "info"
+ # Ensure cert directory in chroot
+ chroot_sdcard mkdir -p /usr/share/ca-certificates/extra/
+ # Copy certificate into chroot
+ chroot_sdcard bash -c "cp /host${USERPATCHES_PATH}/squid-self-signed.crt /usr/share/ca-certificates/extra/"
+ # Append to ca-certificates.conf if missing
+ chroot_sdcard bash -c 'grep -Fxq "extra/squid-self-signed.crt" /etc/ca-certificates.conf || echo "extra/squid-self-signed.crt" >> /etc/ca-certificates.conf'
+ chroot_sdcard update-ca-certificates
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # CHROOT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Remove cert after "apt_lists_copy_from_host_to_image_and_update" has been executed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function pre_umount_final_image__unprepare_https_proxy_inside_chroot() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chroot_sdcard rm /usr/share/ca-certificates/extra/squid-self-signed.crt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| run_host_command_logged sed -i "'/extra\/squid-self-signed.crt/d'" "${SDCARD}/etc/ca-certificates.conf" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chroot_sdcard update-ca-certificates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+39
to
+43
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. Fix function pre_umount_final_image__unprepare_https_proxy_inside_chroot() {
- chroot_sdcard rm /usr/share/ca-certificates/extra/squid-self-signed.crt
- run_host_command_logged sed -i "'/extra\/squid-self-signed.crt/d'" "${SDCARD}/etc/ca-certificates.conf"
- chroot_sdcard update-ca-certificates
+ # Remove certificate file if present
+ chroot_sdcard bash -c '[[ -f /usr/share/ca-certificates/extra/squid-self-signed.crt ]] && rm /usr/share/ca-certificates/extra/squid-self-signed.crt'
+ # Remove entry from conf
+ chroot_sdcard sed -i '/extra\/squid-self-signed.crt/d' /etc/ca-certificates.conf
+ chroot_sdcard update-ca-certificates
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # HOST | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # remove | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #function post_umount_final_image__unprepare_host_for_https_proxy() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # if [ -f /usr/share/ca-certificates/extra/squid-self-signed.crt ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # display_alert "Found cert file: /usr/share/ca-certificates/extra/squid-self-signed.crt. Removing..." "${EXTENSION}" "info" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # run_host_command_logged rm /usr/share/ca-certificates/extra/squid-self-signed.crt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # run_host_command_logged sed -i "'/extra\/squid-self-signed.crt/d'" /etc/ca-certificates.conf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # run_host_command_logged update-ca-certificates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # display_alert "Host unprepared for https proxy" "${EXTENSION}" "info" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # display_alert "Cert file not found" "${EXTENSION}" "error" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # removing cert casuses log upload to fail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.