Private Repository, Public Packages: How a Registry Publishes What Its Owners Think Is Closed

TL;DR: On Forgejo, the software behind Codeberg, a container image or Helm chart belongs to its owner, not to the repository it was built from. A private repository in a public organization therefore publishes everything you build from it. This case study follows a fictional company through finding that out, measuring what was exposed, and closing it without breaking the cluster that pulls from the registry. The most useful lesson is the last one: the check most people use to prove that a credential can pull answers yes to everybody, including nobody.
About this case study. Larkspur Data, its organization and its numbers are fictional, a composite of a pattern that is easy to fall into. The mechanism is not: every command below is real, and the measurement table was taken on a throwaway organization on Codeberg (Forgejo 16.0) in October 2026.
The setup
Larkspur Data is a small analytics consultancy with a three-person platform team. Its code
lives on Codeberg in one organization, larkspur-data: the platform’s own repositories, the
infrastructure definitions, and one repository per client application. A Kubernetes cluster
runs everything, with Argo CD syncing manifests, Kargo promoting versions between
environments and Argo Workflows running CI. Images and Helm charts go to the registry that
Codeberg runs next to the git hosting, under the same organization.
Eleven of the organization’s thirteen repositories are private. The team checked that more than once, because it is what the web interface shows: a private repository answers 404 to a visitor who is not logged in. The organization itself was created public, years ago, so the two open-source repositories could be found. Nobody has looked at that setting since.
The symptom
Nothing reported it. There was no alert and no odd traffic. One of the team was preparing to open-source a small tool and wanted to know what else was already public, and instead of asking the repositories, asked the registry. The question a container runtime asks before it pulls is a short exchange: get a token, then list the tags. Asked with no credentials at all:
token=$(curl -s "https://codeberg.org/v2/token?service=container_registry&scope=repository:larkspur-data/platform-docs:pull" | jq -r .token)
curl -s -H "Authorization: Bearer $token" https://codeberg.org/v2/larkspur-data/platform-docs/tags/list
It answered with eighty tags. platform-docs is the image that serves the team’s internal
documentation: runbooks, the disaster-recovery guide, the incident-response guide, how
secrets reach the cluster. Nothing in the exchange had asked who was calling.
It was not one image. Every package in the organization answered the same way.
What was out there
The first job was to count, before fixing anything, because the size of the hole decides how urgent the rest is and what has to be rotated afterwards.
| Group | Packages | What they are |
|---|---|---|
| Internal documentation | 1 | the docs site, every version since it was first published |
| Platform and CI | 9 | the platform’s own images, the infrastructure images, the CI toolchain images, two patched third-party images |
| Client applications | 21 | the image and the Helm chart of every client application |
| Total | 31 | several thousand versions, the oldest six months old |
The question that mattered more than the count was whether any of it carried a secret. A repository’s secret scanning sees source; an image is source plus whatever the build pulled in, copied, or baked into an environment file. So the team exported the newest version of every package and ran a secret scanner over the unpacked filesystems and charts:
crane export "codeberg.org/larkspur-data/$image:$tag" - | tar -x -C "/tmp/scan/$image"
gitleaks dir --report-format json --report-path "/tmp/scan/$image.json" "/tmp/scan/$image"
Expect noise, and read it rather than counting it. In images that carry a toolchain, generic
API-key rules fire on sources nobody at the company wrote: Go’s standard library and its
tests, Perl and Linux headers, a high-entropy constant in V8’s v8-internal.h. Every hit has
to be traced to a path before the scan means anything. Larkspur’s traced to toolchains only.
The documentation names secrets and describes where they live, but holds none of their
values, and that is the difference between a case study and a rotation weekend.
Why: packages belong to owners, not repositories
Forgejo’s documentation says it in one table, under “Access Restrictions”: read access to an organization’s package is “public, if org is public, otherwise for org members only”. The repository the package was built from does not appear in that sentence. Gitea’s documentation, which Forgejo inherits, adds the half that explains the second surprise of the story: a token needs the package permission to read packages, and an organization team’s package permission “applies to all packages of the organization, regardless of the repositories assigned to the team”.
The rule does not mention linking a package to a repository at all. Most packages are not
linked to anything, and the registry API reports "repository": null for them; they are owned
by the organization, and the organization decides.
To show the mechanism rather than describe it, here is the same exchange measured on a throwaway organization: public, one private repository, one image pushed by the owner and linked to nothing. The same two questions with different credentials, before and after switching the organization to private:
| Case | /v2/token | tags/list |
|---|---|---|
| organization public, anonymous | 200 | 200, tags listed |
| organization private, anonymous | 200 | 401 reqPackageAccess |
| organization private, valid login of a non-member | 200 | 401 reqPackageAccess |
| member, token without package scope | 200 | 401 reqPackageAccess |
| member, token with package scope | 200 | 200 |
| wrong password | 401 | not reached |
The repository page answered 404 throughout. The package answered 200 until the organization changed. Keep the second column in mind; it is the subject of the section after next.
Who else is pulling anonymously
Making the organization private is one click. Making it private without breaking the cluster that pulls from it is the actual work, because anything that has been pulling anonymously starts failing the moment the click happens, and some of those things run at six in the morning while nobody watches.
So the first real job is an inventory of every pull that does not authenticate. For running
workloads the question is mechanical: which pod specs reference the organization’s images and
have no imagePullSecrets, either on the pod or on its service account.
kubectl get sa -A -o json \
| jq -r '.items[] | select(.imagePullSecrets) | "\(.metadata.namespace)/\(.metadata.name)"' > /tmp/sa-with-secrets
for kind in deployments statefulsets daemonsets cronjobs jobs; do
kubectl get "$kind" -A -o json | jq -r --arg k "$kind" '
.items[] | (.spec.jobTemplate.spec.template.spec // .spec.template.spec) as $s
| select([$s.containers[].image, ($s.initContainers // [])[].image] | any(test("codeberg.org/larkspur-data")))
| select(($s.imagePullSecrets // []) | length == 0)
| "\($k) \(.metadata.namespace)/\(.metadata.name) sa=\($s.serviceAccountName // "default")"'
done | while read -r kind name sa; do
grep -qx "${name%%/*}/${sa#sa=}" /tmp/sa-with-secrets || echo "ANONYMOUS $kind $name"
done
At Larkspur that found three deployments: a security scanner’s operator and storage, whose init container runs a patched image, and a metrics exporter. Workflow templates are not pods until they run, so they need the same question asked of their templates; fourteen of them, the CI pipelines among them, pulled the toolchain images anonymously.
Just as useful is the list of what already authenticates, because it is usually most of the
system: every client namespace had a pull secret, Argo CD held repository credentials for both
the https:// and oci:// prefixes of the organization, and every Kargo project had registry
credentials for its warehouse. The team checked each of those credentials against the
registry before trusting the list. They checked them the wrong way, and did not know it yet.
The order that keeps the lights on
Credentials first, the switch last, and nothing in between that depends on luck.
For workflows, nobody wants to touch fourteen templates and then discover a fifteenth, so the secret goes into the controller’s defaults, which every workflow inherits whatever its service account:
# values for the argo-workflows chart
controller:
workflowDefaults:
spec:
imagePullSecrets:
- name: codeberg-registry-pull-secret
The scanner’s chart takes an imagePullSecrets value of its own, and the exporter gets one in
its Deployment. The secret itself is an ExternalSecret that builds a dockerconfigjson from
a read token in the vault, the same shape the client namespaces already use.
The first attempt put that secret into a ClusterExternalSecret, one object fanning it out
to the three platform namespaces. It merged, and Argo CD refused to sync it: the platform’s
AppProject does not permit that cluster-scoped kind, and a refused resource fails the whole
sync, so the workflow defaults did not arrive either. Nothing broke, because the organization
was still public, which is exactly why the order matters. The same secret then went in as one
namespaced ExternalSecret per application, inside what each project already allowed.
Proving it, by pulling
A configuration that looks right is a claim. The only evidence that a pull will work after the switch is a pull that happens after the switch, so the team made pulls happen instead of reading specs:
- a throwaway workflow with one step per toolchain image, each with
imagePullPolicy: Always, so that an image cached on a node cannot answer for the registry; - a test pod with the same policy in the scanner’s and the exporter’s namespaces, in the documentation namespace, and in one namespace per client;
- a hard refresh of every Argo CD application whose chart comes from the organization’s
oci://prefix, and a refresh of every Kargo warehouse.
All of it passed once with the organization still public, as a baseline. Then the organization went private and all of it ran again: every image pulled, every application compared cleanly, every warehouse stayed healthy, and the next pull request’s pipeline went green against a registry nobody could read anonymously any more. The anonymous exchange from the top of this post now ends in a 401.
Then the team ran the one thing that is not a pod and not a sync: Renovate, which checks the registry for newer versions of the images the repositories pin. It reported a lookup failure for every image of the organization it tracks.
The check that lied
Renovate’s token belonged to a member of the organization. It had passed the credential check. And the registry refused it, because it had no package scope: a token needs the package permission, and this one had none.
It passed because of what was checked. To verify a credential, the team had asked the
registry’s token endpoint for a pull token with it, and got a 200. Look at the table again:
/v2/token answers 200 to everyone. Anonymous callers get a bearer too; decoded, it says
"UserID": -1 and "Scope": "", a token for nobody. The endpoint refuses a wrong password
and nothing else. Whether the caller may pull is decided one step later, when the bearer meets
tags/list or a manifest, and that is the only answer that means anything.
So the audit had verified that every credential was a valid login. Every one was. One of them
could not pull, and the check could not have said so, because it never asked. The fix was one
host rule pointing Renovate’s registry lookups at the token the pull secrets are built from.
The lesson fits in a sentence: a 200 from /v2/token proves nothing; ask tags/list with the
bearer it returns.
I wrote about the same class of failure in my own system in Eighteen Days of Silence: a check that reports success because success was the only outcome it could observe.
A five-minute audit for your own organization
If you host images on Codeberg or any Forgejo or Gitea instance, this is the whole test. It uses no credentials, on purpose:
owner=your-organization
for image in $(curl -s "https://codeberg.org/api/v1/packages/$owner?type=container&limit=50" | jq -r '.[].name' | sort -u); do
token=$(curl -s "https://codeberg.org/v2/token?service=container_registry&scope=repository:$owner/$image:pull" | jq -r .token)
code=$(curl -s -o /dev/null -w '%{http_code}' -H "Authorization: Bearer $token" "https://codeberg.org/v2/$owner/$image/tags/list")
echo "$code $owner/$image"
done
A 200 means anyone can pull it. If the packages API itself answers anonymously, the listing
is already the answer; if it does not, list the images with your own token and keep the two
registry calls anonymous. The API pages at fifty, so a large organization needs a loop over
page=. And never conclude anything from the token endpoint alone.
What not to fix
Not every public package is a mistake. A personal account that publishes a blog’s images, for example, cannot hide them without hiding the account and every public repository on it, and the images contain nothing but the published site. That is a fine trade, as long as it is a trade someone made rather than a default nobody looked at. The test is whether you can say, for each owner, why its visibility is what it is.
Honest limitations
- Nobody can say who pulled what. The package API returns no download counts, and there is no access log to ask. The exposure window is known; its use is not.
- What was pulled stays pulled. Making an owner private stops the next pull, not the last.
- A secret scan of the latest versions is evidence, not proof. Older versions stay packed, and a pattern matcher finds what looks like a secret, not what is one.
- Larkspur is fictional. Its numbers and its morning are a composite. The access rules, the commands and the measurement table are real; the table was taken on a throwaway organization, not on anyone’s production.
The boring part
What would have saved Larkspur the morning, in order:
- Treat the owner’s visibility as the visibility of every package it owns. On Forgejo and Gitea a private repository protects the source and nothing built from it.
- Audit with the question a runtime asks: anonymous token, then
tags/list. Run it on a schedule, so the next public owner fails a check instead of waiting for a curious morning. - Before closing a registry, inventory every anonymous pull, workflows included, and put the credential into defaults rather than into each consumer.
- Verify by pulling with
imagePullPolicy: Always, and run the things that are not pods, such as dependency bots, before calling it done. - Never verify access at the token endpoint.
For the shape of a cluster like this one, see From Git Push to Production Without a CI Vendor and The CI That Lives in Your Cluster.