You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The bssh-server provides a comprehensive policy-based system for controlling file transfers in SFTP and SCP operations. The filter system allows administrators to allow, deny, or log file operations based on various criteria.
|**Directory**|`directory`| Component anywhere in path |`.git`, `.ssh`|
737
+
|**Composite**|`composite`| AND/OR/NOT logic | See below |
738
+
739
+
### Glob Pattern Matching
740
+
741
+
Glob patterns support standard wildcards:
742
+
-`*` - matches any sequence of characters
743
+
-`?` - matches any single character
744
+
-`[abc]` - matches any character in the set
745
+
-`[!abc]` - matches any character not in the set
746
+
747
+
```yaml
748
+
rules:
749
+
- pattern: "*.key"# All .key files
750
+
- pattern: "secret?.txt"# secret1.txt, secretA.txt, etc.
751
+
- pattern: "[0-9]*.log"# Log files starting with a digit
752
+
```
753
+
754
+
### Extension Matching
755
+
756
+
Multi-extension matching is case-insensitive by default:
757
+
758
+
```yaml
759
+
rules:
760
+
- name: "block-executables"
761
+
extensions: ["exe", "bat", "sh", "ps1", "cmd"]
762
+
action: deny
763
+
764
+
- name: "block-archives"
765
+
extensions: ["zip", "tar", "gz", "rar", "7z"]
766
+
action: deny
767
+
```
768
+
769
+
### Composite Rules
770
+
771
+
Composite rules allow combining multiple matchers with logical operators:
772
+
773
+
**AND Logic** - All matchers must match:
774
+
```yaml
775
+
- name: "env-outside-home"
776
+
composite:
777
+
type: and
778
+
matchers:
779
+
- pattern: "*.env"
780
+
- not:
781
+
path_prefix: "/home"
782
+
action: deny
783
+
```
784
+
785
+
**OR Logic** - Any matcher must match:
786
+
```yaml
787
+
- name: "sensitive-files"
788
+
composite:
789
+
type: or
790
+
matchers:
791
+
- pattern: "*.key"
792
+
- pattern: "*.pem"
793
+
- pattern: "*.p12"
794
+
action: deny
795
+
```
796
+
797
+
**NOT Logic** - Invert the match (whitelist pattern):
798
+
```yaml
799
+
- name: "whitelist-data-only"
800
+
composite:
801
+
type: not
802
+
matcher:
803
+
path_prefix: "/data"
804
+
action: deny # Deny everything NOT in /data
805
+
```
806
+
807
+
### Operation and User Restrictions
808
+
809
+
Rules can be limited to specific operations or users:
810
+
811
+
```yaml
812
+
rules:
813
+
# Prevent deletion of log files
814
+
- name: "protect-logs"
815
+
pattern: "*.log"
816
+
action: deny
817
+
operations: ["delete"]
818
+
819
+
# Block uploads of executables for guest users
820
+
- name: "guest-no-executables"
821
+
extensions: ["exe", "sh", "bat"]
822
+
action: deny
823
+
operations: ["upload"]
824
+
users: ["guest", "anonymous"]
825
+
```
826
+
827
+
**Available Operations:**
828
+
- `upload` - File uploads
829
+
- `download`- File downloads
830
+
- `delete`- File deletion
831
+
- `rename`- File rename/move
832
+
- `createdir`- Directory creation
833
+
- `listdir`- Directory listing
834
+
- `stat`- Reading file attributes
835
+
- `setstat`- Modifying file attributes
836
+
- `symlink`- Creating symbolic links
837
+
- `readlink`- Reading symbolic link targets
838
+
839
+
### Security Features
840
+
841
+
**Path Traversal Protection:**
842
+
All paths are normalized before matching to prevent bypass attempts:
843
+
```
844
+
/var/../etc/passwd -> /etc/passwd
845
+
/home/user/../../etc -> /etc
846
+
```
847
+
848
+
**First Match Wins:**
849
+
Rules are evaluated in order. The first matching rule determines the action. If no rules match, the default action (configurable, defaults to `allow`) is used.
850
+
851
+
### SizeAwareFilter Trait
852
+
853
+
For size-based filtering (e.g., blocking large uploads), the `SizeAwareFilter` trait provides:
854
+
855
+
```rust
856
+
use bssh::server::filter::{SizeAwareFilter, FilterResult, Operation};
857
+
use bssh::server::filter::path::SizeMatcher;
858
+
859
+
// Create a size matcher for files over 100MB
860
+
let large_file_matcher = SizeMatcher::min(100 * 1024 * 1024);
0 commit comments