Coder Social home page Coder Social logo

bjeanes / nss_zerotier Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 16 KB

A NSS module to allow host lookup from joined ZeroTier networks

License: Mozilla Public License 2.0

Rust 58.07% Makefile 25.83% Dockerfile 16.11%
nsswitch nss libnss zerotier zerotier-network zerotier-one libnss-zerotier cdylib rust-crate

nss_zerotier's Introduction

nss_zerotier

A NSS module to allow host lookup from joined ZeroTier networks

This is just getting started, but the idea is that it will return results only to *.zt requests under the following logic:

  • <nodeid>.zt - the host with <nodeid> as its Node ID in any network to which the current machine belongs.
  • <host>.zt - the first member found with <host> as its name in any network to which the current machine belongs. NOTE: The "name" in ZeroTier Central must be a valid hostname (which ZeroTier Central does not enforce).
  • <host>.<network>.zt - the first member found in <network> with <host> as its name. NOTE: The "names" in ZeroTier Central must both form a valid hostname in combination (which ZeroTier Central does not enforce).
  • localhost.zt - special case to return the addresses for the current machine (maybe, still thinking on this)

It will read the ZT token from the following places, in the following order:

  1. ZEROTIER_TOKEN environment variable
  2. $HOME/.zeroTierOneAuthToken, if present and readable by current user
  3. /var/lib/zerotier-one/authtoken.secret, if present and readable by current user

Other than the environment variable, these are the same places that zerotier-one and zerotier-cli check. I am not currently aware of any environment variable which the ZeroTier tools check, but if there is one, this will be adjusted to align.

Installation

$ make
   Compiling ...
   Compiling nss_zerotier v0.1.0 (/home/bjeanes/Code/nss_zerotier)
    Finished release [optimized] target(s) in 11.08s
$ sudo make install
install -m755 -d /usr/lib/
install -m644 target/release/libnss_zerotier.so /usr/lib/libnss_zerotier.so.2
ldconfig -n /usr/lib/
  • TODO: provide a Makefile
  • TODO: pre-compile releases and attach to GitHub Releases
  • TODO: package as an AUR for ArchLinux

Usage

After installation, you should be able to query the database using getent:

$ getent -s zerotier hosts
10.144.17.130	d37fa4928f.zt vorpal.home.zt vorpal.zt
10.144.119.0	124df28d26.zt tumtum.home.zt tumtum.zt
10.144.70.159	68f86f5d48.zt nas.home.zt nas.zt
$ getent -s zerotier hosts nas.zt
10.144.70.159	68f86f5d48.zt nas.home.zt nas.zt

To enable the zerotier NSS module system-wide, you'll need to edit /etc/nsswitch.conf and edit the hosts entry. For example:

# ...
passwd: files mymachines systemd
group: files mymachines systemd
shadow: files
publickey: files
-hosts: files mymachines myhostname resolve [!UNAVAIL=return] dns
+hosts: files mymachines myhostname zerotier resolve [!UNAVAIL=return] dns
networks: files
# ...

Compatibility

This should (once implemented) work on any operating system which uses Name Service Switch, but I am not yet familiar with any potential variations in the glibc representation for the required callbacks and data structures.

In theory, that means Linux and BSD flavours should be easily supported. I personally am building this on an ArchLinux machine.

I know macOS has some facilities for custom resolvers but I also know it is not based on NSS. Potentially, this could eventually offer some equivalent there but it is not currently a goal.

Alternatives

License

MPL. See LICENSE file.

nss_zerotier's People

Contributors

bjeanes avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

tymiles003

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.