Skip to content

Commit 4d06592

Browse files
committed
Revert 1.3 change
1 parent 6b421dc commit 4d06592

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

articles/iot-edge/how-to-access-host-storage-from-module.md

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ On version 1.4 and newer, there's no need for manually setting ownership or perm
8080
> [!NOTE]
8181
> Automatic permission management of host bound storage only applies to system modules, IoT Edge agent and Edge hub. For custom modules, manual management of permissions and ownership of bound host storage is required if the custom module container is not running as `root` user.
8282
83+
84+
8385
## Link module storage to device storage for custom modules
8486

8587
If your custom module requires access to persistent storage on the host file system, use the module's create options to bind a storage folder in module container to a folder on the host machine. For example:
@@ -99,8 +101,11 @@ If your custom module requires access to persistent storage on the host file sys
99101
}
100102
```
101103

104+
102105
Replace `<HostStoragePath>` and `<ModuleStoragePath>` with your host and module storage path; both values must be an absolute path. Refer to the [Docker Engine Mount specification](https://any-api.com/docker_com/engine/docs/Definitions/Mount) for option details.
103106

107+
108+
104109
### Host system permissions
105110

106111
Make sure that the user profile your module is using has the required read, write, and execute permissions to the host system directory. By default, containers run as `root` user that already has the required permissions. But your module's Dockerfile might specify use of a non-root user in which case host storage permissions must be manually configured.
@@ -115,10 +120,88 @@ sudo chmod 700 <HostStoragePath>
115120

116121
::: moniker range="<=iotedge-2020-11"
117122

118-
When modules invoke the IoT Edge daemon's workload API to encrypt data, the encryption key is derived using the module ID and module's generation ID. A generation ID is used to protect secrets if a module is removed from the deployment and then another module with the same module ID is later deployed to the same device. You can view a module's generation ID using the Azure CLI command [az iot hub module-identity show](/cli/azure/iot/hub/module-identity).
123+
In addition to storing data using Azure storage services or in your device's container storage, you can also dedicate storage on the host IoT Edge device itself for improved reliability, especially when operating offline.
124+
125+
## Link module storage to device storage
126+
127+
To enable a link from module storage to the storage on the host system, create an environment variable for your module that points to a storage folder in the container. Then, use the create options to bind that storage folder to a folder on the host machine.
128+
129+
For example, if you wanted to enable the IoT Edge hub to store messages in your device's local storage and retrieve them later, you can configure the environment variables and the create options in the Azure portal in the **Runtime Settings** section.
130+
131+
1. For both IoT Edge hub and IoT Edge agent, add an environment variable called **storageFolder** that points to a directory in the module.
132+
1. For both IoT Edge hub and IoT Edge agent, add binds to connect a local directory on the host machine to a directory in the module. For example, for version 1.1:
133+
134+
![Add create options and environment variables for local storage](./media/how-to-access-host-storage-from-module/offline-storage.png)
135+
136+
Or, you can configure the local storage directly in the deployment manifest. For example, for version 1.1:
137+
138+
```json
139+
"systemModules": {
140+
"edgeAgent": {
141+
"settings": {
142+
"image": "mcr.microsoft.com/azureiotedge-agent:1.1",
143+
"createOptions": {
144+
"HostConfig": {
145+
"Binds":["<HostStoragePath>:<ModuleStoragePath>"]
146+
}
147+
}
148+
},
149+
"type": "docker",
150+
"env": {
151+
"storageFolder": {
152+
"value": "<ModuleStoragePath>"
153+
}
154+
}
155+
},
156+
"edgeHub": {
157+
"settings": {
158+
"image": "mcr.microsoft.com/azureiotedge-hub:1.1",
159+
"createOptions": {
160+
"HostConfig": {
161+
"Binds":["<HostStoragePath>:<ModuleStoragePath>"],
162+
"PortBindings":{"5671/tcp":[{"HostPort":"5671"}],"8883/tcp":[{"HostPort":"8883"}],"443/tcp":[{"HostPort":"443"}]}}}
163+
},
164+
"type": "docker",
165+
"env": {
166+
"storageFolder": {
167+
"value": "<ModuleStoragePath>"
168+
}
169+
},
170+
"status": "running",
171+
"restartPolicy": "always"
172+
}
173+
}
174+
```
175+
176+
Replace `<HostStoragePath>` and `<ModuleStoragePath>` with your host and module storage path; both values must be an absolute path. If using version 1.3, update each image version with `1.3`. For example, `mcr.microsoft.com/azureiotedge-agent:1.3`.
177+
178+
For example, on a Linux system, `"Binds":["/etc/iotedge/storage/:/iotedge/storage/"]` means the directory **/etc/iotedge/storage** on your host system is mapped to the directory **/iotedge/storage/** in the container. On a Windows system, as another example, `"Binds":["C:\\temp:C:\\contemp"]` means the directory **C:\\temp** on your host system is mapped to the directory **C:\\contemp** in the container.
179+
180+
You can find more details about create options from [docker docs](https://docs.docker.com/engine/api/v1.32/#operation/ContainerCreate).
181+
182+
## Host system permissions
183+
184+
On Linux devices, make sure that the user profile for your module has the required read, write, and execute permissions to the host system directory. Returning to the earlier example of enabling IoT Edge hub to store messages in your device's local storage, you need to grant permissions to its user profile, UID 1000. There are several ways to manage directory permissions on Linux systems, including using `chown` to change the directory owner and then `chmod` to change the permissions, such as:
185+
186+
```bash
187+
sudo chown 1000 <HostStoragePath>
188+
sudo chmod 700 <HostStoragePath>
189+
```
190+
191+
On Windows devices, you will also need to configure permissions on the host system directory. You can use PowerShell to set permissions:
119192

193+
```powershell
194+
$acl = get-acl <HostStoragePath>
195+
$ace = new-object system.security.AccessControl.FileSystemAccessRule('Authenticated Users','FullControl','Allow')
196+
$acl.AddAccessRule($ace)
197+
$acl | Set-Acl
198+
```
120199
::: moniker-end
121200

201+
## Encrypted data in module storage
202+
203+
When modules invoke the IoT Edge daemon's workload API to encrypt data, the encryption key is derived using the module ID and module's generation ID. A generation ID is used to protect secrets if a module is removed from the deployment and then another module with the same module ID is later deployed to the same device. You can view a module's generation ID using the Azure CLI command [az iot hub module-identity show](/cli/azure/iot/hub/module-identity).
204+
122205
If you want to share files between modules across generations, they must not contain any secrets or they will fail to be decrypted.
123206

124207
## Next steps

0 commit comments

Comments
 (0)