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

Update sshd configuration (UsePAM no, sshd_config.d) #148

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

jay7x
Copy link
Member

@jay7x jay7x commented Nov 19, 2024

There are 2 related changes:

  1. UsePAM is now disabled everywhere. It causes some hard to debug problems on CentOS9 and Fedora containers, when running on Ubuntu 24.04 host. It's somehow related to user namespaces, AppArmor and pam_unix (/etc/shadow access).
  2. As more and more distros adopts /etc/ssh/sshd_config.d directory for ssh configs, now Dockerfile overrides settings in those files as well.

Comment on lines 560 to 561
-e 's/^#?MaxAuthTries.*/MaxAuthTries 1000/' \
/etc/ssh/sshd_config
Copy link
Member

Choose a reason for hiding this comment

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

If you use xargs, you must drop the filename here:

Suggested change
-e 's/^#?MaxAuthTries.*/MaxAuthTries 1000/' \
/etc/ssh/sshd_config
-e 's/^#?MaxAuthTries.*/MaxAuthTries 1000/'

Having said that, you can simply use:

Suggested change
-e 's/^#?MaxAuthTries.*/MaxAuthTries 1000/' \
/etc/ssh/sshd_config
-e 's/^#?MaxAuthTries.*/MaxAuthTries 1000/' \
/etc/ssh/sshd_config /etc/ssh/sshd_config.d/*

When I run it locally it shows a warning, but still operates on the file.

$ echo UsePAM > ssh_test
$ sed -i 's/PAM/pam/' ssh_test ssh_test.d/*
sed: can't read ssh_test.d/*: No such file or directory
$ cat ssh_test 
Usepam

And ls will show the same warning, so it doesn't make a difference.

Copy link
Contributor

@vchepkov vchepkov Nov 19, 2024

Choose a reason for hiding this comment

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

what if replace it with find? don't need xargs then either

find  /etc/ssh/sshd_config /etc/ssh/sshd_config.d/ -type f -exec sed ...
{}\;

Copy link
Member

Choose a reason for hiding this comment

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

Or that, but ls is usually not the right tool to use.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, was committing in rush, so missed the 2>/dev/null after ls.

sed returns error code when file is missing. This breaks container build because of && between commands.

Copy link
Member Author

Choose a reason for hiding this comment

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

let me use find as suggested by @vchepkov then

There are 2 related changes:
1. UsePAM is now disabled everywhere. It causes some hard to debug
   problems on CentOS9 and Fedora containers, when running on Ubuntu
   24.04 host. It's somehow related to user namespaces, AppArmor and
   pam_unix (/etc/shadow access).
2. As more and more distros adopts /etc/ssh/sshd_config.d directory for
   ssh configs, now Dockerfile overrides settings in those files as
   well.
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Feel free to merge this without my suggestion.

-e 's/^#?MaxAuthTries.*/MaxAuthTries 1000/' \
/etc/ssh/sshd_config
{} \\;
Copy link
Member

Choose a reason for hiding this comment

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

Nit : GNU find also supports + instead of ; to run it xargs style. What I like about it is that it doesn't need escaping:

Suggested change
{} \\;
{} +

Copy link
Contributor

Choose a reason for hiding this comment

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

there is a difference though, + would put every file in the command line
maybe for inline sed it doesn't matter, not sure

Copy link
Member

Choose a reason for hiding this comment

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

You're right, but for sed is doesn't matter so it's actually more efficient when you don't have to start sed multiple times. In this case it really won't be noticeable, but there are cases where it can.

@bastelfreak
Copy link
Member

I'm going forward with merging this to unblock our pipelines.

@bastelfreak bastelfreak merged commit 4f9cfb2 into voxpupuli:master Nov 20, 2024
10 checks passed
@jay7x jay7x deleted the fix_ssh branch November 20, 2024 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants