Skip to content

Commit 8515f09

Browse files
authored
App Sandbox build setting ends up in iOS signed app (#432)
1 parent db2620b commit 8515f09

File tree

3 files changed

+23
-58
lines changed

3 files changed

+23
-58
lines changed

Sources/SWBCore/SigningSupport.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public protocol PlatformSigningContext
3030
func shouldPassEntitlementsFileContentToCodeSign() -> Bool
3131

3232
func requiresEntitlements(_ scope: MacroEvaluationScope, hasProfile: Bool, productFileType: FileTypeSpec) -> Bool
33+
34+
func supportsAppSandboxAndHardenedRuntime() -> Bool
3335
}
3436

3537
extension PlatformSigningContext
@@ -58,12 +60,19 @@ extension PlatformSigningContext
5860
{
5961
return hasProfile || scope.evaluate(BuiltinMacros.ENTITLEMENTS_REQUIRED)
6062
}
63+
64+
@_spi(Testing) public func supportsAppSandboxAndHardenedRuntime() -> Bool {
65+
return false
66+
}
6167
}
6268

6369

6470
/// Provides behavior for code signing for the macOS platform.
6571
@_spi(Testing) public struct MacSigningContext: PlatformSigningContext
6672
{
73+
@_spi(Testing) public func supportsAppSandboxAndHardenedRuntime() -> Bool {
74+
return true
75+
}
6776
}
6877

6978

Sources/SWBCore/SpecImplementations/Tools/ProductPackaging.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,12 @@ public final class ProductPackagingToolSpec : GenericCommandLineToolSpec, SpecId
114114
entitlementsDictionary["com.apple.security.get-task-allow"] = nil
115115
}
116116

117-
let isAppSandboxEnabled = cbc.scope.evaluate(BuiltinMacros.ENABLE_APP_SANDBOX)
118-
let isHardenedRuntimeEnabled = cbc.scope.evaluate(BuiltinMacros.ENABLE_HARDENED_RUNTIME)
119-
120117
// rdar://142845111 (Turn on `AppSandboxConflictingValuesEmitsWarning` by default)
121118
if SWBFeatureFlag.enableAppSandboxConflictingValuesEmitsWarning.value {
122119
EntitlementConflictDiagnosticEmitter.checkForConflicts(cbc, delegate, entitlementsDictionary: entitlementsDictionary, entitlementsPath: codeSignEntitlementsInput?.absolutePath)
123120
}
124121

125-
if isAppSandboxEnabled || isHardenedRuntimeEnabled {
122+
if cbc.producer.platform?.signingContext.supportsAppSandboxAndHardenedRuntime() == true {
126123
// Inject entitlements that are settable via build settings.
127124
// This is only supported when App Sandbox or Hardened Runtime is enabled.
128125
for (buildSetting, entitlementPrefix) in Self.sandboxFileAccessSettingsAndEntitlements {

Tests/SWBBuildSystemTests/EntitlementsBuildOperationTests.swift

Lines changed: 13 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -238,24 +238,24 @@ fileprivate struct EntitlementsBuildOperationTests: CoreBasedTests {
238238
}
239239
}
240240

241-
/// Test that the `ProcessProductEntitlementsTaskAction` does not embed build settings based entitlements that are dependent on App Sandbox being enabled, when App Sandbox is disabled.
242-
@Test(.requireSDKs(.macOS))
243-
func macOSAppSandboxEnabledEntitlementsWithSandboxDisabled() async throws {
241+
/// Test that the `ProcessProductEntitlementsTaskAction` does not embed build settings that only apply to macOS.
242+
@Test(.requireSDKs(.iOS))
243+
func iOSAppSandboxAndHardnedRuntimeBuildSettingEnabled() async throws {
244244
try await withTemporaryDirectory { tmpDirPath async throws -> Void in
245245
let testWorkspace = entitlementsTestWorkspace(
246246
sourceRoot: tmpDirPath,
247247
buildSettings: [
248248
"PRODUCT_NAME": "$(TARGET_NAME)",
249249
"INFOPLIST_FILE": "Info.plist",
250-
"CODE_SIGN_IDENTITY": "-",
251-
"RUNTIME_EXCEPTION_ALLOW_DYLD_ENVIRONMENT_VARIABLES": "NO",
252-
"RUNTIME_EXCEPTION_ALLOW_JIT": "NO",
253-
"RUNTIME_EXCEPTION_ALLOW_UNSIGNED_EXECUTABLE_MEMORY": "NO",
254-
"AUTOMATION_APPLE_EVENTS": "NO",
255-
"RUNTIME_EXCEPTION_DEBUGGING_TOOL": "NO",
256-
"RUNTIME_EXCEPTION_DISABLE_EXECUTABLE_PAGE_PROTECTION": "NO",
257-
"RUNTIME_EXCEPTION_DISABLE_LIBRARY_VALIDATION": "NO",
258-
"ENABLE_APP_SANDBOX": "NO",
250+
"AD_HOC_CODE_SIGNING_ALLOWED": "YES",
251+
"RUNTIME_EXCEPTION_ALLOW_DYLD_ENVIRONMENT_VARIABLES": "YES",
252+
"RUNTIME_EXCEPTION_ALLOW_JIT": "YES",
253+
"RUNTIME_EXCEPTION_ALLOW_UNSIGNED_EXECUTABLE_MEMORY": "YES",
254+
"AUTOMATION_APPLE_EVENTS": "YES",
255+
"RUNTIME_EXCEPTION_DEBUGGING_TOOL": "YES",
256+
"RUNTIME_EXCEPTION_DISABLE_EXECUTABLE_PAGE_PROTECTION": "YES",
257+
"RUNTIME_EXCEPTION_DISABLE_LIBRARY_VALIDATION": "YES",
258+
"ENABLE_APP_SANDBOX": "YES",
259259
"ENABLE_FILE_ACCESS_DOWNLOADS_FOLDER": "readwrite",
260260
"ENABLE_FILE_ACCESS_PICTURE_FOLDER": "readonly",
261261
"ENABLE_FILE_ACCESS_MUSIC_FOLDER": "readwrite",
@@ -271,7 +271,7 @@ fileprivate struct EntitlementsBuildOperationTests: CoreBasedTests {
271271
"ENABLE_RESOURCE_ACCESS_PHOTO_LIBRARY": "YES",
272272
"ENABLE_RESOURCE_ACCESS_USB": "YES",
273273
"ENABLE_RESOURCE_ACCESS_PRINTING": "YES",
274-
"SDKROOT": "macosx"
274+
"SDKROOT": "iphoneos"
275275
]
276276
)
277277

@@ -481,47 +481,6 @@ fileprivate struct EntitlementsBuildOperationTests: CoreBasedTests {
481481
}
482482
}
483483

484-
/// Test that the `ProcessProductEntitlementsTaskAction` does not embed build settings based entitlements that are dependent on Hardened Runtime being enabled, when Hardened Runtime is disabled.
485-
@Test(.requireSDKs(.macOS))
486-
func macOSHardenedRuntimeEnabledEntitlementsWithHardenedRuntimeDisabled() async throws {
487-
try await withTemporaryDirectory { tmpDirPath async throws -> Void in
488-
let testWorkspace = entitlementsTestWorkspace(
489-
sourceRoot: tmpDirPath,
490-
buildSettings: [
491-
"PRODUCT_NAME": "$(TARGET_NAME)",
492-
"INFOPLIST_FILE": "Info.plist",
493-
"CODE_SIGN_IDENTITY": "-",
494-
"ENABLE_HARDENED_RUNTIME": "NO",
495-
"RUNTIME_EXCEPTION_ALLOW_DYLD_ENVIRONMENT_VARIABLES": "YES",
496-
"RUNTIME_EXCEPTION_ALLOW_JIT": "YES",
497-
"RUNTIME_EXCEPTION_ALLOW_UNSIGNED_EXECUTABLE_MEMORY": "YES",
498-
"AUTOMATION_APPLE_EVENTS": "YES",
499-
"RUNTIME_EXCEPTION_DEBUGGING_TOOL": "YES",
500-
"RUNTIME_EXCEPTION_DISABLE_EXECUTABLE_PAGE_PROTECTION": "YES",
501-
"RUNTIME_EXCEPTION_DISABLE_LIBRARY_VALIDATION": "YES",
502-
"ENABLE_FILE_ACCESS_DOWNLOADS_FOLDER": "readwrite",
503-
"ENABLE_FILE_ACCESS_PICTURE_FOLDER": "readonly",
504-
"ENABLE_FILE_ACCESS_MUSIC_FOLDER": "readwrite",
505-
"ENABLE_FILE_ACCESS_MOVIES_FOLDER": "readonly",
506-
"ENABLE_INCOMING_NETWORK_CONNECTIONS": "YES",
507-
"ENABLE_OUTGOING_NETWORK_CONNECTIONS": "YES",
508-
"ENABLE_RESOURCE_ACCESS_AUDIO_INPUT": "YES",
509-
"ENABLE_RESOURCE_ACCESS_BLUETOOTH": "YES",
510-
"ENABLE_RESOURCE_ACCESS_CALENDARS": "YES",
511-
"ENABLE_RESOURCE_ACCESS_CAMERA": "YES",
512-
"ENABLE_RESOURCE_ACCESS_CONTACTS": "YES",
513-
"ENABLE_RESOURCE_ACCESS_LOCATION": "YES",
514-
"ENABLE_RESOURCE_ACCESS_PHOTO_LIBRARY": "YES",
515-
"SDKROOT": "macosx"
516-
]
517-
)
518-
519-
try await buildTestBinaryAndValidateEntitlements(testWorkspace: testWorkspace, expectedEntitlements: [
520-
"com.apple.application-identifier": "$(AppIdentifierPrefix)$(CFBundleIdentifier)",
521-
])
522-
}
523-
}
524-
525484
@Test(.requireSDKs(.iOS))
526485
func simulatorEntitlementsSections() async throws {
527486
try await withTemporaryDirectory { tmpDirPath in

0 commit comments

Comments
 (0)