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

Override the default ssh askpass flow on project clone step #1291

Merged
merged 2 commits into from
Aug 5, 2024

Conversation

vinokurig
Copy link
Contributor

@vinokurig vinokurig commented Jul 30, 2024

What does this PR do?

We support project clone from ssh urls, but if the ssh key has a passphrase, the project clone step will fail because the default ssh askpass flow will be invoked, but it does not support any other input then a manual input from keyboard. To override the default flow, a script file is used. The passphrase file must be mounted to /etc/ssh/ folder. The SSH_ASKPASS env variables defines the script file for the ssh flow, see: https://man.openbsd.org/ssh-add#ENVIRONMENT. The current open-ssh version does not support the SSH_ASKPASS_REQUIRE key, so we need to set the DISPLAY env variable as the command process does not have an associated terminal.

What issues does this PR fix or reference?

https://issues.redhat.com/browse/CRW-6614
Fix #1294

Is it tested? How?

  1. Setup ssh key with passphrase: https://github.com/devfile/devworkspace-operator/blob/main/docs/additional-configuration.adoc#configuring-devworkspaces-to-use-ssh-keys-for-git-operations.
  2. Try to start a workspace from an ssh url.

PR Checklist

  • E2E tests pass (when PR is ready, comment /test v8-devworkspace-operator-e2e, v8-che-happy-path to trigger)
    • v8-devworkspace-operator-e2e: DevWorkspace e2e test
    • v8-che-happy-path: Happy path for verification integration with Che

Copy link

openshift-ci bot commented Jul 30, 2024

Hi @vinokurig. Thanks for your PR.

I'm waiting for a devfile member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@vinokurig
Copy link
Contributor Author

/test v8-devworkspace-operator-e2e, v8-che-happy-path

Copy link

openshift-ci bot commented Jul 30, 2024

@vinokurig: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test v8-devworkspace-operator-e2e, v8-che-happy-path

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@AObuchow
Copy link
Collaborator

/ok-to-test

@AObuchow
Copy link
Collaborator

AObuchow commented Jul 31, 2024

Thanks for the PR @vinokurig :) I didn't get a chance to properly look at this today, but I should be able to tomorrow (Wednesday).

Copy link
Collaborator

@dkwon17 dkwon17 left a comment

Choose a reason for hiding this comment

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

I added my passphrase in the git-ssh-key secret, and it is working

Copy link
Collaborator

@AObuchow AObuchow left a comment

Choose a reason for hiding this comment

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

Left some minor comments regarding documentation but the functionality works as expected & I like this solution of leveraging ssh-add's features :)

docs/additional-configuration.adoc Show resolved Hide resolved
docs/additional-configuration.adoc Outdated Show resolved Hide resolved
@@ -211,7 +212,8 @@ EOF
kubectl create secret -n "$NAMESPACE" generic git-ssh-key \
--from-file=dwo_ssh_key="$SSH_KEY" \
--from-file=dwo_ssh_key.pub="$SSH_PUB_KEY" \
--from-file=ssh_config=/tmp/ssh_config
--from-file=ssh_config=/tmp/ssh_config \
--from-literal=passphrase="$PASSPHRASE"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to verify that adding the --from-literal=passphrase="$PASSPHRASE" will not break things if the user does not provide a passphrase. Perhaps we should add an alternate instruction for users that are providing a passphrase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried the command without the PASSPHRASE env variable and it worked ok, but the passphrase key of the secret data has no value:

data:
  dwo_ssh_key: ***
  dwo_ssh_key.pub: ***
  passphrase: ''
  ssh_config: ***

Such empty keys will not be mounted to the container file system as files and if the ssh-askpass.sh is executed it will throw an error about missing passphrase file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for checking. Just to confirm: if the user's SSH key does not have a passphrase, will ssh-askpass.sh be invoked? I imagine it won't, based on it's documentation:

If ssh-add **needs** a passphrase, it will read the passphrase from the current terminal if it was run from a terminal...

The concern is just making sure that users are able to copy & paste the instructions and have them work, even if their SSH key does not have a passphrase (though their secret will have an empty passphrase data field).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if the user's SSH key does not have a passphrase, will ssh-askpass.sh be invoked?

I have tried the flow with SSH key with an empty passphrase, and neither the default askpass scriptn nore the provided ssh-askpass.sh script was not invoked.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perfect!

Copy link
Collaborator

@AObuchow AObuchow left a comment

Choose a reason for hiding this comment

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

LGTM, great work @vinokurig :)
I've opened #1294 for tracking in the DWO milestones.

Please squash your fixup commit before we merge this PR :)

@vinokurig
Copy link
Contributor Author

vinokurig commented Aug 2, 2024

@AObuchow Thank you for the review. Looks like we need @dmytro-ndp approval after he verifies the functionality.

PASSPHRASE_FILE_PATH="/etc/ssh/passphrase"
if [ ! -f $PASSPHRASE_FILE_PATH ]; then
echo "Error: passphrase file is missing in the '/etc/ssh/' directory" 1>&2
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

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

@vinokurig could you elaborate a bit? why do we exit 1 if the optional passphrase is missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passphrase is optional because we do not need to specify passphrase if the ssh key is generated with an empty passphrase, but if the ssh key is generated WITH a passphrase we do not consider the passphrase as optional.

Copy link
Contributor

@ibuziuk ibuziuk left a comment

Choose a reason for hiding this comment

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

@vinokurig have we checked that old ssh keys would be working as expected

@ibuziuk ibuziuk requested a review from musienko-maxim August 5, 2024 10:18
@ibuziuk
Copy link
Contributor

ibuziuk commented Aug 5, 2024

@musienko-maxim please review, we need QA approval for that one

Copy link

openshift-ci bot commented Aug 5, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AObuchow, dkwon17, musienko-maxim, vinokurig

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ibuziuk ibuziuk merged commit e176ec0 into devfile:main Aug 5, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support ssh keys with passphrases in project clone container
5 participants