Skip to content
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

Handle empty array for shadowsocks.dnsServers #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alexandre-abrioux
Copy link
Contributor

@alexandre-abrioux alexandre-abrioux commented Dec 8, 2021

This PR makes sure that an empty array [] for the value of shadowsocks.dnsServers will create an empty DNS_ADDRS environment variable.

@@ -55,7 +55,7 @@ spec:
{{- end }}
{{- with .Values.shadowsocks.dnsServers }}
- name: DNS_ADDRS
value: {{ join "," . }}
value: {{ quote join "," . }}
Copy link
Owner

Choose a reason for hiding this comment

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

You forgot the parentheses here. This will cause the following exception:

Error: template: shadowsocks/templates/deployment.yaml:58:30: executing "shadowsocks/templates/deployment.yaml" at <join>: wrong number of args for join: want 2 got 0

Copy link
Contributor Author

@alexandre-abrioux alexandre-abrioux Dec 11, 2021

Choose a reason for hiding this comment

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

Hi! Thanks for the feedback, I got confused in the tests, my change wasn't even working.

I force-pushed a fix. To test it please create a value-test.yaml with the following content:

shadowsocks:
  dnsServers: []

; and then run helm install --dry-run --values values-test.yaml --debug test .
You should get the following:

env:
  - ...
  - name: DNS_ADDRS
    value: ""

@alexandre-abrioux alexandre-abrioux changed the title use quote for DNS_ADDRS Use quote for DNS_ADDRS Dec 11, 2021
@alexandre-abrioux alexandre-abrioux changed the title Use quote for DNS_ADDRS Handle empty array for shadowsocks.dnsServers Dec 11, 2021
@@ -53,10 +53,8 @@ spec:
key: {{ .existingSecret.passwordKey }}
{{- end }}
{{- end }}
{{- with .Values.shadowsocks.dnsServers }}
- name: DNS_ADDRS
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should probably surround this part with {{- if .Values.shadowsocks.dnsServers }} ... {{- end }}. Passing an empty DNS_ADDRS value to the shadowsocks/shadowsocks-libev image would get the following error:

2021-12-16 14:08:40 ERROR: failed to set nameservers

Copy link
Contributor Author

@alexandre-abrioux alexandre-abrioux Dec 16, 2021

Choose a reason for hiding this comment

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

@predatorray You are right, there is a bug in the shadowsocks/shadowsocks-libev docker image. For the moment you are not able to use an empty DNS_ADDRS value, which means you are not able to use Kubernetes's internal DNS server (the one that is already setup in /etc/resolv.conf). I've submitted a fix on the same day that I've opened this PR, but it hasn't been merged yet: shadowsocks/shadowsocks-libev#2866. I will keep you posted once it's released!

Copy link
Owner

Choose a reason for hiding this comment

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

I don't quite understand the bug you mentioned in that issue. As I tested on my laptop, the process can be started if we either provide a non-empty DNS_ADDRS or just leave it unset. The problem only occurs if we provide an empty string. Maybe the simplest way is the solution I suggested in the previous comment.

Copy link
Contributor Author

@alexandre-abrioux alexandre-abrioux Dec 16, 2021

Choose a reason for hiding this comment

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

The solution you suggested won't work. Let me rephrase: the goal of this PR is to be able to set an empty string for DNS_ADDRS in order to use Kubernetes' internal DNS server, instead of the default 8.8.8.8. Doing so will allow shadowsocks proxy users to access any of the cluster's services, like a VPN hosted on the cluster for instance.

To use Kubernetes' internal DNS server, I need to set the DNS_ADDRS env var as an empty string. That way, the -d option of ss-server won't be used, and the DNS server IP address will be fetched from /etc/resolv.conf.

See the documentation of ss-server:

-d <addr>
Setup name servers for internal DNS resolver (libc-ares). The default server is fetched from /etc/resolv.conf.

The bug is that, as of today, even if you pass an empty string for DNS_ADDRS in the docker image, the -d option is still used, so you get

ERROR: failed to set nameservers.

This will be fixed in shadowsocks/shadowsocks-libev#2866

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for your explanation! Yes, this is indeed a problem. The image does not provide any mechanism to reset the -d option to its default behavior but instead using 8.8.8.8,8.8.4.4 as its default value. Let's see what is the suggestion from the maintainer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @predatorray! The fix for the Docker image was merged in shadowsocks/shadowsocks-libev#2866. The proposed change for the Helm Chart is now relevant 🙂 I am using it in production, and it works like a charm!

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks @alexandre-abrioux for your efforts to push this feature forward. Considering it as an incompatible change, since setting DNS_ADDRS to be an empty will fail using the latest stable image, let's wait for the release of a new stable image for this and change the appVersion in the Chart.yaml accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants