Skip to content

net-misc/openssh*: Add no-subsystems USE flag#31615

Closed
krnowak wants to merge 2 commits intogentoo:masterfrom
flatcar-hub:krnowak/openssh-no-subsystem
Closed

net-misc/openssh*: Add no-subsystems USE flag#31615
krnowak wants to merge 2 commits intogentoo:masterfrom
flatcar-hub:krnowak/openssh-no-subsystem

Conversation

@krnowak
Copy link
Copy Markdown
Contributor

@krnowak krnowak commented Jun 26, 2023

  • Fix permissions of the daemon drop-ins directory and files inside it. They should be accessible only for root.

  • Put the Insert option before options that introduce conditional blocks to avoid having the drop-in files to be included conditionally. For client configs the options that introduce such blocks are Match and Host options, for daemon configs it is the Match option.

  • Move the Subsystem option out of the toplevel daemon config into a separate drop-in. That way we can add the drop-in into INSTALL_MASK if we want to provide custom drop-in with a different settings for subsystems. This is necessary as there is no way to override a once-specified subsystem - doing so results in daemon printing an error and quitting.

Bug: https://bugs.gentoo.org/906639
Bug: https://bugs.gentoo.org/907068
Signed-off-by: Krzesimir Nowak knowak@microsoft.com

The diffs between the ebuilds are (for net-misc/openssh, the contrib package has mostly the same diff):

22c22
< KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~loong ~m68k ~mips ppc ppc64 ~riscv ~s390 sparc x86 ~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris"
---
> KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris"
229a230,262
> insert_include() {
> 	local src_config=${1}
> 	local options=${2}
> 	local includedir=${3}
> 	local name copy regexp_options regexp lineno comment_options
> 
> 	name=${src_config##*/}
> 	copy="${T}/${name}"
> 	cp -a "${src_config}" "${copy}"
> 
> 	# Catch "Option ", "#Option " or "# Option ".
> 	regexp_options=${options//,/'\|'}
> 	regexp='^[[:space:]]*#\?[[:space:]]*\('"${regexp_options}"'\)[[:space:]]'
> 	{ grep -ne "${regexp}" -m 1 "${copy}" || die; } | cut -d : -f 1 >"${T}/lineno"
> 	lineno=$(<"${T}"/lineno)
> 	rm -f "${T}/lineno"
> 	# We have found a first line with the option, now find a first
> 	# non-comment line just above the comments of the option.
> 	lineno=$(head -n "${lineno}" "${copy}" | grep -ne '^[[:space:]]*\([^#]\|$\)' | tail -n 1 | cut -d : -f 1)
> 
> 	comment_options=${options//,/ or }
> 	{
> 		head -n $((lineno)) "${copy}"
> 		cat <<-EOF || die
> 		# Make sure that all ${comment_options} options are below this Include!
> 		Include "${EPREFIX}/${includedir}/*.conf"
> 
> 		EOF
> 		tail -n "+${lineno}" "${copy}"
> 	} >"${src_config}"
> 	rm -f "${copy}"
> }
> 
243,248c276,278
< 	cat <<-EOF >> "${ED}"/etc/ssh/ssh_config || die
< 	Include "${EPREFIX}/etc/ssh/ssh_config.d/*.conf"
< 	EOF
< 	cat <<-EOF >> "${ED}"/etc/ssh/sshd_config || die
< 	Include "${EPREFIX}/etc/ssh/sshd_config.d/*.conf"
< 	EOF
---
> 
> 	insert_include "${ED}"/etc/ssh/ssh_config 'Host,Match' '/etc/ssh/ssh_config.d'
> 	insert_include "${ED}"/etc/ssh/sshd_config 'Match' '/etc/ssh/sshd_config.d'
266a297,300
> 	# Move sshd's Subsystem option to a drop-in file.
> 	grep -ie 'subsystem' "${ED}"/etc/ssh/sshd_config >"${ED}"/etc/ssh/sshd_config.d/9999999gentoo-subsystem.conf || die
> 	sed -i -e '/[Ss]ubsystem/d' "${ED}"/etc/ssh/sshd_config
> 
291a326,329
> 
> 	local sshd_drop_ins=("${ED}"/etc/ssh/sshd_config.d/*.conf)
> 	fperms 0700 /etc/ssh/sshd_config.d
> 	fperms 0600 "${sshd_drop_ins[@]#${ED}}"

@gentoo-bot
Copy link
Copy Markdown

Pull Request assignment

Submitter: @krnowak
Areas affected: ebuilds
Packages affected: net-misc/openssh, net-misc/openssh-contrib

net-misc/openssh: @gentoo/base-system
net-misc/openssh-contrib: @chutz, @robbat2

Linked bugs

No bugs to link found. If your pull request references any of the Gentoo bug reports, please add appropriate GLEP 66 tags to the commit message and request reassignment.

If you do not receive any reply to this pull request, please open or link a bug to attract the attention of maintainers.


In order to force reassignment and/or bug reference scan, please append [please reassign] to the pull request title.

Docs: Code of ConductCopyright policy (expl.) ● DevmanualGitHub PRsProxy-maint guide

@gentoo-bot gentoo-bot added assigned PR successfully assigned to the package maintainer(s). no bug found No Bug/Closes found in the commits. labels Jun 26, 2023
@gentoo-repo-qa-bot
Copy link
Copy Markdown
Collaborator

Pull request CI report

Report generated at: 2023-06-26 11:55 UTC
Newest commit scanned: 9f6b424
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/7e218f3b17/output.html

@thesamesam
Copy link
Copy Markdown
Member

Thanks!

On IRC, we discussed this a bit. @chutz is fine with the idea, I felt a little bit uneasy about the USE flag for it if there's no better option. @floppym suggested we do this w/ a config patch:

Could possibly move the default Subsystem sftp to a drop-in that they could INSTALL_MASK.

Aside, it might be worth us considering while here:

@krnowak
Copy link
Copy Markdown
Contributor Author

krnowak commented Jun 29, 2023

Thanks!

On IRC, we discussed this a bit. @chutz is fine with the idea, I felt a little bit uneasy about the USE flag for it if there's no better option. @floppym suggested we do this w/ a config patch:

Could possibly move the default Subsystem sftp to a drop-in that they could INSTALL_MASK.

That would work for Flatcar too, and it wouldn't involve the USE flag. I'll update the PR.

Aside, it might be worth us considering while here:

I'll try fixing those as well.

@krnowak krnowak force-pushed the krnowak/openssh-no-subsystem branch 2 times, most recently from f5470d3 to 51d8feb Compare June 29, 2023 11:44
@gentoo-repo-qa-bot
Copy link
Copy Markdown
Collaborator

Pull request CI report

Report generated at: 2023-06-29 11:45 UTC
Newest commit scanned: f5470d3
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/58182b0814/output.html

@krnowak krnowak force-pushed the krnowak/openssh-no-subsystem branch from 51d8feb to 18f7ab1 Compare June 29, 2023 11:47
@gentoo-repo-qa-bot
Copy link
Copy Markdown
Collaborator

Pull request CI report

Report generated at: 2023-06-29 12:00 UTC
Newest commit scanned: 18f7ab1
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/7791a7fe96/output.html

@krnowak krnowak force-pushed the krnowak/openssh-no-subsystem branch 2 times, most recently from 93ba7f2 to a7e1561 Compare June 29, 2023 12:09
@krnowak
Copy link
Copy Markdown
Contributor Author

krnowak commented Jun 29, 2023

Please have a look. Thanks.

@gentoo-repo-qa-bot
Copy link
Copy Markdown
Collaborator

Pull request CI report

Report generated at: 2023-06-29 12:15 UTC
Newest commit scanned: 93ba7f2
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/4547a742ae/output.html

@gentoo-repo-qa-bot
Copy link
Copy Markdown
Collaborator

Pull request CI report

Report generated at: 2023-06-29 12:45 UTC
Newest commit scanned: a7e1561
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/957310c534/output.html

@krnowak
Copy link
Copy Markdown
Contributor Author

krnowak commented Jun 29, 2023

For the record:

  • permissions now (note also the new gentoo-subsystems.conf file):
-rw------- 1 root root 3139 Jun 29 12:45 <ROOTFS>/etc/ssh/sshd_config
drwx------ 2 root root 4096 Jun 29 12:45 <ROOTFS>/etc/ssh/sshd_config.d
-rw------- 1 root root   79 Jun 29 12:45 <ROOTFS>/etc/ssh/sshd_config.d/9999999gentoo-subsystem.conf
-rw------- 1 root root  316 Jun 29 12:45 <ROOTFS>/etc/ssh/sshd_config.d/9999999gentoo.conf
  • relevant sshd config fragment (subsystems gone, include moved before the Match example):
…
#VersionAddendum none

# no default banner path
#Banner none


# Make sure that all Match options are below this Include!
Include "//etc/ssh/sshd_config.d/*.conf"


# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
…

(the double slash here is a bit jarring, probably could be fixed with "${ED%/}" or something)

  • relevant ssh config fragment:
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.

# Make sure that all Host or Match options are below this Include!
Include "//etc/ssh/ssh_config.d/*.conf"


# Site-wide defaults for some commonly used options.  For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

# Host *
#   ForwardAgent no
#   ForwardX11 no

(Include placement is not perfect, should be over the "Site-wide defaults" comment, meh.) (fixed)

  • contents of 9999999gentoo-subsystem.conf:
# override default of no subsystems
Subsystem	sftp	/usr/lib64/misc/sftp-server

@krnowak krnowak force-pushed the krnowak/openssh-no-subsystem branch from a7e1561 to 533feba Compare June 29, 2023 14:51
@gentoo-repo-qa-bot
Copy link
Copy Markdown
Collaborator

Pull request CI report

Report generated at: 2023-06-29 15:20 UTC
Newest commit scanned: 533feba
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/805ae38ce7/output.html

insert_include() {
local src_config=${1}
local options=${2}
local includedir=${3}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I find it a bit easier to read with these on a single line, though that is just cosmetic.


name=${src_config##*/}
copy="${T}/${name}"
cp -a "${src_config}" "${copy}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pleas add || die to the end of this, since there is nothing catching if this fails

regexp='^[[:space:]]*#\?[[:space:]]*\('"${regexp_options}"'\)[[:space:]]'
{ grep -ne "${regexp}" -m 1 "${copy}" || die; } | cut -d : -f 1 >"${T}/lineno"
lineno=$(<"${T}"/lineno)
rm -f "${T}/lineno"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than writing to a file, then reading and deleting the file, you could do this in one line with a process substitution. You can also use pipefail in the process substitution to catch the failure (you aren't catching a failure in the cut command above). Something like this:

lineno=$(set -o pipefail; grep -ne "${regexp}" -m 1 "${copy}" | cut -d : -f 1 || die)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wrote it in such a convoluted way, because I wanted to make sure that if grep fails, the build fails. But I didn't know that die kills the build even if called from the subshell. I'll rewrite it.

EOF
tail -n "+${lineno}" "${copy}"
} >"${src_config}"
rm -f "${copy}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is probably not entirely necessary as ${T} gets removed at the end of the merge, however if you are going to call rm, use a || die

Include "${EPREFIX}/${includedir}/*.conf"

EOF
tail -n "+${lineno}" "${copy}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These commands should have || die after them (the head, and tail)

# non-comment line just above the comments of the option. The
# lineno - 2 is here to ignore the line just above the option
# in case the comment block is separated by an empty line.
lineno=$(head -n $((lineno - 2)) "${copy}" | grep -ne '^[[:space:]]*\([^#]\|$\)' | tail -n 1 | cut -d : -f 1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably want a || die in here, see the example with set -o pipefail above.

@krnowak krnowak force-pushed the krnowak/openssh-no-subsystem branch from 533feba to 49dbb3c Compare June 30, 2023 05:32
@krnowak
Copy link
Copy Markdown
Contributor Author

krnowak commented Jun 30, 2023

Addressed the issues and rebased to master.

@gentoo-repo-qa-bot
Copy link
Copy Markdown
Collaborator

Pull request CI report

Report generated at: 2023-06-30 05:45 UTC
Newest commit scanned: 49dbb3c
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/0b74c7ce14/output.html

@krnowak krnowak requested a review from chutz July 4, 2023 05:59
krnowak added a commit to flatcar/scripts that referenced this pull request Jul 5, 2023
- Mark the package as stable.
- Remove the socket unit's rate limiting.
- Fixes to configuration handling. We are trying to upstream these
  changes, so this package will be eventually moved to
  portage-stable. But updating it in coreos-overlay for now to drop
  the use of the obsolete cygwin USE flags.

Upstream PR: gentoo/gentoo#31615
krnowak added a commit to flatcar/scripts that referenced this pull request Jul 7, 2023
- Mark the package as stable.
- Remove the socket unit's rate limiting.
- Fixes to configuration handling. We are trying to upstream these
  changes, so this package will be eventually moved to
  portage-stable. But updating it in coreos-overlay for now to drop
  the use of the obsolete cygwin USE flags.

Upstream PR: gentoo/gentoo#31615
dongsupark pushed a commit to flatcar/scripts that referenced this pull request Jul 27, 2023
- Mark the package as stable.
- Remove the socket unit's rate limiting.
- Fixes to configuration handling. We are trying to upstream these
  changes, so this package will be eventually moved to
  portage-stable. But updating it in coreos-overlay for now to drop
  the use of the obsolete cygwin USE flags.

Upstream PR: gentoo/gentoo#31615
@krnowak krnowak force-pushed the krnowak/openssh-no-subsystem branch from 49dbb3c to d42ed1d Compare July 28, 2023 09:59
@krnowak
Copy link
Copy Markdown
Contributor Author

krnowak commented Jul 28, 2023

Updated to base my changes on top of new 9.3_p2 ebuilds.

@krnowak
Copy link
Copy Markdown
Contributor Author

krnowak commented Jul 28, 2023

@krnowak could you post a fresh diff of the ebuilds please (the vanilla one is fine)?

Meh, I wanted to update it, but something must have distracted me, sorry about that. Thanks for reminding.

Here goes for openssh (diff openssh-9.3_p2.ebuild openssh-9.3_p2-r1.ebuild):

22c22
< KEYWORDS="~alpha amd64 arm arm64 hppa ~ia64 ~loong ~m68k ~mips ppc ppc64 ~riscv ~s390 sparc x86 ~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris"
---
> KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~arm64-macos ~ppc-macos ~x64-macos ~x64-solaris"
229a230,260
> insert_include() {
> 	local src_config=${1} options=${2} includedir=${3}
> 	local name copy regexp_options regexp lineno comment_options
> 
> 	name=${src_config##*/}
> 	copy="${T}/${name}"
> 	cp -a "${src_config}" "${copy}" || die
> 
> 	# Catch "Option ", "#Option " or "# Option ".
> 	regexp_options=${options//,/'\|'}
> 	regexp='^[[:space:]]*#\?[[:space:]]*\('"${regexp_options}"'\)[[:space:]]'
> 	lineno=$(set -o pipefail; grep -ne "${regexp}" -m 1 "${copy}" | cut -d : -f 1 || die)
> 	# We have found a first line with the option, now find a first
> 	# non-comment line just above the comments of the option. The
> 	# lineno - 2 is here to ignore the line just above the option
> 	# in case the comment block is separated by an empty line.
> 	lineno=$(set -o pipefail; head -n $((lineno - 2)) "${copy}" | grep -ne '^[[:space:]]*\([^#]\|$\)' | tail -n 1 | cut -d : -f 1 || die)
> 
> 	comment_options=${options//,/ or }
> 	{
> 		head -n "${lineno}" "${copy}" || die
> 		cat <<-EOF || die
> 		# Make sure that all ${comment_options} options are below this Include!
> 		Include "${EPREFIX}/${includedir}/*.conf"
> 
> 		EOF
> 		tail -n "+${lineno}" "${copy}" || die
> 	} >"${src_config}"
> 	rm -f "${copy}" || die
> }
> 
243,248c274,276
< 	cat <<-EOF >> "${ED}"/etc/ssh/ssh_config || die
< 	Include "${EPREFIX}/etc/ssh/ssh_config.d/*.conf"
< 	EOF
< 	cat <<-EOF >> "${ED}"/etc/ssh/sshd_config || die
< 	Include "${EPREFIX}/etc/ssh/sshd_config.d/*.conf"
< 	EOF
---
> 
> 	insert_include "${ED}"/etc/ssh/ssh_config 'Host,Match' '/etc/ssh/ssh_config.d'
> 	insert_include "${ED}"/etc/ssh/sshd_config 'Match' '/etc/ssh/sshd_config.d'
266a295,298
> 	# Move sshd's Subsystem option to a drop-in file.
> 	grep -ie 'subsystem' "${ED}"/etc/ssh/sshd_config >"${ED}"/etc/ssh/sshd_config.d/9999999gentoo-subsystem.conf || die
> 	sed -i -e '/[Ss]ubsystem/d' "${ED}"/etc/ssh/sshd_config
> 
291a324,327
> 
> 	local sshd_drop_ins=("${ED}"/etc/ssh/sshd_config.d/*.conf)
> 	fperms 0700 /etc/ssh/sshd_config.d
> 	fperms 0600 "${sshd_drop_ins[@]#${ED}}"

openssh-contrib is the same (diff openssh-contrib-9.3_p2.ebuild openssh-contrib-9.3_p2-r1.ebuild):

342a343,373
> insert_include() {
> 	local src_config=${1} options=${2} includedir=${3}
> 	local name copy regexp_options regexp lineno comment_options
> 
> 	name=${src_config##*/}
> 	copy="${T}/${name}"
> 	cp -a "${src_config}" "${copy}" || die
> 
> 	# Catch "Option ", "#Option " or "# Option ".
> 	regexp_options=${options//,/'\|'}
> 	regexp='^[[:space:]]*#\?[[:space:]]*\('"${regexp_options}"'\)[[:space:]]'
> 	lineno=$(set -o pipefail; grep -ne "${regexp}" -m 1 "${copy}" | cut -d : -f 1 || die)
> 	# We have found a first line with the option, now find a first
> 	# non-comment line just above the comments of the option. The
> 	# lineno - 2 is here to ignore the line just above the option
> 	# in case the comment block is separated by an empty line.
> 	lineno=$(set -o pipefail; head -n $((lineno - 2)) "${copy}" | grep -ne '^[[:space:]]*\([^#]\|$\)' | tail -n 1 | cut -d : -f 1 || die)
> 
> 	comment_options=${options//,/ or }
> 	{
> 		head -n "${lineno}" "${copy}" || die
> 		cat <<-EOF || die
> 		# Make sure that all ${comment_options} options are below this Include!
> 		Include "${EPREFIX}/${includedir}/*.conf"
> 
> 		EOF
> 		tail -n "+${lineno}" "${copy}" || die
> 	} >"${src_config}"
> 	rm -f "${copy}" || die
> }
> 
356,361c387,389
< 	cat <<-EOF >> "${ED}"/etc/ssh/ssh_config || die
< 	Include "${EPREFIX}/etc/ssh/ssh_config.d/*.conf"
< 	EOF
< 	cat <<-EOF >> "${ED}"/etc/ssh/sshd_config || die
< 	Include "${EPREFIX}/etc/ssh/sshd_config.d/*.conf"
< 	EOF
---
> 
> 	insert_include "${ED}"/etc/ssh/ssh_config 'Host,Match' '/etc/ssh/ssh_config.d'
> 	insert_include "${ED}"/etc/ssh/sshd_config 'Match' '/etc/ssh/sshd_config.d'
379a408,411
> 	# Move sshd's Subsystem option to a drop-in file.
> 	grep -ie 'subsystem' "${ED}"/etc/ssh/sshd_config >"${ED}"/etc/ssh/sshd_config.d/9999999gentoo-subsystem.conf || die
> 	sed -i -e '/[Ss]ubsystem/d' "${ED}"/etc/ssh/sshd_config
> 
404a437,440
> 
> 	local sshd_drop_ins=("${ED}"/etc/ssh/sshd_config.d/*.conf)
> 	fperms 0700 /etc/ssh/sshd_config.d
> 	fperms 0600 "${sshd_drop_ins[@]#${ED}}"

dongsupark pushed a commit to flatcar/scripts that referenced this pull request Jul 28, 2023
- Mark the package as stable.
- Remove the socket unit's rate limiting.
- Fixes to configuration handling. We are trying to upstream these
  changes, so this package will be eventually moved to
  portage-stable. But updating it in coreos-overlay for now to drop
  the use of the obsolete cygwin USE flags.

Upstream PR: gentoo/gentoo#31615
dongsupark pushed a commit to flatcar/scripts that referenced this pull request Jul 28, 2023
- Mark the package as stable.
- Remove the socket unit's rate limiting.
- Fixes to configuration handling. We are trying to upstream these
  changes, so this package will be eventually moved to
  portage-stable. But updating it in coreos-overlay for now to drop
  the use of the obsolete cygwin USE flags.

Upstream PR: gentoo/gentoo#31615
dongsupark pushed a commit to flatcar/scripts that referenced this pull request Jul 28, 2023
- Mark the package as stable.
- Remove the socket unit's rate limiting.
- Fixes to configuration handling. We are trying to upstream these
  changes, so this package will be eventually moved to
  portage-stable. But updating it in coreos-overlay for now to drop
  the use of the obsolete cygwin USE flags.

Upstream PR: gentoo/gentoo#31615
@krnowak krnowak force-pushed the krnowak/openssh-no-subsystem branch from d42ed1d to 42130ac Compare August 8, 2023 17:44
@gentoo-repo-qa-bot
Copy link
Copy Markdown
Collaborator

Pull request CI report

Report generated at: 2023-08-08 17:56 UTC
Newest commit scanned: 42130ac
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/294823753e/output.html

@krnowak krnowak force-pushed the krnowak/openssh-no-subsystem branch from 42130ac to 52b1841 Compare September 25, 2023 14:29
@gentoo-repo-qa-bot
Copy link
Copy Markdown
Collaborator

Pull request CI report

Report generated at: 2023-09-25 14:40 UTC
Newest commit scanned: 52b1841
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/7297a9d179/output.html

krnowak added a commit to flatcar/scripts that referenced this pull request Sep 25, 2023
None of these modifications are Flatcar-specific. We are trying to
upstream them in gentoo/gentoo#31615. When
they reach Gentoo, we can move net-misc/openssh to portage-stable.
krnowak added a commit to flatcar/scripts that referenced this pull request Sep 26, 2023
None of these modifications are Flatcar-specific. We are trying to
upstream them in gentoo/gentoo#31615. When
they reach Gentoo, we can move net-misc/openssh to portage-stable.
krnowak added a commit to flatcar/scripts that referenced this pull request Sep 26, 2023
None of these modifications are Flatcar-specific. We are trying to
upstream them in gentoo/gentoo#31615. When
they reach Gentoo, we can move net-misc/openssh to portage-stable.
krnowak added a commit to flatcar/scripts that referenced this pull request Sep 28, 2023
None of these modifications are Flatcar-specific. We are trying to
upstream them in gentoo/gentoo#31615. When
they reach Gentoo, we can move net-misc/openssh to portage-stable.
krnowak added a commit to flatcar/scripts that referenced this pull request Sep 29, 2023
None of these modifications are Flatcar-specific. We are trying to
upstream them in gentoo/gentoo#31615. When
they reach Gentoo, we can move net-misc/openssh to portage-stable.
krnowak added a commit to flatcar/scripts that referenced this pull request Oct 11, 2023
None of these modifications are Flatcar-specific. We are trying to
upstream them in gentoo/gentoo#31615. When
they reach Gentoo, we can move net-misc/openssh to portage-stable.

An exception from above paragraph is marking the ebuild as stable on
amd64 and arm64.
krnowak added a commit to flatcar/scripts that referenced this pull request Jan 5, 2024
None of these modifications are Flatcar-specific. We are trying to
upstream them in gentoo/gentoo#31615. When
they reach Gentoo, we can move net-misc/openssh to portage-stable.

An exception from above paragraph is marking the ebuild as stable on
amd64 and arm64.
krnowak added a commit to flatcar/scripts that referenced this pull request Mar 22, 2024
None of these modifications are Flatcar-specific. We are trying to
upstream them in gentoo/gentoo#31615. When
they reach Gentoo, we can move net-misc/openssh to portage-stable.

An exception from above paragraph is marking the ebuild as stable on
amd64 and arm64.
chewi added a commit to flatcar-hub/gentoo that referenced this pull request May 17, 2024
- Put the Insert option before options that introduce conditional
  blocks to avoid having the drop-in files to be included
  conditionally. For client configs the options that introduce such
  blocks are Match and Host options, for daemon configs it is the
  Match option.

- Move the Subsystem option out of the toplevel daemon config into a
  separate drop-in. That way we can add the drop-in into INSTALL_MASK
  if we want to provide custom drop-in with a different settings for
  subsystems. This is necessary as there is no way to override a
  once-specified subsystem - doing so results in daemon printing an
  error and quitting.

Bug: https://bugs.gentoo.org/907068
Co-authored-by: James Le Cuirot <chewi@gentoo.org>
Signed-off-by: Krzesimir Nowak <knowak@microsoft.com>
Closes: gentoo#31615
Signed-off-by: James Le Cuirot <chewi@gentoo.org>
@chewi chewi force-pushed the krnowak/openssh-no-subsystem branch from 52b1841 to e320d3f Compare May 17, 2024 14:50
@chewi
Copy link
Copy Markdown
Member

chewi commented May 17, 2024

I've reworked this to use sed, which is a lot simpler, although I'm open to using a patch instead. The permissions issue has already been resolved in the meantime. Please see what you think.

--- openssh-9.7_p1-r2.ebuild    2024-04-18 18:07:48.688948905 +0100
+++ openssh-9.7_p1-r3.ebuild    2024-05-17 15:11:57.455234035 +0100
@@ -217,15 +217,21 @@
        econf "${myconf[@]}"
 }
 
-tweak_ssh_configs() {
-       cat <<-EOF >> ssh_config.out || die
+insert_include() {
+       local file=${1} options=${2} includedir=${3}
 
-       Include "${EPREFIX}/etc/ssh/ssh_config.d/*.conf"
+       local snippet=$(cat <<-EOF || die
+       # Make sure that all ${options//,/ or } options are below this Include!
+       Include "${includedir}/*.conf"
        EOF
-       cat <<-EOF >> sshd_config.out || die
+       )
 
-       Include "${EPREFIX}/etc/ssh/sshd_config.d/*.conf"
-       EOF
+       # Catch "Option ", "#Option " or "# Option ".
+       local regexp_options=${options//,/|}
+
+       # Insert the snippet before the comment block immediately preceeding the
+       # first matching option. There may be blank lines in-between.
+       sed -i -z -r "s:\n(#[^\n]*\n)*\s*#?\s*(${regexp_options})\b:\n${snippet//$'\n'/\\n}\n\0:" "${file}" || die
 }
 
 create_config_dropins() {
@@ -258,6 +264,11 @@
        ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
        EOF
 
+       # Move sshd's Subsystem option to a drop-in file.
+       sed -i "/[Ss]ubsystem/{
+               w ${WORKDIR}/etc/ssh/sshd_config.d/9999999gentoo-subsystem.conf
+               d }" "${S}"/sshd_config || die
+
        cat <<-EOF > "${WORKDIR}"/etc/ssh/sshd_config.d/9999999gentoo.conf || die
        # Allow client to pass locale environment variables (bug #367017)
        AcceptEnv ${locale_vars[*]}
@@ -287,7 +298,10 @@
 
 src_compile() {
        default
-       tweak_ssh_configs
+
+       insert_include "${S}"/ssh_config 'Host,Match' "${EPREFIX}"/etc/ssh/ssh_config.d
+       insert_include "${S}"/sshd_config 'Match' "${EPREFIX}"/etc/ssh/sshd_config.d
+
        create_config_dropins
 }
 

@gentoo-repo-qa-bot
Copy link
Copy Markdown
Collaborator

Pull request CI report

Report generated at: 2024-05-17 15:50 UTC
Newest commit scanned: e320d3f
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/73c450597f/output.html

- Put the Insert option before options that introduce conditional
  blocks to avoid having the drop-in files to be included
  conditionally. For client configs the options that introduce such
  blocks are Match and Host options, for daemon configs it is the
  Match option.

- Move the Subsystem option out of the toplevel daemon config into a
  separate drop-in. That way we can add the drop-in into INSTALL_MASK
  if we want to provide custom drop-in with a different settings for
  subsystems. This is necessary as there is no way to override a
  once-specified subsystem - doing so results in daemon printing an
  error and quitting.

Bug: https://bugs.gentoo.org/907068
Co-authored-by: James Le Cuirot <chewi@gentoo.org>
Signed-off-by: Krzesimir Nowak <knowak@microsoft.com>
Closes: gentoo#31615
Signed-off-by: James Le Cuirot <chewi@gentoo.org>
@chewi chewi force-pushed the krnowak/openssh-no-subsystem branch from e320d3f to cfa3ebb Compare June 10, 2024 15:09
@gentoo-repo-qa-bot
Copy link
Copy Markdown
Collaborator

Pull request CI report

Report generated at: 2024-06-10 15:46 UTC
Newest commit scanned: cfa3ebb
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/1f2390b205/output.html

- Put the Include option before options that introduce conditional
  blocks to avoid having the drop-in files to be included
  conditionally. For client configs the options that introduce such
  blocks are Match and Host options, for daemon configs it is the
  Match option.

- Move the Subsystem option out of the top-level daemon config into a
  separate drop-in. That way we can add the drop-in into INSTALL_MASK
  if we want to provide custom drop-in with a different settings for
  subsystems. This is necessary as there is no way to override a
  once-specified subsystem - doing so results in daemon printing an
  error and quitting.

Bug: https://bugs.gentoo.org/907068
Closes: gentoo#31615
Signed-off-by: James Le Cuirot <chewi@gentoo.org>
@chewi
Copy link
Copy Markdown
Member

chewi commented Jun 10, 2024

Right, since this was going nowhere, I've redone it as a patch. Simpler and safer. Here's the new ebuild diff.

--- openssh-9.7_p1-r3.ebuild    2024-06-10 16:02:00.897892259 +0100
+++ openssh-9.7_p1-r4.ebuild    2024-06-10 16:39:15.468810717 +0100
@@ -78,6 +78,7 @@
 PATCHES=(
        "${FILESDIR}/${PN}-9.4_p1-Allow-MAP_NORESERVE-in-sandbox-seccomp-filter-maps.patch"
        "${FILESDIR}/${PN}-9.6_p1-fix-xmss-c99.patch"
+       "${FILESDIR}/${PN}-9.7_p1-config-tweaks.patch"
 )
 
 pkg_pretend() {
@@ -217,17 +218,6 @@
        econf "${myconf[@]}"
 }
 
-tweak_ssh_configs() {
-       cat <<-EOF >> ssh_config.out || die
-
-       Include "${EPREFIX}/etc/ssh/ssh_config.d/*.conf"
-       EOF
-       cat <<-EOF >> sshd_config.out || die
-
-       Include "${EPREFIX}/etc/ssh/sshd_config.d/*.conf"
-       EOF
-}
-
 create_config_dropins() {
        local locale_vars=(
                # These are language variables that POSIX defines.
@@ -266,6 +256,11 @@
        AcceptEnv COLORTERM
        EOF
 
+       cat <<-EOF > "${WORKDIR}"/etc/ssh/sshd_config.d/9999999gentoo-subsystem.conf || die
+       # override default of no subsystems
+       Subsystem       sftp    ${EPREFIX}/usr/libexec/sftp-server
+       EOF
+
        if use pam ; then
                cat <<-EOF > "${WORKDIR}"/etc/ssh/sshd_config.d/9999999gentoo-pam.conf || die
                UsePAM yes
@@ -287,7 +282,6 @@
 
 src_compile() {
        default
-       tweak_ssh_configs
        create_config_dropins
 }

@gentoo-repo-qa-bot
Copy link
Copy Markdown
Collaborator

Pull request CI report

Report generated at: 2024-06-10 16:36 UTC
Newest commit scanned: 8fa356b
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/3c960e0d9d/output.html

@chewi chewi deleted the krnowak/openssh-no-subsystem branch June 10, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assigned PR successfully assigned to the package maintainer(s). no bug found No Bug/Closes found in the commits.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants