Skip to content

Commit a106216

Browse files
authored
CLOUDP-342319 - Fix proxy env vars (#398)
# Summary This PR fixes a bug where the mongodb agents were not using the `NO_PROXY` environment variable set on the operator. This is an issue with the agent where setting the `httpProxy` flag will ignore the environment variables. Therefore, running the agent without that flag work properly whether the variables are set or not. To make sure this is tested, the `e2e_operator_proxy` test was updated by adding a `NO_PROXY` variable set to cloud-qa and asserting that the proxy does not intercept those calls. ## Proof of Work Ran a [patch](https://spruce.mongodb.com/version/68b6ca1169f9af0007311434/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC) where the test was updated, but the fix was not added. It failed, proving that the setting the `NO_PROXY` variable did not work. With the fix, the CI should be green. ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you added changelog file? - use `skip-changelog` label if not needed - refer to [Changelog files and Release Notes](https://github.com/mongodb/mongodb-kubernetes/blob/master/CONTRIBUTING.md#changelog-files-and-release-notes) section in CONTRIBUTING.md for more details
1 parent b7211ae commit a106216

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Fix proxy environment variables
3+
kind: fix
4+
date: 2025-09-02
5+
---
6+
7+
* Fixed an issue where the MongoDB Agents did not adhere to the `NO_PROXY` environment variable configured on the operator.

docker/mongodb-kubernetes-init-database/content/agent-launcher.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ else
144144
script_log "Mongodb Agent is configured to run in \"headless\" mode using local config file"
145145
fi
146146

147-
148-
149-
if [[ -n "${HTTP_PROXY-}" ]]; then
150-
agentOpts+=("-httpProxy=${HTTP_PROXY}")
151-
fi
147+
# We never set the -httpProxy flag.
148+
# Without the flag, the agent relies solely on standard environment variables (HTTP_PROXY, HTTPS_PROXY, NO_PROXY).
149+
# This avoids conflicts between environment settings and agent CLI parameters.
150+
# For reference, see the agent implementation:
151+
# https://github.com/10gen/mms-automation/blob/19f44a18cc089ec3734e2b496fdde82b124cd945/go_planner/src/com.tengen/cm/backup/commonbackup/connections.go#L158
152152

153153
if [[ -n "${SSL_TRUSTED_MMS_SERVER_CERTIFICATE-}" ]]; then
154154
agentOpts+=("-httpsCAFile=${SSL_TRUSTED_MMS_SERVER_CERTIFICATE}")

docker/mongodb-kubernetes-tests/tests/operator/operator_proxy.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22

3-
import yaml
43
from kubernetes import client
54
from kubetester import create_or_update_configmap
65
from kubetester.create_or_replace_from_yaml import (
@@ -12,7 +11,6 @@
1211
from kubetester.mongodb import MongoDB
1312
from kubetester.operator import Operator
1413
from kubetester.phase import Phase
15-
from oauthlib.oauth1.rfc5849.endpoints import resource
1614
from pytest import fixture, mark
1715

1816
MDB_RESOURCE = "replica-set"
@@ -45,7 +43,10 @@ def operator_with_proxy(namespace: str, operator_installation_config: dict[str,
4543
os.environ["HTTP_PROXY"] = os.environ["HTTPS_PROXY"] = squid_proxy
4644
helm_args = operator_installation_config.copy()
4745
helm_args["customEnvVars"] += (
48-
f"\&MDB_PROPAGATE_PROXY_ENV=true" + f"\&HTTP_PROXY={squid_proxy}" + f"\&HTTPS_PROXY={squid_proxy}"
46+
f"\&MDB_PROPAGATE_PROXY_ENV=true"
47+
+ f"\&HTTP_PROXY={squid_proxy}"
48+
+ f"\&HTTPS_PROXY={squid_proxy}"
49+
+ "\&NO_PROXY=cloud-qa.mongodb.com"
4950
)
5051
return Operator(namespace=namespace, helm_args=helm_args).install()
5152

@@ -78,7 +79,7 @@ def test_proxy_logs_requests(namespace: str):
7879
pod_name = proxy_pods[0].metadata.name
7980
container_name = "squid"
8081
pod_logs = KubernetesTester.read_pod_logs(namespace, pod_name, container_name)
81-
assert "cloud-qa.mongodb.com" in pod_logs
82+
assert "cloud-qa.mongodb.com" not in pod_logs
8283
assert "api-agents-qa.mongodb.com" in pod_logs
8384
assert "api-backup-qa.mongodb.com" in pod_logs
8485

0 commit comments

Comments
 (0)