Skip to content

Commit 934c65a

Browse files
authored
fix flaky envoy integration tests involving intentions (hashicorp#8996)
There is a delay between an intentions change being made, and it being reflected in the Envoy runtime configuration. Now that the enforcement happens inside of Envoy instead of over in the agent, our tests need to explicitly wait until the xDS reconfiguration is complete before attempting to assert intentions worked. Also remove a few double retry loops.
1 parent a2c50d3 commit 934c65a

File tree

5 files changed

+53
-28
lines changed

5 files changed

+53
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
snapshot_envoy_admin localhost:19000 s1 || true
4+
snapshot_envoy_admin localhost:19001 s2 || true

test/integration/connect/envoy/case-badauthz/verify.bats

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ load helpers
2626
assert_upstream_has_endpoints_in_status 127.0.0.1:19000 s2.default.primary HEALTHY 1
2727
}
2828

29+
@test "s2 should have network rbac rules loaded from xDS" {
30+
retry_default assert_envoy_network_rbac_policy_count localhost:19001 1
31+
}
32+
2933
@test "s1 upstream should NOT be able to connect to s2" {
3034
run retry_default must_fail_tcp_connection localhost:5000
3135

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
snapshot_envoy_admin localhost:19000 s1 || true
4+
snapshot_envoy_admin localhost:19001 s2 || true

test/integration/connect/envoy/case-http-badauthz/verify.bats

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ load helpers
2727
assert_upstream_has_endpoints_in_status 127.0.0.1:19000 1a47f6e1~s2.default.primary HEALTHY 1
2828
}
2929

30-
@test "s1 upstream should NOT be able to connect to s2" {
31-
run retry_default must_fail_http_connection localhost:5000
32-
33-
echo "OUTPUT $output"
30+
@test "s2 should have http rbac rules loaded from xDS" {
31+
retry_default assert_envoy_http_rbac_policy_count localhost:19001 1
32+
}
3433

35-
[ "$status" == "0" ]
34+
@test "s1 upstream should NOT be able to connect to s2" {
35+
retry_default must_fail_http_connection localhost:5000
3636
}

test/integration/connect/envoy/helpers.bash

+36-23
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ function assert_proxy_presents_cert_uri {
110110
local DC=${3:-primary}
111111
local NS=${4:-default}
112112

113-
114113
CERT=$(retry_default get_cert $HOSTPORT)
115114

116115
echo "WANT SERVICE: ${NS}/${SERVICENAME}"
@@ -153,36 +152,48 @@ function assert_envoy_version {
153152
echo $VERSION | grep "/$ENVOY_VERSION/"
154153
}
155154

155+
function assert_envoy_http_rbac_policy_count {
156+
local HOSTPORT=$1
157+
local EXPECT_COUNT=$2
158+
159+
GOT_COUNT=$(get_envoy_http_rbac_once $HOSTPORT | jq '.rules.policies | length')
160+
[ "${GOT_COUNT:-0}" -eq $EXPECT_COUNT ]
161+
}
162+
163+
function get_envoy_http_rbac_once {
164+
local HOSTPORT=$1
165+
run curl -s -f $HOSTPORT/config_dump
166+
[ "$status" -eq 0 ]
167+
echo "$output" | jq --raw-output '.configs[2].dynamic_listeners[].active_state.listener.filter_chains[0].filters[0].config.http_filters[] | select(.name == "envoy.filters.http.rbac") | .config'
168+
}
169+
170+
function assert_envoy_network_rbac_policy_count {
171+
local HOSTPORT=$1
172+
local EXPECT_COUNT=$2
173+
174+
GOT_COUNT=$(get_envoy_network_rbac_once $HOSTPORT | jq '.rules.policies | length')
175+
[ "${GOT_COUNT:-0}" -eq $EXPECT_COUNT ]
176+
}
177+
178+
function get_envoy_network_rbac_once {
179+
local HOSTPORT=$1
180+
run curl -s -f $HOSTPORT/config_dump
181+
[ "$status" -eq 0 ]
182+
echo "$output" | jq --raw-output '.configs[2].dynamic_listeners[].active_state.listener.filter_chains[0].filters[] | select(.name == "envoy.filters.network.rbac") | .config'
183+
}
184+
156185
function get_envoy_listener_filters {
157186
local HOSTPORT=$1
158187
run retry_default curl -s -f $HOSTPORT/config_dump
159188
[ "$status" -eq 0 ]
160-
local ENVOY_VERSION=$(echo $output | jq --raw-output '.configs[0].bootstrap.node.metadata.envoy_version')
161-
local QUERY=''
162-
# from 1.13.0 on the config json looks slightly different
163-
# 1.10.x, 1.11.x, 1.12.x are not affected
164-
if [[ "$ENVOY_VERSION" =~ ^1\.1[012]\. ]]; then
165-
QUERY='.configs[2].dynamic_active_listeners[].listener | "\(.name) \( .filter_chains[0].filters | map(.name) | join(","))"'
166-
else
167-
QUERY='.configs[2].dynamic_listeners[].active_state.listener | "\(.name) \( .filter_chains[0].filters | map(.name) | join(","))"'
168-
fi
169-
echo "$output" | jq --raw-output "$QUERY"
189+
echo "$output" | jq --raw-output '.configs[2].dynamic_listeners[].active_state.listener | "\(.name) \( .filter_chains[0].filters | map(.name) | join(","))"'
170190
}
171191

172192
function get_envoy_http_filters {
173193
local HOSTPORT=$1
174194
run retry_default curl -s -f $HOSTPORT/config_dump
175195
[ "$status" -eq 0 ]
176-
local ENVOY_VERSION=$(echo $output | jq --raw-output '.configs[0].bootstrap.node.metadata.envoy_version')
177-
local QUERY=''
178-
# from 1.13.0 on the config json looks slightly different
179-
# 1.10.x, 1.11.x, 1.12.x are not affected
180-
if [[ "$ENVOY_VERSION" =~ ^1\.1[012]\. ]]; then
181-
QUERY='.configs[2].dynamic_active_listeners[].listener | "\(.name) \( .filter_chains[0].filters[] | select(.name == "envoy.http_connection_manager") | .config.http_filters | map(.name) | join(","))"'
182-
else
183-
QUERY='.configs[2].dynamic_listeners[].active_state.listener | "\(.name) \( .filter_chains[0].filters[] | select(.name == "envoy.http_connection_manager") | .config.http_filters | map(.name) | join(","))"'
184-
fi
185-
echo "$output" | jq --raw-output "$QUERY"
196+
echo "$output" | jq --raw-output '.configs[2].dynamic_listeners[].active_state.listener | "\(.name) \( .filter_chains[0].filters[] | select(.name == "envoy.http_connection_manager") | .config.http_filters | map(.name) | join(","))"'
186197
}
187198

188199
function get_envoy_cluster_config {
@@ -241,7 +252,7 @@ function get_upstream_endpoint_in_status_count {
241252
local HOSTPORT=$1
242253
local CLUSTER_NAME=$2
243254
local HEALTH_STATUS=$3
244-
run retry_default curl -s -f "http://${HOSTPORT}/clusters?format=json"
255+
run curl -s -f "http://${HOSTPORT}/clusters?format=json"
245256
[ "$status" -eq 0 ]
246257
# echo "$output" >&3
247258
echo "$output" | jq --raw-output "
@@ -364,7 +375,7 @@ function get_healthy_service_count {
364375
local DC=$2
365376
local NS=$3
366377

367-
run retry_default curl -s -f ${HEADERS} "127.0.0.1:8500/v1/health/connect/${SERVICE_NAME}?dc=${DC}&passing&ns=${NS}"
378+
run curl -s -f ${HEADERS} "127.0.0.1:8500/v1/health/connect/${SERVICE_NAME}?dc=${DC}&passing&ns=${NS}"
368379
[ "$status" -eq 0 ]
369380
echo "$output" | jq --raw-output '. | length'
370381
}
@@ -549,6 +560,8 @@ function must_fail_http_connection {
549560

550561
echo "OUTPUT $output"
551562

563+
[ "$status" == "0" ]
564+
552565
local expect_response="${2:-403 Forbidden}"
553566
# Should fail request with 503
554567
echo "$output" | grep "${expect_response}"

0 commit comments

Comments
 (0)