feat: Support kitchen login with the Docker transport - #462
Merged
Conversation
`Kitchen::Transport::Base::Connection#login_command` raises "Remote login not supported" unless a transport overrides it, so `kitchen login` has never worked for instances using the Docker transport. Implement it as an interactive `docker exec` against the instance's container: `/bin/bash --login -i` on Linux platforms and `powershell` on Windows ones. Kitchen runs the result through `Kernel.exec` in its multi-argument form, which bypasses the shell, so the argv is built as individual tokens and values are left unquoted. The transport's socket, TLS, username, working_dir, env_variables and privileged settings are all carried over; interactive/tty are forced on and detach forced off, since a detached exec would return a session the user cannot type into. Ported forward from the unmerged #421, reworked to read the connection's own `@options` rather than reaching into the container object with `instance_variable_get`, and extended to cover Windows containers. spec/inspec_helper_spec.rb evaluated `defined?(Kitchen::Verifier::CincAuditor)` at spec-file load time to choose between two examples. RSpec loads every spec file before running any example, so requiring the transport from a new spec file defined that constant and invalidated the already-selected example. Move the check inside the example and load the helper explicitly so it no longer depends on spec load order. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
test/integration/{capabilities,default}/disabled/ held three files whose entire
contents were commented out when busser-serverspec was dropped. They are not
referenced by kitchen.yml or any workflow.
Also ignore bin/* and .idea/*, both from #421.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Carries forward the work from #421 that is still relevant against current
main.Most of #421 has landed since it was opened in July 2024 — several parts byte-identically, which suggests they were cherry-picked. Triaging all 19 files against
main:Already landed —
.github/CODEOWNERS,.markdownlint.yaml,release-please-config.json,.release-please-manifest.json, theENV k=vfixes incontainer_helper.rbanddockerfile_helper.rb, themoby-danglingregex inimage_helper.rb, commenting outkitchen_transport_api_version 1, andkitchen.windows.yml→ltsc2022.Superseded —
ci.yml→lint.yml(mainis on Ruby 3.4 /actions@v7), release-pleasev4(mainis onv5), thekitchen.ymlplatform refresh, andtest/Dockerfile(mainusesalmalinux:latest+dnf, which is what @Stromweld asked for in review).Obsolete — the
inspec/csv/syslogGemfile pins, sincemainreplaced InSpec with cinc-auditor.That leaves three things, all of which are in this PR.
1.
kitchen loginsupport (the substantive part)Kitchen::Transport::Base::Connection#login_commandraises"Remote login not supported in ..."unless a transport overrides it, andmain's Docker transport never did — sokitchen loginhas never worked for instances using this transport. This implements it as an interactivedocker execagainst the instance's container.Two changes from #421's version:
@optionsinstead ofcontainer.instance_variable_get(:@config). That reflection was unnecessary:Base::Connectionalready stores the merged config-plus-state as@options, and it is literally the same hash handed toContainer::Linux.new(@options)a few lines up.mainsupports them (there's awindows-2022platform inkitchen.ymland a Windows job in CI), so a Linux-only/bin/bashwould fail confusingly there. Linux gets/bin/bash --login -i, Windows getspowershell, dispatched off@options[:platform]the same way#containeralready does — which is now deduped into awindows_container?helper.One deliberate behavioural difference from #421: it forced
usernametonil(i.e. log in as root). This keeps the configuredusername, so the shell matches the environment Test Kitchen actually runs the provisioner in. The kitchen user has NOPASSWD sudo, so root is onesudo -iaway.Argv is built as individual tokens rather than packed strings like
"-H #{socket}", becauseinstance.rbruns the result throughKernel.execin its multi-argument form, which bypasses the shell. Values are left unquoted for the same reason — there is no shell to strip the quotes back off.2. Remove dead
disabled/integration specsThree files under
test/integration/*/disabled/whose entire contents have been commented out since busser-serverspec was dropped. Not referenced bykitchen.ymlor any workflow.3.
.gitignorebin/*and.idea/*, straight from #421.Also in here
spec/inspec_helper_spec.rbevaluateddefined?(Kitchen::Verifier::CincAuditor)at spec-file load time to pick between two examples. RSpec loads every spec file before running any example, so the new spec'srequire "kitchen/transport/docker"— which chains toinspec_helper.rband defines that constant — invalidated the already-selected example. The conditional now happens inside the example, and the helper is loaded explicitly, so it no longer depends on spec load order. This was a latent fragility; the new file only exposed it.Testing
bundle exec rspec— 34 examples, 0 failures (was 25 before; 9 new). Confirmed stable across seeds 1/2/999/12345 for the load-order fix.bundle exec rake style— 28 files, no offenses.Kitchen::ActionFailed: Remote login not supportedbefore the implementation existed.dockerCLI for both Linux and Windows configs. Both parse cleanly, reaching the daemon-connect stage — meaning flags, subcommand, container ID and shell were all accepted:Not verified: no live
kitchen loginagainst a running container — there was no Docker daemon available on the machine I built this on. Worth someone doing a quick manualkitchen converge && kitchen loginon one Linux and one Windows instance before merge.Type of Change
feat
Check List
Closes #421
🤖 Generated with Claude Code