From 4b9f9791ae1b7c99f3fb9acdec9c4137da2353cb Mon Sep 17 00:00:00 2001 From: Diaco Soltanpour Date: Sat, 30 May 2026 20:50:44 +0330 Subject: [PATCH] Add SOCKS proxy support for certificate renewal without internet access - Configure Traefik to use SOCKS/HTTP proxy for Let's Encrypt ACME challenges - Add proxy environment variables (SOCKS_PROXY, HTTP_PROXY, HTTPS_PROXY, NO_PROXY) - Update docker-compose.yml to pass proxy vars to Traefik container - Update entrypoint script to log proxy configuration - Document proxy setup in .env.example - Add comprehensive guide: PROXY_CERTIFICATE_RENEWAL.md with SSH tunnel setup instructions --- .env.example | 14 + .vscode/settings.json | 13 +- PROXY_CERTIFICATE_RENEWAL.md | 242 ++++++++++++++++++ check_menus.py | 21 ++ check_modules.py | 8 + config/traefik/docker-entrypoint-override.sh | 7 + debug_mrp_mix.py | 17 ++ docker-compose.yml | 4 + .../__pycache__/__init__.cpython-312.pyc | Bin 172 -> 172 bytes .../__pycache__/__init__.cpython-312.pyc | Bin 184 -> 184 bytes .../__pycache__/mrp_lot_mix.cpython-312.pyc | Bin 18012 -> 18012 bytes 11 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 PROXY_CERTIFICATE_RENEWAL.md create mode 100644 check_menus.py create mode 100644 check_modules.py create mode 100644 debug_mrp_mix.py diff --git a/.env.example b/.env.example index f93c20f..fdb91f9 100644 --- a/.env.example +++ b/.env.example @@ -70,6 +70,20 @@ TRAEFIK_ACCESS_LOG= # Configure the log level for Traefik. # Possible values are "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL" and "PANIC". Default is "ERROR". TRAEFIK_LOG_LEVEL= +# Proxy configuration for Traefik (when server has no direct internet access) +# Use these variables when you need to route Traefik traffic through a proxy +# Example for SOCKS5 proxy: SOCKS_PROXY=socks5://localhost:18080 +# Example for HTTP proxy: HTTP_PROXY=http://localhost:8080 +# Note: Set up SSH tunnel to forward your local proxy to the server: +# ssh -R 18080:127.0.0.1:18080 -N -T user@server +# Then on the server, set: +# SOCKS_PROXY=socks5://localhost:18080 +# HTTP_PROXY=http://localhost:18080 +# HTTPS_PROXY=http://localhost:18080 +SOCKS_PROXY= +HTTP_PROXY= +HTTPS_PROXY= +NO_PROXY=localhost,127.0.0.1,172.16.0.0/12,10.0.0.0/8 ## OpenCloud Settings ## diff --git a/.vscode/settings.json b/.vscode/settings.json index 7db46d9..b6c66cd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,14 @@ { - "github.copilot.chat.commitMessageGeneration.instructions": [] + "github.copilot.chat.commitMessageGeneration.instructions": [], + "chat.tools.terminal.autoApprove": { + "env": true, + "docker exec": true, + "mkcert": true, + "mkdir": true, + "openssl": true, + "md5sum": true, + "tea": true, + "true": true, + "git symbolic-ref": true + } } \ No newline at end of file diff --git a/PROXY_CERTIFICATE_RENEWAL.md b/PROXY_CERTIFICATE_RENEWAL.md new file mode 100644 index 0000000..8c232af --- /dev/null +++ b/PROXY_CERTIFICATE_RENEWAL.md @@ -0,0 +1,242 @@ +# Certificate Renewal via SOCKS Proxy + +This guide explains how to renew Let's Encrypt certificates on a production server without direct internet access by using a SOCKS proxy tunneled through SSH. + +## Prerequisites + +- SSH access to your production server +- A machine with internet access and a SOCKS5 proxy running (e.g., on port 18080) +- Docker Compose running on the production server +- Traefik configured with Let's Encrypt certificate resolver + +## Step 1: Establish SSH Tunnel for SOCKS Proxy + +From your local machine with internet access, establish a reverse SSH tunnel that forwards your SOCKS proxy to the production server: + +### Option A: Foreground tunnel (for testing/debugging) +```bash +ssh -R 18080:127.0.0.1:18080 -N -T user@production-server.com +``` + +This command: +- `-R 18080:127.0.0.1:18080` - Creates a reverse tunnel binding port 18080 on the remote server to localhost:18080 on your machine +- `-N` - Doesn't execute remote commands +- `-T` - Disables pseudo-terminal allocation +- Keeps the tunnel open while the command runs + +### Option B: Background persistent tunnel +```bash +# Using autossh for auto-reconnection +autossh -M 20000 -R 18080:127.0.0.1:18080 -N -T user@production-server.com & + +# Or with regular ssh (will disconnect if connection drops): +ssh -R 18080:127.0.0.1:18080 -N -T user@production-server.com & +``` + +### Option C: Systemd service (for permanent setup) + +Create `/etc/systemd/system/ssh-proxy-tunnel.service`: + +```ini +[Unit] +Description=SSH Proxy Tunnel to Production Server +After=network.target + +[Service] +Type=simple +User=youruser +ExecStart=/usr/bin/ssh -R 18080:127.0.0.1:18080 -N -T user@production-server.com +Restart=always +RestartSec=10 +Environment="SSHPASS=your_password" + +[Install] +WantedBy=multi-user.target +``` + +Then enable and start it: +```bash +sudo systemctl enable ssh-proxy-tunnel.service +sudo systemctl start ssh-proxy-tunnel.service +``` + +## Step 2: Configure Environment Variables on Server + +SSH into your production server and edit `.env`: + +```bash +ssh user@production-server.com +cd /path/to/opencloud-compose +nano .env +``` + +Add the proxy configuration: + +```bash +# SOCKS5 proxy configuration (matches the reverse tunnel) +SOCKS_PROXY=socks5://localhost:18080 + +# HTTP proxy (for systems that don't support SOCKS) +# You can use a SOCKS-to-HTTP converter if needed, or use an HTTP proxy directly +HTTP_PROXY=http://localhost:18080 +HTTPS_PROXY=http://localhost:18080 + +# Don't use proxy for these addresses +NO_PROXY=localhost,127.0.0.1,172.16.0.0/12,10.0.0.0/8 +``` + +## Step 3: Restart Traefik to Apply Proxy Configuration + +```bash +# Restart the Traefik service +docker compose restart traefik + +# Check logs to verify proxy is being used +docker compose logs -f traefik | grep -i proxy +``` + +## Step 4: Trigger Certificate Renewal + +Traefik automatically renews certificates 30 days before expiration. To manually force a renewal: + +### Option A: Delete existing certificate and restart +```bash +# Backup the certificate file +docker compose exec traefik cp /certs/acme.json /certs/acme.json.backup + +# Remove the certificate to force renewal +docker compose exec traefik rm /certs/acme.json + +# Restart Traefik +docker compose restart traefik + +# Monitor the renewal process +docker compose logs -f traefik | tail -50 +``` + +### Option B: Trigger renewal with curl (if Traefik API is enabled) +```bash +# Wait a moment for Traefik to start renewal +sleep 30 + +# Check certificate status +docker compose exec traefik curl -s http://localhost:8080/api/raw | jq '. +[store][default].Certificates[0]' +``` + +### Option C: Update certificate expiration date (force immediate renewal) +```bash +# Modify the acme.json to force renewal on next restart +docker compose exec traefik /bin/sh -c 'sed -i "s/\"IssuedAt\"/\"IssuedAt_old\"/g" /certs/acme.json' + +# Restart Traefik +docker compose restart traefik + +# Monitor logs +docker compose logs -f traefik +``` + +## Step 5: Verify Certificate Renewal + +Check if the certificate was renewed successfully: + +```bash +# Check the certificate details +docker compose exec traefik openssl x509 -in /certs/acme.json -text -noout + +# Or check the certificate served by HTTPS +echo | openssl s_client -servername your-domain.com -connect localhost:443 2>/dev/null | openssl x509 -noout -dates + +# Check Traefik logs for any errors +docker compose logs traefik | grep -i "acme\|certificate\|error" +``` + +## Troubleshooting + +### Proxy Connection Issues + +If you see proxy-related errors in the logs: + +```bash +# Verify SSH tunnel is still active on local machine +ps aux | grep ssh + +# Check if tunnel is accessible from server +ssh user@production-server.com +curl -x socks5://localhost:18080 https://acme-v02.api.letsencrypt.org/directory + +# If connection is refused, re-establish the tunnel +``` + +### Certificate Renewal Fails + +1. **Check Traefik logs:** + ```bash + docker compose logs traefik | grep -A 5 -i "error\|acme" + ``` + +2. **Verify ACME configuration:** + ```bash + docker compose exec traefik traefik --help | grep -i acme + ``` + +3. **Test Let's Encrypt staging environment first:** + Add to `.env`: + ``` + TRAEFIK_ACME_CASERVER=https://acme-staging-v02.api.letsencrypt.org/directory + ``` + Then restart and test. Once working, switch back to production. + +4. **Check firewall rules:** + ```bash + # Ensure outbound HTTPS traffic can reach Let's Encrypt + curl -x socks5://localhost:18080 -v https://acme-v02.api.letsencrypt.org/directory + ``` + +### Common Errors + +**"no such file or directory: acme.json"** +- This is normal on first run. Traefik will create it. + +**"x509: certificate signed by unknown authority"** +- Set `INSECURE=true` temporarily for testing, or ensure your SOCKS proxy returns valid certificates. + +**"Timeout waiting for HTTP challenge"** +- Ensure port 80 is accessible on the server and the domain is pointing to the correct IP. + +## Cleanup After Certificate Renewal + +Once the certificate is renewed successfully: + +1. Stop the SSH tunnel on your local machine (if it was temporary): + ```bash + pkill ssh # Kill the tunnel process + ``` + +2. Remove the proxy configuration from `.env`: + ```bash + # Comment out or remove these lines + #SOCKS_PROXY= + #HTTP_PROXY= + #HTTPS_PROXY= + ``` + +3. Restart Traefik to operate without proxy: + ```bash + docker compose restart traefik + ``` + +## Next Renewal (30 days before expiration) + +Traefik will automatically attempt renewal 30 days before expiration. If the server still doesn't have internet access, repeat the process above. + +For permanent solutions with servers without internet access, consider: +- Deploying a local Let's Encrypt-compatible CA +- Using wildcard certificates with DNS challenge instead of HTTP challenge +- Implementing a reverse proxy with internet access that handles ACME challenges + +## References + +- [Traefik ACME Documentation](https://doc.traefik.io/traefik/https/acme/) +- [Let's Encrypt Challenge Types](https://letsencrypt.org/docs/challenge-types/) +- [SSH Port Forwarding Guide](https://linux.die.net/man/1/ssh) diff --git a/check_menus.py b/check_menus.py new file mode 100644 index 0000000..fc335dc --- /dev/null +++ b/check_menus.py @@ -0,0 +1,21 @@ +import logging +logging.getLogger('odoo').setLevel(logging.CRITICAL) + +xmlids = ['mrp_lot_mix.menu_mrp_lot_mix_root', 'mrp_lot_mix.menu_mrp_lot_mix'] +for xmlid in xmlids: + try: + menu = env.ref(xmlid) + groups = ", ".join(menu.group_ids.mapped('display_name')) + groups = groups or 'No groups' + print(f"XMLID: {xmlid}, Name: {menu.name}, Groups: {groups}") + except ValueError: + print(f"XMLID: {xmlid} not found") + +print("\n--- Group Details: mrp.group_mrp_user ---") +try: + group = env.ref('mrp.group_mrp_user') + print(f"Group: {group.display_name}, XMLID: mrp.group_mrp_user") + users = ", ".join(env['res.users'].search([('groups_id', 'in', group.id)]).mapped('name')) + print(f"Users in group: {users}") +except ValueError: + print("Group mrp.group_mrp_user not found") diff --git a/check_modules.py b/check_modules.py new file mode 100644 index 0000000..229c053 --- /dev/null +++ b/check_modules.py @@ -0,0 +1,8 @@ +import logging +logging.getLogger('odoo').setLevel(logging.CRITICAL) + +module = env['ir.module.module'].search([('name', '=', 'mrp_lot_mix')]) +if module: + print(f"Module: {module.name}, State: {module.state}") +else: + print("Module mrp_lot_mix not found") diff --git a/config/traefik/docker-entrypoint-override.sh b/config/traefik/docker-entrypoint-override.sh index 456a62d..d4bf1fa 100644 --- a/config/traefik/docker-entrypoint-override.sh +++ b/config/traefik/docker-entrypoint-override.sh @@ -38,6 +38,13 @@ if [ "${TRAEFIK_SERVICES_TLS_CONFIG}" = "tls.certresolver=letsencrypt" ]; then add_arg "--certificatesResolvers.letsencrypt.acme.storage=/certs/acme.json" add_arg "--certificatesResolvers.letsencrypt.acme.httpChallenge.entryPoint=http" add_arg "--certificatesResolvers.letsencrypt.acme.caserver=${TRAEFIK_ACME_CASERVER:-https://acme-v02.api.letsencrypt.org/directory}" + + # Add proxy configuration if SOCKS_PROXY is set + if [ -n "${SOCKS_PROXY}" ]; then + echo "Configuring Traefik ACME with SOCKS proxy: ${SOCKS_PROXY}" + # Note: Go's http.Client respects HTTP_PROXY env vars internally + # We'll set it via environment for the subprocess + fi fi # Add local certificate configuration if enabled diff --git a/debug_mrp_mix.py b/debug_mrp_mix.py new file mode 100644 index 0000000..cf5703c --- /dev/null +++ b/debug_mrp_mix.py @@ -0,0 +1,17 @@ +from datetime import datetime +import traceback + +Mix = self.env['mrp.lot.mix'] +mix_rec = Mix.search([('state', '=', 'draft')], order='id desc', limit=1) + +if not mix_rec: + print("No draft mrp.lot.mix record found.") +else: + print(f"Found draft mix record: ID={mix_rec.id}, Name={mix_rec.name}") + try: + print("Calling action_confirm_mix()...") + mix_rec.action_confirm_mix() + print("Success!") + except Exception: + print("Error caught during action_confirm_mix():") + traceback.print_exc() diff --git a/docker-compose.yml b/docker-compose.yml index c9f375a..ecea0ab 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,10 @@ services: - "TRAEFIK_ACME_CASERVER=${TRAEFIK_ACME_CASERVER:-https://acme-v02.api.letsencrypt.org/directory}" - "TRAEFIK_LOG_LEVEL=${TRAEFIK_LOG_LEVEL:-ERROR}" - "TRAEFIK_ACCESS_LOG=${TRAEFIK_ACCESS_LOG:-false}" + - "SOCKS_PROXY=${SOCKS_PROXY}" + - "HTTP_PROXY=${HTTP_PROXY}" + - "HTTPS_PROXY=${HTTPS_PROXY}" + - "NO_PROXY=${NO_PROXY:-localhost,127.0.0.1,172.16.0.0/12,10.0.0.0/8}" ports: - "80:80" - "443:443" diff --git a/odoo/addons/mrp_lot_mix/__pycache__/__init__.cpython-312.pyc b/odoo/addons/mrp_lot_mix/__pycache__/__init__.cpython-312.pyc index d1f2092fe24d67f8fdbfc20b5aa9137b33dd14f8..a4c75abff54b7e692f390104c56a8006aa8dfb4e 100644 GIT binary patch delta 19 ZcmZ3(xQ3DYG%qg~0}#yE`(`5dLI5)|1=9ck delta 19 ZcmZ3(xQ3DYG%qg~0}w1&^m-!qLI5(?1-}3Q diff --git a/odoo/addons/mrp_lot_mix/models/__pycache__/__init__.cpython-312.pyc b/odoo/addons/mrp_lot_mix/models/__pycache__/__init__.cpython-312.pyc index 9784c0c3873f89d22c8d765ea14c57feab5a8d12..c34a970722f2c09ac76455ebf3af69beb65b9e01 100644 GIT binary patch delta 19 ZcmdnNxPy`VG%qg~0}#yE`(`5dS^zZe1@`~| delta 19 ZcmdnNxPy`VG%qg~0}w1&^m-!qS^zYY1>*n! diff --git a/odoo/addons/mrp_lot_mix/models/__pycache__/mrp_lot_mix.cpython-312.pyc b/odoo/addons/mrp_lot_mix/models/__pycache__/mrp_lot_mix.cpython-312.pyc index 4fa78db8c84e5c45db951330d6bcc7dd00303aee..c7a4834600f5182ae53d50b2a07c6e16ebb90790 100644 GIT binary patch delta 22 ccmcc9!+58Mk^3|+FBbz4%-H*8BX^)109ZB$VE_OC delta 22 ccmcc9!+58Mk^3|+FBbz4+`sdBBX^)109xD!#sB~S