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

feat(docker): Add ssh-client to Docker image to access private modules via ssh #553

Merged
merged 10 commits into from
Aug 15, 2023

Conversation

lchastel
Copy link
Contributor

Put an x into the box if that apply:

  • This PR introduces breaking change.
  • This PR fixes a bug.
  • This PR adds new functionality.
  • [ X ] This PR enhances existing functionality.

Description of your changes

I have external private module in my terraform code (source="ssh://git@....").

In checkov we need to clone external module.
I'm using private module in git. So git need to use ssh to clone them.

I add the installation of ssh-client in the docker image.
It fixes the issue "error: cannot run ssh: No such file or directory"

How can we test changes

From a low level point of view, start the docker image and try to clone a repository via SSH.
From a high level point of view, create a module accessible in ssh, call it from terraform, enable terraform_checkov in pre-commit.

@lchastel lchastel changed the title ssh-client for external private module in ssh fix: ssh-client for external private module in ssh Aug 10, 2023
@lchastel lchastel changed the title fix: ssh-client for external private module in ssh Fix: ssh-client for external private module in ssh Aug 10, 2023
@lchastel lchastel changed the title Fix: ssh-client for external private module in ssh fix: ssh-client for external private module in ssh Aug 10, 2023
Dockerfile Outdated Show resolved Hide resolved
Copy link
Collaborator

@yermulnik yermulnik left a comment

Choose a reason for hiding this comment

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

LGTM

@yermulnik
Copy link
Collaborator

@lchastel Please address GH workflow failure and let's gain approval from @MaxymVlasov and/or @antonbabenko as well

@lchastel lchastel changed the title fix: ssh-client for external private module in ssh fix: The ssh-client for external private module in ssh Aug 10, 2023
Copy link
Collaborator

@MaxymVlasov MaxymVlasov left a comment

Choose a reason for hiding this comment

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

@@ -73,6 +73,11 @@ commandTests:
command: "su-exec"
expectedOutput: ["^Usage: su-exec user-spec command \\[args\\]\\n$"]

- name: "ssh"
command: "ssh"
expectedOutput: ["^usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]$"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should escape square brackets please.
Also should expectedOutput capture only first line of output or all output lines? @MaxymVlasov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Escape square brackets done.

Copy link
Collaborator

@MaxymVlasov MaxymVlasov Aug 14, 2023

Choose a reason for hiding this comment

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

expectedOutput capture the whole output, so, in case it is multiline, I recommend just ending comparison regex with the end of the line, but without $, like here:

expectedOutput: [ "TFLint version ([0-9]+\\.){2}[0-9]+\\n" ]

I'm fine just to check the string in line which includes the version number (sorry that not mentioned it explicitly in the previous comment)

So for openssh it will be something like:

$ ssh -v localhost
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f  31 Mar 2020
...
...

IE, here check should be related just to OpenSSH_8.2p1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The command is "ssh -V"
On my computer I have :
OpenSSH_8.4p1 Debian-5+deb11u1, OpenSSL 1.1.1n 15 Mar 2022
On alpine (base on pre-commit-terraform image), I have
OpenSSH_9.1p1, OpenSSL 3.0.9 30 May 2023

I'm trying with "^OpenSSH_[0-9]+\.[0-9]+.*\n$"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest this as it is less specific "^OpenSSH_[0-9]+\.[0-9]+"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@MaxymVlasov MaxymVlasov changed the title fix: The ssh-client for external private module in ssh feat(docker): Add ssh-client to Docker image for private modules accessible via ssh Aug 15, 2023
@MaxymVlasov MaxymVlasov added feature New feature or request area/docker labels Aug 15, 2023
@MaxymVlasov MaxymVlasov changed the title feat(docker): Add ssh-client to Docker image for private modules accessible via ssh feat(docker): Add ssh-client to Docker image to access private modules via ssh Aug 15, 2023
@MaxymVlasov MaxymVlasov merged commit 1d76157 into antonbabenko:master Aug 15, 2023
6 checks passed
antonbabenko pushed a commit that referenced this pull request Aug 15, 2023
# [1.82.0](v1.81.2...v1.82.0) (2023-08-15)

### Features

* **docker:** Add ssh-client to Docker image to access private modules via ssh ([#553](#553)) ([1d76157](1d76157))
@antonbabenko
Copy link
Owner

This PR is included in version 1.82.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docker feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants