|
1 |
| -# ES.Docker.SFTP |
2 |
| -SFTP Server for Docker |
| 1 | +# SFTP ([SSH File Transfer Protocol](https://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol)) server using [OpenSSH](https://en.wikipedia.org/wiki/OpenSSH) |
| 2 | +This project provides a Docker image for hosting a SFTP server. Included are `Docker` (`docker-cli` and `docker-compose`) and `Kubernetes` (`kubectl` and `helm`) deployment scripts |
| 3 | + |
| 4 | +[](https://dev.azure.com/emberstack/OpenSource/_build/latest?definitionId=16&branchName=master) |
| 5 | +[](https://github.com/emberstack/docker-sftp/releases/latest) |
| 6 | +[](https://github.com/emberstack/docker-sftp/releases/latest) |
| 7 | +[](https://microbadger.com/images/emberstack/sftp) |
| 8 | +[](https://microbadger.com/images/emberstack/sftp) |
| 9 | +[](https://hub.docker.com/r/emberstack/sftp) |
| 10 | +[](https://hub.docker.com/r/remberstack/sftp) |
| 11 | +[](LICENSE) |
| 12 | + |
| 13 | + |
| 14 | +> Supports architectures: `amd64`. Coming soon: `arm` and `arm64` |
| 15 | +
|
| 16 | +## Usage |
| 17 | + |
| 18 | +The SFTP server can be easily deployed to any platform that can host containers based on Docker. |
| 19 | +Below are deployment methods for: |
| 20 | +- Docker CLI |
| 21 | +- Docker-Compose |
| 22 | +- Kubernetes using Helm (recommended for Kubernetes) |
| 23 | +- Kubernetes (manual) |
| 24 | + |
| 25 | +Process: |
| 26 | +1) Create server configuration |
| 27 | +2) Mount volumes as needed |
| 28 | +3) Set host file for consistent server fingerprint |
| 29 | + |
| 30 | +### Configuration |
| 31 | + |
| 32 | +The SFTP server uses a `json` based configuration file for default server options and to define users. This file has to be mounted on `/sftp/config/sftp.json` inside the container. |
| 33 | +Environment variable based configuration is not supported (see the `Advanced Configuration` section below for the reasons). |
| 34 | + |
| 35 | +Below is the simplest configuration file for the SFTP server: |
| 36 | + |
| 37 | +```json |
| 38 | +{ |
| 39 | + "global": { |
| 40 | + "chroot": { |
| 41 | + "directory": "%h", |
| 42 | + "startPath": "sftp" |
| 43 | + }, |
| 44 | + "directories": [ "sftp" ] |
| 45 | + }, |
| 46 | + "users": [ |
| 47 | + { |
| 48 | + "username": "demo", |
| 49 | + "password": "password" |
| 50 | + }, |
| 51 | + { |
| 52 | + "username": "demo2", |
| 53 | + "password": "password" |
| 54 | + } |
| 55 | + ] |
| 56 | +} |
| 57 | +``` |
| 58 | +This configuration creates a user `demo` with the password `demo`. |
| 59 | +A directory "sftp" is created for each user in the own home and is accessible for read/write. |
| 60 | +The user is `chrooted` to the `/home/demo` directory. Upon connect, the start directory is `sftp`. |
| 61 | + |
| 62 | +You can add additional users, default directories or customize start directories per user. You can also define the `uid` and `gid` for each user. See the `Advanced Configuration` section below for all configuration options. |
| 63 | + |
| 64 | + |
| 65 | +### Deployment using Docker CLI |
| 66 | + |
| 67 | +> Simple Docker CLI run |
| 68 | +
|
| 69 | +```shellsession |
| 70 | +$ docker run -p 22:22 -d emberstack/sftp --name sftp |
| 71 | +``` |
| 72 | +This will start a SFTP in the container `sftp` with the default configuration. You can connect to it and login with the `user: demo` and `password: demo`. |
| 73 | + |
| 74 | +> Provide your configuration |
| 75 | +
|
| 76 | +```shellsession |
| 77 | +$ docker run -p 22:22 -d emberstack/sftp --name sftp -v /host/sftp.conf:/sftp/config/sftp.conf:ro |
| 78 | +``` |
| 79 | +This will override the default (`/sftp/config/sftp.conf`) configuration with the one from the host `/host/sftp.conf`. |
| 80 | + |
| 81 | +> Mount a directory from the host for the user 'demo' |
| 82 | +
|
| 83 | +```shellsession |
| 84 | +$ docker run -p 22:22 -d emberstack/sftp --name sftp -v /host/sftp.conf:/sftp/config/sftp.conf:ro -v /host/demo:/home/demo/sftp |
| 85 | +``` |
| 86 | +This will mount the `demo` directory from the host on the `sftp` directory for the "demo" user. |
| 87 | + |
| 88 | + |
| 89 | +### Deployment using Docker Compose |
| 90 | + |
| 91 | +> Simple docker-compose configuration |
| 92 | +
|
| 93 | +Create a docker-compose configuration file: |
| 94 | +```yaml |
| 95 | +version: '3' |
| 96 | +services: |
| 97 | + sftp: |
| 98 | + image: "emberstack/sftp" |
| 99 | + ports: |
| 100 | + - "22:22" |
| 101 | + volumes: |
| 102 | + - ../config-samples/sample.sftp.json:/sftp/config/sftp.json:ro |
| 103 | +``` |
| 104 | +And run it using docker-compose |
| 105 | +```shellsession |
| 106 | +$ docker-compose -p sftp -f docker-compose.yaml up -d |
| 107 | +``` |
| 108 | + |
| 109 | +The above configuration is available in the `deploy\docker-compose` folder in this repository. You can use it to start customizing the deployment for your environment. |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +### Deployment to Kubernetes using Helm |
| 114 | + |
| 115 | +Use Helm to install the latest released chart: |
| 116 | +```shellsession |
| 117 | +$ helm repo add emberstack https://emberstack.github.io/helm-charts |
| 118 | +$ helm repo update |
| 119 | +$ helm upgrade --install sftp emberstack/sftp |
| 120 | +``` |
| 121 | + |
| 122 | +You can customize the values of the helm deployment by using the following Values: |
| 123 | + |
| 124 | +| Parameter | Description | Default | |
| 125 | +| ------------------------------------ | -------------------------------------------------------------------------------- | ------------------------------------------------------- | |
| 126 | +| `nameOverride` | Overrides release name | `""` | |
| 127 | +| `fullnameOverride` | Overrides release fullname | `""` | |
| 128 | +| `image.repository` | Container image repository | `emberstack/sftp` | |
| 129 | +| `image.tag` | Container image tag | `latest` | |
| 130 | +| `image.pullPolicy` | Container image pull policy | `Always` if `image.tag` is `latest`, else `IfNotPresent`| |
| 131 | +| `storage.volumes` | Defines additional volumes for the pod | `{}` | |
| 132 | +| `storage.volumeMounts` | Defines additional volumes mounts for the sftp container | `{}` | |
| 133 | +| `configuration.global.chroot.directory` | Global chroot directory for the `sftp` user group. Can be overriden per-user | `"%h"` | |
| 134 | +| `configuration.global.chroot.startPath` | Start path for the `sftp` user group. Can be overriden per-user | `"sftp"` | |
| 135 | +| `configuration.global.directories` | Directories that get created for all `sftp` users. Can be appended per user | `["sftp"]` | |
| 136 | +| `configuration.users` | Array of users and their properties | Contains `demo` user by default | |
| 137 | +| `configuration.users[].username` | Set the user's username | N/A | |
| 138 | +| `configuration.users[].password` | Set the user's password. If empty or `null`, password authentication is disabled | N/A | |
| 139 | +| `configuration.users[].passwordEncrypted` | `true` or `false`. Indicates if the password value is already encrypted | `false` | |
| 140 | +| `configuration.users[].passwordEncrypted` | `true` or `false`. Indicates if the password value is already encrypted | `false` | |
| 141 | +| `configuration.users[].chroot` | If set, will override global `chroot` settings for this user. | `null` | |
| 142 | +| `configuration.users[].directories` | Array of additional directories created for this user | `null` | |
| 143 | +| `initContainers` | Additional initContainers for the pod | `{}` | |
| 144 | +| `resources` | Resource limits | `{}` | |
| 145 | +| `nodeSelector` | Node labels for pod assignment | `{}` | |
| 146 | +| `tolerations` | Toleration labels for pod assignment | `[]` | |
| 147 | +| `affinity` | Node affinity for pod assignment | `{}` | |
| 148 | + |
| 149 | +> Find us on [Helm Hub](https://hub.helm.sh/charts/emberstack) |
| 150 | +
|
| 151 | + |
| 152 | +### Deployment to Kubernetes using kubectl |
| 153 | +Each release (found on the [Releases](https://github.com/EmberStack/docker-sftp/releases) GitHub page) contains the manual deployment file (`sftp.yaml`). |
| 154 | + |
| 155 | +```shellsession |
| 156 | +$ kubectl apply -f https://github.com/EmberStack/docker-sftp/releases/latest/download/sftp.yaml |
| 157 | +``` |
| 158 | + |
| 159 | +## Advanced Configuration |
| 160 | + |
| 161 | +TODO: This section is under development due to the number of configuration options being added. Please open an issue on the [emberstack/docker-sftp](https://github.com/emberstack/docker-sftp) project if you need help. |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | +## Final Word |
| 166 | +This project is a work in progress. More features and configuration options will be added. If you want to contribute or have feedback, please feel free to create an Issue or contrinute with a Pull Request. |
| 167 | +This project was initially inspired by [atmoz/sftp](https://github.com/atmoz/sftp) but has changed from the original design to increase flexibility and range of supported deployment options. This is no longer a lightweight SFTP server, the target being a rich set of features, to the detriment of simplicity. If you're looking for a simple SFTP docker image, please consider the [atmoz/sftp](https://github.com/atmoz/sftp) project. |
0 commit comments