|
| 1 | +name: Nitro Enclave Build |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + runner: |
| 7 | + description: "Runner label for the build job." |
| 8 | + type: string |
| 9 | + default: "ubuntu-latest" |
| 10 | + artifact_name: |
| 11 | + description: "Name for the uploaded EIF artifact." |
| 12 | + type: string |
| 13 | + default: "nitro-enclave-image" |
| 14 | + retention_days: |
| 15 | + description: "Artifact retention in days." |
| 16 | + type: number |
| 17 | + default: 1 |
| 18 | + cli_commit: |
| 19 | + description: >- |
| 20 | + Commit SHA of aws-nitro-enclaves-cli to build from. |
| 21 | + WARNING: changing this value can alter PCR0 and PCR2 measurements |
| 22 | + because nitro-cli controls the kernel and init ramdisk bundled |
| 23 | + into the EIF. Coordinate with downstream attestation policies. |
| 24 | + type: string |
| 25 | + default: "18a5f6f35f110c0f235f193ae3caff9434d64ee1" # v1.4.5 |
| 26 | + outputs: |
| 27 | + image_artifact_name: |
| 28 | + description: "Name of the artifact containing the EIF." |
| 29 | + value: ${{ jobs.build.outputs.image_artifact_name }} |
| 30 | + output_file: |
| 31 | + description: "Path to the EIF file within the artifact." |
| 32 | + value: ${{ jobs.build.outputs.output_file }} |
| 33 | + pcr0: |
| 34 | + description: "PCR0 measurement (enclave image hash)." |
| 35 | + value: ${{ jobs.build.outputs.pcr0 }} |
| 36 | + pcr1: |
| 37 | + description: "PCR1 measurement (Linux kernel hash)." |
| 38 | + value: ${{ jobs.build.outputs.pcr1 }} |
| 39 | + pcr2: |
| 40 | + description: "PCR2 measurement (application hash)." |
| 41 | + value: ${{ jobs.build.outputs.pcr2 }} |
| 42 | + |
| 43 | +permissions: |
| 44 | + contents: read |
| 45 | + |
| 46 | +jobs: |
| 47 | + build: |
| 48 | + runs-on: ${{ inputs.runner }} |
| 49 | + timeout-minutes: 30 |
| 50 | + outputs: |
| 51 | + image_artifact_name: ${{ steps.eif.outputs.image_artifact_name }} |
| 52 | + output_file: ${{ steps.eif.outputs.output_file }} |
| 53 | + pcr0: ${{ steps.eif.outputs.pcr0 }} |
| 54 | + pcr1: ${{ steps.eif.outputs.pcr1 }} |
| 55 | + pcr2: ${{ steps.eif.outputs.pcr2 }} |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 58 | + |
| 59 | + - name: Set up Docker Buildx |
| 60 | + uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0 |
| 61 | + |
| 62 | + - name: Build enclave image |
| 63 | + run: docker buildx bake --provenance=false --allow fs.read=./docker/certs enclave |
| 64 | + |
| 65 | + - name: Restore nitro-cli from cache |
| 66 | + id: cli-cache |
| 67 | + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 |
| 68 | + with: |
| 69 | + path: /tmp/nitro-install |
| 70 | + key: nitro-cli-${{ inputs.cli_commit }}-${{ runner.os }}-${{ runner.arch }} |
| 71 | + |
| 72 | + - name: Install Rust toolchain |
| 73 | + if: steps.cli-cache.outputs.cache-hit != 'true' |
| 74 | + uses: actions-rust-lang/setup-rust-toolchain@46268bd060767258de96ed93c1251119784f2ab6 # v1 |
| 75 | + with: |
| 76 | + toolchain: stable |
| 77 | + |
| 78 | + - name: Build nitro-cli from source |
| 79 | + if: steps.cli-cache.outputs.cache-hit != 'true' |
| 80 | + env: |
| 81 | + COMMIT: ${{ inputs.cli_commit }} |
| 82 | + run: | |
| 83 | + sudo apt-get update |
| 84 | + sudo apt-get install -y --no-install-recommends \ |
| 85 | + curl tar build-essential clang gcc \ |
| 86 | + libssl-dev pkg-config musl-tools |
| 87 | +
|
| 88 | + mkdir -p /tmp/nitro-src |
| 89 | + curl -sSfL "https://github.com/aws/aws-nitro-enclaves-cli/archive/${COMMIT}.tar.gz" | \ |
| 90 | + tar -C /tmp/nitro-src -xz --strip-components=1 |
| 91 | +
|
| 92 | + cd /tmp/nitro-src |
| 93 | + make vsock-proxy-native nitro-cli-native |
| 94 | + mkdir -p /tmp/nitro-install |
| 95 | + NITRO_CLI_INSTALL_DIR=/tmp/nitro-install make install-tools |
| 96 | +
|
| 97 | + - name: Install nitro-cli |
| 98 | + run: sudo cp -a /tmp/nitro-install/. / |
| 99 | + |
| 100 | + - name: Build EIF |
| 101 | + id: eif |
| 102 | + run: | |
| 103 | + sudo mkdir -p /var/log/nitro_enclaves |
| 104 | + sudo chmod 777 /var/log/nitro_enclaves |
| 105 | +
|
| 106 | + nitro-cli build-enclave \ |
| 107 | + --docker-uri nitro-enclave-signer/enclave:latest \ |
| 108 | + --output-file enclave.eif |
| 109 | +
|
| 110 | + nitro-cli describe-eif \ |
| 111 | + --eif-path enclave.eif \ |
| 112 | + > describe_eif.json |
| 113 | +
|
| 114 | + echo "image_artifact_name=${{ inputs.artifact_name }}" >> "$GITHUB_OUTPUT" |
| 115 | + echo "output_file=enclave.eif" >> "$GITHUB_OUTPUT" |
| 116 | + pcr0=$(jq -er '.Measurements.PCR0' describe_eif.json) |
| 117 | + pcr1=$(jq -er '.Measurements.PCR1' describe_eif.json) |
| 118 | + pcr2=$(jq -er '.Measurements.PCR2' describe_eif.json) |
| 119 | + echo "pcr0=${pcr0}" >> "$GITHUB_OUTPUT" |
| 120 | + echo "pcr1=${pcr1}" >> "$GITHUB_OUTPUT" |
| 121 | + echo "pcr2=${pcr2}" >> "$GITHUB_OUTPUT" |
| 122 | +
|
| 123 | + - name: Upload EIF and metadata |
| 124 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 125 | + with: |
| 126 | + name: ${{ inputs.artifact_name }} |
| 127 | + retention-days: ${{ inputs.retention_days }} |
| 128 | + path: | |
| 129 | + enclave.eif |
| 130 | + describe_eif.json |
0 commit comments