Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ You can customize the values of the helm deployment by using the following Value
| `configuration.Users[].GID` | Sets the user's GID. A group is created for this value and the user is included | `null` |
| `configuration.Users[].Chroot` | If set, will override global `Chroot` settings for this user. | `null` |
| `configuration.Users[].Directories` | Array of additional directories created for this user | `null` |
| `configuration.Users[].Umask` | If set, will set a user-specific `umask` value for this user. | `null` |
| `initContainers` | Additional initContainers for the pod | `{}` |
| `resources` | Resource limits | `{}` |
| `nodeSelector` | Node labels for pod assignment | `{}` |
Expand Down
3 changes: 3 additions & 0 deletions src/ES.SFTP/Configuration/Elements/UserDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ public class UserDefinition
public ChrootDefinition Chroot { get; set; } = new();
public List<string> Directories { get; set; } = new();
public List<string> PublicKeys { get; set; } = new();

// Umask property for user-specific file permissions
public string Umask { get; set; }
}
17 changes: 14 additions & 3 deletions src/ES.SFTP/SSH/SSHService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ private async Task UpdateConfiguration()
PKIandPassword = sftpConfig.Global.PKIandPassword
};

var exceptionalUsers = sftpConfig.Users.Where(s => s.Chroot != null).ToList();
var exceptionalChrootUsers = sftpConfig.Users.Where(s => s.Chroot != null).ToList();
var exceptionalUmaskUsers = sftpConfig.Users.Where(s => !string.IsNullOrWhiteSpace(s.Umask)).ToList();

var standardDeclarations = new[]
{
Expand All @@ -82,7 +83,17 @@ private async Task UpdateConfiguration()
: s.Username)
);

sshdConfig.MatchBlocks.AddRange(exceptionalUsers.Select(s => new MatchBlock
sshdConfig.MatchBlocks.AddRange(exceptionalUmaskUsers.Select(s => new MatchBlock
{
Criteria = MatchBlock.MatchCriteria.User,
Match = {s.Username},
Declarations = new List<string>(standardDeclarations)
{
$"ForceCommand internal-sftp -u {s.Umask}"
}
}));

sshdConfig.MatchBlocks.AddRange(exceptionalChrootUsers.Select(s => new MatchBlock
{
Criteria = MatchBlock.MatchCriteria.User,
Match = {s.Username},
Expand All @@ -99,7 +110,7 @@ private async Task UpdateConfiguration()
{
Criteria = MatchBlock.MatchCriteria.User,
Match = {"*"},
//Except = exceptionalUsers.Select(s => s.Username).ToList(),
//Except = exceptionalChrootUsers.Select(s => s.Username).ToList(),
Declarations = new List<string>(standardDeclarations)
{
$"ChrootDirectory {sftpConfig.Global.Chroot.Directory}",
Expand Down