SwiftPM Wants to Stop Storing Publish Tokens in CI. Your App Store Connect Key Is the Same Problem.

NativeFirst Team 8 min read
A ring of old iron keys hanging from a nail on a weathered wooden wall

Every heist movie spends ninety minutes on the vault. The laser grid, the pressure plates, the guy who can hold his breath for four minutes.

Real supply chain attacks skip all of that. Somebody finds a token in a CI log, and the vault opens because the token says it should.

A pitch landed on the Swift forums yesterday that goes after exactly this: Trusted Publishing in SwiftPM. It’s one day old and has one post, so this is early. But the idea is borrowed from ecosystems that learned it the hard way, and it’s worth ten minutes of your attention even if you’ve never published a package to a registry in your life. Especially then, actually. I’ll get to why.


The problem: a key that never expires

Today, if you publish a package to a Swift package registry, SwiftPM authenticates with a stored credential. The pitch says it plainly: SwiftPM only supports long-lived credentials for registry auth.

In practice that means a token pasted into your CI provider’s secrets page. It sits there for months. It works from any machine, for any version of your package, at any hour. Nobody remembers who created it.

A long-lived token is a house key under the doormat. It’s fine every single day until the one day it isn’t, and you find out from someone else.

The JavaScript world got the full demonstration last year, when a worm spread through npm by stealing maintainers’ publish tokens and using them to publish infected versions of their own packages. No vault cracking. Just keys that were lying around, still valid.


The idea: prove where you’re running instead

Trusted publishing flips the model. Instead of holding a secret, your CI job proves where it’s running.

GitHub Actions and GitLab CI can both mint an OIDC token for a job: a short-lived, signed statement that says “this is repository X, running this workflow, on this ref.” You don’t store it anywhere. It’s created for the job and it’s dead minutes later.

The registry gets configured once with a rule like “accept publishes for this package only from this repo, on a tag.” When a job shows up with a token whose claims match, it’s allowed to publish. No match, no publish.

PyPI has done this since 2023. npm, RubyGems and crates.io followed. Swift is the one showing up to the party after the dishes are done, which is fine. It means we get to copy the version with the bugs already found.


How the pitch works

Two pieces.

First, SwiftPM looks for an environment variable called SWIFT_OIDC_TOKEN. If it’s set, swift package-registry publish uses it and ignores every other credential.

Second, the registry spec gets a new endpoint. SwiftPM trades the OIDC token for a registry token before uploading anything:

POST /hogwarts/Lumos/1.2.3/oidc/publish-token HTTP/1.1
Accept: application/vnd.swift.registry.v1+json
Authorization: Bearer <oidc-token>

The registry answers with a token that can do exactly one thing: publish version 1.2.3 of hogwarts.Lumos. Not 1.2.4. Not a different package. Then SwiftPM does the normal upload with that token.

SwiftPM deliberately doesn’t fetch the OIDC token itself, which keeps it vendor neutral. On GitLab the CI config can inject it directly. On GitHub Actions you fetch it in a step, and the pitch includes the workflow:

permissions:
  id-token: write
steps:
  - run: |
      TOKEN=$(curl -sH "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
        "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=https://packages.example.com" | jq -r .value)
      echo "::add-mask::$TOKEN"
      echo "SWIFT_OIDC_TOKEN=$TOKEN" >> "$GITHUB_ENV"
  - run: swift package-registry publish mona.LinkedList 1.2.3

I haven’t run this. Nobody has, the feature doesn’t exist yet. But look at what’s missing from that file: a secret. There’s no ${{ secrets.REGISTRY_TOKEN }} anywhere. There’s nothing to leak, rotate, or forget about.

The separate exchange step is a nice detail too. The pitch considered sending the OIDC token straight to the publish endpoint and rejected it, partly because SwiftPM would upload the entire archive before the registry got around to saying no. Failing before the upload is the polite option.


The part I liked most: the wildcard trap

Most proposals tell you what to build. This one also tells registry authors how they’ll get it wrong.

Say a registry lets you write a matching rule with a wildcard, and you want “any repo in my org, on tag 1.2.3”:

repo:Lumos/*:ref:refs/tags/1.2.3

Looks reasonable. Now someone with push access to Lumos/docs, a repo nobody thinks of as sensitive, creates a branch. They name the branch x:ref:refs/tags/1.2.3. The token for that branch carries this subject:

repo:Lumos/docs:ref:refs/heads/x:ref:refs/tags/1.2.3

The * happily swallows docs:ref:refs/heads/x, the rule matches, and a random branch in the docs repo just published your library. A branch name passed a check meant for a tag.

It’s a string-matching bug wearing a security costume. The pitch’s fix is to ban the clever stuff: no wildcards, and one {version} placeholder that the registry fills in from the URL.

{
  "issuer": "https://token.actions.githubusercontent.com",
  "claims": { "sub": "repo:hogwarts/Lumos:ref:refs/tags/{version}" }
}

Exact repo, exact tag, nothing to be creative with. It also recommends replay protection, so a token that’s been used once can’t be used again while it’s still technically alive.


”I don’t publish to a registry.” Me neither.

Most iOS developers add packages by git URL. There’s no big public Swift registry, and the registry feature mostly lives inside companies running something like Artifactory or CodeArtifact. So for a lot of us this pitch changes nothing directly.

Here’s the uncomfortable bit, though. Open your CI secrets page.

There’s a decent chance it contains an App Store Connect API key. A .p8 file, base64-encoded, next to a key ID and an issuer ID. That key doesn’t expire. The JWTs you sign with it live for twenty minutes at most, but the key that signs them lives until someone remembers to revoke it. And it probably has a role generous enough to upload a build under your name.

That’s the same doormat. Different house.

As far as I know, Apple doesn’t offer anything like trusted publishing for App Store Connect, so you can’t fix this properly yet. You can shrink it:

  • Give the key the smallest role that still does the job. A key that only uploads builds doesn’t need Admin. Check what yours has. I’d bet it’s whatever was selected the day someone was in a hurry.
  • Put release secrets in a protected environment. GitHub environments can require a reviewer and restrict which branches or tags can use them. A pull request from a fork should never be in the same room as your .p8.
  • Use OIDC where it already exists. AWS and Google Cloud both accept GitHub’s OIDC tokens today. If your pipeline holds a static cloud access key or a Firebase service account JSON, that one you can actually delete this week.
  • Rotate on a calendar, not on an incident. If a key is older than the app’s current major version, it’s due.
  • Consider letting Apple hold it. Xcode Cloud handles signing and upload without you storing a key at all. Whatever else you think of it, there’s nothing in there to steal.

I wrote about the SwiftPM manifest being executable code a while back. That’s the inbound half of the supply chain: what you pull in. This pitch is the outbound half: who’s allowed to ship as you. A key in CI sits right where the two meet, because the code you pull in runs in the same job that holds the key.

It’s the same lesson as the apps shipping LLM API keys in their binaries. A credential that lives forever will eventually be found by someone patient. And as the Copilot autofix story showed, CI is where the patient people are looking now.


Where this goes

Honestly, nowhere fast. It’s a pitch, not a proposal under review. It needs discussion, a formal review, an implementation, and then registries have to build their side. If you’ve followed the other SwiftPM pitches I’ve covered, you know the timeline is measured in seasons.

But the direction is right, and it’s cheap to prepare for. If you run a private registry at work, send the thread to whoever owns it. If you don’t, spend five minutes on your secrets page and ask one question of each entry: if this leaked today, how long would it keep working?

If the answer is “until I notice,” that’s your to-do list. It belongs on the same pre-release checklist as everything in the Polish & Ship lesson: the unglamorous stuff that nobody sees when it’s done right.

The best token is the one that’s already expired by the time anyone finds it.

Share this post

Share on X LinkedIn

Comments

Leave a comment

0/1000

N

NativeFirst Team

Editorial

The NativeFirst team — engineers and designers building native Apple apps and writing the courses we wish we had when we started.