This example shows a secure development pattern that separates network data streams from file data streams.
Let's examine a Client
program using file systems and Berkeley sockets. To handle its calls, we will start not one but two separate VFS processes from the VfsFirst
and VfsSecond
executable files. We will use environment variables to assign the file backends to work via the channel to VfsFirst
and assign the network backends to work via the channel to VfsSecond
. We will use the standard backends client and server. This way, we will redirect the file calls of the Client
to VfsFirst
and redirect the network calls to VfsSecond
. To pass the environment variables to processes, we will add the Env
program to the solution.
The init description of the solution is provided below. The Client
process will be connected to the VfsFirst
and VfsSecond
processes, and each of the three processes will be connected to the Env
process. Please note that the name of the IPC channel to the Env
process is defined by using the ENV_SERVICE_NAME
variable.
init.yaml
entities:
- name: Env
- name: Client
connections:
- target: Env
id: {var: ENV_SERVICE_NAME, include: env/env.h}
- target: VfsFirst
id: VFS1
- target: VfsSecond
id: VFS2
- name: VfsFirst
connections:
- target: Env
id: {var: ENV_SERVICE_NAME, include: env/env.h}
- name: VfsSecond
connections:
- target: Env
id: {var: ENV_SERVICE_NAME, include: env/env.h}
To send all file calls to VfsFirst
, we define the value of the _VFS_FILESYSTEM_BACKEND
environment variable as follows:
VfsFirst
: _VFS_FILESYSTEM_BACKEND=server:<name of the IPC channel to VfsFirst>
Client
: _VFS_FILESYSTEM_BACKEND=client:<name of the IPC channel to VfsFirst>
To send network calls to VfsSecond
, we use the equivalent _VFS_NETWORK_BACKEND
environment variable:
VfsSecond
: _VFS_NETWORK_BACKEND=server:<name of the IPC channel to the VfsSecond>
Client
: _VFS_NETWORK_BACKEND=client: <name of the IPC channel to the VfsSecond>
We define the value of environment variables through the Env
program, which is presented below.
env.c
#include <env/env.h>
#include <stdlib.h>
int main(void)
{
const char* vfs_first_envs[] = { "_VFS_FILESYSTEM_BACKEND=server:VFS1" };
ENV_REGISTER_VARS("VfsFirst", vfs_first_envs);
const char* vfs_second_envs[] = { "_VFS_NETWORK_BACKEND=server:VFS2" };
ENV_REGISTER_VARS("VfsSecond", vfs_second_envs);
const char* client_envs[] = { "_VFS_FILESYSTEM_BACKEND=client:VFS1", "_VFS_NETWORK_BACKEND=client:VFS2" };
ENV_REGISTER_VARS("Client", client_envs);
envServerRun();
return EXIT_SUCCESS;
}
Page top