From 910bd9a0557069d2bf0578532b0c2f215b8f7f1e Mon Sep 17 00:00:00 2001 From: smtmfft Date: Thu, 18 Apr 2024 11:18:05 +0800 Subject: [PATCH] add --init back for offline bootstrap, to avoid config-id-after-prove issue. --- docker/config_sgx.sh | 2 +- docker/docker-compose.yml | 21 ++++++++++++++++++- docker/entrypoint.sh | 42 +++++++++++++++++-------------------- host/config/config.sgx.json | 2 +- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/docker/config_sgx.sh b/docker/config_sgx.sh index 47fa412d8..27ffe35eb 100755 --- a/docker/config_sgx.sh +++ b/docker/config_sgx.sh @@ -15,7 +15,7 @@ echo "Ready to config container: $CONTAINER_ID" echo "Old config" docker exec $CONTAINER_ID cat /etc/raiko/config.sgx.json echo -docker exec $CONTAINER_ID sed -i "s/456/$NEW_ID/" /etc/raiko/config.sgx.json +docker exec $CONTAINER_ID sed -i "s/123456/$NEW_ID/" /etc/raiko/config.sgx.json # post-check update echo "New config" docker exec $CONTAINER_ID cat /etc/raiko/config.sgx.json \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 4671dd90c..eacaeda48 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,5 +1,24 @@ version: "3.9" services: + init: + build: + context: .. + dockerfile: Dockerfile + image: gcr.io/evmchain/raiko:latest + container_name: raiko-init + command: --init + devices: + - "/dev/sgx_enclave:/dev/sgx_enclave" + - "/dev/sgx_provision:/dev/sgx_provision" + volumes: + - /var/log/raiko:/var/log/raiko + - ${HOME}/.config/gramine:/root/.config/gramine + - ${HOME}/.config/raiko:/root/.config/raiko + environment: + # you can use your own PCCS host + #- PCCS_HOST=host.docker.internal:8081 + depends_on: + - pccs raiko: build: context: .. @@ -19,9 +38,9 @@ services: environment: # Set to 0 (which is the default) to run on real hardware; use 1 for testing - SGX_DIRECT=${SGX_DIRECT} + - SGX_INSTANCE_ID=${SGX_INSTANCE_ID} # you can use your own PCCS host #- PCCS_HOST=host.docker.internal:8081 - # use the host's network to connect to the PCCS #extra_hosts: # - "host.docker.internal:host-gateway" diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 941d3e7c9..88d3e492d 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -7,14 +7,14 @@ RAIKO_DOCKER_VOLUME_PATH="/root/.config/raiko" RAIKO_DOCKER_VOLUME_CONFIG_PATH="$RAIKO_DOCKER_VOLUME_PATH/config" RAIKO_DOCKER_VOLUME_SECRETS_PATH="$RAIKO_DOCKER_VOLUME_PATH/secrets" RAIKO_DOCKER_VOLUME_PRIV_KEY_PATH="$RAIKO_DOCKER_VOLUME_SECRETS_PATH/priv.key" -RAIKO_GUEST_APP_DIR="/opt/raiko/provers/sgx" +RAIKO_APP_DIR="/opt/raiko/bin" RAIKO_GUEST_APP_FILENAME="sgx-guest" -RAIKO_INPUT_MANIFEST_FILENAME="$RAIKO_GUEST_APP_FILENAME.manifest" +RAIKO_INPUT_MANIFEST_FILENAME="$RAIKO_GUEST_APP_FILENAME.docker.manifest.template" RAIKO_OUTPUT_MANIFEST_FILENAME="$RAIKO_GUEST_APP_FILENAME.manifest.sgx" RAIKO_SIGNED_MANIFEST_FILENAME="$RAIKO_GUEST_APP_FILENAME.sig" function sign_gramine_manifest() { - cd "$RAIKO_GUEST_APP_DIR" + cd "$RAIKO_APP_DIR" gramine-sgx-sign --manifest "$RAIKO_INPUT_MANIFEST_FILENAME" --output "$RAIKO_OUTPUT_MANIFEST_FILENAME" mkdir -p "$RAIKO_DOCKER_VOLUME_CONFIG_PATH" cp "$RAIKO_OUTPUT_MANIFEST_FILENAME" "$RAIKO_SIGNED_MANIFEST_FILENAME" "$RAIKO_DOCKER_VOLUME_CONFIG_PATH" @@ -23,7 +23,7 @@ function sign_gramine_manifest() { function bootstrap() { mkdir -p "$RAIKO_DOCKER_VOLUME_SECRETS_PATH" - cd "$RAIKO_GUEST_APP_DIR" + cd "$RAIKO_APP_DIR" gramine-sgx "$RAIKO_GUEST_APP_FILENAME" bootstrap cd - } @@ -35,24 +35,20 @@ else fi sed -i "s/https:\/\/localhost:8081/https:\/\/${MY_PCCS_HOST}/g" /etc/sgx_default_qcnl.conf - +sed -i "s/123456/${SGX_INSTANCE_ID}/" /etc/raiko/config.sgx.json /restart_aesm.sh -/opt/raiko/bin/raiko-host "$@" - -# if [[ $# -eq 1 && $1 == "--init" ]]; then -# if [[ ! -f "$GRAMINE_PRIV_KEY" ]]; then -# gramine-sgx-gen-private-key -# fi -# sign_gramine_manifest -# bootstrap -# else -# if [[ ! -f "$RAIKO_DOCKER_VOLUME_PRIV_KEY_PATH" ]]; then -# echo "Application was not bootstrapped. "\ -# "$RAIKO_DOCKER_VOLUME_PRIV_KEY_PATH is missing. Bootstrap it first." >&2 -# exit 1 -# fi - -# sign_gramine_manifest -# /opt/raiko/bin/raiko-host "$@" -# fi +echo $# +if [[ $# -eq 1 && $1 == "--init" ]]; then + echo "start bootstrap" + bootstrap +else + echo "start proving" + if [[ ! -f "$RAIKO_DOCKER_VOLUME_PRIV_KEY_PATH" ]]; then + echo "Application was not bootstrapped. "\ + "$RAIKO_DOCKER_VOLUME_PRIV_KEY_PATH is missing. Bootstrap it first." >&2 + exit 1 + fi + + /opt/raiko/bin/raiko-host "$@" +fi diff --git a/host/config/config.sgx.json b/host/config/config.sgx.json index 0557d3a97..3bf717a03 100644 --- a/host/config/config.sgx.json +++ b/host/config/config.sgx.json @@ -1,6 +1,6 @@ { "network": "taiko_a7", "sgx": { - "instance_id": 456 + "instance_id": 123456 } } \ No newline at end of file