[Bug 42517] New: Allow option to set StrictHostKeyChecking=accept-new for SFTP
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 Bug ID: 42517 Summary: Allow option to set StrictHostKeyChecking=accept-new for SFTP Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Architecture, internals, and plumbing Assignee: koha-bugs@lists.koha-community.org Reporter: lisette@bywatersolutions.com QA Contact: testopia@bugs.koha-community.org SFTP keys have to be accepted on the command line level currently, it would be helpful if in the kohaconf we could set StrictHostKeyChecking=accept-new to streamline sftp setups, but still have it be controlled from the server side. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 Tristin Stagg <tristin.stagg@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |tristin.stagg@bywatersoluti | |ons.com --- Comment #1 from Tristin Stagg <tristin.stagg@bywatersolutions.com> --- Yes! When Koha acts as an SFTP client, often times server administrators will need to go on the server and accept host keys before the integration works. I think we are OK with Koha integrations automatically accepting this on our behalf. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |tomascohen@gmail.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 --- Comment #2 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Should we instead have some step in which the handshake is done, and the new key printed in a modal or smth, and the staff accept/confirm it? -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 --- Comment #3 from Kyle M Hall (khall) <kyle@bywatersolutions.com> --- Created attachment 198535 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=198535&action=edit Bug 42517: Update database Patch from commit 75a0dac -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 --- Comment #4 from Kyle M Hall (khall) <kyle@bywatersolutions.com> --- Created attachment 198536 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=198536&action=edit Bug 42517: Allow option to set StrictHostKeyChecking=accept-new for SFTP This version of the patch sets the option at the file transport level for maximum flexibility and self-service ability. 1) Run updatedatabase.pl 2) Restart all the things! 3) Install and start an SSH server, give the kohadev-koha user a password, allow password auth, and clear any cached host key: apt-get update && apt-get install -y openssh-server mkdir -p /run/sshd && /usr/sbin/sshd echo "kohadev-koha:koha" | chpasswd sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config pkill -HUP sshd su - kohadev-koha -c 'rm -f ~/.ssh/known_hosts' 4) In the staff client create a new file transport with Transport: SFTP Host: localhost Port: 22 Strict host key checking: No (always accept the host key automatically) Authentication mode: Password-based Username: kohadev-koha Password: koha 5) Wipe known_hosts again, chnage strict host key checking to yes 6) rm -f ~/.ssh/known_hosts 7) Connection test fails with "Host key verification failed"! 8) Set transport to accept-new 9) Connection test passes! 10) Edit the transport again, switch back to "Yes" 11) Connection test still passes -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 --- Comment #5 from Kyle M Hall (khall) <kyle@bywatersolutions.com> --- Created attachment 198537 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=198537&action=edit Bug 42517: Add unit tests Patch from commit 7bcb861 -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 --- Comment #6 from Kyle M Hall (khall) <kyle@bywatersolutions.com> --- Created attachment 198538 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=198538&action=edit Bug 42517: Update schema file [DO NOT PUSH] Patch from commit 13a257d -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 Kyle M Hall (khall) <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kyle@bywatersolutions.com Status|NEW |Needs Signoff -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 Kyle M Hall (khall) <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |kyle@bywatersolutions.com |ity.org | -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |martin.renvoize@openfifth.c |y.org |o.uk CC| |martin.renvoize@openfifth.c | |o.uk -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |39190 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39190 [Bug 39190] Rework new (S)FTP classes to be polymorphic classes -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 Bug 42517 depends on bug 39190, which changed state. Bug 39190 Summary: Rework new (S)FTP classes to be polymorphic classes https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39190 What |Removed |Added ---------------------------------------------------------------------------- Status|Needs documenting |RESOLVED Resolution|--- |FIXED -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 --- Comment #7 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- I think that suggestion points at the right destination, but the wrong bug to do it in. Agreed on the direction: an explicit trust ceremony (do the handshake, show the fingerprint, staff confirm, Koha remembers the key) is the standard UX in every serious SFTP client and is genuinely stronger than accept-new. Trust-on-first-use is only as strong as your first connection not being intercepted, whereas a displayed fingerprint can be checked out-of-band against what the vendor published. It also degrades gracefully on key rotation: the connection fails and staff re-confirm the new fingerprint through the same flow. The strongest argument for it, though, is where the trust gets stored rather than the modal itself. Today trust lives in ~koha/.ssh/known_hosts, which is filesystem-local state: - Multiple app servers each have their own known_hosts, so accept-new has to happen once per box, and 'yes' fails on any box that hasn't connected yet. - Ephemeral deployments (containers) lose the file on redeploy, so 'yes' breaks after every rebuild. - It's shared with everything else the koha user does over SSH, and with every other transport; there is no per-transport trust. A confirm-and-pin flow would naturally store the accepted host key on the file_transports row, and the implementation is clean with Net::SFTP::Foreign: write the pinned key to a temporary file at connect time and pass -o UserKnownHostsFile=... -o StrictHostKeyChecking=yes. Trust becomes deployment-independent, per-transport and auditable. Why I don't think it should block this bug: 1. Scope. This bug is a small self-service knob: stop hardcoding StrictHostKeyChecking=no. The proposal is a feature: a keyscan step (probably a synchronous API endpoint, since the existing connection test runs as a background job), fingerprint UI handling multiple key types, DB storage of pinned keys, and a re-confirm flow on key change. That deserves its own bug. 2. They're not mutually exclusive. The enum survives either way: 'no' stays useful for dev/test, and a pinning feature is essentially how 'yes' becomes actually usable in production. Nothing in this patchset paints us into a corner; the pinning work slots in behind the same column. 3. An honest limitation of the modal too: ssh-keyscan is subject to the same first-connection interception risk as accept-new. The modal only adds security if staff actually compare the fingerprint against an out-of-band value. It makes informed trust possible, which is worth doing, but the marginal security of blocking this bug on it is small, while the operational value of accept-new over the hardcoded 'no' is immediate. So my proposal: land this bug as the incremental improvement it is, and open a follow-up bug for "confirm and pin host keys per file transport" (fingerprint confirmation UI, key stored on the transport row, connections made with a generated UserKnownHostsFile and strict checking). The multi-server/ephemeral-deployment argument should go in that follow-up, because that is where the current known_hosts approach actually breaks. A cheap middle step in the meantime: the SFTP code already captures the ssh -v stderr, so after an accept-new first connection the accepted fingerprint is in the debug output. Surfacing it in the transport's status messages would let staff review what was trusted after the fact, without any new handshake machinery. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #198535|0 |1 is obsolete| | Attachment #198536|0 |1 is obsolete| | Attachment #198537|0 |1 is obsolete| | Attachment #198538|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 --- Comment #8 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 202093 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202093&action=edit Bug 42517: Update database Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 --- Comment #9 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 202094 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202094&action=edit Bug 42517: Allow option to set StrictHostKeyChecking=accept-new for SFTP This version of the patch sets the option at the file transport level for maximum flexibility and self-service ability. 1) Run updatedatabase.pl 2) Restart all the things! 3) Install and start an SSH server, give the kohadev-koha user a password, allow password auth, and clear any cached host key: apt-get update && apt-get install -y openssh-server mkdir -p /run/sshd && /usr/sbin/sshd echo "kohadev-koha:koha" | chpasswd sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config pkill -HUP sshd su - kohadev-koha -c 'rm -f ~/.ssh/known_hosts' 4) In the staff client create a new file transport with Transport: SFTP Host: localhost Port: 22 Strict host key checking: No (always accept the host key automatically) Authentication mode: Password-based Username: kohadev-koha Password: koha 5) Wipe known_hosts again, chnage strict host key checking to yes 6) rm -f ~/.ssh/known_hosts 7) Connection test fails with "Host key verification failed"! 8) Set transport to accept-new 9) Connection test passes! 10) Edit the transport again, switch back to "Yes" 11) Connection test still passes Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 --- Comment #10 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 202095 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202095&action=edit Bug 42517: Add unit tests Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 --- Comment #11 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 202096 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202096&action=edit Bug 42517: Update schema file [DO NOT PUSH] Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 --- Comment #12 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 202097 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202097&action=edit Bug 42517: (QA follow-up) Address QA review findings This patch addresses points raised during QA review: * Make the atomicupdate file executable (koha-qa file_permissions) * Add strict_host_key_checking to the config fields list in Koha::File::Transport->store so editing the option triggers the automatic connection re-test the confirmation modal promises * Make the confirmation modal message reflect the selected strict host key checking value ('yes' will never auto-accept a host key) and fix the "servers" typo while we're there * Preserve the stored strict_host_key_checking value when editing a non-SFTP transport: the select is disabled for those transports so the parameter is not submitted, and the value was silently reset to 'no' (the least secure option) * Validate strict_host_key_checking at store time, following the pattern from bug 39224, so an invalid value can never be persisted regardless of how the field was populated (admin form, set_from_api or a direct accessor call) * Cover the new field in the REST API tests (valid values roundtrip, invalid values are rejected) and cover the store-time validation in Transport.t Test plan: 1. prove t/db_dependent/Koha/File/Transport.t \ t/db_dependent/Koha/File/Transport/SFTP.t \ t/db_dependent/api/v1/file_transports.t => SUCCESS: all green (yarn api:bundle first if the spec bundle is stale) 2. Edit an SFTP transport, set strict host key checking to 'accept-new', switch the transport to FTP and save; edit again => SUCCESS: the stored value is preserved rather than being silently reset to 'no' 3. Edit an SFTP transport and cycle the strict host key checking select before saving => SUCCESS: the confirmation modal message reflects the selected value Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42517 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|martin.renvoize@openfifth.c |dcook@prosentient.com.au |o.uk | -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org