[PATCH 1/1] kas-container: propagate host timezone via entrypoint

9 views
Skip to first unread message

Felix Moessbauer

unread,
Jul 29, 2025, 5:10:10 AMJul 29
to kas-...@googlegroups.com, jan.k...@siemens.com, christi...@siemens.com, Felix Moessbauer
Bind-mounting /etc/timezone into the container overwrites the symlinks
target, as both docker and podman mount without the AT_SYMLINK_NOFOLLOW
flag. This breaks yocto builds which rely on correct information in
/usr/share/zoneinfo/*. To fix this, we pass the host timezone via an
environment variable to the container and patch the timezone in the
entrypoint. By that, we also preserve the difference between the TZ
variable and the /etc/timezone, /etc/localtime data.

Fixes: 378366395 ("kas-container: propagate timezone information ...")
Signed-off-by: Felix Moessbauer <felix.mo...@siemens.com>
---
container-entrypoint | 5 +++++
kas-container | 9 ++-------
2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/container-entrypoint b/container-entrypoint
index 927248db7..d62aa9c0a 100755
--- a/container-entrypoint
+++ b/container-entrypoint
@@ -67,6 +67,11 @@ else
if [ -d /var/kas/userdata/.ssh ]; then
cp -a /var/kas/userdata/.ssh /builder/
fi
+ # adjust timezone to host
+ if [ -n "${KAS_HOST_TZ}" ] && [ -f "/usr/share/zoneinfo/${KAS_HOST_TZ}" ]; then
+ echo "${KAS_HOST_TZ}" > /etc/timezone
+ ln -sf "/usr/share/zoneinfo/${KAS_HOST_TZ}" /etc/localtime
+ fi

GOSU="gosu builder"
fi
diff --git a/kas-container b/kas-container
index e8735884d..a768cfe32 100755
--- a/kas-container
+++ b/kas-container
@@ -687,13 +687,8 @@ if [ -n "${SSTATE_MIRRORS}" ]; then
set -- "$@" -e "SSTATE_MIRRORS=${SSTATE_MIRRORS}"
fi

-# propagate timezone information
-if [ -f "/etc/localtime" ]; then
- set -- "$@" -v "$(realpath -e "/etc/localtime")":/etc/localtime:ro
-fi
-if [ -f "/etc/timezone" ]; then
- set -- "$@" -v "$(realpath -e "/etc/timezone")":/etc/timezone:ro
-fi
+# propagate timezone information to entrypoint
+set -- "$@" -e "KAS_HOST_TZ=$(cat /etc/timezone)"

for var in TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK KAS_CLONE_DEPTH \
KAS_PREMIRRORS DISTRO_APT_PREMIRRORS BB_NUMBER_THREADS PARALLEL_MAKE \
--
2.50.0

MOESSBAUER, Felix

unread,
Jul 29, 2025, 5:22:50 AMJul 29
to kas-...@googlegroups.com, Storm, Christian, Kiszka, Jan
This does not work on Fedora, as they don't provide the /etc/timezone
file. I'm considering to use timedatectl to get the current timezone,
as this is available on all systemd based distributions.

Felix

>  
>  for var in TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK
> KAS_CLONE_DEPTH \
>             KAS_PREMIRRORS DISTRO_APT_PREMIRRORS BB_NUMBER_THREADS
> PARALLEL_MAKE \

--
Siemens AG
Linux Expert Center
Friedrich-Ludwig-Bauer-Str. 3
85748 Garching, Germany

Felix Moessbauer

unread,
Jul 29, 2025, 5:31:59 AMJul 29
to kas-...@googlegroups.com, jan.k...@siemens.com, christi...@siemens.com, Felix Moessbauer
Bind-mounting /etc/timezone into the container overwrites the symlinks
target, as both docker and podman mount without the AT_SYMLINK_NOFOLLOW
flag. This breaks yocto builds which rely on correct information in
/usr/share/zoneinfo/*. To fix this, we pass the host timezone via an
environment variable to the container and patch the timezone in the
entrypoint. By that, we also preserve the difference between the TZ
variable and the /etc/timezone, /etc/localtime data.

Fixes: 378366395 ("kas-container: propagate timezone information ...")
Closes: #162
Signed-off-by: Felix Moessbauer <felix.mo...@siemens.com>
---
Changes since v1:

- Do not rely on existence of /etc/timezone (e.g. it is missing on Fedora).
Instead, use timedatectl, which is available on all systemd based
distributions.
- add closes tag

container-entrypoint | 5 +++++
kas-container | 9 +++------
2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/container-entrypoint b/container-entrypoint
index 927248db7..d62aa9c0a 100755
--- a/container-entrypoint
+++ b/container-entrypoint
@@ -67,6 +67,11 @@ else
if [ -d /var/kas/userdata/.ssh ]; then
cp -a /var/kas/userdata/.ssh /builder/
fi
+ # adjust timezone to host
+ if [ -n "${KAS_HOST_TZ}" ] && [ -f "/usr/share/zoneinfo/${KAS_HOST_TZ}" ]; then
+ echo "${KAS_HOST_TZ}" > /etc/timezone
+ ln -sf "/usr/share/zoneinfo/${KAS_HOST_TZ}" /etc/localtime
+ fi

GOSU="gosu builder"
fi
diff --git a/kas-container b/kas-container
index e8735884d..526a11ca9 100755
--- a/kas-container
+++ b/kas-container
@@ -687,12 +687,9 @@ if [ -n "${SSTATE_MIRRORS}" ]; then
set -- "$@" -e "SSTATE_MIRRORS=${SSTATE_MIRRORS}"
fi

-# propagate timezone information
-if [ -f "/etc/localtime" ]; then
- set -- "$@" -v "$(realpath -e "/etc/localtime")":/etc/localtime:ro
-fi
-if [ -f "/etc/timezone" ]; then
- set -- "$@" -v "$(realpath -e "/etc/timezone")":/etc/timezone:ro
+# propagate timezone information to entrypoint
+if command -v timedatectl >/dev/null; then
+ set -- "$@" -e "KAS_HOST_TZ=$(timedatectl | grep 'Time zone:' | awk '{print $3}')"
fi

for var in TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK KAS_CLONE_DEPTH \
--
2.50.0

MOESSBAUER, Felix

unread,
Jul 29, 2025, 11:57:32 AMJul 29
to kas-...@googlegroups.com, Storm, Christian, Kiszka, Jan
We should use "timedatectl show" to get a machine readable output.
However, the question still remains if the Timezone=<tz> always
corresponds to a timezone in /usr/share/zoneinfo/.

As pointed out in the GitHub issue, the Timezone field might contain a
"custom timezone" which is not an ISO 3166-1 alpha-2 code, hence there
is no corresponding file in /usr/share/zoneinfo/.

I'm wondering, if that really matters for us, as the guard in the
entrypoint would anyways reject that and fallback to UTC.

Felix

> '{print $3}')"
>  fi
>  
>  for var in TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK
> KAS_CLONE_DEPTH \

--

Felix Moessbauer

unread,
Jul 30, 2025, 4:11:40 AMJul 30
to kas-...@googlegroups.com, Felix Moessbauer, jan.k...@siemens.com, christi...@siemens.com
Bind-mounting /etc/timezone into the container overwrites the symlinks
target, as both docker and podman mount without the AT_SYMLINK_NOFOLLOW
flag. This breaks yocto builds which rely on correct information in
/usr/share/zoneinfo/*. To fix this, we pass the host timezone via an
environment variable to the container and patch the timezone in the
entrypoint. By that, we also preserve the difference between the TZ
variable and the /etc/timezone, /etc/localtime data.

Fixes: 378366395 ("kas-container: propagate timezone information ...")
Closes: #162
Signed-off-by: Felix Moessbauer <felix.mo...@siemens.com>
---
Changes since v2:

- use machine readable output of timedatectl

Changes since v1:

- Do not rely on existence of /etc/timezone (e.g. it is missing on Fedora).
Instead, use timedatectl, which is available on all systemd based
distributions.
- add closes tag

container-entrypoint | 5 +++++
kas-container | 9 +++------
2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/container-entrypoint b/container-entrypoint
index 927248db7..d62aa9c0a 100755
--- a/container-entrypoint
+++ b/container-entrypoint
@@ -67,6 +67,11 @@ else
if [ -d /var/kas/userdata/.ssh ]; then
cp -a /var/kas/userdata/.ssh /builder/
fi
+ # adjust timezone to host
+ if [ -n "${KAS_HOST_TZ}" ] && [ -f "/usr/share/zoneinfo/${KAS_HOST_TZ}" ]; then
+ echo "${KAS_HOST_TZ}" > /etc/timezone
+ ln -sf "/usr/share/zoneinfo/${KAS_HOST_TZ}" /etc/localtime
+ fi

GOSU="gosu builder"
fi
diff --git a/kas-container b/kas-container
index e8735884d..299f14bb5 100755
--- a/kas-container
+++ b/kas-container
@@ -687,12 +687,9 @@ if [ -n "${SSTATE_MIRRORS}" ]; then
set -- "$@" -e "SSTATE_MIRRORS=${SSTATE_MIRRORS}"
fi

-# propagate timezone information
-if [ -f "/etc/localtime" ]; then
- set -- "$@" -v "$(realpath -e "/etc/localtime")":/etc/localtime:ro
-fi
-if [ -f "/etc/timezone" ]; then
- set -- "$@" -v "$(realpath -e "/etc/timezone")":/etc/timezone:ro
+# propagate timezone information to entrypoint
+if command -v timedatectl >/dev/null; then
+ set -- "$@" -e "KAS_HOST_TZ=$(timedatectl show -P Timezone)"
fi

for var in TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK KAS_CLONE_DEPTH \
--
2.50.0

Jan Kiszka

unread,
Jul 30, 2025, 6:07:45 AMJul 30
to Felix Moessbauer, kas-...@googlegroups.com, christi...@siemens.com
timedatectl: invalid option -- 'P'
(systemd 254)

Jan

> fi
>
> for var in TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK KAS_CLONE_DEPTH \

--
Siemens AG, Foundational Technologies
Linux Expert Center

MOESSBAUER, Felix

unread,
Jul 30, 2025, 6:32:52 AMJul 30
to Kiszka, Jan, kas-...@googlegroups.com, Storm, Christian
Apparently, this option was added in version 256.
We need to replace this by the semantically identical

timedatectl show -p Timezone --value

This is supported from systemd 239 on, which should be widely supported
(e.g. debian bullseye has it).

I'll send a v4.

Felix

>
> Jan
>
> >  fi
> >  
> >  for var in TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK
> > KAS_CLONE_DEPTH \

--

Felix Moessbauer

unread,
Jul 30, 2025, 6:39:09 AMJul 30
to kas-...@googlegroups.com, jan.k...@siemens.com, christi...@siemens.com, Felix Moessbauer
Bind-mounting /etc/timezone into the container overwrites the symlinks
target, as both docker and podman mount without the AT_SYMLINK_NOFOLLOW
flag. This breaks yocto builds which rely on correct information in
/usr/share/zoneinfo/*. To fix this, we pass the host timezone via an
environment variable to the container and patch the timezone in the
entrypoint. By that, we also preserve the difference between the TZ
variable and the /etc/timezone, /etc/localtime data.

Fixes: 378366395 ("kas-container: propagate timezone information ...")
Closes: #162
Signed-off-by: Felix Moessbauer <felix.mo...@siemens.com>
---
Changes since v3:

- write timedatectl in a way that is systemd 239 compatible and silently
ignore errors
index e8735884d..9388c81a9 100755
--- a/kas-container
+++ b/kas-container
@@ -687,12 +687,9 @@ if [ -n "${SSTATE_MIRRORS}" ]; then
set -- "$@" -e "SSTATE_MIRRORS=${SSTATE_MIRRORS}"
fi

-# propagate timezone information
-if [ -f "/etc/localtime" ]; then
- set -- "$@" -v "$(realpath -e "/etc/localtime")":/etc/localtime:ro
-fi
-if [ -f "/etc/timezone" ]; then
- set -- "$@" -v "$(realpath -e "/etc/timezone")":/etc/timezone:ro
+# propagate timezone information to entrypoint (requires systemd 239)
+if command -v timedatectl >/dev/null; then
+ set -- "$@" -e "KAS_HOST_TZ=$(timedatectl show -p Timezone --value 2>/dev/null)"
fi

for var in TERM KAS_DISTRO KAS_MACHINE KAS_TARGET KAS_TASK KAS_CLONE_DEPTH \
--
2.50.0

Jan Kiszka

unread,
Aug 7, 2025, 12:09:12 PMAug 7
to Felix Moessbauer, kas-...@googlegroups.com, christi...@siemens.com
Thanks, applied.

Jan
Reply all
Reply to author
Forward
0 new messages