@@ -17,9 +17,11 @@ BLUEPRINT_FILE=${TEMPDIR}/blueprint.toml
1717COMPOSE_START=${TEMPDIR} /compose-start.json
1818COMPOSE_INFO=${TEMPDIR} /compose-info.json
1919DESCR_INST=${TEMPDIR} /descr-inst.json
20+ AUTH_SG=${TEMPDIR} /auth-sgrule.json
2021DESCR_SGRULE=${TEMPDIR} /descr-sgrule.json
2122KEYPAIR=${TEMPDIR} /keypair.pem
2223INSTANCE_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
2527if type -p podman 2> /dev/null >&2 ; then
122124
123125greenprint " 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)
126128SGID=$( 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
130141GIT_COMMIT=" ${GIT_COMMIT:- ${CI_COMMIT_SHA} } "
131142OSBUILD_GIT_COMMIT=$( cat Schutzfile | jq -r ' .["' " ${ID} -${VERSION_ID} " ' "].dependencies.osbuild.commit' )
@@ -150,9 +161,15 @@ subprocessPIDs+=( $! )
150161
151162ssh -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
157174greenprint " 🔥 opening worker-executor port on firewall"
158175ssh -oStrictHostKeyChecking=no -i " $KEYPAIR " " fedora@$EXECUTOR_IP " sudo firewall-cmd --zone=public --add-port=8001/tcp --permanent || true
0 commit comments