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

[ADD] ssh key text as env variable #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vrenaville
Copy link

  • Purpose
    We need to use an old rancher, that do not support secrets deploy with CLI, we want to use environment variable instead
  • Before
    ssh key was only available with secret or volume
  • Before
    ssh key can be define with a secret, volume or env variable

Copy link
Owner

@jnovack jnovack left a comment

Choose a reason for hiding this comment

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

Please make the changes requested.

Additionally, please add an additional test to validate this configuration.

README.md Outdated
@@ -190,6 +190,12 @@ the `known_hosts` file is provided. This can help avoid issues for hosts with
dynamic IP addresses, but removes some additional protection against DNS
spoofing attacks. Host IP Checking is enabled by default.

#### ENV_SSH_KEY
Copy link
Owner

@jnovack jnovack Mar 26, 2021

Choose a reason for hiding this comment

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

Standard _FILE convention for VARIABLE is VARIABLE_FILE. Please use VARIABLE, not ENV_VARIABLE.

Additionally, VARIABLE_FILE is an override for VARIABLE, not VARIABLE being an override for VARIABLE_FILE. Thus, if VARIABLE_FILE exists, it shall override VARIABLE, always.

@@ -1,8 +1,11 @@
#!/usr/bin/dumb-init /bin/sh
source version.sh

if [ -n "${ENV_SSH_KEY}" ]; then
Copy link
Owner

Choose a reason for hiding this comment

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

See above.

if [ -n "${ENV_SSH_KEY}" ]; then
echo "$ENV_SSH_KEY" > /id_rsa/custom_rsa
KEY_FILE=/id_rsa/custom_rsa
else KEY_FILE=${SSH_KEY_FILE:=/id_rsa}
Copy link
Owner

Choose a reason for hiding this comment

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

split into two lines and indent

@vrenaville
Copy link
Author

@jnovack

Thanks for your comments !
I have update my pr regarding your returns.
Let me know if it's not the right way

Thanks for your help and work

Copy link
Owner

@jnovack jnovack left a comment

Choose a reason for hiding this comment

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

Please do not forget to run your test before committing.

README.md Outdated
#### SSH_KEY

You can specify the SSH key using Environnement variable, please note
that SSH_KEY_FILE parameter will be ignored
Copy link
Owner

Choose a reason for hiding this comment

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

I believe it is the opposite. If SSH_KEY_FILE is specified, SSH_KEY is ignored.

_FILE takes precedence (unless I'm wrong here, in which case show me an app where non _FILE takes precedence over _FILE).

SSH_KEY_FILE=/id_rsa/custom_rsa
else
KEY_FILE=${SSH_KEY_FILE:=/id_rsa}
fi
Copy link
Owner

Choose a reason for hiding this comment

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

Your order is backwards here. Since SSH_KEY_FILE overrides SSH_KEY, the logic has to flow differently.

Why set KEY_FILE twice? KEY_FILE is set to SSH_KEY_FILE if and only if it exists, use that logic.

@@ -1,8 +1,14 @@
#!/usr/bin/dumb-init /bin/sh
source version.sh

if [ -n "${SSH_KEY}" ]; then
echo "$SSH_KEY" > /id_rsa/custom_rsa
Copy link
Owner

Choose a reason for hiding this comment

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

There should be no reason to have an extra file on disk.

We've already defined /id_rsa as the custom to file to use, (a) why create another, and (b) why use a completely non-standard directory?

@@ -80,6 +80,45 @@ services:
- SSH_TARGET_PORT=22
- SSH_TUNNEL_PORT=11111
- SSH_KEY_FILE=/opt/id_rsa
- SSH_KEY= |-
Copy link
Owner

Choose a reason for hiding this comment

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

One always overrides the other. You cannot test both in the same container. In fact, you need a third test to test that one does properly override the other.

@vrenaville
Copy link
Author

Thanks for you time, I will work on it the week , not a lot a spare time actually

@gurneyalex
Copy link

hello @jnovack, I'm a colleague of @vrenaville who's been busy on other topics lately and was not able to follow up on this PR. I'll take over from him as this issue is still important for us (we are migrating away from Rancher but this migration won't be complete for some time, and so we need to patch our way around to keep this tunnel up for one of our customers. I'll update the PR next week. Thanks for you patience.

@gurneyalex
Copy link

I just updated that PR, taking your remarks into account.

@vrenaville
Copy link
Author

@gurneyalex Thanks for your time and work, It seems LGTM to me

@arsa-dev
Copy link

arsa-dev commented Nov 9, 2023

Hi @jnovack, I'm also interested on this feature to be merged, there is anything else to do or where I can help after latest @gurneyalex changes, so this can be merged?

@gurneyalex
Copy link

@arsa-dev we lost interest in getting this merged, and I won't be touching the PR anymore. Feel free to fork our code and try to resubmit the PR, maybe you will have success.

@jnovack
Copy link
Owner

jnovack commented May 28, 2024

Hi @jnovack, I'm also interested on this feature to be merged, there is anything else to do or where I can help after latest @gurneyalex changes, so this can be merged?

If you'd like to help, the huge thing is the tests are not passing. This does not look close to functional. make docker-test fails, so I cannot merge a PR that actively breaks other user's environments, would not be responsible.

For some reason, there was an rm added which fails, and then a simple test of connection gets connection refused, so something else failed.

target-1          | rm: can't remove '/root/.ssh/target.txt': No such file or directory
remote-1          | rm: can't remove '/root/.ssh/remote.txt': No such file or directory
target-1          | sed: unmatched '/'
remote-1          | sed: unmatched '/'
remote-1          | sed: unmatched '/'
remote-1          | sed: unmatched '/'
target-1          | chpasswd: password for 'root' changed
remote-1          | chpasswd: password for 'root' changed
local-1           | user/repo dirty revision local built 1970-01-01T00:00:00Z
local-with-env-1  | user/repo dirty revision local built 1970-01-01T00:00:00Z
local-with-env-1  | Agent pid 10
local-1           | Agent pid 8
local-1           | Identity added: (stdin) (testing)
local-with-env-1  | Identity added: (stdin) (testing)
local-with-env-1  | [INFO ] Using autossh 1.4g
local-with-env-1  | [INFO ] Tunneling 203.0.113.10:11112  on root@203.0.113.10:22  to 203.0.113.100:22
local-with-env-1  | [INFO ] # autossh -M 0 -N -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -t -t -R 203.0.113.10:11112:203.0.113.100:22 -p 22 root@203.0.113.10
local-1           | [INFO ] Using autossh 1.4g
local-1           | [INFO ] Tunneling 203.0.113.10:11111  on root@203.0.113.10:22  to 203.0.113.100:22
local-1           | [INFO ] # autossh -M 0 -N -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -t -t -R 203.0.113.10:11111:203.0.113.100:22 -p 22 root@203.0.113.10
local-1           | ssh: connect to host 203.0.113.10 port 22: Connection refused
local-with-env-1  | ssh: connect to host 203.0.113.10 port 22: Connection refused
remote-1          | ssh-keygen: generating new host keys: RSA ECDSA ED25519
remote-1          | Server listening on 0.0.0.0 port 22.
remote-1          | Server listening on :: port 22.
local-1 exited with code 1

@arsa-dev
Copy link

Hi @jnovack, thanks you for your time reviewing again this old PR. Unfortunately I'm currently really busy but having this idea working and released would be great! I'll really try to manage it to free some time and fork this PR, review the reason behind the failing tests and resubmit in a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants