git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #153825 from ymatsiuk/ymatsiuk/teleport-module-test-init

nixos/teleport: init + tests

commitee7e31edb4050395efa8ea969cb21d3ed7674e3d authorAaron Andersen <aaron@fosslib.net> dateTue 11 Jan 2022, 07:29 (5 years ago) parent3ddd5f90806c26
7 files changed+214
nixos/doc/manual/from_md/release-notes/rl-2205.section.xml+9 nixos/doc/manual/release-notes/rl-2205.section.md+2 nixos/modules/module-list.nix+1 nixos/modules/services/networking/teleport.nix+99 nixos/tests/all-tests.nix+1 nixos/tests/teleport.nix+99 pkgs/servers/teleport/default.nix+3
nixos/doc/manual/from_md/release-notes/rl-2205.section.xml+9
@@ -119,6 +119,15 @@
119119 <link xlink:href="options.html#opt-services.archisteamfarm.enable">services.archisteamfarm</link>.
120120 </para>
121121 </listitem>
122+ <listitem>
123+ <para>
124+ <link xlink:href="https://goteleport.com">teleport</link>,
125+ allows engineers and security professionals to unify access
126+ for SSH servers, Kubernetes clusters, web applications, and
127+ databases across all environments. Available at
128+ <link linkend="opt-services.teleport.enable">services.teleport</link>.
129+ </para>
130+ </listitem>
122131 </itemizedlist>
123132 </section>
124133 <section xml:id="sec-release-22.05-incompatibilities">
nixos/doc/manual/release-notes/rl-2205.section.md+2
@@ -37,6 +37,8 @@ In addition to numerous new and upgraded packages, this release has the followin
3737
3838- [ArchiSteamFarm](https://github.com/JustArchiNET/ArchiSteamFarm), a C# application with primary purpose of idling Steam cards from multiple accounts simultaneously. Available as [services.archisteamfarm](options.html#opt-services.archisteamfarm.enable).
3939
40+- [teleport](https://goteleport.com), allows engineers and security professionals to unify access for SSH servers, Kubernetes clusters, web applications, and databases across all environments. Available at [services.teleport](#opt-services.teleport.enable).
41+
4042## Backward Incompatibilities {#sec-release-22.05-incompatibilities}
4143
4244- `pkgs.ghc` now refers to `pkgs.targetPackages.haskellPackages.ghc`.
nixos/modules/module-list.nix+1
@@ -891,6 +891,7 @@
891891 ./services/networking/tcpcrypt.nix
892892 ./services/networking/teamspeak3.nix
893893 ./services/networking/tedicross.nix
894+ ./services/networking/teleport.nix
894895 ./services/networking/thelounge.nix
895896 ./services/networking/tinc.nix
896897 ./services/networking/tinydns.nix
nixos/modules/services/networking/teleport.nixnew file+99
@@ -0,0 +1,99 @@
1+{ config, pkgs, lib, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.teleport;
7+ settingsYaml = pkgs.formats.yaml { };
8+in
9+{
10+ options = {
11+ services.teleport = with lib.types; {
12+ enable = mkEnableOption "the Teleport service";
13+
14+ settings = mkOption {
15+ type = settingsYaml.type;
16+ default = { };
17+ example = literalExpression ''
18+ {
19+ teleport = {
20+ nodename = "client";
21+ advertise_ip = "192.168.1.2";
22+ auth_token = "60bdc117-8ff4-478d-95e4-9914597847eb";
23+ auth_servers = [ "192.168.1.1:3025" ];
24+ log.severity = "DEBUG";
25+ };
26+ ssh_service = {
27+ enabled = true;
28+ labels = {
29+ role = "client";
30+ };
31+ };
32+ proxy_service.enabled = false;
33+ auth_service.enabled = false;
34+ }
35+ '';
36+ description = ''
37+ Contents of the <literal>teleport.yaml</literal> config file.
38+ The <literal>--config</literal> arguments will only be passed if this set is not empty.
39+
40+ See <link xlink:href="https://goteleport.com/docs/setup/reference/config/"/>.
41+ '';
42+ };
43+
44+ insecure.enable = mkEnableOption ''
45+ starting teleport in insecure mode.
46+
47+ This is dangerous!
48+ Sensitive information will be logged to console and certificates will not be verified.
49+ Proceed with caution!
50+
51+ Teleport starts with disabled certificate validation on Proxy Service, validation still occurs on Auth Service
52+ '';
53+
54+ diag = {
55+ enable = mkEnableOption ''
56+ endpoints for monitoring purposes.
57+
58+ See <link xlink:href="https://goteleport.com/docs/setup/admin/troubleshooting/#troubleshooting/"/>
59+ '';
60+
61+ addr = mkOption {
62+ type = str;
63+ default = "127.0.0.1";
64+ description = "Metrics and diagnostics address.";
65+ };
66+
67+ port = mkOption {
68+ type = int;
69+ default = 3000;
70+ description = "Metrics and diagnostics port.";
71+ };
72+ };
73+ };
74+ };
75+
76+ config = mkIf config.services.teleport.enable {
77+ environment.systemPackages = [ pkgs.teleport ];
78+
79+ systemd.services.teleport = {
80+ wantedBy = [ "multi-user.target" ];
81+ after = [ "network.target" ];
82+ serviceConfig = {
83+ ExecStart = ''
84+ ${pkgs.teleport}/bin/teleport start \
85+ ${optionalString cfg.insecure.enable "--insecure"} \
86+ ${optionalString cfg.diag.enable "--diag-addr=${cfg.diag.addr}:${toString cfg.diag.port}"} \
87+ ${optionalString (cfg.settings != { }) "--config=${settingsYaml.generate "teleport.yaml" cfg.settings}"}
88+ '';
89+ ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
90+ LimitNOFILE = 65536;
91+ Restart = "always";
92+ RestartSec = "5s";
93+ RuntimeDirectory = "teleport";
94+ Type = "simple";
95+ };
96+ };
97+ };
98+}
99+
nixos/tests/all-tests.nix+1
@@ -471,6 +471,7 @@ in
471471 systemd-unit-path = handleTest ./systemd-unit-path.nix {};
472472 taskserver = handleTest ./taskserver.nix {};
473473 telegraf = handleTest ./telegraf.nix {};
474+ teleport = handleTest ./teleport.nix {};
474475 tiddlywiki = handleTest ./tiddlywiki.nix {};
475476 tigervnc = handleTest ./tigervnc.nix {};
476477 timezone = handleTest ./timezone.nix {};
nixos/tests/teleport.nixnew file+99
@@ -0,0 +1,99 @@
1+{ system ? builtins.currentSystem
2+, config ? { }
3+, pkgs ? import ../.. { inherit system config; }
4+}:
5+
6+with import ../lib/testing-python.nix { inherit system pkgs; };
7+
8+let
9+ minimal = { config, ... }: {
10+ services.teleport.enable = true;
11+ };
12+
13+ client = { config, ... }: {
14+ services.teleport = {
15+ enable = true;
16+ settings = {
17+ teleport = {
18+ nodename = "client";
19+ advertise_ip = "192.168.1.20";
20+ auth_token = "8d1957b2-2ded-40e6-8297-d48156a898a9";
21+ auth_servers = [ "192.168.1.10:3025" ];
22+ log.severity = "DEBUG";
23+ };
24+ ssh_service = {
25+ enabled = true;
26+ labels = {
27+ role = "client";
28+ };
29+ };
30+ proxy_service.enabled = false;
31+ auth_service.enabled = false;
32+ };
33+ };
34+ networking.interfaces.eth1.ipv4.addresses = [{
35+ address = "192.168.1.20";
36+ prefixLength = 24;
37+ }];
38+ };
39+
40+ server = { config, ... }: {
41+ services.teleport = {
42+ enable = true;
43+ settings = {
44+ teleport = {
45+ nodename = "server";
46+ advertise_ip = "192.168.1.10";
47+ };
48+ ssh_service.enabled = true;
49+ proxy_service.enabled = true;
50+ auth_service = {
51+ enabled = true;
52+ tokens = [ "node:8d1957b2-2ded-40e6-8297-d48156a898a9" ];
53+ };
54+ };
55+ diag.enable = true;
56+ insecure.enable = true;
57+ };
58+ networking = {
59+ firewall.allowedTCPPorts = [ 3025 ];
60+ interfaces.eth1.ipv4.addresses = [{
61+ address = "192.168.1.10";
62+ prefixLength = 24;
63+ }];
64+ };
65+ };
66+in
67+{
68+ minimal = makeTest {
69+ # minimal setup should always work
70+ name = "teleport-minimal-setup";
71+ meta.maintainers = with pkgs.lib.maintainers; [ ymatsiuk ];
72+ nodes = { inherit minimal; };
73+
74+ testScript = ''
75+ minimal.wait_for_open_port("3025")
76+ minimal.wait_for_open_port("3080")
77+ minimal.wait_for_open_port("3022")
78+ '';
79+ };
80+
81+ basic = makeTest {
82+ # basic server and client test
83+ name = "teleport-server-client";
84+ meta.maintainers = with pkgs.lib.maintainers; [ ymatsiuk ];
85+ nodes = { inherit server client; };
86+
87+ testScript = ''
88+ with subtest("teleport ready"):
89+ server.wait_for_open_port("3025")
90+ client.wait_for_open_port("3022")
91+
92+ with subtest("check applied configuration"):
93+ server.wait_until_succeeds("tctl get nodes --format=json | ${pkgs.jq}/bin/jq -e '.[] | select(.spec.hostname==\"client\") | .metadata.labels.role==\"client\"'")
94+ server.wait_for_open_port("3000")
95+ client.succeed("journalctl -u teleport.service --grep='DEBU'")
96+ server.succeed("journalctl -u teleport.service --grep='Starting teleport in insecure mode.'")
97+ '';
98+ };
99+}
pkgs/servers/teleport/default.nix+3
@@ -6,6 +6,7 @@
66, protobuf
77, stdenv
88, xdg-utils
9+, nixosTests
910
1011, withRoleTester ? true
1112}:
@@ -95,6 +96,8 @@ buildGo117Module rec {
9596 $out/bin/teleport version | grep ${version} > /dev/null
9697 '';
9798
99+ passthru.tests = nixosTests.teleport;
100+
98101 meta = with lib; {
99102 description = "Certificate authority and access plane for SSH, Kubernetes, web applications, and databases";
100103 homepage = "https://goteleport.com/";