Skip to content

Conversation

@FXHibon
Copy link

@FXHibon FXHibon commented Jul 17, 2023

As atmoz/sftp is a docker image by design, one can already simply change the exposed port of the running server using the appropriate docker run options, to map the internal port 22 to any external port.
It works very well in the majority of cases, as I've been able to experiment it myself.

However, there are a few cases where it is either not wanted or not possible to use this port mapping features.

For example, if you use atmoz/sftp in a CircleCI build, you won't be able to change the port mapping ( https://discuss.circleci.com/t/change-db-containers-ports/30234/6 ), even while the port 22 is reserved by CircleCI, and not usable to containers launched in the tests.

I've read about the custom scripts located in /etc/sftp.d ( https://github.com/atmoz/sftp#execute-custom-scripts-or-applications ) that might already allow one to override everything we want, but that might sounds a bit overengineered to provide a custom executable bash scripts to update a simple config key (this is opinionated, I'm ready to hear any different opinions on this)

Given the reasons listed above, I feel that it is reasonable to allow a user to override the SSHD port using a simple environment variable.

This Pull Request suggests an implementation of this.

@FXHibon FXHibon force-pushed the override-sshd-port branch from 1599bc9 to e34a4a2 Compare July 17, 2023 14:45
@adrian-amaglio
Copy link

Hello,
I made it work with the current image by adding this script in /etc/sftp.d/
It allow you to change any SSHD configuration parameter via env vars.
For instance, you can set the ssh port by setting the SSHD_CONFIG_Port env var.

#!/bin/bash    
    
config_file=/etc/ssh/sshd_config    
    
# Browse env var        
while IFS='=' read key value ; do    
    # Until we get this specific prefix        
    if [[ "$key" == SSHD_CONFIG_* ]] ; then    
        key=${key#SSHD_CONFIG_}                    
                                       
        # If the config instruction exists in the config file    
        if [ -n "$(grep -F "$key" "$config_file")" ] ; then      
            # Replace it                                         
            sed -i "s#^$key .*\$#$key $value#" "$config_file"      
        else        
            # Else, add it                                           
            echo "$key $value" >> "$config_file"    
        fi        
    fi            
done < <(env)    

@Patabugen
Copy link

I found this PR because I need exactly this feature - @atmoz any chance of merging it?

@letompouce
Copy link

This PR seems to add a lot of bashisms for a unique and specific SSHd configuration stanza.

In my context I'd favor #383 ; then customizing Port would be a matter of:

echo 'Port 12345' > port.conf
docker run -p 12345:22 -v $PWD/port.conf:/etc/ssh/sshd_config.d/port.conf atmoz/sftp

And you'd be able to customize anything shd_config.

In both cases, removing the EXPOSE statement is required as it would bring confusion; in both cases doing so kills the autodetection features of tooling such as Traefik.

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