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

[wip] telnetd: init module #40160

Closed
wants to merge 6 commits into from
Closed

[wip] telnetd: init module #40160

wants to merge 6 commits into from

Conversation

teto
Copy link
Member

@teto teto commented May 8, 2018

Motivation for this change

I am trying to package mininet, which I believe rely on mininet.
Eitherway it doesn't hurt to have a telnet module.

It doesn't seem to work though, I can't connect to it via telnet 127.0.0.1. journalctl -b doesn't show any error. I wonder if that's firewall related

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: telnet

Partial log (click to expand)

these paths will be fetched (0.07 MiB download, 0.18 MiB unpacked):
  /nix/store/fhrlryhspp3f5rhkp1mi1m4yzx4czrr8-telnet-1.2
copying path '/nix/store/fhrlryhspp3f5rhkp1mi1m4yzx4czrr8-telnet-1.2' from 'https://cache.nixos.org'...
/nix/store/fhrlryhspp3f5rhkp1mi1m4yzx4czrr8-telnet-1.2

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: telnet

Partial log (click to expand)

these paths will be fetched (0.06 MiB download, 0.18 MiB unpacked):
  /nix/store/gs2l6q78kjp08r7z783p1xck24c8hx08-telnet-1.2
copying path '/nix/store/gs2l6q78kjp08r7z783p1xck24c8hx08-telnet-1.2' from 'https://cache.nixos.org'...
/nix/store/gs2l6q78kjp08r7z783p1xck24c8hx08-telnet-1.2

networking.firewall.allowedUDPPorts = [ cfg.port ];

users.extraUsers.telnetd.uid = config.ids.uids.telnetd;
users.extraGroups.telnetd.gid = config.ids.gids.telnetd;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does telnet need static id?

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't I guess. I copied other modules but why do other services need a static id either ?

Copy link
Member

@Mic92 Mic92 May 8, 2018

Choose a reason for hiding this comment

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

They need static uids to avoid having to adjust the owner of large amount of files on service startup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but does telnet create any files of its own?

Copy link
Member Author

Choose a reason for hiding this comment

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

not that I know


config = mkIf config.services.telnet.enable {

networking.firewall.allowedUDPPorts = [ cfg.port ];
Copy link
Member

Choose a reason for hiding this comment

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

Should this not be tcp?

Copy link
Member

Choose a reason for hiding this comment

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

Firewall ports should not be opened by default. Please add a dedicated option for that: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/networking/ssh/sshd.nix#L140

Copy link
Member Author

Choose a reason for hiding this comment

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

it should ! still remember the nagle lesson with telnet thanks

Copy link
Member Author

Choose a reason for hiding this comment

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

The option on the link you mention defaults to true so it doesn't add much security :s

Copy link
Member

Choose a reason for hiding this comment

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

yes. ssh is the only service where we make it true by default. All other services defaults to false.

Copy link
Member

Choose a reason for hiding this comment

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

This is a convention we have for nixos and exception might surprise users.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok I fixed it

};

port = mkOption {
default = 12345;
Copy link
Member

Choose a reason for hiding this comment

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

default port for telnet is 23.

default = false;
type = types.bool;
description = ''
Enable telnetd.
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if we should put a warning here since due missing encryption telnet should be only used in trusted networks. Also your mininet example might be about man-in-the-middle attacks on telnet.

@teto
Copy link
Member Author

teto commented May 8, 2018

It doesn't seem to bind though I gave the module CAP_NET_BIND_SERVICE capability (later tried with =+ep)
telnetd[28847]: bind: Permission denied

@@ -307,6 +307,7 @@
duplicati = 289;
monetdb = 290;
restic = 291;
telnetd = 292;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not used anymore

@matthewbauer
Copy link
Member

@GrahamcOfBorg eval

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: telnet

Partial log (click to expand)

these paths will be fetched (0.06 MiB download, 0.18 MiB unpacked):
  /nix/store/gs2l6q78kjp08r7z783p1xck24c8hx08-telnet-1.2
copying path '/nix/store/gs2l6q78kjp08r7z783p1xck24c8hx08-telnet-1.2' from 'https://cache.nixos.org'...
/nix/store/gs2l6q78kjp08r7z783p1xck24c8hx08-telnet-1.2

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: telnet

Partial log (click to expand)

/nix/store/fhrlryhspp3f5rhkp1mi1m4yzx4czrr8-telnet-1.2

@teto
Copy link
Member Author

teto commented May 9, 2018

for some reason telnetd can't bind even though it has the capability and though I set Restart="always", the service won't restart on nixos-rebuild so it's not easy to test. It seems like busybox binds to ipv6 first so I added (locally a -b 127.0.0.1)

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: telnet

Partial log (click to expand)

/nix/store/gs2l6q78kjp08r7z783p1xck24c8hx08-telnet-1.2

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: telnet

Partial log (click to expand)

/nix/store/fhrlryhspp3f5rhkp1mi1m4yzx4czrr8-telnet-1.2

@teto teto changed the title telnetd: init module [wip] telnetd: init module May 14, 2018
@Mic92
Copy link
Member

Mic92 commented May 14, 2018

The problem was that telnetd was forking:

Either use Type=forking or pass the -F flag to telnetd:

diff --git a/nixos/modules/services/web-servers/telnet.nix b/nixos/modules/services/web-servers/telnet.nix
index ce21c480794..7fc527e42c9 100644
--- a/nixos/modules/services/web-servers/telnet.nix
+++ b/nixos/modules/services/web-servers/telnet.nix
@@ -4,11 +4,7 @@ with lib;
 
 let
   cfg = config.services.telnet;
-
-  user = "telnetd";
-in
-{
-
+in {
   options.services.telnet = {
 
     enable = mkOption {
@@ -42,34 +38,24 @@ in
     networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
 
     users.extraUsers = singleton {
-      name = user;
+      name = "telnetd";
       group = "telnetd";
       description = "Telnet daemon";
     };
 
-    # users.extraGroups = singleton {
-    #   name = "telnetd";
-    # };
+    users.extraGroups = singleton {
+      name = "telnetd";
+    };
 
     systemd.services.telnetd = {
       description = "Telnet server";
       wantedBy = [ "multi-user.target" ];
 
-      # binds by default to ipv6 ?
-      # script = "${pkgs.busybox}/bin/telnetd -p ${toString cfg.port} -b 127.0.0.1";
-
       serviceConfig = {
-        # defaults to ipv6 otherwise ?
-        ExecStart="${pkgs.busybox}/bin/telnetd -p ${toString cfg.port} -b 127.0.0.1";
-        User = user;
+        ExecStart="${pkgs.busybox}/bin/telnetd -p ${toString cfg.port} -F";
+        User = "telnetd";
         Group = "telnetd";
-        AmbientCapabilities="CAP_NET_BIND_SERVICE";
-        CapabilityBoundingSet = "CAP_NET_BIND_SERVICE=+eip";
-        # RuntimeDirectory = [ "telnetd" ];
-        Restart = "always";
-        RestartSec = "500ms";
-        # StartLimitInterval = 86400;
-        StartLimitBurst = 5;
+        AmbientCapabilities = "cap_net_bind_service";
       };
     };
   };

However I still cannot login.

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: telnet

Partial log (click to expand)

these paths will be fetched (0.06 MiB download, 0.18 MiB unpacked):
  /nix/store/gs2l6q78kjp08r7z783p1xck24c8hx08-telnet-1.2
copying path '/nix/store/gs2l6q78kjp08r7z783p1xck24c8hx08-telnet-1.2' from 'https://cache.nixos.org'...
/nix/store/gs2l6q78kjp08r7z783p1xck24c8hx08-telnet-1.2

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: telnet

Partial log (click to expand)

these paths will be fetched (0.07 MiB download, 0.18 MiB unpacked):
  /nix/store/fhrlryhspp3f5rhkp1mi1m4yzx4czrr8-telnet-1.2
copying path '/nix/store/fhrlryhspp3f5rhkp1mi1m4yzx4czrr8-telnet-1.2' from 'https://cache.nixos.org'...
/nix/store/fhrlryhspp3f5rhkp1mi1m4yzx4czrr8-telnet-1.2

@Mic92
Copy link
Member

Mic92 commented May 15, 2018

I was not able to login though. It kept closing my connection without logging useful information. I am also not sure how this is supposed to work. Because the user is running as telnetd it should not be possible to give me a shell for a different user.

@teto
Copy link
Member Author

teto commented May 15, 2018

The push was just to sync my computers sry xD
The -F flag refers to some 3rd party software forauthentication so I prefered to use the forking mechanism. I can't login either and I see nothing in journalctl -b telnetd.

It appears I don't really need this immediately so I'll put it on hold.

@matthewbauer
Copy link
Member

Is busybox the right place to get telnetd? Inetutils also has it.

@teto
Copy link
Member Author

teto commented Jun 25, 2018

closing since it doesn't seem like a hard requirement for mininet (my initial motivation) and I can't make it work. thanks for the comments, hopefully someone will pick it up.

@teto teto closed this Jun 25, 2018
@teto teto mentioned this pull request May 25, 2019
@teto teto deleted the telnet branch September 24, 2023 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants