Skip to content

Commit 31c19d1

Browse files
Add public key config via configuration.Users.PublicKeys (#16)
1 parent 8690b44 commit 31c19d1

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ You can customize the values of the helm deployment by using the following Value
136136
| `configuration.Users[].Username` | Set the user's username | N/A |
137137
| `configuration.Users[].Password` | Set the user's password. If empty or `null`, password authentication is disabled | N/A |
138138
| `configuration.Users[].PasswordIsEncrypted` | `true` or `false`. Indicates if the password value is already encrypted | `false` |
139+
| `configuration.Users[].PublicKeys` | Set the user's public keys | `[]` |
139140
| `configuration.Users[].UID` | Sets the user's UID. | `null` |
140141
| `configuration.Users[].GID` | Sets the user's GID. A group is created for this value and the user is included | `null` |
141142
| `configuration.Users[].Chroot` | If set, will override global `Chroot` settings for this user. | `null` |

src/ES.SFTP.Host/Business/Configuration/UserDefinition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ public class UserDefinition
1111
public int? GID { get; set; }
1212
public ChrootDefinition Chroot { get; set; }
1313
public List<string> Directories { get; set; } = new List<string>();
14+
public List<string> PublicKeys { get; set; } = new List<string>();
1415
}
1516
}

src/ES.SFTP.Host/Orchestrator.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,15 @@ await ProcessUtil.QuickRun("chown",
413413
if (File.Exists(sshAuthKeysPath)) File.Delete(sshAuthKeysPath);
414414
var authKeysBuilder = new StringBuilder();
415415
foreach (var file in Directory.GetFiles(sshKeysDir))
416+
{
417+
_logger.LogDebug("Adding public key '{file}' for user '{user}'", file, username);
416418
authKeysBuilder.AppendLine(await File.ReadAllTextAsync(file));
419+
}
420+
foreach (var publicKey in user.PublicKeys)
421+
{
422+
_logger.LogDebug("Adding public key from config for user '{user}'", username);
423+
authKeysBuilder.AppendLine(publicKey);
424+
}
417425
await File.WriteAllTextAsync(sshAuthKeysPath, authKeysBuilder.ToString());
418426
await ProcessUtil.QuickRun("chown", $"{user.Username} {sshAuthKeysPath}");
419427
await ProcessUtil.QuickRun("chmod", $"400 {sshAuthKeysPath}");

src/deploy/docker-compose/docker-compose.override.dev.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ services:
99
- "2222:22"
1010
volumes:
1111
- ../samples/sample.dev.sftp.json:/app/config/sftp.json:ro
12-
- ../samples/.ssh/id_demo_rsa.pub:/home/demo/.ssh/keys/id_rsa.pub:ro
13-
- ../samples/.ssh/id_demo2_rsa.pub:/home/demo2/.ssh/keys/id_rsa.pub:ro
12+
- ../samples/.ssh/id_demo2_rsa.pub:/home/demo2/.ssh/keys/id_rsa.pub:ro

src/deploy/samples/sample.dev.sftp.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
"Users": [
1010
{
1111
"Username": "demo",
12-
"Password": "demo"
12+
"Password": "demo",
13+
"PublicKeys": [
14+
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC++8/LkNAu1DPEjnBhzjTF3dkFY+jbRDIsQ/2JkGpRdEHmcCMBTMZGL9PCEEGjWo1Lfocfnk5hWrcloTMCh+rD5VCFNyPCEePK6nyEzZHwcQk9t6dWQwyjtLG8uAhVA30sl0Uw48YcNl9aF8FzpPMWnC7omM2VQPqq0Le05Hu50q0rW97z0vnxpQe+gdNhXOTq0FQ+J2wCwGc7Lxn5uXmZEozmZvlyFVEw6eFlyo9BwLluTHqd5wh9z+jx2U8dQfnIofrgd2Dp86tGNnvS59L/T/0llP8mbvTZNfusMJiO4gNNlsYhj4lQxUQaDL7gy9fxl8Pqf0eGnpOXluSMpAET1oFY5kKgHbfl6peepZzPQ77LQZDNDkrTwqc47VDNlxkdBmV9mp1R+C6no8Ws1Rkk+xYoNbXy6wVOEZy6VSydOy1OsUPpc1hMALYtkxNs88RBeVi/2uQZ8ssXwyKhTIs4zB0JXnSJbOrnkE/NiR8m6r7Nj21oRPcg0Jihl6gq7nU= winromulus@Maximus"
15+
]
1316
},
1417
{
1518
"Username": "demo2",
1619
"Password": "demo2"
1720
}
1821
]
19-
}
22+
}

0 commit comments

Comments
 (0)