Skip to content

Commit 30cec02

Browse files
authored
device: support distinct remount args for encrypted and unencrypted policies (#896)
SNT-359 Support new RemovableMediaAction and EncryptedRemovableMediaAction along with RemovableMediaRemountFlags and EncryptedRemovableMediaRemountFlags Deprecate BlockUSBMount and USBRemountMode
1 parent 9eb4125 commit 30cec02

26 files changed

Lines changed: 891 additions & 513 deletions

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ bazel_dep(name = "boringssl", version = "0.20260211.0")
1717
bazel_dep(name = "protos", version = "1.0.1", repo_name = "northpolesec_protos")
1818
git_override(
1919
module_name = "protos",
20-
commit = "96ef1e30fd33c455b90ca40815fcda789a2ee609",
20+
commit = "82ff2bad461c860ee9c48c342e51d1a59bd40065",
2121
remote = "https://github.com/northpolesec/protos",
2222
)
2323

Source/common/SNTBlockMessage.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ + (NSAttributedString*)attributedBlockMessageForDeviceEvent:(SNTDeviceEvent*)eve
111111
@"(e.g. USB device) is blocked from mounting");
112112

113113
// Use the actual event.remountArgs rather than global config,
114-
// since RemountUSBMode can be both for BlockUnencryptedRemovableMediaMount and BlockUSBMount
114+
// since we have distinct RemovableMediaRemountFlags and EncryptedRemovableMediaRemountFlags
115115
if (event.remountArgs.count > 0) {
116116
return [SNTBlockMessage formatMessage:[[SNTConfigurator configurator] remountUSBBlockMessage]
117117
withFallback:defaultRemountMessage];

Source/common/SNTCommonEnums.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ typedef NS_ENUM(NSInteger, SNTDeviceManagerStartupPreferences) {
189189
SNTDeviceManagerStartupPreferencesForceRemount,
190190
};
191191

192+
typedef NS_ENUM(NSInteger, SNTRemovableMediaAction) {
193+
SNTRemovableMediaActionAllow,
194+
SNTRemovableMediaActionBlock,
195+
SNTRemovableMediaActionRemount,
196+
};
197+
192198
typedef NS_ENUM(NSInteger, SNTSyncType) {
193199
SNTSyncTypeNormal,
194200
SNTSyncTypeClean,

Source/common/SNTConfigBundle.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
- (void)syncType:(void (^)(SNTSyncType))block;
2929
- (void)allowlistRegex:(void (^)(NSString*))block;
3030
- (void)blocklistRegex:(void (^)(NSString*))block;
31-
- (void)blockUSBMount:(void (^)(BOOL))block;
32-
- (void)blockUnencryptedRemovableMediaMount:(void (^)(BOOL))block;
33-
- (void)remountUSBMode:(void (^)(NSArray*))block;
31+
- (void)removableMediaAction:(void (^)(NSString*))block;
32+
- (void)removableMediaRemountFlags:(void (^)(NSArray<NSString*>*))block;
33+
- (void)encryptedRemovableMediaAction:(void (^)(NSString*))block;
34+
- (void)encryptedRemovableMediaRemountFlags:(void (^)(NSArray<NSString*>*))block;
3435
- (void)blockNetworkMount:(void (^)(BOOL))block;
3536
- (void)bannedNetworkMountBlockMessage:(void (^)(NSString*))block;
3637
- (void)allowedNetworkMountHosts:(void (^)(NSArray<NSString*>*))block;

Source/common/SNTConfigBundle.mm

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ @interface SNTConfigBundle ()
2525
@property NSNumber* syncType;
2626
@property NSString* allowlistRegex;
2727
@property NSString* blocklistRegex;
28-
@property NSNumber* blockUSBMount;
29-
@property NSNumber* blockUnencryptedRemovableMediaMount;
30-
@property NSArray* remountUSBMode;
28+
@property NSString* removableMediaAction;
29+
@property NSArray<NSString*>* removableMediaRemountFlags;
30+
@property NSString* encryptedRemovableMediaAction;
31+
@property NSArray<NSString*>* encryptedRemovableMediaRemountFlags;
3132
@property NSNumber* blockNetworkMount;
3233
@property NSString* bannedNetworkMountBlockMessage;
3334
@property NSArray<NSString*>* allowedNetworkMountHosts;
@@ -64,9 +65,10 @@ - (void)encodeWithCoder:(NSCoder*)coder {
6465
ENCODE(coder, syncType);
6566
ENCODE(coder, allowlistRegex);
6667
ENCODE(coder, blocklistRegex);
67-
ENCODE(coder, blockUSBMount);
68-
ENCODE(coder, blockUnencryptedRemovableMediaMount);
69-
ENCODE(coder, remountUSBMode);
68+
ENCODE(coder, removableMediaAction);
69+
ENCODE(coder, removableMediaRemountFlags);
70+
ENCODE(coder, encryptedRemovableMediaAction);
71+
ENCODE(coder, encryptedRemovableMediaRemountFlags);
7072
ENCODE(coder, blockNetworkMount);
7173
ENCODE(coder, bannedNetworkMountBlockMessage);
7274
ENCODE(coder, allowedNetworkMountHosts);
@@ -99,9 +101,10 @@ - (instancetype)initWithCoder:(NSCoder*)decoder {
99101
DECODE(decoder, syncType, NSNumber);
100102
DECODE(decoder, allowlistRegex, NSString);
101103
DECODE(decoder, blocklistRegex, NSString);
102-
DECODE(decoder, blockUSBMount, NSNumber);
103-
DECODE(decoder, blockUnencryptedRemovableMediaMount, NSNumber);
104-
DECODE_ARRAY(decoder, remountUSBMode, NSString);
104+
DECODE(decoder, removableMediaAction, NSString);
105+
DECODE_ARRAY(decoder, removableMediaRemountFlags, NSString);
106+
DECODE(decoder, encryptedRemovableMediaAction, NSString);
107+
DECODE_ARRAY(decoder, encryptedRemovableMediaRemountFlags, NSString);
105108
DECODE(decoder, blockNetworkMount, NSNumber);
106109
DECODE(decoder, bannedNetworkMountBlockMessage, NSString);
107110
DECODE_ARRAY(decoder, allowedNetworkMountHosts, NSString);
@@ -153,21 +156,27 @@ - (void)blocklistRegex:(void (^)(NSString*))block {
153156
}
154157
}
155158

156-
- (void)blockUSBMount:(void (^)(BOOL))block {
157-
if (self.blockUSBMount) {
158-
block([self.blockUSBMount boolValue]);
159+
- (void)removableMediaAction:(void (^)(NSString*))block {
160+
if (self.removableMediaAction) {
161+
block(self.removableMediaAction);
159162
}
160163
}
161164

162-
- (void)blockUnencryptedRemovableMediaMount:(void (^)(BOOL))block {
163-
if (self.blockUnencryptedRemovableMediaMount) {
164-
block([self.blockUnencryptedRemovableMediaMount boolValue]);
165+
- (void)encryptedRemovableMediaAction:(void (^)(NSString*))block {
166+
if (self.encryptedRemovableMediaAction) {
167+
block(self.encryptedRemovableMediaAction);
165168
}
166169
}
167170

168-
- (void)remountUSBMode:(void (^)(NSArray*))block {
169-
if (self.remountUSBMode) {
170-
block(self.remountUSBMode);
171+
- (void)encryptedRemovableMediaRemountFlags:(void (^)(NSArray<NSString*>*))block {
172+
if (self.encryptedRemovableMediaRemountFlags) {
173+
block(self.encryptedRemovableMediaRemountFlags);
174+
}
175+
}
176+
177+
- (void)removableMediaRemountFlags:(void (^)(NSArray<NSString*>*))block {
178+
if (self.removableMediaRemountFlags) {
179+
block(self.removableMediaRemountFlags);
171180
}
172181
}
173182

Source/common/SNTConfigBundleTest.mm

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ @interface SNTConfigBundle (Testing)
2727
@property NSNumber* syncType;
2828
@property NSString* allowlistRegex;
2929
@property NSString* blocklistRegex;
30-
@property NSNumber* blockUSBMount;
31-
@property NSNumber* blockUnencryptedRemovableMediaMount;
32-
@property NSArray* remountUSBMode;
30+
@property NSString* removableMediaAction;
31+
@property NSArray<NSString*>* removableMediaRemountFlags;
32+
@property NSString* encryptedRemovableMediaAction;
33+
@property NSArray<NSString*>* encryptedRemovableMediaRemountFlags;
3334
@property NSNumber* blockNetworkMount;
3435
@property NSString* bannedNetworkMountBlockMessage;
3536
@property NSArray<NSString*>* allowedNetworkMountHosts;
@@ -61,17 +62,18 @@ @implementation SNTConfigBundleTest
6162

6263
- (void)testGettersWithValues {
6364
__block XCTestExpectation* exp = [self expectationWithDescription:@"Result Blocks"];
64-
exp.expectedFulfillmentCount = 28;
65+
exp.expectedFulfillmentCount = 29;
6566
NSDate* nowDate = [NSDate now];
6667

6768
SNTConfigBundle* bundle = [[SNTConfigBundle alloc] init];
6869
bundle.clientMode = @(SNTClientModeLockdown);
6970
bundle.syncType = @(SNTSyncTypeNormal);
7071
bundle.allowlistRegex = @"allow";
7172
bundle.blocklistRegex = @"block";
72-
bundle.blockUSBMount = @(YES);
73-
bundle.blockUnencryptedRemovableMediaMount = @(YES);
74-
bundle.remountUSBMode = @[ @"foo" ];
73+
bundle.removableMediaAction = @"Block";
74+
bundle.removableMediaRemountFlags = @[ @"foo" ];
75+
bundle.encryptedRemovableMediaAction = @"Remount";
76+
bundle.encryptedRemovableMediaRemountFlags = @[ @"rdonly" ];
7577
bundle.blockNetworkMount = @(YES);
7678
bundle.bannedNetworkMountBlockMessage = @"Network mount blocked";
7779
bundle.allowedNetworkMountHosts = @[ @"example.com", @"localhost" ];
@@ -116,18 +118,23 @@ - (void)testGettersWithValues {
116118
[exp fulfill];
117119
}];
118120

119-
[bundle blockUSBMount:^(BOOL val) {
120-
XCTAssertNotEqual(val, NO);
121+
[bundle removableMediaAction:^(NSString* val) {
122+
XCTAssertEqualObjects(val, @"Block");
121123
[exp fulfill];
122124
}];
123125

124-
[bundle blockUnencryptedRemovableMediaMount:^(BOOL val) {
125-
XCTAssertNotEqual(val, NO);
126+
[bundle removableMediaRemountFlags:^(NSArray<NSString*>* val) {
127+
XCTAssertEqualObjects(val, @[ @"foo" ]);
126128
[exp fulfill];
127129
}];
128130

129-
[bundle remountUSBMode:^(NSArray* val) {
130-
XCTAssertEqualObjects(val, @[ @"foo" ]);
131+
[bundle encryptedRemovableMediaAction:^(NSString* val) {
132+
XCTAssertEqualObjects(val, @"Remount");
133+
[exp fulfill];
134+
}];
135+
136+
[bundle encryptedRemovableMediaRemountFlags:^(NSArray<NSString*>* val) {
137+
XCTAssertEqualObjects(val, @[ @"rdonly" ]);
131138
[exp fulfill];
132139
}];
133140

@@ -264,15 +271,19 @@ - (void)testGettersWithoutValues {
264271
XCTFail(@"This shouldn't be called");
265272
}];
266273

267-
[bundle blockUSBMount:^(BOOL val) {
274+
[bundle removableMediaAction:^(NSString* val) {
275+
XCTFail(@"This shouldn't be called");
276+
}];
277+
278+
[bundle removableMediaRemountFlags:^(NSArray<NSString*>* val) {
268279
XCTFail(@"This shouldn't be called");
269280
}];
270281

271-
[bundle blockUnencryptedRemovableMediaMount:^(BOOL val) {
282+
[bundle encryptedRemovableMediaAction:^(NSString* val) {
272283
XCTFail(@"This shouldn't be called");
273284
}];
274285

275-
[bundle remountUSBMode:^(NSArray* val) {
286+
[bundle encryptedRemovableMediaRemountFlags:^(NSArray<NSString*>* val) {
276287
XCTFail(@"This shouldn't be called");
277288
}];
278289

Source/common/SNTConfigurator.h

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -847,32 +847,47 @@ extern NSString* _Nonnull const kEnableMenuItemUserOverride;
847847
#pragma mark - USB Settings
848848

849849
///
850-
/// USB Mount Blocking. Defaults to false.
850+
/// The action to apply to all removable media. Defaults to Allow.
851+
/// If unset, falls back to deprecated BlockUSBMount + RemountUSBMode.
851852
///
852-
@property(nonatomic, readonly) BOOL blockUSBMount;
853+
@property(nonatomic, readonly) SNTRemovableMediaAction removableMediaAction;
853854

854855
///
855-
/// Set the block USB mount state as received from a sync server.
856+
/// Set the removable media action as received from a sync server.
856857
///
857-
- (void)setSyncServerBlockUSBMount:(BOOL)enabled;
858+
- (void)setSyncServerRemovableMediaAction:(nullable NSString*)action;
858859

859860
///
860-
/// If YES, unencrypted external USB storage devices will be blocked from mounting.
861-
/// Encrypted devices will be allowed (or remounted per RemountUSBMode).
862-
/// This setting is independent of BlockUSBMount. Defaults to NO.
861+
/// Mount flags for removable media when action is "Remount".
862+
/// If unset, falls back to deprecated RemountUSBMode.
863863
///
864-
@property(nonatomic, readonly) BOOL blockUnencryptedRemovableMediaMount;
864+
@property(nullable, nonatomic, readonly) NSArray<NSString*>* removableMediaRemountFlags;
865865

866866
///
867-
/// Set the block unencrypted USB mount state as received from a sync server.
867+
/// Set the removable media remount flags as received from a sync server.
868868
///
869-
- (void)setSyncServerBlockUnencryptedRemovableMediaMount:(BOOL)enabled;
869+
- (void)setSyncServerRemovableMediaRemountFlags:(nullable NSArray<NSString*>*)flags;
870870

871871
///
872-
/// Comma-separated `$ mount -o` arguments used for forced remounting of USB devices. Default
873-
/// to fully allow/deny without remounting if unset.
872+
/// The action to apply to encrypted removable media.
873+
/// If unset, encrypted volumes use removableMediaAction.
874874
///
875-
@property(nullable, nonatomic) NSArray<NSString*>* remountUSBMode;
875+
@property(nonatomic, readonly) SNTRemovableMediaAction encryptedRemovableMediaAction;
876+
877+
///
878+
/// Set the encrypted removable media action as received from a sync server.
879+
///
880+
- (void)setSyncServerEncryptedRemovableMediaAction:(nullable NSString*)action;
881+
882+
///
883+
/// Mount flags for encrypted removable media when action is "Remount".
884+
///
885+
@property(nullable, nonatomic, readonly) NSArray<NSString*>* encryptedRemovableMediaRemountFlags;
886+
887+
///
888+
/// Set the encrypted removable media remount flags as received from a sync server.
889+
///
890+
- (void)setSyncServerEncryptedRemovableMediaRemountFlags:(nullable NSArray<NSString*>*)flags;
876891

877892
///
878893
/// Network Mount Blocking. Defaults to false.

0 commit comments

Comments
 (0)