Revision History | |
---|---|
Revision 1.1 | 27 November 2017 |
Document timestamp clamping. Drop prohibition of overwriting the variable, and instead specify more tightly how to set it. | |
Revision 1.0 | 01 September 2015 |
Initial version. |
Table of Contents
This specification defines a distribution-agnostic standard for build systems to exchange a timestamp.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
The canonical URI for this document is: https://reproducible-builds.org/specs/source-date-epoch/.
Whilst anyone can inspect the source code of free software for malicious flaws, most distributions provide binary (or "compiled") packages to end users. The motivation behind "reproducible" builds is to allow verification that no flaws have been introduced during this compilation process by promising identical binary packages are always generated from a given source.
This prevents against the installation of backdoor-introducing malware on developers' machines as an attacker would need to simultaneously infect all the developers attempting to reproduce the build. In addition, a reproducible build has other technical advantages:
Requires the removal of any non-deterministic and/or unsafe behaviour, eg. connecting to the internet to download build-dependencies or reading from uninitialised memory
Detects corrupted or outdated build environments
Provides validation of packages built on foreign architectures
Reduces time-to-detection of a build host compromise
Can show that proposed changes have no impact on binaries
Software packages are often unreproducible because they embed compile-time timestamps into generated files. As the current time changes between builds, this results in the binaries containing different contents. Futhermore, these dates are unreliable indicators of the software's age given that software can be arbitrarily rebuilt.
An improvement is to use the last modification time of the source; if the source is then modified, the binaries will change by design. This timestamp is also more informative as it reflects the actual age of the software and not when it was last compiled.
However, in the context of a distribution, the last modification time is not a property of the upstream source, but rather of the packaging that encapsulates it.
This specification therefore defines a distribution-agnostic standard for upstream build processes to consume this timestamp from packaging systems. The intended result is a build where the output looks as if the build had happened instantly at the time specified in that timestamp.
A UNIX timestamp, defined as the number of seconds,
excluding leap seconds, since 01 Jan
1970 00:00:00 UTC
.
The value MUST be exported through the operating system's usual environment mechanism.
The value MUST be an ASCII representation of an integer with no fractional component, identical to the output format of date +%s.
The value MUST be reproducible (deterministic) across different executions of the build, depending only on the source code. It SHOULD be set to the last modification time of the source, incorporating any packaging-specific modifications.
Build processes MUST use this variable for embedded timestamps in place of the "current" date and time.
Where build processes embed timestamps that are not "current", but are nevertheless still specific to one execution of the build process, they MUST use a timestamp no later than the value of this variable. This is often called "timestamp clamping".
Build processes MUST NOT unset this variable for child processes if it is already present.
Formatting MUST be deferred until runtime if an end user should observe the value in their own locale or timezone.
If the value is malformed, the build process SHOULD exit with a non-zero error code.
Distributions could set SOURCE_DATE_EPOCH
by using
the value of a changelog file. For instance, Debian packages can
set it to the value of the latest entry of
debian/changelog
.
Developers could set SOURCE_DATE_EPOCH
to the date
of the latest commit in their version control system. In this case,
it is recommended to also update all source file timestamps, which
git does not do by itself, otherwise old timestamps specific to the
developer's working tree may be embedded into the output.
Though it is not forbidden to set SOURCE_DATE_EPOCH
several times during a build, such as for different child modules,
build processes doing this should ensure that any differing values
do not interfere with each other in a nondeterministic way.
One can reasonably assume that all source timestamps are
before SOURCE_DATE_EPOCH
and all builds take
place after it. This means we can efficiently both preserve
source-based timestamps and omit build-specific timestamps,
by rewriting timestamps more recent than SOURCE_DATE_EPOCH
back to the latter. See for example the --clamp-mtime
option to GNU tar.
Other examples are available at https://reproducible-builds.org/docs/source-date-epoch/.
Copyright © 2015-2017 See Contributors List
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.