Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(linux-client): remove FIREZONE_ID from example systemd file #4714

Merged
merged 18 commits into from
Apr 25, 2024

Conversation

ReactorScram
Copy link
Collaborator

@ReactorScram ReactorScram commented Apr 19, 2024

For tests it doesn't hurt, but this will be used as a template for the systemd service we ship to production, and that can't have the ID there.

So I'm also cleaning up a few other problems I noticed:

  • I wanted to split the service files as part of Release binary naming #4531, so that the GUI Client and headless Client can have separate sandbox rules. e.g, the headless Client won't be allowed to create Unix domain sockets
  • I'm punting more things to systemd, which allows us to tighten down the sandbox further, e.g. creating /var/lib/dev.firezone.client and /run/dev.firezone.client for us
  • Closes ux(linux-client): panic if DNS control fails #4461

In this specific case it doesn't hurt, but when we go to make the Deb
package, the ID can't go there.
@ReactorScram ReactorScram self-assigned this Apr 19, 2024
Copy link

vercel bot commented Apr 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
firezone ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 24, 2024 9:07pm

@github-actions github-actions bot added the kind/refactor Code refactoring label Apr 19, 2024
Copy link

github-actions bot commented Apr 19, 2024

Terraform Cloud Plan Output

Plan: 15 to add, 14 to change, 15 to destroy.

Terraform Cloud Plan

Copy link

github-actions bot commented Apr 19, 2024

Performance Test Results

TCP

Test Name Received/s Sent/s Retransmits
direct-tcp-client2server 244.2 MiB (+2%) 245.7 MiB (+2%) 267 (+33%)
direct-tcp-server2client 240.0 MiB (-2%) 241.4 MiB (-2%) 216 (-44%)
relayed-tcp-client2server 225.1 MiB (-1%) 225.9 MiB (-1%) 265 (+11%)
relayed-tcp-server2client 234.9 MiB (-3%) 235.4 MiB (-3%) 401 (-22%)

UDP

Test Name Total/s Jitter Lost
direct-udp-client2server 50.0 MiB (0%) 0.31ms (-1%) 0.00% (NaN%)
direct-udp-server2client 50.0 MiB (-0%) 0.01ms (-58%) 0.00% (NaN%)
relayed-udp-client2server 50.0 MiB (+0%) 0.10ms (+147%) 0.00% (NaN%)
relayed-udp-server2client 50.0 MiB (+0%) 0.03ms (+165%) 0.00% (NaN%)

@@ -23,19 +23,19 @@ ProtectKernelModules=true
ProtectKernelTunables=true
# Docs say it's useless when running as root, but defense-in-depth
ProtectProc=invisible
ProtectSystem=full
ProtectSystem=strict
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX
RestrictNamespaces=true
RestrictRealtime=true
RestrictSUIDSGID=true
StateDirectory=dev.firezone.client
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This asks systemd to make /var/lib/dev.firezone.client and mount it for us, since we're trying to minimize our own access to the FS

SystemCallArchitectures=native
# TODO: Minimize
SystemCallFilter=@aio @basic-io @file-system @io-event @ipc @network-io @signal @system-service
UMask=177
UMask=077
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think directories have to be u+x in order to do anything? Whatever I was doing to write the device ID file, it doesn't work with umask 177.

@ReactorScram ReactorScram linked an issue Apr 22, 2024 that may be closed by this pull request
@ReactorScram ReactorScram marked this pull request as ready for review April 22, 2024 17:27
Comment on lines +275 to +283
if let Err(error) = match dns_control_method {
None => Ok(()),
Some(DnsControlMethod::EtcResolvConf) => etc_resolv_conf::configure(&dns_config)
.await
.map_err(Error::ResolvConf)?,
Some(DnsControlMethod::NetworkManager) => configure_network_manager(&dns_config)?,
Some(DnsControlMethod::Systemd) => configure_systemd_resolved(&dns_config).await?,
.map_err(Error::ResolvConf),
Some(DnsControlMethod::NetworkManager) => configure_network_manager(&dns_config),
Some(DnsControlMethod::Systemd) => configure_systemd_resolved(&dns_config).await,
} {
panic!("Failed to control DNS: {error}");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I ran into #4461 while working on this PR and this diff closes it

tokio::fs::remove_file(SOCK_PATH).await.ok();
let listener = UnixListener::bind(SOCK_PATH).context("Couldn't bind UDS")?;
std::os::unix::fs::chown(SOCK_PATH, Some(ROOT_USER), Some(fz_gid.into()))
let sock_path = sock_path();
Copy link
Member

Choose a reason for hiding this comment

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

I know some services use this as a guard against accidentally launching the service twice. Should we just bail out if we find an existing sock file here and ask the user to remove it instead?

Copy link
Collaborator Author

@ReactorScram ReactorScram Apr 25, 2024

Choose a reason for hiding this comment

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

Maybe. If we can have systemd create it for us that would be cool, then it can also clean it up. I made an issue to look into it soon

@ReactorScram ReactorScram added this pull request to the merge queue Apr 25, 2024
Merged via the queue into main with commit bc94078 Apr 25, 2024
134 checks passed
@ReactorScram ReactorScram deleted the refactor/move-firezone-id branch April 25, 2024 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/refactor Code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ux(linux-client): panic if DNS control fails
2 participants