Skip to content

Change the way we pass information to urunit in Linux guests#308

Merged
urunc-bot[bot] merged 5 commits intomainfrom
feat_env_config_urunit
Oct 26, 2025
Merged

Change the way we pass information to urunit in Linux guests#308
urunc-bot[bot] merged 5 commits intomainfrom
feat_env_config_urunit

Conversation

@cmainas
Copy link
Copy Markdown
Contributor

@cmainas cmainas commented Oct 21, 2025

Currently we are using the Linux kernel boot parameters to pass environment variables for the application execution in Linux VMs. Furthermore, urunit was responsible to properly handle the application arguments. However, this approach has the following limitations:

  1. There was no way to pass more information for the application execution inside the Linux guest (e.g. working dir, uid etc.).
  2. The Linux kernel boot parameters has a limit of characters that can handle and in case we have too many environment variables or a lot of arguments for the application, we are risking to hit that limit. We observed such cases in k8s deployments with many services, where k8s adds environment variables for each deployed service.
  3. With Linux kernel boot parameters, we could not pass any non-POSIX environment variables, which unfortunately are used from some containers.

For all the above reason, we change the way we pass information to urunit by using "urunit configuration file" instead of kernel boot parameters. In particular, if we set the URUNIT_CONFIG environment variable to point to a file, then urunit will try to parse this file and expects to read the following configuration format:

UES
/* list of environment variables */
UEE
UCS
UID:<uid>
GID:<gid>
WD:<working_dir>
UCE

Parsing a confguration like this, urunit will set the environment variables for the application execution, the uid,gid and at last switch to the working directory for the application.

In order to minimize the dependencies for the Linux kernel running as guest, we choose to pass this file as an initrd and set the retain_initrd kernel boot parameter. In that way, urunit can mount sysfs at /sys and read the configuration file from /sys/firmware/initrd where the Linux kernel will store the initrd. In case the guest is configured to boot with an initrd, then urunc will archive the configuration file using the cpio format and concatenate it with the user specified initrd. The linux kernel is smart enough to properly unpack concatenated initrd and hence the urunit configuration file will appear in the guest rootfs. Therefore, with that method, there are only the following requirements for the guest kernel:

  • Support for initrd CONFIG_BLK_DEV_INITRD
  • Support for sysfs CONFIG_SYSFS

Of course, urunc fills the above configuration, based on the container's configuration and specifically, the Process struct of the spec.

@netlify
Copy link
Copy Markdown

netlify Bot commented Oct 21, 2025

Deploy Preview for urunc ready!

Name Link
🔨 Latest commit 1aa48ec
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/68fde32619126100080ce827
😎 Deploy Preview https://deploy-preview-308--urunc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@cmainas cmainas force-pushed the feat_env_config_urunit branch 2 times, most recently from d50236a to 18d2f94 Compare October 22, 2025 15:47
@cmainas cmainas marked this pull request as ready for review October 22, 2025 16:07
@cmainas cmainas requested a review from ananos October 22, 2025 16:07
@cmainas cmainas force-pushed the feat_env_config_urunit branch from 18d2f94 to 55837c9 Compare October 22, 2025 16:54
@cmainas cmainas force-pushed the feat_env_config_urunit branch from 55837c9 to cc7d667 Compare October 23, 2025 10:24
Copy link
Copy Markdown
Contributor

@ananos ananos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @cmainas, LGTM!

There are cases where containers use non-POSIX environment variables or
cases where the environment variables can exceed the limit of characters
in Linux kernel boot parameters. Therefore, the environment variables
were not set correctly.

To fix the above issue, we change the way we pass the environment
variables to the guest in Linux with the the help of urunit. In
particular, instead of using the Linux kernel boot parameters, we use
store the environment variables in a file and let urunit read that file
and set the environment variables for the application inside the Linux
VM.

In order to minimize the depedencies of the guest kernel and provide a
croos-monitor solution, we pass the urunit configuration file as an
initrd for the guest and instruct Linux kernel to keep it with the
retain_initrd kernel boot parameter. In that way, urunit simply reads
the contents of /sys/firmware/initrd and is able to get the
configuration file.

If the guest is configured to use an initrd then we format the urunit
configuration file in the cpio format and concatenate the user provided
initrd with the one we created for the urunit configuration file. The
Linux kernel is able to properly extract concatenated initrds and
therefore the configuration file will appear in the rootfs of the VM.

PR: #308
Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk>
Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
The guest can append further cli args for the monitor, since the VMM
interface calls the MonitorCli function. However, this function was not
compatible with Firecracker, which uses a json configuration file to
define the VM arguments.

THis commit partially fixes this by updating the return value of
MonitorCli, in order to use a new struct. The current implementation was
also necessary for Linux to define the extra initrd file with the urunit
configuration. Therefore, for the time being the MonitrCliArgs consists
of only two fields, one for initr and one for other cli args. However,
in the future we can iterate over it and update it.

PR: #308
Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk>
Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
Update the urunit configuration file to enable passing extra information
for the execution environment of the application inside the Linux VM. In
particular, this commit passess the following information to urunit:
- uid of the Linux process inside the VM
- gid of the Linux process inside the VM
- working directory of the Linux process inside the VM

The format that is used is the following:

UES
/* env vars */
UEE
UCS
UID:<uid>
GID:<gid>
WD:<working_directory>
UCE

PR: #308
Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk>
Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
Update the tutorail for running existing containers over Linux in urunc
in order to include the new changes on passing information to the guest
from the host.

PR: #308
Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk>
Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
Update the prvious tests in Linux for environment variables to also
check the correct setting of uid,gid and working directory except of the
environment variables.

PR: #308
Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk>
Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
@github-actions github-actions Bot force-pushed the feat_env_config_urunit branch from cc7d667 to 1aa48ec Compare October 26, 2025 09:00
@urunc-bot urunc-bot Bot merged commit 4010ca7 into main Oct 26, 2025
5 of 7 checks passed
urunc-bot Bot pushed a commit that referenced this pull request Oct 26, 2025
There are cases where containers use non-POSIX environment variables or
cases where the environment variables can exceed the limit of characters
in Linux kernel boot parameters. Therefore, the environment variables
were not set correctly.

To fix the above issue, we change the way we pass the environment
variables to the guest in Linux with the the help of urunit. In
particular, instead of using the Linux kernel boot parameters, we use
store the environment variables in a file and let urunit read that file
and set the environment variables for the application inside the Linux
VM.

In order to minimize the depedencies of the guest kernel and provide a
croos-monitor solution, we pass the urunit configuration file as an
initrd for the guest and instruct Linux kernel to keep it with the
retain_initrd kernel boot parameter. In that way, urunit simply reads
the contents of /sys/firmware/initrd and is able to get the
configuration file.

If the guest is configured to use an initrd then we format the urunit
configuration file in the cpio format and concatenate the user provided
initrd with the one we created for the urunit configuration file. The
Linux kernel is able to properly extract concatenated initrds and
therefore the configuration file will appear in the rootfs of the VM.

PR: #308
Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk>
Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
urunc-bot Bot pushed a commit that referenced this pull request Oct 26, 2025
The guest can append further cli args for the monitor, since the VMM
interface calls the MonitorCli function. However, this function was not
compatible with Firecracker, which uses a json configuration file to
define the VM arguments.

THis commit partially fixes this by updating the return value of
MonitorCli, in order to use a new struct. The current implementation was
also necessary for Linux to define the extra initrd file with the urunit
configuration. Therefore, for the time being the MonitrCliArgs consists
of only two fields, one for initr and one for other cli args. However,
in the future we can iterate over it and update it.

PR: #308
Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk>
Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
urunc-bot Bot pushed a commit that referenced this pull request Oct 26, 2025
Update the urunit configuration file to enable passing extra information
for the execution environment of the application inside the Linux VM. In
particular, this commit passess the following information to urunit:
- uid of the Linux process inside the VM
- gid of the Linux process inside the VM
- working directory of the Linux process inside the VM

The format that is used is the following:

UES
/* env vars */
UEE
UCS
UID:<uid>
GID:<gid>
WD:<working_directory>
UCE

PR: #308
Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk>
Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
urunc-bot Bot pushed a commit that referenced this pull request Oct 26, 2025
Update the tutorail for running existing containers over Linux in urunc
in order to include the new changes on passing information to the guest
from the host.

PR: #308
Signed-off-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk>
Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
@ananos ananos deleted the feat_env_config_urunit branch October 26, 2025 09:00
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change the way we pass environment variables in Linux containers Configure the execution environment inside a Linux VM

2 participants