Skip to content

Commit f8cb17b

Browse files
authored
Merge pull request #209937 from veyalla/update-module-storage-docs
update module storage for 1.4
2 parents 8ed3551 + 02eb2f6 commit f8cb17b

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed

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

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,112 @@ services: iot-edge
1414

1515
[!INCLUDE [iot-edge-version-all-supported](../../includes/iot-edge-version-all-supported.md)]
1616

17+
::: moniker range=">=iotedge-1.4"
18+
19+
IoT Edge modules can use storage on the host IoT Edge device itself for improved reliability, especially when operating offline.
20+
21+
## Configure system modules to use persistent storage
22+
23+
By default, IoT Edge system modules, IoT Edge agent and IoT Edge hub, store state in the ephemeral file system of their container instance. This state is lost when the container instance is recycled, for example, when module image version or createOptions is updated.
24+
25+
For production scenarios, use a persistent storage location on the host filesystem to store system module state. Doing so improves solution robustness and cloud message delivery guarantees.
26+
27+
To set up system modules to use persistent storage:
28+
29+
1. For both IoT Edge hub and IoT Edge agent, add an environment variable called **storageFolder** that points to a directory in the module.
30+
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:
31+
32+
![Screenshot that shows the add create options and environment variables for local storage](./media/how-to-access-host-storage-from-module/offline-storage-1-4.png)
33+
34+
Or, you can configure the local storage directly in the deployment manifest. For example:
35+
36+
```json
37+
"systemModules": {
38+
"edgeAgent": {
39+
"settings": {
40+
"image": "mcr.microsoft.com/azureiotedge-agent:1.4",
41+
"createOptions": {
42+
"HostConfig": {
43+
"Binds":["<HostStoragePath>:<ModuleStoragePath>"]
44+
}
45+
}
46+
},
47+
"type": "docker",
48+
"env": {
49+
"storageFolder": {
50+
"value": "<ModuleStoragePath>/edgeAgent"
51+
}
52+
}
53+
},
54+
"edgeHub": {
55+
"settings": {
56+
"image": "mcr.microsoft.com/azureiotedge-hub:1.4",
57+
"createOptions": {
58+
"HostConfig": {
59+
"Binds":["<HostStoragePath>:<ModuleStoragePath>"],
60+
"PortBindings":{"5671/tcp":[{"HostPort":"5671"}],"8883/tcp":[{"HostPort":"8883"}],"443/tcp":[{"HostPort":"443"}]}}}
61+
},
62+
"type": "docker",
63+
"env": {
64+
"storageFolder": {
65+
"value": "<ModuleStoragePath>"
66+
}
67+
},
68+
"status": "running",
69+
"restartPolicy": "always"
70+
}
71+
}
72+
```
73+
74+
Replace `<HostStoragePath>` and `<ModuleStoragePath>` with your host and module storage path; both values must be an absolute path and `<HostStoragePath>` must exist.
75+
76+
### Automatic host system permissions management
77+
78+
On version 1.4 and newer, there's no need for manually setting ownership or permissions for host storage backing the `storageFolder`. Permissions and ownership are automatically managed by the system modules during startup.
79+
80+
> [!NOTE]
81+
> 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.
82+
83+
84+
85+
## Link module storage to device storage for custom modules
86+
87+
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:
88+
89+
```json
90+
{
91+
"HostConfig": {
92+
"Mounts": [
93+
{
94+
"Target": "<ModuleStoragePath>",
95+
"Source": "<HostStoragePath>",
96+
"Type": "bind",
97+
"ReadOnly": false
98+
}
99+
]
100+
}
101+
}
102+
```
103+
104+
105+
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.
106+
107+
108+
109+
### Host system permissions
110+
111+
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.
112+
113+
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. For example to allow host storage access to a module running as non-root user ID 1000, use the following commands:
114+
115+
```bash
116+
sudo chown 1000 <HostStoragePath>
117+
sudo chmod 700 <HostStoragePath>
118+
```
119+
::: moniker-end
120+
121+
::: moniker range="<=iotedge-2020-11"
122+
17123
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.
18124

19125
## Link module storage to device storage
@@ -90,10 +196,11 @@ $ace = new-object system.security.AccessControl.FileSystemAccessRule('Authentica
90196
$acl.AddAccessRule($ace)
91197
$acl | Set-Acl
92198
```
199+
::: moniker-end
93200

94201
## Encrypted data in module storage
95202

96-
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).
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).
97204

98205
If you want to share files between modules across generations, they must not contain any secrets or they will fail to be decrypted.
99206

157 KB
Loading

0 commit comments

Comments
 (0)