-
Notifications
You must be signed in to change notification settings - Fork 17
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
Remove and replace additional operations in enclave start #1289
Changes from 20 commits
bf0d0f5
2a0ad43
040e4b3
3ea6a29
33649e1
510a66e
8c08a13
8192fbc
1fb6935
981ceb0
71b4eaf
ed5aa75
107c5be
a4dd616
d4ce039
587e428
d852887
cf357f8
af53aa0
6f9c565
5b336e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,4 @@ | |
"enable_phone_support": true, | ||
"enable_v1_phone_support": false, | ||
"enable_v2_encryption": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,93 +7,87 @@ LOG_FILE="/home/start.txt" | |
set -x | ||
exec &> >(tee -a "$LOG_FILE") | ||
|
||
set -o pipefail | ||
ulimit -n 65536 | ||
|
||
# -- setup loopback device | ||
echo "Setting up loopback device..." | ||
ifconfig lo 127.0.0.1 | ||
|
||
# -- start vsock proxy | ||
echo "Starting vsock proxy..." | ||
/app/vsockpx --config /app/proxies.nitro.yaml --daemon --workers $(( ( $(nproc) + 3 ) / 4 )) --log-level 3 | ||
|
||
# -- load config from identity service | ||
echo "Loading config from identity service via proxy..." | ||
|
||
#wait for config service, then download config | ||
OVERRIDES_CONFIG="/app/conf/config-overrides.json" | ||
|
||
RETRY_COUNT=0 | ||
MAX_RETRY=20 | ||
until curl -s -f -o "${OVERRIDES_CONFIG}" -x socks5h://127.0.0.1:3305 http://127.0.0.1:27015/getConfig | ||
do | ||
echo "Waiting for config service to be available" | ||
RETRY_COUNT=$(( RETRY_COUNT + 1)) | ||
if [ $RETRY_COUNT -gt $MAX_RETRY ]; then | ||
echo "Config Server did not return a response. Exiting" | ||
exit 1 | ||
fi | ||
sleep 2 | ||
done | ||
PARAMETERIZED_CONFIG="/app/conf/config-overrides.json" | ||
OPERATOR_CONFIG="/tmp/final-config.json" | ||
|
||
DEBUG_MODE=$(jq -r ".debug_mode" < "${OVERRIDES_CONFIG}") | ||
setup_auxiliaries() { | ||
set -o pipefail | ||
ulimit -n 65536 | ||
|
||
# -- setup loopback device | ||
echo "Setting up loopback device..." | ||
ifconfig lo 127.0.0.1 | ||
|
||
# -- start vsock proxy | ||
echo "Starting vsock proxy..." | ||
/app/vsockpx --config /app/proxies.nitro.yaml --daemon --workers $(( ( $(nproc) + 3 ) / 4 )) --log-level 3 | ||
|
||
if [[ "$DEBUG_MODE" == "true" ]]; then | ||
LOGBACK_CONF="./conf/logback-debug.xml" | ||
else | ||
LOGBACK_CONF="./conf/logback.xml" | ||
# -- setup syslog-ng | ||
echo "Starting syslog-ng..." | ||
/usr/sbin/syslog-ng --verbose | ||
fi | ||
} | ||
|
||
# check the config is valid. Querying for a known missing element (empty) makes jq parse the file, but does not echo the results | ||
if jq empty "${OVERRIDES_CONFIG}"; then | ||
echo "Identity service returned valid config" | ||
else | ||
echo "Failed to get a valid config from identity service" | ||
exit 1 | ||
fi | ||
|
||
export DEPLOYMENT_ENVIRONMENT=$(jq -r ".environment" < "${OVERRIDES_CONFIG}") | ||
export CORE_BASE_URL=$(jq -r ".core_base_url" < "${OVERRIDES_CONFIG}") | ||
export OPTOUT_BASE_URL=$(jq -r ".optout_base_url" < "${OVERRIDES_CONFIG}") | ||
echo "DEPLOYMENT_ENVIRONMENT=${DEPLOYMENT_ENVIRONMENT}" | ||
if [ -z "${DEPLOYMENT_ENVIRONMENT}" ]; then | ||
echo "DEPLOYMENT_ENVIRONMENT cannot be empty" | ||
exit 1 | ||
fi | ||
if [ "${DEPLOYMENT_ENVIRONMENT}" != "prod" ] && [ "${DEPLOYMENT_ENVIRONMENT}" != "integ" ]; then | ||
echo "Unrecognized DEPLOYMENT_ENVIRONMENT ${DEPLOYMENT_ENVIRONMENT}" | ||
exit 1 | ||
fi | ||
build_parameterized_config() { | ||
curl -s -f -o "${PARAMETERIZED_CONFIG}" -x socks5h://127.0.0.1:3305 http://127.0.0.1:27015/getConfig | ||
REQUIRED_KEYS=("optout_base_url" "core_base_url" "api_token" "environment") | ||
for key in "${REQUIRED_KEYS[@]}"; do | ||
if ! jq -e "has(\"${key}\")" "${PARAMETERIZED_CONFIG}" > /dev/null; then | ||
echo "Error: Key '${key}' is missing. Please add it to flask config server" | ||
exit 1 | ||
fi | ||
done | ||
FILTER=$(printf '. | {') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do this logic differently in each implementation: In GCP in Java code, in Azure in MAA attestation, and in AWS it was in make_config.py. |
||
for key in "${REQUIRED_KEYS[@]}"; do | ||
FILTER+="$key: .${key}, " | ||
done | ||
FILTER+="debug_mode: .debug_mode, " | ||
FILTER=${FILTER%, }'}' | ||
jq "${FILTER}" "${PARAMETERIZED_CONFIG}" > "${PARAMETERIZED_CONFIG}.tmp" && mv "${PARAMETERIZED_CONFIG}.tmp" "${PARAMETERIZED_CONFIG}" | ||
} | ||
|
||
build_operator_config() { | ||
CORE_BASE_URL=$(jq -r ".core_base_url" < "${PARAMETERIZED_CONFIG}") | ||
OPTOUT_BASE_URL=$(jq -r ".optout_base_url" < "${PARAMETERIZED_CONFIG}") | ||
DEPLOYMENT_ENVIRONMENT=$(jq -r ".environment" < "${PARAMETERIZED_CONFIG}") | ||
DEBUG_MODE=$(jq -r ".debug_mode" < "${PARAMETERIZED_CONFIG}") | ||
|
||
IDENTITY_SCOPE_LOWER=$(echo "${IDENTITY_SCOPE}" | tr '[:upper:]' '[:lower:]') | ||
DEPLOYMENT_ENVIRONMENT_LOWER=$(echo "${DEPLOYMENT_ENVIRONMENT}" | tr '[:upper:]' '[:lower:]') | ||
DEFAULT_CONFIG="/app/conf/${IDENTITY_SCOPE_LOWER}-${DEPLOYMENT_ENVIRONMENT_LOWER}-config.json" | ||
|
||
jq -s '.[0] * .[1]' "${DEFAULT_CONFIG}" "${PARAMETERIZED_CONFIG}" > "${OPERATOR_CONFIG}" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to ensure CORE_BASE_URL is not set to random core, as this will result in operator sending token + pcr0 to overridden malicious core. Basically, updates the logic to always replace URL in config. If prod, use default prod URL otherwise allow override. This check is not done in GCP, as we attest GCP confidential compute by calling GCP endpoints. Please correct if wrong @atarassov-ttd |
||
if [[ "$DEPLOYMENT_ENVIRONMENT" == "prod" ]]; then | ||
if [[ "$DEBUG_MODE" == "true" ]]; then | ||
echo "Cannot run in DEBUG_MODE in production environment. Exiting." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
echo "Loading config final..." | ||
export FINAL_CONFIG="/app/conf/config-final.json" | ||
if [ "${IDENTITY_SCOPE}" = "UID2" ]; then | ||
python3 /app/make_config.py /app/conf/prod-uid2-config.json /app/conf/integ-uid2-config.json ${OVERRIDES_CONFIG} "$(nproc)" > ${FINAL_CONFIG} | ||
elif [ "${IDENTITY_SCOPE}" = "EUID" ]; then | ||
python3 /app/make_config.py /app/conf/prod-euid-config.json /app/conf/integ-euid-config.json ${OVERRIDES_CONFIG} "$(nproc)" > ${FINAL_CONFIG} | ||
else | ||
echo "Unrecognized IDENTITY_SCOPE ${IDENTITY_SCOPE}" | ||
exit 1 | ||
fi | ||
#TODO: Remove below logic after remote config management is implemented | ||
|
||
if [[ "$DEPLOYMENT_ENVIRONMENT" != "prod" ]]; then | ||
#Allow override of base URL in non-prod environments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to remove all configs we pass and keep it simple, but there are lot of intricacies This bit, can be removed once we complete remote config management, and use optour url returned by core. |
||
CORE_PATTERN="https://core.*uidapi.com" | ||
OPTOUT_PATTERN="https://optout.*uidapi.com" | ||
if [[ "$DEPLOYMENT_ENVIRONMENT" == "euid" ]]; then | ||
CORE_PATTERN="https://core.*euid.eu" | ||
OPTOUT_PATTERN="https://optout.*euid.eu" | ||
fi | ||
sed -i "s#${CORE_PATTERN}#${CORE_BASE_URL}#g" "${OPERATOR_CONFIG}" | ||
sed -i "s#${OPTOUT_PATTERN}#${OPTOUT_BASE_URL}#g" "${OPERATOR_CONFIG}" | ||
fi | ||
|
||
} | ||
|
||
# -- replace base URLs if both CORE_BASE_URL and OPTOUT_BASE_URL are provided | ||
# -- using hardcoded domains is fine because they should not be changed frequently | ||
if [ -n "${CORE_BASE_URL}" ] && [ "${CORE_BASE_URL}" != "null" ] && [ -n "${OPTOUT_BASE_URL}" ] && [ "${OPTOUT_BASE_URL}" != "null" ] && [ "${DEPLOYMENT_ENVIRONMENT}" != "prod" ]; then | ||
echo "Replacing core and optout URLs by ${CORE_BASE_URL} and ${OPTOUT_BASE_URL}..." | ||
setup_auxiliaries | ||
build_parameterized_config | ||
build_operator_config | ||
|
||
sed -i "s#https://core-integ.uidapi.com#${CORE_BASE_URL}#g" "${FINAL_CONFIG}" | ||
sed -i "s#https://core-prod.uidapi.com#${CORE_BASE_URL}#g" "${FINAL_CONFIG}" | ||
sed -i "s#https://core.integ.euid.eu#${CORE_BASE_URL}#g" "${FINAL_CONFIG}" | ||
sed -i "s#https://core.prod.euid.eu#${CORE_BASE_URL}#g" "${FINAL_CONFIG}" | ||
DEBUG_MODE=$(jq -r ".debug_mode" < "${OPERATOR_CONFIG}") | ||
LOGBACK_CONF="./conf/logback.xml" | ||
|
||
sed -i "s#https://optout-integ.uidapi.com#${OPTOUT_BASE_URL}#g" "${FINAL_CONFIG}" | ||
sed -i "s#https://optout-prod.uidapi.com#${OPTOUT_BASE_URL}#g" "${FINAL_CONFIG}" | ||
sed -i "s#https://optout.integ.euid.eu#${OPTOUT_BASE_URL}#g" "${FINAL_CONFIG}" | ||
sed -i "s#https://optout.prod.euid.eu#${OPTOUT_BASE_URL}#g" "${FINAL_CONFIG}" | ||
if [[ "$DEBUG_MODE" == "true" ]]; then | ||
LOGBACK_CONF="./conf/logback-debug.xml" | ||
fi | ||
|
||
# -- set pwd to /app so we can find default configs | ||
|
@@ -106,7 +100,7 @@ java \ | |
-XX:MaxRAMPercentage=95 -XX:-UseCompressedOops -XX:+PrintFlagsFinal \ | ||
-Djava.security.egd=file:/dev/./urandom \ | ||
-Djava.library.path=/app/lib \ | ||
-Dvertx-config-path="${FINAL_CONFIG}" \ | ||
-Dvertx-config-path="${OPERATOR_CONFIG}" \ | ||
-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory \ | ||
-Dlogback.configurationFile=${LOGBACK_CONF} \ | ||
-Dhttp_proxy=socks5://127.0.0.1:3305 \ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed now? @Ian-Nara
We populate configs after processing in
uid2-operator/scripts/aws/ec2.py
Line 135 in 9b94fd5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the lower() calls to these is still useful, unless I missed that in the ec2.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we ensure it is lower as part of validations