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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

sshd service: Default to INFO logLevel (upstream default) #100255

Merged
merged 1 commit into from Jun 23, 2021

Conversation

@nh2
Copy link
Contributor

@nh2 nh2 commented Oct 11, 2020

Motivation for this change

This brings NixOS in line with upstream and other Linux distributions, and reduces log spam on servers due to bruteforcing botnets.

The previous justification (added in #40692) for using VERBOSE is incorrect, because OpenSSH does use level INFO to log "which key was used to log in" for sccessful logins, see:

https://github.com/openssh/openssh-portable/blob/6247812c76f70b2245f3c23f5074665b3d436cae/auth.c#L323-L328

I've verified it; sshd logs with VERBOSE look like:

sshd: Connection from 192.0.2.1 port 45668 on 192.0.2.2 port 22 rdomain ""
sshd: Accepted key RSA SHA256:Cabc123abc123abc12/abc123abc123abc123abc123 found at /etc/ssh/authorized_keys.d/root:1
sshd: Postponed publickey for root from 192.0.2.1 port 45668 ssh2 [preauth]
sshd: Accepted key RSA SHA256:Cabc123abc123abc12/abc123abc123abc123abc123 found at /etc/ssh/authorized_keys.d/root:1
sshd: Accepted publickey for root from 192.0.2.1 port 45668 ssh2: RSA SHA256:Cabc123abc123abc12/abc123abc123abc123abc123
sshd: pam_unix(sshd:session): session opened for user root by (uid=0)
systemd-logind: [馃] New session 12 of user root.

and with INFO look like:

sshd: Accepted publickey for root from 192.0.2.1 port 45694 ssh2: RSA SHA256:Cabc123abc123abc12/abc123abc123abc123abc123
sshd: pam_unix(sshd:session): session opened for user root by (uid=0)
systemd-logind: [馃] New session 12 of user root.

As shown, the fingerprint for the successful login is still printed with INFO.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • 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 nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

CC @bjornfor @volth @Izorkin from #40692.

CC recent sshd committers @aanderse @Infinisil @jeaye

CC @eelco @lovek323 @fpletz as fail2ban maintainers, and @c0bw3b @Baughn as recent fail2ban service committers.

@nh2 nh2 requested a review from Izorkin Oct 11, 2020
@nh2 nh2 self-assigned this Oct 11, 2020
@nh2
Copy link
Contributor Author

@nh2 nh2 commented Oct 11, 2020

I got the bit about fail2ban from https://wiki.archlinux.org/index.php/fail2ban#Custom_SSH_jail which says:

It may be necessary to set LogLevel VERBOSE in /etc/ssh/sshd_config to allow full fail2ban monitoring as otherwise password failures may not be logged correctly.

On the motivation of the change, I believe that following the OpenSSH upstream default should take precedence over making OpenSSH play well with fail2ban out-of-the-box.

If we instead concluded that we should keep a higher default SSH log level to benefit fail2ban, then we should document that in the sshd options.

@Izorkin
Copy link
Contributor

@Izorkin Izorkin commented Oct 11, 2020

Also try adding to fail2ban service this variant - services.openssh.logLevel = mkDefault "VERBOSE";

Copy link
Contributor

@aneeshusa aneeshusa left a comment

SGTM as openssh maintainer though I didn't test

nixos/modules/services/networking/ssh/sshd.nix Outdated Show resolved Hide resolved
@nh2 nh2 force-pushed the sshd-default-log-level-info branch from 2d84df0 to afb7b56 Oct 11, 2020
@nh2 nh2 force-pushed the sshd-default-log-level-info branch from afb7b56 to c6840c8 Nov 8, 2020
@nh2
Copy link
Contributor Author

@nh2 nh2 commented Nov 8, 2020

Also try adding to fail2ban service this variant - services.openssh.logLevel = mkDefault "VERBOSE";

@Izorkin Nice idea, I implemented that.

I'll wait another half-a-month in case more feedback arrives, after that I'll probably merge it.

Izorkin
Izorkin approved these changes Nov 8, 2020
The previous justification for using "VERBOSE" is incorrect,
because OpenSSH does use level INFO to log "which key was used
to log in" for sccessful logins, see:
https://github.com/openssh/openssh-portable/blob/6247812c76f70b2245f3c23f5074665b3d436cae/auth.c#L323-L328

Also update description to the wording of the sshd_config man page.

`fail2ban` needs, sshd to be "VERBOSE" to work well, thus
the `fail2ban` module sets it to "VERBOSE" if enabled.

The docs are updated accordingly.
@nh2 nh2 force-pushed the sshd-default-log-level-info branch from c6840c8 to a48fea4 Jun 22, 2021
@nh2 nh2 requested a review from ryantm as a code owner Jun 22, 2021
@nh2
Copy link
Contributor Author

@nh2 nh2 commented Jun 22, 2021

I fixed the merge conflicts and squashed the commits, as they better fit into one.

@nh2 nh2 merged commit 959c4e8 into NixOS:master Jun 23, 2021
21 checks passed
@aanderse
Copy link
Member

@aanderse aanderse commented Jun 23, 2021

Thanks @nh2!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants