|
| 1 | +--- |
| 2 | +title: Creating an AWS IoT Greengrass custom component |
| 3 | + |
| 4 | +weight: 5 |
| 5 | + |
| 6 | +layout: "learningpathall" |
| 7 | +--- |
| 8 | + |
| 9 | +### Introduction |
| 10 | + |
| 11 | +In this section, you create an AWS IoT Greengrass custom component that uses an artifact package to test PAC/BTI support on target Arm devices. |
| 12 | + |
| 13 | +### S3 bucket creation for the custom component artifact |
| 14 | + |
| 15 | +1. In the AWS Console, go to **S3**. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +2. Create a bucket and give it a name. Keep the default settings for this tutorial. |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +3. Select **Create bucket**. |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +4. Record the bucket name. You will use it in the YAML recipe. |
| 28 | + |
| 29 | +5. On your local machine, clone the asset repository: |
| 30 | + |
| 31 | +```bash |
| 32 | +git clone https://github.com/DougAnsonAustinTx/pac-bti-gg-assets |
| 33 | +cd ./pac-bti-gg-assets |
| 34 | +``` |
| 35 | + |
| 36 | +6. In the S3 bucket view, select **Upload** and upload this artifact from the cloned repository: |
| 37 | +`./arm-pac-bti-greengrass-demo-mqtt-trigger.zip` |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +7. Select **Add files**, choose the artifact, and then select **Upload**. |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +Your artifact is now available in S3. Next, create the custom Greengrass component. |
| 46 | + |
| 47 | +### Custom component creation |
| 48 | + |
| 49 | +1. In the AWS Console, go to **IoT Core** -> **Greengrass devices** and select **Components**. |
| 50 | + |
| 51 | +2. Select **Create component**. |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +3. Select **Enter recipe as YAML** and clear the default sample content. |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +4. Copy and paste the following YAML recipe into the editor. |
| 60 | + |
| 61 | +{{% notice Note %}} |
| 62 | +In the YAML code below, locate **YOUR_S3_BUCKET** and replace it with the S3 bucket name you created in the previous step. |
| 63 | +{{% /notice %}} |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +```yaml |
| 68 | +RecipeFormatVersion: '2020-01-25' |
| 69 | +ComponentName: arm-com.arm.demo.PacBtiDemo |
| 70 | +ComponentVersion: '1.0.4' |
| 71 | +ComponentDescription: Demonstrate how PAC/BTI changes the exploit outcome for the same vulnerable app deployed with AWS IoT Greengrass. |
| 72 | +ComponentPublisher: Arm |
| 73 | +ComponentType: aws.greengrass.generic |
| 74 | + |
| 75 | +ComponentConfiguration: |
| 76 | + DefaultConfiguration: |
| 77 | + accessControl: |
| 78 | + aws.greengrass.ipc.mqttproxy: |
| 79 | + com.arm.demo.PacBtiDemo:mqttproxy:1: |
| 80 | + policyDescription: Allow the PAC/BTI demo to subscribe for attack triggers and publish result events. |
| 81 | + operations: |
| 82 | + - aws.greengrass#PublishToIoTCore |
| 83 | + - aws.greengrass#SubscribeToIoTCore |
| 84 | + resources: |
| 85 | + - arm/demo/*/security/pacbti/attack/trigger |
| 86 | + - arm/demo/*/security/pacbti/attack/result |
| 87 | + |
| 88 | +Manifests: |
| 89 | + - Platform: |
| 90 | + os: linux |
| 91 | + |
| 92 | + Artifacts: |
| 93 | + - Uri: s3://YOUR_S3_BUCKET/arm-pac-bti-greengrass-demo-mqtt-trigger.zip |
| 94 | + Unarchive: ZIP |
| 95 | + Permission: |
| 96 | + Read: OWNER |
| 97 | + Execute: OWNER |
| 98 | + |
| 99 | + Lifecycle: |
| 100 | + Install: |
| 101 | + RequiresPrivilege: true |
| 102 | + Script: |- |
| 103 | + set -e |
| 104 | +
|
| 105 | + PROJECT_ROOT="{artifacts:decompressedPath}/arm-pac-bti-greengrass-demo-mqtt-trigger/arm-pac-bti-greengrass-demo" |
| 106 | + WORK_DIR="{work:path}" |
| 107 | + VENV_DIR="{work:path}/venv" |
| 108 | +
|
| 109 | + python3 -m venv "${VENV_DIR}" |
| 110 | + "${VENV_DIR}/bin/python" -m pip install --upgrade pip |
| 111 | + "${VENV_DIR}/bin/pip" install --no-cache-dir awsiotsdk |
| 112 | +
|
| 113 | + bash "${PROJECT_ROOT}/greengrass/install.sh" \ |
| 114 | + "${PROJECT_ROOT}" \ |
| 115 | + "${WORK_DIR}" |
| 116 | +
|
| 117 | + Run: |
| 118 | + Script: |- |
| 119 | + set -e |
| 120 | +
|
| 121 | + PROJECT_ROOT="{artifacts:decompressedPath}/arm-pac-bti-greengrass-demo-mqtt-trigger/arm-pac-bti-greengrass-demo" |
| 122 | + WORK_DIR="{work:path}" |
| 123 | + VENV_DIR="{work:path}/venv" |
| 124 | +
|
| 125 | + BUILD_FLAVOR="$(cat "${WORK_DIR}/state/selected_flavor")" |
| 126 | + BINARY="${WORK_DIR}/build/${BUILD_FLAVOR}/vuln_demo" |
| 127 | + OUTPUT_DIR="${WORK_DIR}/results" |
| 128 | + THING_NAME="{iot:thingName}" |
| 129 | + TRIGGER_TOPIC="arm/demo/${THING_NAME}/security/pacbti/attack/trigger" |
| 130 | + RESULT_TOPIC="arm/demo/${THING_NAME}/security/pacbti/attack/result" |
| 131 | +
|
| 132 | +
|
| 133 | + mkdir -p "${OUTPUT_DIR}" |
| 134 | +
|
| 135 | + echo "THING_NAME=${THING_NAME}" |
| 136 | + echo "TRIGGER_TOPIC=${TRIGGER_TOPIC}" |
| 137 | + echo "RESULT_TOPIC=${RESULT_TOPIC}" |
| 138 | +
|
| 139 | + if [ ! -x "${VENV_DIR}/bin/python" ]; then |
| 140 | + echo "Virtual environment Python not found at ${VENV_DIR}/bin/python" |
| 141 | + exit 1 |
| 142 | + fi |
| 143 | +
|
| 144 | + if [ ! -x "${BINARY}" ]; then |
| 145 | + echo "Binary not found or not executable: ${BINARY}" |
| 146 | + exit 1 |
| 147 | + fi |
| 148 | +
|
| 149 | + export PYTHONUNBUFFERED=1 |
| 150 | +
|
| 151 | + exec "${VENV_DIR}/bin/python" "${PROJECT_ROOT}/tools/demo_runner.py" \ |
| 152 | + --project-root "${PROJECT_ROOT}" \ |
| 153 | + --binary "${BINARY}" \ |
| 154 | + --build-flavor "${BUILD_FLAVOR}" \ |
| 155 | + --output-dir "${OUTPUT_DIR}" \ |
| 156 | + --trigger-topic "${TRIGGER_TOPIC}" \ |
| 157 | + --result-topic "${RESULT_TOPIC}" |
| 158 | +``` |
| 159 | +
|
| 160 | +5. After you update the bucket name, select **Create component**. |
| 161 | +
|
| 162 | + |
| 163 | +
|
| 164 | +6. Confirm the custom component appears in the component list. |
| 165 | +
|
| 166 | + |
| 167 | +
|
| 168 | +### What we've accomplished |
| 169 | +
|
| 170 | +You created an AWS IoT Greengrass custom component and connected it to the S3-hosted artifact. In the next section, you'll deploy it to both Greengrass core devices. |
0 commit comments