Skip to content

Commit 6f5b0ce

Browse files
committed
fix(setup): Set curl --resolve flag conditionally
curl 8.x no longer treats CURLOPT_RESOLVE parse failures as a warning. Because 'elasticsearch' is not an IP address, using it as the ADDR segment in the --resolve flag is illegal. In 7.x, curl would print a warning but fall back to the hostname in the URL, as if --resolve had not been set. This issue went under the radar because: 1. curl 8.x is used in Elastic v8 images (Ubuntu base[1]), whereas our default Elastic v9 images still ship with curl 7.x (RHEL base[2]). 2. The warning was not printed due to the usage of the -s flag. Fixes #1137 [1]: https://github.com/elastic/elasticsearch/blob/v8.19.8/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/DockerBase.java#L16 [2]: https://github.com/elastic/elasticsearch/blob/v9.2.2/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/DockerBase.java#L17
1 parent ec159fa commit 6f5b0ce

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

setup/lib.sh

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ function augment_curl_args {
2929
if [[ -n "${ELASTIC_PASSWORD:-}" ]]; then
3030
args_ref+=( '-u' "elastic:${ELASTIC_PASSWORD}" )
3131
fi
32+
if [[ -n "${ELASTICSEARCH_ADDR:-}" ]]; then
33+
args_ref+=( '--resolve' "elasticsearch:9200:${ELASTICSEARCH_ADDR}" )
34+
fi
3235
}
3336

3437
# Poll the 'elasticsearch' service until it responds with HTTP code 200.
3538
function wait_for_elasticsearch {
36-
local elasticsearch_host="${ELASTICSEARCH_HOST:-elasticsearch}"
37-
38-
local -a args=( '-s' '-D-' '-m15' '-w' '%{http_code}' 'https://elasticsearch:9200/'
39-
'--resolve' "elasticsearch:9200:${elasticsearch_host}" '--cacert' "$es_ca_cert"
40-
)
39+
local -a args=( '-s' '-D-' '-m15' '-w' '%{http_code}' 'https://elasticsearch:9200/' '--cacert' "$es_ca_cert" )
4140

4241
augment_curl_args args
4342

@@ -70,11 +69,7 @@ function wait_for_elasticsearch {
7069

7170
# Poll the Elasticsearch users API until it returns users.
7271
function wait_for_builtin_users {
73-
local elasticsearch_host="${ELASTICSEARCH_HOST:-elasticsearch}"
74-
75-
local -a args=( '-s' '-D-' '-m15' 'https://elasticsearch:9200/_security/user?pretty'
76-
'--resolve' "elasticsearch:9200:${elasticsearch_host}" '--cacert' "$es_ca_cert"
77-
)
72+
local -a args=( '-s' '-D-' '-m15' 'https://elasticsearch:9200/_security/user?pretty' '--cacert' "$es_ca_cert" )
7873

7974
augment_curl_args args
8075

@@ -119,11 +114,9 @@ function wait_for_builtin_users {
119114
function check_user_exists {
120115
local username=$1
121116

122-
local elasticsearch_host="${ELASTICSEARCH_HOST:-elasticsearch}"
123-
124117
local -a args=( '-s' '-D-' '-m15' '-w' '%{http_code}'
125118
"https://elasticsearch:9200/_security/user/${username}"
126-
'--resolve' "elasticsearch:9200:${elasticsearch_host}" '--cacert' "$es_ca_cert"
119+
'--cacert' "$es_ca_cert"
127120
)
128121

129122
augment_curl_args args
@@ -154,11 +147,9 @@ function set_user_password {
154147
local username=$1
155148
local password=$2
156149

157-
local elasticsearch_host="${ELASTICSEARCH_HOST:-elasticsearch}"
158-
159150
local -a args=( '-s' '-D-' '-m15' '-w' '%{http_code}'
160151
"https://elasticsearch:9200/_security/user/${username}/_password"
161-
'--resolve' "elasticsearch:9200:${elasticsearch_host}" '--cacert' "$es_ca_cert"
152+
'--cacert' "$es_ca_cert"
162153
'-X' 'POST'
163154
'-H' 'Content-Type: application/json'
164155
'-d' "{\"password\" : \"${password}\"}"
@@ -187,11 +178,9 @@ function create_user {
187178
local password=$2
188179
local role=$3
189180

190-
local elasticsearch_host="${ELASTICSEARCH_HOST:-elasticsearch}"
191-
192181
local -a args=( '-s' '-D-' '-m15' '-w' '%{http_code}'
193182
"https://elasticsearch:9200/_security/user/${username}"
194-
'--resolve' "elasticsearch:9200:${elasticsearch_host}" '--cacert' "$es_ca_cert"
183+
'--cacert' "$es_ca_cert"
195184
'-X' 'POST'
196185
'-H' 'Content-Type: application/json'
197186
'-d' "{\"password\":\"${password}\",\"roles\":[\"${role}\"]}"
@@ -219,11 +208,9 @@ function ensure_role {
219208
local name=$1
220209
local body=$2
221210

222-
local elasticsearch_host="${ELASTICSEARCH_HOST:-elasticsearch}"
223-
224211
local -a args=( '-s' '-D-' '-m15' '-w' '%{http_code}'
225212
"https://elasticsearch:9200/_security/role/${name}"
226-
'--resolve' "elasticsearch:9200:${elasticsearch_host}" '--cacert' "$es_ca_cert"
213+
'--cacert' "$es_ca_cert"
227214
'-X' 'POST'
228215
'-H' 'Content-Type: application/json'
229216
'-d' "$body"

0 commit comments

Comments
 (0)