Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
id: meta
with:
images: ghcr.io/pendulum-project/ntpd-rs
images: ghcr.io/trifectatechfoundation/statime
tags: |
type=sha
type=semver,pattern={{version}}
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ resolver = "3"
version = "2.0.0-alpha.20261113"
edition = "2024"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/pendulum-project/ntpd-rs"
homepage = "https://github.com/pendulum-project/ntpd-rs"
repository = "https://github.com/trifectatechfoundation/statime"
homepage = "https://github.com/trifectatechfoundation/statime"
readme = "./README.md"
description = "Full-featured implementation of NTP with NTS support"
description = "A full-featured time synchronization daemon, including NTP, NTS and CSPTP support."
publish = true
rust-version = "1.95" # MSRV

Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ RUN apt update \
WORKDIR /build
COPY . /build

ARG NTPDRS_BUILD_FEATURES=""
ENV NTPDRS_BUILD_FEATURES="${NTPDRS_BUILD_FEATURES}"
ARG STATIME_BUILD_FEATURES=""
ENV STATIME_BUILD_FEATURES="${STATIME_BUILD_FEATURES}"

# Run the build command.
# Note that this mounts several cache directories to speed up subsequent builds.
Expand All @@ -24,7 +24,7 @@ ENV NTPDRS_BUILD_FEATURES="${NTPDRS_BUILD_FEATURES}"
RUN --mount=type=cache,target=/usr/local/cargo/git/db \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/build/target/ \
cargo build --locked --release --features="${NTPDRS_BUILD_FEATURES}" \
cargo build --locked --release --features="${STATIME_BUILD_FEATURES}" \
&& mkdir -p /build/artifacts \
&& cp target/release/statime-daemon /build/artifacts \
&& cp target/release/statime /build/artifacts \
Expand All @@ -45,7 +45,7 @@ COPY --from=builder /build/artifacts/statime /usr/local/bin/statime
COPY --from=builder /build/artifacts/statime-exporter /usr/local/bin/statime-exporter

# Setup a user and group for the runner
ARG USER=ntpd-rs
ARG USER=statime
ENV USER=${USER}
ARG UID=10001
ENV UID=${UID}
Expand Down
2 changes: 0 additions & 2 deletions clock-steering/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//! Logic for steering OS clocks, aimed at NTP and PTP.
//!
//! This code is used in our implementations of NTP [ntpd-rs](https://github.com/pendulum-project/ntpd-rs) and PTP [statime](https://github.com/pendulum-project/statime).
#[cfg(target_os = "linux")]
mod linux_ioctls;
Expand Down
36 changes: 18 additions & 18 deletions docs/development/ca.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ openssl req -x509 -new -nodes -key ca.key -sha256 -days 1825 -out ca.pem
Here, `-days` is the number of days that this certificate is valid, the value in
the command here results in a validity of five years. OpenSSL will ask for
several pieces of information during the setup of the root certificate. The
ntpd-rs daemon does not impose particular requirements to the information in
Statime daemon does not impose particular requirements to the information in
your root certificate, so feel free to leave things empty. Note that this
command bases the certificate validity based on the current system time, so make
sure that it is reasonably accurate.
Expand All @@ -50,54 +50,54 @@ Once our CA root is setup, we can continue generating the server key and
certificate. First, we start by generating a private key for the server:

```sh
openssl genrsa -out ntpd-rs.test.key 2048
openssl genrsa -out statime.test.key 2048
```

This time we omit the `-des3` CLI flag, so the private key is not protected with
a password. The ntpd-rs daemon does not support password encrypted private keys,
a password. The Statime daemon does not support password encrypted private keys,
so we cannot password protect our private key. Once the private key is
generated, we need to create a certificate signing request. We again can use
openssl to do this for us:

```sh
openssl req -new -key ntpd-rs.test.key -out ntpd-rs.test.csr
openssl req -new -key statime.test.key -out statime.test.csr
```

OpenSSL will once again ask for some information, but ntpd-rs once again does
OpenSSL will once again ask for some information, but Statime once again does
not impose any requirements on the information requested, so feel free to leave
things empty once again. With the certificate signing request generated, we now
only need a little bit of configuration to tell the CA root how the generated
certificate will be used, to do this, create a file called `ntpd-rs.ext` with
the following contents, replacing the `ntpd-rs.test` domain name with your own
certificate will be used, to do this, create a file called `statime.ext` with
the following contents, replacing the `statime.test` domain name with your own
domain name.

```ini title="/path/to/some/ca-data/ntpd-rs.ext"
```ini title="/path/to/some/ca-data/statime.ext"
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = keyEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = ntpd-rs.test
DNS.1 = statime.test
```

Note that the domain name does not actually have to exist, but it will be the
domain name that clients somehow have to connect to (e.g. by setting an
`/etc/hosts` entry). We now have enough information to generate a certificate:

```sh
openssl x509 -req -in ntpd-rs.test.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out ntpd-rs.test.crt -days 1825 -sha256 -extfile ntpd-rs.ext
openssl x509 -req -in statime.test.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out statime.test.crt -days 1825 -sha256 -extfile statime.ext
```

The above command gives the certificate a period validity of 5 years. If a
different lifetime is desired, change the number following the `-days` argument
to the number of days the certificate should be valid. The generated certificate
should be concatenated together with the CA certificate, as ntpd-rs needs the
should be concatenated together with the CA certificate, as Statime needs the
full certificate chain in order to operate. We can use a simple command to do
this:

```sh
cat ntpd-rs.test.crt ca.pem > ntpd-rs.test.chain.pem
cat statime.test.crt ca.pem > statime.test.chain.pem
```

## Using the generated certificate
Expand All @@ -110,13 +110,13 @@ following `[[nts-ke-server]]` section (or update an existing section):

[[nts-ke-server]]
listen = "[::]:4460"
certificate-chain-path = "/path/to/some/ca-data/ntpd-rs.test.chain.pem"
private-key-path = "/path/to/some/ca-data/ntpd-rs.test.key"
certificate-chain-path = "/path/to/some/ca-data/statime.test.chain.pem"
private-key-path = "/path/to/some/ca-data/statime.test.key"

# ...
```

Finally, restart your ntpd-rs daemon by running `systemctl restart ntpd-rs`.
Finally, restart your Statime daemon by running `systemctl restart statime`.
Your server should now be ready to handle NTS!

!!! Danger
Expand All @@ -133,13 +133,13 @@ that you should only ever share the `ca.pem` file and never the `ca.key` file!
In your client, now you will need to make sure that the domain name under which
you reach the server is the same as the domain name for which you configured
the server certificate. In our example above we used the domain name
`ntpd-rs.test`. If we wanted the server to be able to reach itself, we can
`statime.test`. If we wanted the server to be able to reach itself, we can
simply add a `/etc/hosts` entry for this, like such:

```txt title="/etc/hosts" hl_lines="3"
...
127.0.0.1 localhost
127.0.0.1 ntpd-rs.test
127.0.0.1 statime.test
...
```

Expand All @@ -151,7 +151,7 @@ CA root certificate:

[[source]]
mode = "nts"
address = "ntpd-rs.test"
address = "statime.test"
certificate-authority = "/path/to/some/ca-data/ca.pem"

# ...
Expand Down
22 changes: 12 additions & 10 deletions docs/development/code-structure.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Code structure

This document gives a high-level overview of the structure of ntpd-rs.
This document gives a high-level overview of the structure of Statime.

## Crates

ntpd-rs is split into several crates with three goals in mind:
Statime is split into several crates with three goals in mind:

- Split the logic of protocol handling from the details around asynchronous
network handling
Expand All @@ -13,9 +13,10 @@ ntpd-rs is split into several crates with three goals in mind:
- Limit the scopes where we use unsafe code, ensuring that it is more
straightforward to verify.

The main `statime-ntp` and `statime` crates are set up such that neither contains any
unsafe code. Unsafe code is limited to the (external) `timestamped-socket`, `clock-steering` and `pps-time` crates,
which are purposefully kept small and only offer a safe API.
The main `statime-ntp` and `statime` crates are set up such that neither
contains any unsafe code. Unsafe code is limited to the `timestamped-socket`,
`clock-steering` and `pps-time` crates, which are purposefully kept small and
only offer a safe API.

### statime-ntp

Expand All @@ -33,20 +34,21 @@ ensure that source and steering logic is regularly called.

### timestamped-socket

The [`timestamped-socket` crate](https://github.com/pendulum-project/timestamped-socket) provides an async interface to the Linux kernel's
The `timestamped-socket` crate provides an async interface to the Linux kernel's
kernel-level network timestamping functionality. It wraps the system calls for
configuring kernel-level timestamping and for retrieving the actual timestamps.
Touching the network layer uses `libc` and is inherently unsafe.

### clock-steering

The [`clock-steering` crate](https://github.com/pendulum-project/clock-steering) wraps the system calls needed for controlling the system
clock. Touching the system clock uses `libc` and is inherently unsafe.
The `clock-steering` crate wraps the system calls needed for controlling the
system clock. Touching the system clock uses `libc` and is inherently unsafe.

### pps-time

The [`pps-time` crate](https://github.com/pendulum-project/pps-time) wraps the system calls needed to interact with a PPS device. To
interact with PPS devices ioctl system calls are used, which uses `libc` and is inherently unsafe.
The `pps-time` crate wraps the system calls needed to interact with a PPS
device. To interact with PPS devices ioctl system calls are used, which uses
`libc` and is inherently unsafe.

### statime

Expand Down
4 changes: 2 additions & 2 deletions docs/development/flowdiagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/development/further-reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

- (Link) NTP at the [IETF Datatracker][1]
- (Video) Introduction to the project: [NTP for the modern era @ GOSIM][2]
- (Paper) Clock steering and selection algorithm in ntpd-rs: [docs/algorithm/algorithm.pdf][3]
- (Paper) Clock steering and selection algorithm: [docs/algorithm/algorithm.pdf][3]
- (Link) [NTP Pool website][4]

[1]: https://datatracker.ietf.org/wg/ntp/documents/
[2]: https://www.youtube.com/watch?v=p_zC5zSRRng
[3]: https://github.com/pendulum-project/ntpd-rs/blob/main/docs/algorithm/algorithm.pdf
[3]: https://github.com/trifectatechfoundation/statime/blob/main/docs/algorithm/algorithm.pdf
[4]: https://www.ntppool.org
8 changes: 4 additions & 4 deletions docs/development/threat-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ The used methodology is entirely manual, but is derived from

We model the following actors:

- System Admin: Administrator of the system running ntpd-rs
- System User: Non-administrator user of the system running ntpd-rs
- System Admin: Administrator of the system running Statime
- System User: Non-administrator user of the system running Statime
- Reference Source: A remote time server we use as a source for our time.
- External Client: A remote user that is allowed to use this instance of
ntpd-rs to receive time.
Statime to receive time.
- Anonymous: Any other party

### Assets
Expand Down Expand Up @@ -432,7 +432,7 @@ We model the following assets:

![](flowdiagram.svg)

- The security boundaries between the admin and system users and ntpd-rs run
- The security boundaries between the admin and system users and Statime run
through the Unix sockets used for communication.
- The security boundaries for reference sources and external clients run
through the network sockets used for communication.
8 changes: 4 additions & 4 deletions docs/examples/conf/statime-OpenRC-confd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# The configuration file path for the ntpd-daemon where settings for the
# configuration of ntpd-rs are stored
# The configuration file path for the daemon where settings for the
# configuration of Statime are stored
CONFIG="/etc/statime/statime.toml"

# The unprivileged user and group to run as
# do not change unless you know what you're doing
USER=ntpd-rs
GROUP=ntpd-rs
USER=statime
GROUP=statime
10 changes: 5 additions & 5 deletions docs/examples/conf/statime-OpenRC-initd
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

supervisor=supervise-daemon

name=ntpd-rs
description="Network Time Protocol (ntpd-rs)"
name=statime
description="Time Synchronization Daemon (Statime)"
command=/usr/bin/statime-daemon
command_args="-c $CONFIG"
# log the stderror and stdout to /var/log/ntpd-rs.log
# log the stderror and stdout to /var/log/statime.log
output_log=/var/log/${RC_SVCNAME}.log
error_log=/var/log/${RC_SVCNAME}.log

if [ $RC_UNAME = "Linux" ]; then
# on linux ntpd-rs can run unprivileged due to the capabilities below
# on linux Statime can run unprivileged due to the capabilities below
command_user="${USER}:${GROUP}"
capabilities="^cap_net_bind_service,^cap_sys_time"
no_new_privs=1
Expand Down Expand Up @@ -52,7 +52,7 @@ stop_pre() {

return 0
}

reload() {
checkconfig || return $?
ebegin "Reloading $RC_SVCNAME"
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/conf/statime-metrics.service
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[Unit]
Description=Network Time Service (ntpd-rs) metrics exporter
Documentation=https://github.com/pendulum-project/ntpd-rs
Description=Time Synchronization Daemon (Statime) metrics exporter
Documentation=https://github.com/trifectatechfoundation/statime

[Service]
Type=notify
Restart=always
ExecStart=/usr/bin/statime-metrics
Environment="RUST_LOG=info"
User=ntpd-rs-observe
Group=ntpd-rs-observe
User=statime-observe
Group=statime-observe

[Install]
WantedBy=multi-user.target
8 changes: 4 additions & 4 deletions docs/examples/conf/statime-metrics.strict.service
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[Unit]
Description=Network Time Service (ntpd-rs) metrics exporter
Documentation=https://github.com/pendulum-project/ntpd-rs
Description=Time Synchronization Daemon (Statime) metrics exporter
Documentation=https://github.com/trifectatechfoundation/statime

[Service]
Type=notify
Restart=always
ExecStart=/usr/bin/statime-metrics
Environment="RUST_LOG=info"
User=ntpd-rs-observe
Group=ntpd-rs-observe
User=statime-observe
Group=statime-observe

NoNewPrivileges=yes
AmbientCapabilities=
Expand Down
10 changes: 5 additions & 5 deletions docs/examples/conf/statime.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Unit]
Description=Network Time Service (ntpd-rs)
Documentation=https://github.com/pendulum-project/ntpd-rs
Description=Time Synchronization Daemon (Statime)
Documentation=https://github.com/trifectatechfoundation/statime
After=network-online.target
Wants=network-online.target
Conflicts=systemd-timesyncd.service ntp.service chrony.service
Expand All @@ -10,9 +10,9 @@ Type=notify
Restart=no
ExecStart=/usr/bin/statime-daemon
Environment="RUST_LOG=info"
RuntimeDirectory=ntpd-rs
User=ntpd-rs
Group=ntpd-rs
RuntimeDirectory=statime
User=statime
Group=statime
AmbientCapabilities=CAP_SYS_TIME CAP_NET_BIND_SERVICE

[Install]
Expand Down
Loading
Loading