Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] systemd: ensure reproducible builds by clearly exposing the time epoch support
@ 2019-09-05 23:07 Ross Burton
  2019-09-06  8:02 ` Mikko.Rapeli
  0 siblings, 1 reply; 4+ messages in thread
From: Ross Burton @ 2019-09-05 23:07 UTC (permalink / raw)
  To: openembedded-core

systemd has the ability to check the time on boot and if it's earlier than an
epoch determined at build time, set the time to that epoch.  This is useful for
systems where the system time is January 1st 1970 (because the unix timestamp
was 0 at boot) as then at least the time is reset to something approximating the
right year at least.

By default systemd uses the mtime of the NEWS file, which is static for tarballs
and corresponds to the time the release was made, but for git checkouts this is
simply the time do_unpack() was executed.  Thus, rebuilding systemd will cause
this embedded timestamp to change.

Remove the PACKAGECONFIG time-epoch which has the logic reversed: enabling
time-epoch will set the epoch to the unix timestamp 0).  Replace with
set-time-epoch with the following semantics:

- When disabled, the time epoch is set to 0 (1st January 1970), so there is no
  time manipulation on boot.

- When enabled, if reproducible builds are configured by setting
  SOURCE_DATE_EPOCH then that timestamp is used for the time epoch.  If
  reproducible builds are not configured then the timestamp of NEWS (thus the
  build time) is used.

The set-time-epoch flag is enabled by default.

[ YOCTO #13473 ]

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/recipes-core/systemd/systemd_242.bb | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/meta/recipes-core/systemd/systemd_242.bb b/meta/recipes-core/systemd/systemd_242.bb
index 6bbe388b1f9..2c101cbbb4a 100644
--- a/meta/recipes-core/systemd/systemd_242.bb
+++ b/meta/recipes-core/systemd/systemd_242.bb
@@ -83,6 +83,7 @@ PACKAGECONFIG ??= " \
     quotacheck \
     randomseed \
     resolved \
+    set-time-epoch \
     smack \
     sysusers \
     timedated \
@@ -166,7 +167,12 @@ PACKAGECONFIG[seccomp] = "-Dseccomp=true,-Dseccomp=false,libseccomp"
 PACKAGECONFIG[selinux] = "-Dselinux=true,-Dselinux=false,libselinux,initscripts-sushell"
 PACKAGECONFIG[smack] = "-Dsmack=true,-Dsmack=false"
 PACKAGECONFIG[sysusers] = "-Dsysusers=true,-Dsysusers=false"
-PACKAGECONFIG[time-epoch] = "-Dtime-epoch=0,,"
+# When enabled use reproducble build timestamp if set as time epoch,
+# or build time if not. When disabled, time epoch is unset.
+def build_epoch(d):
+    epoch = d.getVar('SOURCE_DATE_EPOCH') or "-1"
+    return '-Dtime-epoch=%d' % int(epoch)
+PACKAGECONFIG[set-time-epoch] = "${@build_epoch(d)},-Dtime-epoch=0"
 PACKAGECONFIG[timedated] = "-Dtimedated=true,-Dtimedated=false"
 PACKAGECONFIG[timesyncd] = "-Dtimesyncd=true,-Dtimesyncd=false"
 PACKAGECONFIG[usrmerge] = "-Dsplit-usr=false,-Dsplit-usr=true"
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] systemd: ensure reproducible builds by clearly exposing the time epoch support
  2019-09-05 23:07 [PATCH] systemd: ensure reproducible builds by clearly exposing the time epoch support Ross Burton
@ 2019-09-06  8:02 ` Mikko.Rapeli
  2019-09-06  9:03   ` Ross Burton
  0 siblings, 1 reply; 4+ messages in thread
From: Mikko.Rapeli @ 2019-09-06  8:02 UTC (permalink / raw)
  To: ross.burton; +Cc: openembedded-core

On Fri, Sep 06, 2019 at 12:07:06AM +0100, Ross Burton wrote:
> systemd has the ability to check the time on boot and if it's earlier than an
> epoch determined at build time, set the time to that epoch.  This is useful for
> systems where the system time is January 1st 1970 (because the unix timestamp
> was 0 at boot) as then at least the time is reset to something approximating the
> right year at least.
> 
> By default systemd uses the mtime of the NEWS file, which is static for tarballs
> and corresponds to the time the release was made, but for git checkouts this is
> simply the time do_unpack() was executed.  Thus, rebuilding systemd will cause
> this embedded timestamp to change.
> 
> Remove the PACKAGECONFIG time-epoch which has the logic reversed: enabling
> time-epoch will set the epoch to the unix timestamp 0).  Replace with
> set-time-epoch with the following semantics:
> 
> - When disabled, the time epoch is set to 0 (1st January 1970), so there is no
>   time manipulation on boot.
> 
> - When enabled, if reproducible builds are configured by setting
>   SOURCE_DATE_EPOCH then that timestamp is used for the time epoch.  If
>   reproducible builds are not configured then the timestamp of NEWS (thus the
>   build time) is used.
> 
> The set-time-epoch flag is enabled by default.
> 
> [ YOCTO #13473 ]
> 
> Signed-off-by: Ross Burton <ross.burton@intel.com>
> ---
>  meta/recipes-core/systemd/systemd_242.bb | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/meta/recipes-core/systemd/systemd_242.bb b/meta/recipes-core/systemd/systemd_242.bb
> index 6bbe388b1f9..2c101cbbb4a 100644
> --- a/meta/recipes-core/systemd/systemd_242.bb
> +++ b/meta/recipes-core/systemd/systemd_242.bb
> @@ -83,6 +83,7 @@ PACKAGECONFIG ??= " \
>      quotacheck \
>      randomseed \
>      resolved \
> +    set-time-epoch \

Could this be enabled automatically when local.conf has INHERIT += "reproducible_build" ?

-Mikko

>      smack \
>      sysusers \
>      timedated \
> @@ -166,7 +167,12 @@ PACKAGECONFIG[seccomp] = "-Dseccomp=true,-Dseccomp=false,libseccomp"
>  PACKAGECONFIG[selinux] = "-Dselinux=true,-Dselinux=false,libselinux,initscripts-sushell"
>  PACKAGECONFIG[smack] = "-Dsmack=true,-Dsmack=false"
>  PACKAGECONFIG[sysusers] = "-Dsysusers=true,-Dsysusers=false"
> -PACKAGECONFIG[time-epoch] = "-Dtime-epoch=0,,"
> +# When enabled use reproducble build timestamp if set as time epoch,
> +# or build time if not. When disabled, time epoch is unset.
> +def build_epoch(d):
> +    epoch = d.getVar('SOURCE_DATE_EPOCH') or "-1"
> +    return '-Dtime-epoch=%d' % int(epoch)
> +PACKAGECONFIG[set-time-epoch] = "${@build_epoch(d)},-Dtime-epoch=0"
>  PACKAGECONFIG[timedated] = "-Dtimedated=true,-Dtimedated=false"
>  PACKAGECONFIG[timesyncd] = "-Dtimesyncd=true,-Dtimesyncd=false"
>  PACKAGECONFIG[usrmerge] = "-Dsplit-usr=false,-Dsplit-usr=true"
> -- 
> 2.20.1
> 
> -- 
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] systemd: ensure reproducible builds by clearly exposing the time epoch support
  2019-09-06  8:02 ` Mikko.Rapeli
@ 2019-09-06  9:03   ` Ross Burton
  2019-09-06  9:43     ` Mikko.Rapeli
  0 siblings, 1 reply; 4+ messages in thread
From: Ross Burton @ 2019-09-06  9:03 UTC (permalink / raw)
  To: Mikko.Rapeli; +Cc: openembedded-core

On 06/09/2019 09:02, Mikko.Rapeli@bmw.de wrote:
> Could this be enabled automatically when local.conf has INHERIT += "reproducible_build" ?

The default behaviour is to respect that if enabled, otherwise use the 
upstream default of the build time.  If the recipe followed the 
reproducble_build inherit then if a user wants reproducible builds but 
doesn't want the epoch then they won't be able to disable it (after all, 
an epoch of 0 is reproducible).

Ross


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] systemd: ensure reproducible builds by clearly exposing the time epoch support
  2019-09-06  9:03   ` Ross Burton
@ 2019-09-06  9:43     ` Mikko.Rapeli
  0 siblings, 0 replies; 4+ messages in thread
From: Mikko.Rapeli @ 2019-09-06  9:43 UTC (permalink / raw)
  To: ross.burton; +Cc: openembedded-core

On Fri, Sep 06, 2019 at 10:03:14AM +0100, Ross Burton wrote:
> On 06/09/2019 09:02, Mikko.Rapeli@bmw.de wrote:
> > Could this be enabled automatically when local.conf has INHERIT += "reproducible_build" ?
> 
> The default behaviour is to respect that if enabled, otherwise use the
> upstream default of the build time.  If the recipe followed the
> reproducble_build inherit then if a user wants reproducible builds but
> doesn't want the epoch then they won't be able to disable it (after all, an
> epoch of 0 is reproducible).

Ok, fair enough. Thanks for this patch!

-Mikko

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-09-06  9:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-05 23:07 [PATCH] systemd: ensure reproducible builds by clearly exposing the time epoch support Ross Burton
2019-09-06  8:02 ` Mikko.Rapeli
2019-09-06  9:03   ` Ross Burton
2019-09-06  9:43     ` Mikko.Rapeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox