Skip to content

Commit be46ac2

Browse files
croissannethozza
authored andcommitted
test/cases/worker-executor: verify security group rules
Make sure there's only one egress rule with the worker host as target.
1 parent 89d3885 commit be46ac2

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

test/cases/worker-executor.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ BLUEPRINT_FILE=${TEMPDIR}/blueprint.toml
1717
COMPOSE_START=${TEMPDIR}/compose-start.json
1818
COMPOSE_INFO=${TEMPDIR}/compose-info.json
1919
DESCR_INST=${TEMPDIR}/descr-inst.json
20+
AUTH_SG=${TEMPDIR}/auth-sgrule.json
2021
DESCR_SGRULE=${TEMPDIR}/descr-sgrule.json
2122
KEYPAIR=${TEMPDIR}/keypair.pem
2223
INSTANCE_ID=$(curl -Ls http://169.254.169.254/latest/meta-data/instance-id)
24+
WORKER_HOST=$(curl -Ls http://169.254.169.254/latest/meta-data/local-ipv4)
2325

2426
# Check available container runtime
2527
if type -p podman 2>/dev/null >&2; then
@@ -122,10 +124,19 @@ fi
122124

123125
greenprint "Setting up executor"
124126

125-
# allow the executor to access the internet for the setup
127+
# the executor should be created with exactly one egress rule (allowing traffic to the worker host)
126128
SGID=$(jq -r .Reservations[0].Instances[0].SecurityGroups[0].GroupId "$DESCR_INST")
127-
$AWS_CMD ec2 authorize-security-group-egress --group-id "$SGID" --protocol tcp --cidr 0.0.0.0/0 --port 1-65535 > "$DESCR_SGRULE"
128-
SGRULEID=$(jq -r .SecurityGroupRules[0].SecurityGroupRuleId "$DESCR_SGRULE")
129+
$AWS_CMD ec2 describe-security-group-rules --filters "Name=group-id,Values=$SGID" > "$DESCR_SGRULE"
130+
131+
EGRESS_TARGET=$(jq -r '.SecurityGroupRules[] | select(.IsEgress).CidrIpv4' "$DESCR_SGRULE")
132+
if [ "$EGRESS_TARGET" != "$WORKER_HOST/32" ]; then
133+
echo executors "$EGRESS_TARGET" is not the expected "$WORKER_HOST/32"
134+
exit 1
135+
fi
136+
137+
# allow the executor to access the internet for the setup:
138+
$AWS_CMD ec2 authorize-security-group-egress --group-id "$SGID" --protocol tcp --cidr 0.0.0.0/0 --port 1-65535 > "$AUTH_SG"
139+
SGRULEID=$(jq -r .SecurityGroupRules[0].SecurityGroupRuleId "$AUTH_SG")
129140

130141
GIT_COMMIT="${GIT_COMMIT:-${CI_COMMIT_SHA}}"
131142
OSBUILD_GIT_COMMIT=$(cat Schutzfile | jq -r '.["'"${ID}-${VERSION_ID}"'"].dependencies.osbuild.commit')
@@ -150,9 +161,15 @@ subprocessPIDs+=( $! )
150161

151162
ssh -oStrictHostKeyChecking=no -i "$KEYPAIR" "fedora@$EXECUTOR_IP" sudo dnf install -y osbuild-composer osbuild
152163

153-
# no internet access during the build
154-
# TODO [thozza]: while debugging the test case, it turned out that the worker executor instance in fact has Internet access!
164+
# revoke internet access again during the build
155165
$AWS_CMD ec2 revoke-security-group-egress --group-id "$SGID" --security-group-rule-ids "$SGRULEID"
166+
$AWS_CMD ec2 describe-security-group-rules --filters "Name=group-id,Values=$SGID" > "$DESCR_SGRULE"
167+
168+
SGRULES_LENGTH=$(jq -r '.SecurityGroupRules | length' "$DESCR_SGRULE")
169+
if [ "$SGRULES_LENGTH" != 2 ]; then
170+
echo "Expected exactly 2 security group rules (got $SGRULES_LENGTH)"
171+
exit 1
172+
fi
156173

157174
greenprint "🔥 opening worker-executor port on firewall"
158175
ssh -oStrictHostKeyChecking=no -i "$KEYPAIR" "fedora@$EXECUTOR_IP" sudo firewall-cmd --zone=public --add-port=8001/tcp --permanent || true

0 commit comments

Comments
 (0)