Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

EvilOlaf
Copy link
Member

Description

This is a draft/wip for adding https proxy caching. This is especially designed for machines hosting lots of github runners to reduce their bandwidth usage by sacrificing disk space. http caching has been merged already and only needed minor changes.

Caching https however is way more complicated. Encryption needs to be broken and rewrapped and then obviously downloads will fail due to cert issues. Classic MITM. So a new certificate authority (CA) needs to be put in place to allow these "fake" certs.

Why is this even necessary?
Well one major part is downloads from upstream apt repositories. The other major part is downloading 3rd party repositories and artifacts from OCI/ORAS/whatever the correct name for that system is. They do not allow plain http downloads but redirect to https.
So in order to cache these encryption must be broken on the fly.

On custom runs this works already with the mentioned extension. However when the build framework is used within a GH Actions Runner environment it would need to detect this and enable the extension automatically. No clue how to do that or overall if it is worth diving even deeper into this topic. Therefore this RFC to collect feedback.

Also lots of fail-safe checks are missing.
Sometimes I had to mix run_host_command_logged and chroot_sdcard since pipes don't work using latter.

Documentation summary for feature / change

Yes, this would need documentation.

How Has This Been Tested?

  • custom builds with ENABLE_EXTENSION
  • Test B

Checklist:

  • [no idea] My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Copy link
Contributor

coderabbitai bot commented Jun 14, 2025

Walkthrough

A new Bash script, https_proxy.sh, has been added to manage HTTPS proxy configuration using Squid with SSL bumping and a self-signed certificate. The script introduces three main functions: one to prepare the host system by installing the Squid CA certificate, another to set up the certificate inside a chroot environment before image customization, and a third to clean up the certificate from the chroot after customization. The script utilizes helper functions for command execution and logging, and includes comments regarding prerequisites and future improvements. A function for host certificate removal is present but commented out.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch https
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added size/medium PR with more then 50 and less then 250 lines 08 Milestone: Third quarter release Needs review Seeking for review Framework Framework components labels Jun 14, 2025
@EvilOlaf
Copy link
Member Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jun 14, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
extensions/https_proxy.sh (1)

47-59: Remove or properly document disabled host cleanup
Commented-out code should either be deleted or accompanied by a clear TODO and issue reference. Leaving large blocks of dead code harms readability.

Consider grouping this in a single TODO with rationale or tracking issue instead of full commented function.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc6e97c and 245f901.

📒 Files selected for processing (1)
  • extensions/https_proxy.sh (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
extensions/https_proxy.sh (1)
lib/functions/logging/runners.sh (2)
  • run_host_command_logged (204-206)
  • chroot_sdcard (133-136)

Comment on lines +39 to +43
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix sed quoting and guard certificate removal inside chroot
The sed -i expression is currently quoted incorrectly and may not run. Remove the file only if it exists and correctly strip the entry.

 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
}
function pre_umount_final_image__unprepare_https_proxy_inside_chroot() {
# 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
}
🤖 Prompt for AI Agents
In extensions/https_proxy.sh around lines 39 to 43, fix the sed command by
correcting its quoting so the expression runs properly. Also, add a check to
remove the certificate file inside the chroot only if it exists, and ensure the
sed command correctly removes the certificate entry from the configuration file.

Comment on lines +28 to +35
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Unify chroot operations and properly quote paths
Mixing chroot_sdcard and run_host_command_logged for file edits complicates context. Use chroot_sdcard for all in-chroot manipulations, quote the chroot path, and remove the debugging cat call if not needed.

 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
}
function pre_customize_image__prepare_https_proxy_inside_chroot() {
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
}
🤖 Prompt for AI Agents
In extensions/https_proxy.sh around lines 28 to 35, unify all in-chroot file
operations by replacing run_host_command_logged calls with chroot_sdcard to
maintain consistent context. Properly quote all path variables used inside
chroot_sdcard to handle spaces or special characters safely. Also, remove the
chroot_sdcard cat command used for debugging if it is not necessary for the
final script.

Comment on lines +12 to +24
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Quote variables and ensure idempotent CA config on host
Unquoted ${USERPATCHES_PATH} can break on spaces; appending to /etc/ca-certificates.conf may duplicate entries on re-runs. Guard against duplicates and wrap paths in quotes.

 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
}
function post_family_config__prepare_host_for_https_proxy() {
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
}
🤖 Prompt for AI Agents
In extensions/https_proxy.sh between lines 12 and 24, the variable
USERPATCHES_PATH is used without quotes, which can cause issues if the path
contains spaces. Also, appending the certificate path to
/etc/ca-certificates.conf without checking can lead to duplicate entries on
multiple runs. To fix this, wrap all instances of ${USERPATCHES_PATH} in double
quotes to handle spaces properly, and before appending the certificate path to
/etc/ca-certificates.conf, check if the entry already exists to avoid
duplicates.

@EvilOlaf EvilOlaf added the Help needed We need your involvement label Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
08 Milestone: Third quarter release Framework Framework components Help needed We need your involvement Needs review Seeking for review size/medium PR with more then 50 and less then 250 lines
Development

Successfully merging this pull request may close these issues.

1 participant