Skip to content

Commit 7bd044a

Browse files
committed
Update proxy authentication environment variables and configuration
1 parent 437affa commit 7bd044a

File tree

6 files changed

+25
-10
lines changed

6 files changed

+25
-10
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ All you need is:
8686

8787
#### Environment variables:
8888

89+
Basic authentication is used for proxy access. Configure via environment variables:
90+
* PROXY_USERNAME
91+
* PROXY_PASSWORD
92+
8993
##### Required
9094
You have two available methods of proxy authentication: username and password or IP restriction. You can use either one or both simultaneously.
9195

92-
- `USERNAME`, `PASSWORD` - set the username and password for the forward proxy. The username and password should consist of alphanumeric characters. Using special characters may cause issues due to how URL encoding works.
96+
- `PROXY_USERNAME`, `PROXY_PASSWORD` - set the username and password for the forward proxy. The username and password should consist of alphanumeric characters. Using special characters may cause issues due to how URL encoding works.
9397
- `ONLY_HOST_IP` - set this variable to true if you want to restrict access to the proxy only to the host server (i.e., the IP address of the server running the CloudProxy Docker container).
9498

9599
##### Optional
@@ -102,8 +106,8 @@ See individual provider pages for environment variables required in above provid
102106
For example:
103107

104108
```shell
105-
docker run -e USERNAME='CHANGE_THIS_USERNAME' \
106-
-e PASSWORD='CHANGE_THIS_PASSWORD' \
109+
docker run -e PROXY_USERNAME='CHANGE_THIS_USERNAME' \
110+
-e PROXY_PASSWORD='CHANGE_THIS_PASSWORD' \
107111
-e ONLY_HOST_IP=True \
108112
-e DIGITALOCEAN_ENABLED=True \
109113
-e DIGITALOCEAN_ACCESS_TOKEN='YOUR SECRET ACCESS KEY' \

cloudproxy/providers/aws/functions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111

1212
ec2 = boto3.resource("ec2", region_name=config["providers"]["aws"]["region"])
1313
ec2_client = boto3.client("ec2", region_name=config["providers"]["aws"]["region"])
14-
tags = [{"Key": "cloudproxy", "Value": "cloudproxy"}]
14+
tags = [
15+
{"Key": "cloudproxy", "Value": "cloudproxy"},
16+
{"Key": "Name", "Value": "CloudProxy-Instance"}
17+
]
1518
tag_specification = [
1619
{"ResourceType": "instance", "Tags": tags},
1720
]

cloudproxy/providers/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ def set_auth(username, password):
1313

1414
if settings.config["no_auth"]:
1515
# Remove auth configuration for tinyproxy
16-
filedata = filedata.replace('\nBasicAuth username password\n', '\n')
16+
filedata = filedata.replace('\nBasicAuth PROXY_USERNAME PROXY_PASSWORD\n', '\n')
1717
else:
1818
# Replace username and password in tinyproxy config
19-
filedata = filedata.replace("username", username)
20-
filedata = filedata.replace("password", password)
19+
filedata = filedata.replace("PROXY_USERNAME", username)
20+
filedata = filedata.replace("PROXY_PASSWORD", password)
2121

2222
if settings.config["only_host_ip"]:
2323
ip_address = requests.get('https://ipecho.net/plain').text.strip()

cloudproxy/providers/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
load_dotenv()
5555

5656
# Set proxy authentication
57-
config["auth"]["username"] = os.environ.get("USERNAME", "changeme")
58-
config["auth"]["password"] = os.environ.get("PASSWORD", "changeme")
57+
config["auth"]["username"] = os.environ.get("PROXY_USERNAME", "changeme")
58+
config["auth"]["password"] = os.environ.get("PROXY_PASSWORD", "changeme")
5959
config["age_limit"] = int(os.environ.get('AGE_LIMIT', 0))
6060
config["no_auth"] = config["auth"]["username"] == "changeme" and config["auth"]["password"] == "changeme"
6161
config["only_host_ip"] = os.environ.get("ONLY_HOST_IP", False)

cloudproxy/providers/user_data.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Allow 127.0.0.1
2424
ViaProxyName "tinyproxy"
2525
ConnectPort 443
2626
ConnectPort 563
27-
BasicAuth username password
27+
BasicAuth PROXY_USERNAME PROXY_PASSWORD
2828
EOF
2929

3030
# Setup firewall

tests/test_main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
# Configure test environment
88
os.environ["DIGITALOCEAN_ENABLED"] = "false"
9+
os.environ["PROXY_USERNAME"] = "test_user"
10+
os.environ["PROXY_PASSWORD"] = "test_pass"
11+
os.environ["ONLY_HOST_IP"] = "False"
912

1013
# Create test client
1114
# Note: The HTTPX deprecation warning is internal to the library and doesn't affect functionality
@@ -19,6 +22,11 @@
1922
config["providers"]["digitalocean"]["size"] = "s-1vcpu-1gb"
2023
config["providers"]["digitalocean"]["region"] = "lon1"
2124

25+
# Update auth config with test values
26+
config["auth"]["username"] = os.environ["PROXY_USERNAME"]
27+
config["auth"]["password"] = os.environ["PROXY_PASSWORD"]
28+
config["no_auth"] = False
29+
2230

2331
def test_read_root():
2432
response = client.get("/")

0 commit comments

Comments
 (0)