cherry-pick.v15-5-g9cdd041.systemd-drop-ncat-dependency.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. Subject: Systemd: drop ncat dependency
  2. Origin: v15-5-g9cdd041 <https://github.com/latchset/clevis/commit/v15-5-g9cdd041>
  3. Upstream-Author: Sergio Correia <scorreia@redhat.com>
  4. Date: Wed Dec 2 20:53:48 2020 -0300
  5. When using systemd, i.e., clevis-luks-askpass, we use ncat to send
  6. the decrypted password to the systemd socket as per systemd's password
  7. agents specification [1].
  8. However, systemd itself has a utility that does exactly that,
  9. systemd-reply-password.
  10. In this commit we drop the ncat dependency and instead use
  11. systemd-reply-password in clevis-luks-askpass.
  12. [1] https://systemd.io/PASSWORD_AGENTS/
  13. --- a/INSTALL.md
  14. +++ b/INSTALL.md
  15. @@ -22,7 +22,6 @@
  16. * [tang](https://github.com/latchset/tang)
  17. * [curl](https://github.com/curl/curl)
  18. * [tpm2-tools](https://github.com/tpm2-software/tpm2-tools)
  19. -* [ncat](https://nmap.org/ncat/) (for clevis-luks-askpass)
  20. ### Fedora
  21. --- a/src/luks/systemd/clevis-luks-askpass
  22. +++ /dev/null
  23. @@ -1,76 +0,0 @@
  24. -#!/bin/bash
  25. -set -eu
  26. -# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
  27. -#
  28. -# Copyright (c) 2016 Red Hat, Inc.
  29. -# Author: Harald Hoyer <harald@redhat.com>
  30. -# Author: Nathaniel McCallum <npmccallum@redhat.com>
  31. -#
  32. -# This program is free software: you can redistribute it and/or modify
  33. -# it under the terms of the GNU General Public License as published by
  34. -# the Free Software Foundation, either version 3 of the License, or
  35. -# (at your option) any later version.
  36. -#
  37. -# This program is distributed in the hope that it will be useful,
  38. -# but WITHOUT ANY WARRANTY; without even the implied warranty of
  39. -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  40. -# GNU General Public License for more details.
  41. -#
  42. -# You should have received a copy of the GNU General Public License
  43. -# along with this program. If not, see <http://www.gnu.org/licenses/>.
  44. -#
  45. -
  46. -. clevis-luks-common-functions
  47. -
  48. -# Make sure to exit cleanly if SIGTERM is received.
  49. -trap 'echo "Exiting due to SIGTERM" && exit 0' TERM
  50. -
  51. -loop=
  52. -path=/run/systemd/ask-password
  53. -while getopts ":lp:" o; do
  54. - case "${o}" in
  55. - l) loop=true;;
  56. - p) path="${OPTARG}";;
  57. - *) ;;
  58. - esac
  59. -done
  60. -
  61. -while true; do
  62. - for question in "${path}"/ask.*; do
  63. - # question will expand to itself, in case no files match, so we verify
  64. - # whether it actually exists, before proceeding.
  65. - [ ! -e "${question}" ] && continue
  66. -
  67. - d=
  68. - s=
  69. - while read -r line; do
  70. - case "$line" in
  71. - Id=cryptsetup:*) d="${line##Id=cryptsetup:}";;
  72. - Socket=*) s="${line##Socket=}";;
  73. - esac
  74. - done < "$question"
  75. -
  76. - [ -b "${d}" ] || continue
  77. - [ -S "${s}" ] || continue
  78. -
  79. - if ! pt="$(clevis_luks_unlock_device "${d}")" || [ -z "${pt}" ]; then
  80. - continue
  81. - fi
  82. -
  83. - uuid="$(cryptsetup luksUUID "${d}")"
  84. - if ! printf '+%s' "${pt}" | ncat -U -u --send-only "${s}"; then
  85. - echo "Unable to unlock ${d} (UUID=${uuid}) with recovered passphrase" >&2
  86. - continue
  87. - fi
  88. -
  89. - echo "Unlocked ${d} (UUID=${uuid}) successfully" >&2
  90. - done
  91. -
  92. - [ "${loop}" != true ] && break
  93. - # Checking for pending devices to be unlocked.
  94. - if remaining=$(clevis_devices_to_unlock) && [ -z "${remaining}" ]; then
  95. - break;
  96. - fi
  97. -
  98. - sleep 0.5
  99. -done
  100. --- /dev/null
  101. +++ b/src/luks/systemd/clevis-luks-askpass.in
  102. @@ -0,0 +1,76 @@
  103. +#!/bin/bash
  104. +set -eu
  105. +# vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
  106. +#
  107. +# Copyright (c) 2016 Red Hat, Inc.
  108. +# Author: Harald Hoyer <harald@redhat.com>
  109. +# Author: Nathaniel McCallum <npmccallum@redhat.com>
  110. +#
  111. +# This program is free software: you can redistribute it and/or modify
  112. +# it under the terms of the GNU General Public License as published by
  113. +# the Free Software Foundation, either version 3 of the License, or
  114. +# (at your option) any later version.
  115. +#
  116. +# This program is distributed in the hope that it will be useful,
  117. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  118. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  119. +# GNU General Public License for more details.
  120. +#
  121. +# You should have received a copy of the GNU General Public License
  122. +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  123. +#
  124. +
  125. +. clevis-luks-common-functions
  126. +
  127. +# Make sure to exit cleanly if SIGTERM is received.
  128. +trap 'echo "Exiting due to SIGTERM" && exit 0' TERM
  129. +
  130. +loop=
  131. +path=/run/systemd/ask-password
  132. +while getopts ":lp:" o; do
  133. + case "${o}" in
  134. + l) loop=true;;
  135. + p) path="${OPTARG}";;
  136. + *) ;;
  137. + esac
  138. +done
  139. +
  140. +while true; do
  141. + for question in "${path}"/ask.*; do
  142. + # question will expand to itself, in case no files match, so we verify
  143. + # whether it actually exists, before proceeding.
  144. + [ ! -e "${question}" ] && continue
  145. +
  146. + d=
  147. + s=
  148. + while read -r line; do
  149. + case "$line" in
  150. + Id=cryptsetup:*) d="${line##Id=cryptsetup:}";;
  151. + Socket=*) s="${line##Socket=}";;
  152. + esac
  153. + done < "$question"
  154. +
  155. + [ -b "${d}" ] || continue
  156. + [ -S "${s}" ] || continue
  157. +
  158. + if ! pt="$(clevis_luks_unlock_device "${d}")" || [ -z "${pt}" ]; then
  159. + continue
  160. + fi
  161. +
  162. + uuid="$(cryptsetup luksUUID "${d}")"
  163. + if ! printf '%s' "${pt}" | @SYSTEMD_REPLY_PASS@ 1 "${s}"; then
  164. + echo "Unable to unlock ${d} (UUID=${uuid}) with recovered passphrase" >&2
  165. + continue
  166. + fi
  167. +
  168. + echo "Unlocked ${d} (UUID=${uuid}) successfully" >&2
  169. + done
  170. +
  171. + [ "${loop}" != true ] && break
  172. + # Checking for pending devices to be unlocked.
  173. + if remaining=$(clevis_devices_to_unlock) && [ -z "${remaining}" ]; then
  174. + break;
  175. + fi
  176. +
  177. + sleep 0.5
  178. +done
  179. --- a/src/luks/systemd/dracut/clevis/module-setup.sh.in
  180. +++ b/src/luks/systemd/dracut/clevis/module-setup.sh.in
  181. @@ -36,6 +36,7 @@
  182. inst_multiple \
  183. /etc/services \
  184. + @SYSTEMD_REPLY_PASS@ \
  185. @libexecdir@/clevis-luks-askpass \
  186. clevis-luks-common-functions \
  187. grep sed cut \
  188. @@ -45,8 +46,7 @@
  189. luksmeta \
  190. clevis \
  191. mktemp \
  192. - jose \
  193. - ncat
  194. + jose
  195. dracut_need_initqueue
  196. }
  197. --- a/src/luks/systemd/meson.build
  198. +++ b/src/luks/systemd/meson.build
  199. @@ -1,6 +1,15 @@
  200. systemd = dependency('systemd', required: false)
  201. -if systemd.found()
  202. +sd_reply_pass = find_program(
  203. + join_paths(get_option('prefix'), get_option('libdir'), 'systemd', 'systemd-reply-password'),
  204. + join_paths(get_option('prefix'), 'lib', 'systemd', 'systemd-reply-password'),
  205. + join_paths('/', 'usr', get_option('libdir'), 'systemd', 'systemd-reply-password'),
  206. + join_paths('/', 'usr', 'lib', 'systemd', 'systemd-reply-password'),
  207. + required: false
  208. +)
  209. +
  210. +if systemd.found() and sd_reply_pass.found()
  211. + data.set('SYSTEMD_REPLY_PASS', sd_reply_pass.path())
  212. subdir('dracut')
  213. unitdir = systemd.get_pkgconfig_variable('systemdsystemunitdir')
  214. @@ -12,8 +21,14 @@
  215. configuration: data,
  216. )
  217. + configure_file(
  218. + input: 'clevis-luks-askpass.in',
  219. + output: 'clevis-luks-askpass',
  220. + install_dir: libexecdir,
  221. + configuration: data
  222. + )
  223. +
  224. install_data('clevis-luks-askpass.path', install_dir: unitdir)
  225. - install_data('clevis-luks-askpass', install_dir: libexecdir)
  226. else
  227. warning('Will not install systemd support due to missing dependencies!')
  228. endif