Skip to content

Commit e2fad5f

Browse files
Add Users[].AllowedHosts to allow specific sources for users (#24)
1 parent 74ca6dd commit e2fad5f

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ You can customize the values of the helm deployment by using the following Value
138138
| `configuration.Users[].Username` | Set the user's username | N/A |
139139
| `configuration.Users[].Password` | Set the user's password. If empty or `null`, password authentication is disabled | N/A |
140140
| `configuration.Users[].PasswordIsEncrypted` | `true` or `false`. Indicates if the password value is already encrypted | `false` |
141+
| `configuration.Users[].AllowedHosts` | Set the user's allowed hosts. If empty, any host is allowed | `[]` |
141142
| `configuration.Users[].PublicKeys` | Set the user's public keys | `[]` |
142143
| `configuration.Users[].UID` | Sets the user's UID. | `null` |
143144
| `configuration.Users[].GID` | Sets the user's GID. A group is created for this value and the user is included | `null` |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class UserDefinition
77
public string Username { get; set; }
88
public string Password { get; set; }
99
public bool PasswordIsEncrypted { get; set; }
10+
public List<string> AllowedHosts { get; set; } = new List<string>();
1011

1112
// ReSharper disable once InconsistentNaming
1213
public int? UID { get; set; }

src/ES.SFTP.Host/SSH/Configuration/SSHConfiguration.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public class SSHConfiguration
77
{
88
public List<MatchBlock> MatchBlocks { get; } = new List<MatchBlock>();
99

10+
public List<string> AllowUsers { get; } = new List<string>();
11+
1012
public override string ToString()
1113
{
1214
var builder = new StringBuilder();
@@ -29,6 +31,8 @@ public override string ToString()
2931
builder.AppendLine("# Subsystem");
3032
builder.AppendLine("Subsystem sftp internal-sftp");
3133
builder.AppendLine();
34+
builder.AppendLine("# Allowed users");
35+
builder.AppendLine($"AllowUsers {System.String.Join(" ", AllowUsers)}");
3236
builder.AppendLine();
3337
builder.AppendLine("# Match blocks");
3438
foreach (var matchBlock in MatchBlocks)

src/ES.SFTP.Host/SSH/SSHService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ private async Task UpdateConfiguration()
7070
"AllowTcpForwarding no"
7171
};
7272

73+
sshdConfig.AllowUsers.AddRange(sftpConfig.Users.Select(s =>
74+
s.AllowedHosts.Any()
75+
? $"{s.Username}@{String.Join(",", s.AllowedHosts)}"
76+
: s.Username)
77+
);
78+
7379
sshdConfig.MatchBlocks.AddRange(exceptionalUsers.Select(s => new MatchBlock
7480
{
7581
Criteria = MatchBlock.MatchCriteria.User,

0 commit comments

Comments
 (0)