Sidecar
Sidecar is an auxiliary component of DataFlux Func.
Since DataFlux Func usually runs inside a container, it cannot directly execute Shell commands on the host machine. Sidecar, on the other hand, is a program running on the host machine, acting as a proxy for DataFlux Func to directly execute Shell commands on the host machine.
Download Command
| Bash | |
|---|---|
1 | |
0. Notes Before Reading
This feature requires root privileges
All shell commands mentioned in this article can be run directly as the root user; non-root users need to add sudo to run them
1. System and Environment Requirements
Hosts that can run DataFlux Func can normally run Sidecar as well.
1.1 DataFlux Func Version Requirements
Sidecar must be used with DataFlux Func 1.3.5 and later versions
2. Quick Installation
Under normal circumstances, Sidecar is installed on the same host as DataFlux Func. The following operations assume that they are performed on a host where DataFlux Func has already been installed.
If Sidecar and DataFlux Func run on different hosts, you need to modify the corresponding configuration
2.1 Offline Installation
Before installing Sidecar, you need to download the required resources.
For hosts without public network access, you can copy the resources to the host using a USB flash drive or other removable storage devices.
The downloaded resource files include an automatic installation Script. Run it to perform the installation (see details below).
2.1.1 Download Resource Files with One Command
For Linux, macOS, and other systems, it is recommended to use the official shell command to download the installation package.
Run the following command to automatically download the files required by Sidecar. The download Script will automatically select the x86_64 or aarch64 architecture version based on the current environment:
| Bash | |
|---|---|
1 | |
If you need to download the version for a specific architecture, you can use the following commands to download:
Intel x86_64processor
| Bash | |
|---|---|
1 | |
ARM aarch64processor (i.e., ARM64v8, such as Raspberry Pi, etc.)
| Bash | |
|---|---|
1 | |
After the command is executed, all required files are saved in the newly created dataflux-func-sidecar directory under the current directory.
The download Script only creates a new directory; if the target path already exists, it reports an error and does not automatically delete existing content. To re-download, you can specify another directory via --download-dir=<new directory>.
- If you need to install Sidecar on a server without public network access, you can download it on your local machine first, and then copy the entire directory to the target machine using a USB flash drive or other removable storage devices, or via tools such as
scp - If you need to install Sidecar on a server that can access the public network, just download it directly on the server.
2.1.2 Download Resource Files Manually
For systems where shell commands are inconvenient to use, you can manually download the required resource files.
If you need to download manually, the following is a list of all the files:
| # | Description | File Name | x86_64 Architecture | aarch64 Architecture |
|---|---|---|---|---|
| 1 | Sidecar binary program | dataflux-func-sidecar.tar.gz |
Download | Download |
| 2 | Sidecar service configuration file | dataflux-func-sidecar.service |
Download | Download |
| 3 | Sidecar installation Script | run-sidecar.sh |
Download | Download |
| 4 | Version information | version |
Download | Download |
After manually downloading all files, place them in the newly created dataflux-func-sidecar directory.
If there is an update, you should re-download all files. Do not guess which files have changed and which have not.
When downloading manually, for example with a browser, be careful not to download cached old content!!
2.1.3 Use the Included Script to Install
In the downloaded dataflux-func-sidecar directory,
run the following command to automatically configure and then start the entire Sidecar:
Sidecar does not support Mac. Please copy it to a Linux system before running the installation.
| Bash | |
|---|---|
1 | |
Using the automatic installation Script, you can be up and running in seconds. The following items are automatically configured:
- Create the executable file
/usr/local/bin/dataflux-func-sidecar - Create the
/etc/dataflux-func-sidecarconfiguration file owned by root with permissions0600 - Create the
dffsuser to run the Sidecar program - Create the
/etc/systemd/system/dataflux-func-sidecar.servicesystemd service file and set it to start on boot
After installation is complete, the following installation information will be displayed:
| Text Only | |
|---|---|
1 2 3 4 5 6 7 8 9 10 | |
The output items are described as follows:
| Item | Description | Corresponding Configuration File Item |
|---|---|---|
| Bind | Listening address. Multiple addresses are supported, separated by English commas | BIND |
| Secret Key | Command to view the secret key; the log does not output the secret key value | SECRET_KEY |
The first installation generates a 32-byte secret key using a secure random source. Use the command above to read the configuration on this machine and provide SECRET_KEY to a trusted Sidecar Connector; reinstalling retains the original secret key by default.
In the default installation, Bind has 2 addresses:
127.0.0.1:8099: local network172.17.0.1:8099:docker0, used for communication with DataFlux Func
2.2. Verify Installation
After the default installation of Sidecar is complete, you can verify the installation with the following command:
| Bash | |
|---|---|
1 | |
If the following information is returned, Sidecar is running normally:
| Text Only | |
|---|---|
1 2 3 | |
2.3. Installation Options
The automatic installation Script supports some installation options to accommodate different installation requirements.
During installation, simply add --{parameter}[ parameter configuration (if any)] after the automatic installation command to specify installation options.
For example, specify the listening address:
| Bash | |
|---|---|
1 | |
2.3.1 Available Installation Options
See below for parameter details.
--bind: Specify the listening address
By default, Sidecar listens on 127.0.0.1:8099,172.17.0.1:8099. If the port is occupied, you can choose another listening address.
--secret-key: Specify the secret key
During default installation, DataFlux Func Sidecar automatically generates a random secret key. You can use this parameter to manually specify the secret key.
--regenerate-secret-key: Regenerate the secret key
When upgrading from an old version, if you need to rotate the old automatically generated secret key, run:
| Bash | |
|---|---|
1 2 | |
Then update the Sidecar Connector secret keys of all callers accordingly. This parameter cannot be used together with --secret-key.
3. Invoke Sidecar in DataFlux Func
DataFlux Func provides the Connector for DataFlux Func Sidecar, which can be used to operate Sidecar.
3.1. Create a Sidecar Connector
Go to "Connector / Add Connector / DataFlux Func Sidecar (HTTP)", fill in the Secret Key correctly, and create it.
If you specified a different listening address (modified the Bind parameter) when installing Sidecar, make corresponding changes when creating the Connector.
3.2. Write Code
The following is sample code:
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
3.3. Configure Functions
In the code example above:
"Test Sidecar" is the main execution function, and can be configured for execution as a Func API or a Cron Job.
"Test Sidecar callback" is the function that receives the callback after execution and needs to be configured as a Func API.
In the sample code, the ID part of the Func API address in the callback_url parameter is sidecar-callback; therefore, when configuring the Func API for the callback function, you also need to specify the same ID to keep the URL address consistent.
If Sidecar and DataFlux Func are installed on the same host, they can access each other through docker0, i.e., the IP address is 172.17.0.1
For details about the "Sidecar Connector operation object", see below.
4. Sidecar Connector Operation Object API
The Sidecar Connector operation object allows users to invoke Sidecar to execute Shell commands.
The parameters for DFF.CONN(...) are as follows:
| Parameter | Type | Required / Default Value | Description |
|---|---|---|---|
connector_id |
str | Required | Connector ID |
timeout |
int/float | 10 |
Default HTTP request timeout for the current operation object, in seconds |
SidecarHelper.shell(...)
The parameters for invoking Sidecar to execute Shell commands are as follows:
| Parameter | Type | Required / Default Value | Description |
|---|---|---|---|
cmd |
str | Required | The Shell command to execute For example: "ls -l" |
wait |
bool | True |
Whether to wait for the execution to complete When set to False, this function returns immediately and does not return terminal output |
workdir |
str | None |
The working directory for Shell command execution For example: "/home/dev" |
envs |
dict | None |
Environment variables, with both keys and values as strings For example: {"MY_NAME": "Tom"} |
callback_url |
str | None |
Callback URL. After the command is executed, stdout and stderr are sent to the specified URL via POSTGenerally used together with the wait=False parameter for asynchronous callbacks |
timeout |
int/float | None |
HTTP request timeout for this request, in seconds; if omitted, the operation object's default value of 10 seconds is used; does not change Sidecar's command execution time limit |
In synchronous calls, a client timeout may cause the HTTP request to be canceled; after Sidecar detects the cancellation, it terminates the process group containing the command. Accepted tasks with wait=False are not canceled when the original HTTP request ends, but they are still subject to Sidecar's command timeout and output limits; see Resource Limits for details.
Post-execution Callback
When calling SidecarHelper.shell(...) and specifying the callback_url parameter, Sidecar sends the standard output stdout and standard error stderr to this address via POST after the Shell command has been executed.
The specific structure is as follows:
| Text Only | |
|---|---|
1 2 3 4 5 6 7 8 9 | |
This structure matches the standard POST method of DataFlux Func's 'Func API', so you can directly use 'Func API' to receive the callback after execution
Callbacks wait for up to 30 seconds; on failure, the error is written to the Sidecar service log and is not retried automatically. The initial response for wait=False only indicates that the task has been accepted, not that the command has executed successfully; the reason for command failure must also be checked in the service log.
5. Daily Maintenance
By default, the executable is installed at /usr/local/bin/dataflux-func-sidecar
5.1 Upgrade the System
Simply repeat the installation process; the automatic installation Script will automatically replace the executable and restart the service.
At the same time, the previous configuration file contents will be retained.
5.2 Start/Stop/Restart the Service
The Sidecar service is managed by systemd; simply use systemctl to operate it:
| Bash | |
|---|---|
1 2 3 | |
5.3 View Configuration
The configuration file is located at /etc/dataflux-func-sidecar.
5.4 Resource Limits
The following configurations can be written to /etc/dataflux-func-sidecar; when running the program directly, they can also be passed via environment variables with the same names. Values must be positive 32-bit integers, and changes take effect after restarting the Sidecar service.
| Configuration Item | Default Value | Description |
|---|---|---|
MAX_REQUEST_BODY_BYTES |
1048576 |
Maximum request body size in bytes, 1 MiB by default; returns 413 when exceeded |
MAX_CONCURRENT_COMMANDS |
8 |
Maximum total number of commands and tasks whose callbacks have not yet completed; returns 429 when full |
COMMAND_TIMEOUT_SECONDS |
900 |
Maximum execution time in seconds for a single command; synchronous calls return 504 on timeout |
MAX_OUTPUT_BYTES |
8388608 |
Maximum combined size of standard output and standard error in bytes, 8 MiB by default; when exceeded, the command is terminated and existing output is retained |
When a command times out, a synchronous request is canceled, or output exceeds the limit, processes in the same process group are terminated; programs that actively detach from the process group are not covered by this cleanup. The task quota remains occupied until the callback completes. When the signature nonce cache is full, 503 is returned; after receiving 429 or 503, simply call the Connector again to generate a new signed request.
6. Uninstall
Execute the following commands in order:
| Bash | |
|---|---|
1 2 3 4 5 6 | |
6.1 Verification
| Bash | |
|---|---|
1 2 3 4 | |
/etc/dataflux-func-sidecarcontainsBINDandSECRET_KEY. If you want to keep the configuration for reinstallation, back up this file before uninstalling.If the
dffsuser is also used by other programs, do not executesudo userdel dffs.
7. Security Notes
Because the Sidecar usage pattern essentially sends arbitrary executable code to the host machine, it is dangerous.
Therefore, Sidecar has the following restrictions in implementation and deployment:
- The Sidecar service runs as the
dffsuser (i.e., the abbreviation for DataFlux Func Sidecar) - Sidecar must be configured with a SecretKey before it can normally execute Shell commands
SidecarHelper.shell(...)internally implements HmacSha1 signing to prevent tampering and replay attacks
Since the Sidecar service runs as the dffs user, it cannot execute commands that require root privileges or operate on other users' files. If necessary, you can add the dffs user to a user group or modify file-related permissions. A caller holding the secret key can execute any command within that account's permissions; the resource limits above do not constitute a sandbox against untrusted commands.