# Swift Package Plugins - Network Access

**URL:** <https://forums.swift.org/t/swift-package-plugins-network-access/60693>\
**Category:** Discussion\
**Tags:** packagemanager\
**Created:** [October 6, 2022, 3:04pm UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693 "2022-10-06T15:04:10Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![clayellis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/clayellis/32/43646_2.png) [@clayellis](https://forums.swift.org/u/clayellis)\
**Post date:** [October 6, 2022, 3:04pm UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/1 "2022-10-06T15:04:10Z")

</div>

I'd like to gauge community interest in adding an explicit permission for both Swift Package Manager command and build tool plugins to access the network outside their sandbox. I believe there are compelling reasons for both types of plugins to do so, and I'd like to collect those reasons to advance this to a pitch.

At a minimum, I believe that private plugins (ones that aren't published by the package) should be granted this permission.

If your plugins were granted network access, what kinds of plugins would you write? Alternatively, why should (or shouldn't) plugins be able to access the network?

---

<div class="post-metadata">

**Author:** ![tevelee](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tevelee/32/9775_2.png) [@tevelee](https://forums.swift.org/u/tevelee)\
**Post date:** [October 7, 2022, 10:20am UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/2 "2022-10-07T10:20:22Z")

</div>

My team distributes modular binary xcframeworks to clients. We keep their public interface clean and user-friendly, and for inter-module communication we use [SPI](https://github.com/apple/swift/pull/29810)s (System Programming Interfaces). The distributed xcframework only contains the regular swiftinterface files (without SPI declarations), while private swiftinterface files are stored separately, uploaded to an artifact storage.

In order to build modules which depend on other modules, we have to have access to the inter-module SPIs. So whenever we're building one of these, we need to download the .private.swiftinterface files of the dependent modules from a remote storage and put them next to the regular ones (inside the xcframework bundle) so these APIs become visible to the build system.

Without Swift Package Manager providing network access to the plugin sandbox, we can only fetch these artifacts outside of the realm of SPM.

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [October 7, 2022, 11:46am UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/3 "2022-10-07T11:46:50Z")

</div>

This has come up in the SSWG and we obviously need network access to be able to deploy Swift apps to AWS/GCP/Heroku etc with a Swift plugin. I _believe_ there is a flag to enable network access, similar to how the file access works but someone in the know can correct me

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [October 7, 2022, 1:07pm UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/4 "2022-10-07T13:07:16Z")

</div>

Is this about [app sandbox keys on macOS](https://developer.apple.com/documentation/security/app_sandbox) or something else?

---

<div class="post-metadata">

**Author:** ![filip-sakel](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/filip-sakel/32/8697_2.png) [@filip-sakel](https://forums.swift.org/u/filip-sakel)\
**Post date:** [October 7, 2022, 1:43pm UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/5 "2022-10-07T13:43:06Z")

</div>

> [@clayellis](#):
>
> At a minimum, I believe that private plugins (ones that aren't published by the package) should be granted this permission.

I disagree with this. Forking and editing downloaded packages is very common, so there should be a specific permission. Now, yes, most IDEs ask the user to trust a downloaded directory, but there’s still a huge risk from automatically granting this permission. I think the same is true for storage permissions.

---

<div class="post-metadata">

**Author:** ![clayellis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/clayellis/32/43646_2.png) [@clayellis](https://forums.swift.org/u/clayellis)\
**Post date:** [October 7, 2022, 8:05pm UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/6 "2022-10-07T20:05:01Z")

</div>

> [@0xTim](#):
>
> be able to deploy Swift apps to AWS/GCP/Heroku etc with a Swift plugin

This is an excellent example.

> [@0xTim](#):
>
> I _believe_ there is a flag to enable network access, similar to how the file access works but someone in the know can correct me

If so, it hasn't been advertised and isn't available in as a `PluginPermission`.

---

<div class="post-metadata">

**Author:** ![clayellis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/clayellis/32/43646_2.png) [@clayellis](https://forums.swift.org/u/clayellis)\
**Post date:** [October 7, 2022, 8:06pm UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/7 "2022-10-07T20:06:00Z")

</div>

This is [something else](https://github.com/apple/swift-evolution/blob/main/proposals/0303-swiftpm-extensible-build-tools.md).

---

<div class="post-metadata">

**Author:** ![clayellis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/clayellis/32/43646_2.png) [@clayellis](https://forums.swift.org/u/clayellis)\
**Post date:** [October 7, 2022, 8:07pm UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/8 "2022-10-07T20:07:16Z")

</div>

Great points. I realize I made it sounds like my opinion was in favor of an _implicit_ permission for private plugins — I should've specified an _explicit_ permission.

---

<div class="post-metadata">

**Author:** ![clayellis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/clayellis/32/43646_2.png) [@clayellis](https://forums.swift.org/u/clayellis)\
**Post date:** [October 7, 2022, 8:09pm UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/9 "2022-10-07T20:09:24Z")

</div>

This seems to be a common workaround — pre-fetch the network resources and make them available _before_ building with SPM. I'll make sure to include this motivation.

---

<div class="post-metadata">

**Author:** ![nholloh](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nholloh/32/32561_2.png) [@nholloh](https://forums.swift.org/u/nholloh)\
**Post date:** [October 17, 2023, 7:44am UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/10 "2023-10-17T07:44:39Z")

</div>

Reopening this topic after a year, since I just ran into an issue with the sandbox for prebuild commands where apparently permissions have changed from Xcode 14 to Xcode 15.

I had just finished writing a prebuild command for compiling kotlin multiplatform projects as part of a swift package. The idea is that you can wrap a swift package around your kotlin multiplatform project to give it some native UI and a proper interface while still sharing business logic etc. with Android. The plugin will then run gradle on every build (which lengthens your build time by approx. 2 seconds for incremental builds), but allows you to change things in the kotlin files and rebuild everything right from Xcode. From a developer experience point of view this is in my opinion preferable than having to open the terminal to run gradle manually or working with Android Studio and Xcode at the same time.

Anyway, since the update to Xcode 15, gradle is unable to fetch its binaries from [gradle.org](http://gradle.org).

```swift
Downloading https://services.gradle.org/distributions/gradle-8.0-bin.zip
Exception in thread "main" java.net.UnknownHostException: services.gradle.org

```

If we had an explicit permission for prebuild commands or even build commands to enable network, I could make this work again.

---

<div class="post-metadata">

**Author:** ![hassila](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hassila/32/22647_2.png) [@hassila](https://forums.swift.org/u/hassila)\
**Post date:** [October 26, 2023, 9:58am UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/11 "2023-10-26T09:58:17Z")

</div>

We also just run into this, wanting to download static resources for processing from the net as part of the build chain...

---

<div class="post-metadata">

**Author:** ![mAu888](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mau888/32/32347_2.png) [@mAu888](https://forums.swift.org/u/mAu888)\
**Post date:** [October 29, 2023, 3:23pm UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/12 "2023-10-29T15:23:15Z")

</div>

Dito. I would love to see SPM build tool plugins to be able to get network access for this reason.

---

<div class="post-metadata">

**Author:** ![nholloh](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nholloh/32/32561_2.png) [@nholloh](https://forums.swift.org/u/nholloh)\
**Post date:** [November 13, 2023, 8:01am UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/13 "2023-11-13T08:01:21Z")

</div>

Does anybody have hands-on experience in the Swift Evolution Pitch/Proposal process or can get me in touch with someone who does? I'd love to start the process for this topic, however it would be super helpful to have someone with experience as co author or at least sparring partner to reach out in case I have any questions since this is my first time contributing.

Thanks

---

<div class="post-metadata">

**Author:** ![joshw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joshw/32/34626_2.png) [@joshw](https://forums.swift.org/u/joshw)\
**Post date:** [November 13, 2023, 10:54am UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/14 "2023-11-13T10:54:20Z")

</div>

A way to abstract other permissions would be nice as well - for example, we'd love for plugins to be able to update code outside of derived data.

To do something like 1) pull an OpenAPI spec, 2) generate swift types for all of it.

---

<div class="post-metadata">

**Author:** ![nholloh](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nholloh/32/32561_2.png) [@nholloh](https://forums.swift.org/u/nholloh)\
**Post date:** [November 13, 2023, 12:26pm UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/15 "2023-11-13T12:26:47Z")

</div>

A colleague of mine found a workaround, which does seem to bypass the sandbox. He created a shortcut in the shortcuts app which is then able to access the network, file system, and run shell scripts. He then ran the shortcut from the swift build plugin.

However, this has two major limitations:

- You cannot write a shell script to disk and have shortcuts use it as input, to be able to run any command. At least I could not get it to run like that, likely sandbox permissions interfering again.
- You will need to manually approve privacy related alerts for file system and web access. It will therefore not work for a headless CI with temporary runners, but if you run a self-hosted CI with physical build infrastructure or only need to bypass restrictions on developer machines this may just work for you.

Still, explicit permissions for network and file system access would be a huge win for plugins in my opinion.

---

<div class="post-metadata">

**Author:** ![BrentM](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/brentm/32/15134_2.png) [@BrentM](https://forums.swift.org/u/BrentM)\
**Post date:** [December 6, 2023, 3:43am UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/16 "2023-12-06T03:43:02Z")

</div>

Definitely interested in this.

We use crashlytics in our codebase, automatically uploading dsyms via a swift package plugin would be great. Rather than having to run a bash script in a build phase.

---

<div class="post-metadata">

**Author:** ![nholloh](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nholloh/32/32561_2.png) [@nholloh](https://forums.swift.org/u/nholloh)\
**Post date:** [December 13, 2023, 10:04am UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/17 "2023-12-13T10:04:26Z")

</div>

I just started an evolution discussion on this. I'd love to get your feedback, so please feel encouraged to participate.

> [@\[Pitch\] SwiftPM Plugins - Explicit BuildTool Sandbox Permissions](https://forums.swift.org/t/pitch-swiftpm-plugins-explicit-sandbox-permissions/68963):
>
> Introduction Since there are multiple topics ([1](https://forums.swift.org/t/swiftpm-command-plugins-with-permission-to-access-the-network/56101), [2](https://forums.swift.org/t/swift-package-plugins-network-access/60693)) where people have stated interest in network access for Swift Package Manager Plugins, I wanted to bring them together and draft a first pitch for a discussion. Motivation In the aforementioned discussions we have seen multiple projects which had to rely on workarounds or do not function at all without explicit network permission. [tevelee](https://forums.swift.org/u/tevelee) is distributing modular binary xcframeworks to clients. For inter-module communication they rely on SPIs…

---

<div class="post-metadata">

**Author:** ![markturnip](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/markturnip/32/23088_2.png) [@markturnip](https://forums.swift.org/u/markturnip)\
**Post date:** [January 23, 2024, 1:49am UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/18 "2024-01-23T01:49:48Z")

</div>

this sounds great @nholloh. I wonder if you've tried the other way around - having a Swift package built and linked to a Kotlin Multiplatform?

---

<div class="post-metadata">

**Author:** ![pchmelar](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/pchmelar/32/33968_2.png) [@pchmelar](https://forums.swift.org/u/pchmelar)\
**Post date:** [February 7, 2024, 8:25pm UTC](https://forums.swift.org/t/swift-package-plugins-network-access/60693/19 "2024-02-07T20:25:00Z")

</div>

We are stuck on the same problem - building a KMP module from the SPM Plugin. However, are you sure that enabling the network access will be enough to make it work? I'm trying at least a CommandPlugin with both `writeToPackageDirectory` + `allowNetworkConnections` permissions and it successfully fetches binaries from [gradle.org](http://gradle.org) but then it fails with a following error:

```swift
org.gradle.api.UncheckedIOException: java.net.SocketException: Operation not permitted

```
