-
Notifications
You must be signed in to change notification settings - Fork 2
Automate bare-metal trusted compute deployment in K3 environment. #411
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,149 @@ | ||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||
|
|
||||||||||||||||
| set -euo pipefail | ||||||||||||||||
|
|
||||||||||||||||
| PACKAGE_NAME="trusted-compute-installation-package" | ||||||||||||||||
| PACKAGE_TAR="${PACKAGE_NAME}.tgz" | ||||||||||||||||
| PACKAGE_REPO="registry-rs.edgeorchestration.intel.com/edge-orch/trusted-compute/baremetal/trusted-compute-installation-package" | ||||||||||||||||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||||||||||||||||
| TEMP_DIR="$(mktemp -d -t tc-baremetal-setup-XXXXXX)" | ||||||||||||||||
| PACKAGE_SOURCE="oras" | ||||||||||||||||
|
|
||||||||||||||||
| show_help() { | ||||||||||||||||
| cat <<EOF | ||||||||||||||||
| Usage: $(basename "$0") [OPTIONS] | ||||||||||||||||
|
|
||||||||||||||||
| Options: | ||||||||||||||||
| --local-build Build package locally using make (make build) | ||||||||||||||||
| --help Show this help and exit | ||||||||||||||||
| --h Show this help and exit | ||||||||||||||||
| -h Show this help and exit | ||||||||||||||||
|
|
||||||||||||||||
| Default behavior: | ||||||||||||||||
| Pull latest trusted compute installation package from registry using ORAS. | ||||||||||||||||
| EOF | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| is_k3s_installed() { | ||||||||||||||||
| command -v k3s >/dev/null 2>&1 || [[ -x "/usr/local/bin/k3s" ]] | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| is_trusted_compute_present() { | ||||||||||||||||
| [[ -d "/opt/kata" || -d "/opt/trustagent" || -d "/opt/verifier" ]] | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| cleanup() { | ||||||||||||||||
| if [[ -d "${TEMP_DIR}" ]]; then | ||||||||||||||||
| rm -rf "${TEMP_DIR}" | ||||||||||||||||
| fi | ||||||||||||||||
| } | ||||||||||||||||
| trap cleanup EXIT | ||||||||||||||||
|
|
||||||||||||||||
| while [[ $# -gt 0 ]]; do | ||||||||||||||||
| case "$1" in | ||||||||||||||||
| --local-build) | ||||||||||||||||
| PACKAGE_SOURCE="local" | ||||||||||||||||
| ;; | ||||||||||||||||
| --help|--h|-h) | ||||||||||||||||
| show_help | ||||||||||||||||
| exit 0 | ||||||||||||||||
| ;; | ||||||||||||||||
| *) | ||||||||||||||||
| echo "Error: Unknown option: $1" | ||||||||||||||||
| echo | ||||||||||||||||
| show_help | ||||||||||||||||
| exit 1 | ||||||||||||||||
| ;; | ||||||||||||||||
| esac | ||||||||||||||||
| shift | ||||||||||||||||
| done | ||||||||||||||||
|
|
||||||||||||||||
| if [[ "${PACKAGE_SOURCE}" == "oras" ]]; then | ||||||||||||||||
| if ! command -v oras >/dev/null 2>&1; then | ||||||||||||||||
| echo "Error: oras not found in PATH" | ||||||||||||||||
| echo "Install ORAS and re-run this script, or use --local-build." | ||||||||||||||||
| exit 1 | ||||||||||||||||
| fi | ||||||||||||||||
|
|
||||||||||||||||
| echo "[1/9] Getting latest trusted compute package tag from registry" | ||||||||||||||||
| TAG="$(oras repo tags "${PACKAGE_REPO}" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)" | ||||||||||||||||
|
|
||||||||||||||||
| if [[ -z "${TAG}" ]]; then | ||||||||||||||||
| echo "Error: Could not resolve latest semantic version tag from ${PACKAGE_REPO}" | ||||||||||||||||
| exit 1 | ||||||||||||||||
| fi | ||||||||||||||||
|
|
||||||||||||||||
| echo "[2/9] Pulling ${PACKAGE_REPO}:${TAG} with ORAS" | ||||||||||||||||
| cd "${TEMP_DIR}" | ||||||||||||||||
| oras pull "${PACKAGE_REPO}:${TAG}" | ||||||||||||||||
| else | ||||||||||||||||
| echo "[1/9] Building local installation package with make build" | ||||||||||||||||
| cd "${SCRIPT_DIR}" | ||||||||||||||||
| make build | ||||||||||||||||
|
|
||||||||||||||||
| if [[ ! -f "${SCRIPT_DIR}/${PACKAGE_TAR}" ]]; then | ||||||||||||||||
| echo "Error: ${PACKAGE_TAR} was not created by make build" | ||||||||||||||||
| exit 1 | ||||||||||||||||
| fi | ||||||||||||||||
|
|
||||||||||||||||
| echo "[2/9] Copying locally built package into temp directory: ${TEMP_DIR}" | ||||||||||||||||
| cp "${SCRIPT_DIR}/${PACKAGE_TAR}" "${TEMP_DIR}/" | ||||||||||||||||
| fi | ||||||||||||||||
|
|
||||||||||||||||
| if [[ ! -f "${TEMP_DIR}/${PACKAGE_TAR}" ]]; then | ||||||||||||||||
| echo "Error: ${PACKAGE_TAR} not found in temp directory" | ||||||||||||||||
| exit 1 | ||||||||||||||||
| fi | ||||||||||||||||
|
|
||||||||||||||||
| echo "[3/9] Extracting ${PACKAGE_TAR}" | ||||||||||||||||
| tar -xvf "${PACKAGE_TAR}" | ||||||||||||||||
|
||||||||||||||||
| tar -xvf "${PACKAGE_TAR}" | |
| tar -xzvf "${TEMP_DIR}/${PACKAGE_TAR}" -C "${TEMP_DIR}" |
Copilot
AI
Apr 4, 2026
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.
kubectl create namespace nginx-test will fail on re-runs if the namespace already exists, and because set -e is enabled the script will exit. Consider making this idempotent (e.g., use kubectl apply for the namespace definition, or check existence before creation) so the script can be safely re-run.
| sudo kubectl create namespace nginx-test | |
| sudo kubectl apply -f - <<'EOF' | |
| apiVersion: v1 | |
| kind: Namespace | |
| metadata: | |
| name: nginx-test | |
| EOF |
Copilot
AI
Apr 4, 2026
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.
Using nginx:latest makes the deployed workload non-reproducible and can unexpectedly change over time. Pin to a specific version tag or (preferably) an immutable image digest to ensure deterministic behavior and reduce supply-chain risk.
| image: nginx:latest | |
| image: nginx:1.27.0 |
Copilot
AI
Apr 4, 2026
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.
Verification is prone to flakiness: kubectl logs (and even describe/get output expectations) can fail or be misleading if the pod hasn't started yet, and with set -e the script will exit early. Add an explicit wait (e.g., wait for pod/nginx-default to be Ready with a timeout) before attempting to read logs, and consider ensuring cleanup runs even if verification fails.
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.
In the
--local-buildflow the script remains in${SCRIPT_DIR}after copying the tarball to${TEMP_DIR}, but extraction runstar -xvf \"${PACKAGE_TAR}\"from the current directory. This will fail (or extract the wrong file) because${PACKAGE_TAR}is expected to be in${TEMP_DIR}. Fix by extracting from${TEMP_DIR}explicitly (e.g.,cd \"${TEMP_DIR}\"before extraction or usetar -x... -C \"${TEMP_DIR}\" -f \"${TEMP_DIR}/${PACKAGE_TAR}\"). Also, since the file is.tgz, prefer using gzip-aware extraction flags/behavior to avoid portability issues.