Repository create accepts and persists `visibility: public`, so S09's private-only premise is false and those rows become world-readable when visibility is enforced
## Context
The management API's repository create and update persist `visibility: public` and `internal` and return the value in the `201` and `200` bodies. ADR-021 scopes closed beta to `private`, and S09 says the column holds nothing else. In the issue's reproduction on Artifact Registry v1.453.0 (real S33 JWT, `iam-data-access`, and GLAZ), an Artifact Admin created a `public` npm repository and the registry stored `0`. The registry still denied a principal with no role every operation on it, reads included (`decision_reason: "no role assignment"`). No authorization decision reads the column, so the gap is latent: in production, no repository is readable without a role. The risk lands when a read path first consults the column for access. Every row stored as `public` then turns readable by anyone, unauthenticated callers included, and every `internal` row by organization members. No spec or ADR says what happens to those rows first. The GA epic https://gitlab.com/groups/gitlab-org/-/epics/22707 lists both capabilities at P1: anonymous pull (https://gitlab.com/gitlab-org/gitlab/-/work_items/605689, with the backend work in https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1180) and internal visibility for signed-in users (https://gitlab.com/gitlab-org/gitlab/-/work_items/630572). Both GA issues say their grant is not a visibility level, so whether the column ever grants read stays open until the ADR-021 amendment answers decision 3 of https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1180. The issue came out of a local check of S09's npm and management API enforcement, which found no bypass.
## What exists on main
Read at `f771c7325`.
- `internal/managementapi/create.go`, `validateCreateRequest`: defaults an omitted `visibility` to `private` and maps a present one through `visibilityValues`, the inverse of `visibilityStrings`. `public` and `internal` therefore persist on every format and kind. Only an unknown string gets the `400` "visibility must be one of public, private, internal".
- `internal/managementapi/update.go`, `validateUpdateRequest`: uses the same lookup, so a `PATCH` to `public` or `internal` answers `200` on every kind.
- `internal/managementapi/resource.go`, `visibilityStrings`: maps all three stored values to wire strings for the repository resource. `internal/managementapi/upstream_repositories.go` reuses it for the upstream summary. The handlers answer a stored value the map lacks with `500`.
- `internal/datastore/repositories.go`: `insertRepository` writes `CreateRepositoryInput.Visibility` as given, and `RepositoryVisibilityPublic` is `0`, the Go zero value, so an input that leaves it unset creates a `public` row. In `internal/datastore/migrations/structure.sql`, `repositories.visibility` is `NOT NULL` with no default, and `check_repositories_visibility` admits 0, 1, and 2.
- `api/openapi/v1.yaml`: `Repository`, `CreateRepositoryRequest` (default `private`), `UpdateRepositoryRequest`, and `UpstreamRepositorySummary` all reference one `Visibility` enum of `public`, `private`, and `internal`.
- `internal/authz/decision.go`, `evaluate`: denies an anonymous caller, and a principal with no role assignment, before the `Check`. No production `Check` or `BatchCheckItem` sets `Attributes`, the field `internal/authz/glaz/checker.go` documents as carrying visibility, so no authorization decision reads the column.
- `internal/format/npm/disttags.go`, `cacheControlForVisibility` (hosted packument, dist-tags, and virtual document reads), and `internal/format/npm/download.go`, `DownloadHandler.cacheControl` (hosted tarballs): apart from the management API's serialization, the only production code that branches on the stored value. A `public` row gets `public, max-age=60, stale-while-revalidate=600` on metadata and `public, max-age=31536000, immutable` on a tarball, where every other row gets the `private` directives. Each response carries `Vary: Authorization`.
- `docs/specs/S09-authorization.md`: References says "closed beta stores `private` only", and Data Model says the column "is stored but not consulted". Under Anonymous callers, `Assembly` denies every anonymous request on a matched route with the masked `404`, before resolving the repository.
- `docs/specs/S17-rest-management-api.md`, Repository resource and Resolutions item 5 (Visibility): `visibility` is mutable over all three values, and create and update accept and persist it. Create defaults it to `private` rather than requiring it, because a private default exposes nothing and making the field required later would break clients. Enforcement arrives with ADR-021.
- `docs/specs/S17-rest-management-api.md`, Acceptance Criteria and Error Cases: criteria 4 and 10 and the Create and Update error rows answer an invalid `visibility` with `400 bad_request`. Criterion 151 orders that `400` ahead of the upstream-list `422 limit_exceeded` (numbered at `f771c7325`). Create and criterion 4 record that Phase 1 refused a non-hosted `kind` with `422`.
- `docs/specs/S11-npm-hosted.md`, Authentication and authorization: lists "Unauthenticated reads on public repositories (`repositories.visibility = 0`) are permitted" among the outcomes S11 expects from the auth middlewares. The `Auth` rows of its packument, tarball, dist-tags, and attestation routes make a credential optional on any non-private repository. Those contracts specify the visibility-derived `Cache-Control`.
- `docs/adr/021_authorization.md`, Repository visibility and Public and internal visibility: closed beta supports `private` only, `public` and `internal` wait for GA with the mechanism undecided, and write and management operations need a role regardless of visibility.
- `docs/adr/007_database_schema.md`, Repositories: codes `0=public, 1=private, 2=internal`. Its visibility-audit query lists `visibility = 0` rows only, through the partial index on `(namespace_id, visibility)`.
- `docs/specs/monolith/S07-repository-crud.md`, Resolutions (Visibility levels): the monolith's create input accepts `PRIVATE` only. Its read enum keeps all three values so no read fails coercion. `docs/specs/monolith/S04-repositories-list.md` (Frontend / UX) and `docs/specs/monolith/S05-repository-detail.md` (Header) render visibility as Private only, because "closed beta creates no other value".
- `docs/user/repositories/_index.md`, Visibility: "During beta, visibility is set to private for all repositories."
- `docs/testing/e2e/limitations.md`, "A visibility flip is accepted and no container route reads the value": records that a `PATCH` to `internal` or `public` answers `200`. It blocks `e2e.docker.setup.update-visibility` and `e2e.oci.setup.update-visibility`, and names https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1180 as what lifts them.
- `e2e/functional/harness/grant_test.go`, `TestVisibilityIsNotAnAuthorizationExemption`: creates a `public` OCI repository through the API and asserts that the registry denies a member with no role. `e2e/functional/{maven,npm,oci}/upstreams_test.go` create and patch `internal` repositories so an upstream's value differs from its sibling's `private`. The e2e harness creates repositories only through the management API.
- `internal/managementapi`: `create_test.go`, `update_test.go`, `update_upstream_list_test.go`, `contract_test.go`, `update_delete_integration_test.go`, and `npm_virtual_upstreams_integration_test.go` send `public` or `internal` as an accepted value. `detail_test.go` serializes a stored `internal` row, and `list_test.go` a stored `public` one.
## Change
The specs, the contract, and the code agree on what `repositories.visibility` can hold during closed beta. Every row stored as `public` or `internal` has a recorded fate before any read path consults the column for access. Decision 1 picks how they agree: the management API refuses `public` and `internal`, the issue's preferred proposal, or the documents stop claiming the column holds `private` only. Neither option changes an authorization outcome: the registry keeps denying a caller without a role on every repository. No read path starts consulting the column here. What grants broad read at GA stays with https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1180.
## Acceptance criteria
Criteria 1 and 2 are decisions the specs on main leave open. Criteria 3 to 8 hold under decision 1 (a), and criteria 9 and 10 hold under either option.
1. **Refuse or document (the S09 and S17 spec owners).** S17's Resolutions item 5 accepts and persists every value, and S09 says the column holds `private` only, so one of them changes. (a) Refuse `public` and `internal` on create and update while closed beta is `private`-only. Refusing a value does not make the field required, so S17's compatibility reason still holds. If GA brings the values back, accepting them again is a backward-compatible widening. monolith/S07's create input already sends `PRIVATE` only. The cost: a client that sends either value gets the refusal instead of a `201` or `200`, and the tests in criterion 8 change. (a) also picks the status. The issue proposes `400 bad_request` through S17's invalid-visibility path, with the request schemas narrowed to `private`. The S17 precedent for an enum value a phase does not serve is `422`: Phase 1 refused a non-hosted `kind` that way. Each row created before (a) deploys adds to decision 2, so (a) costs less the earlier it lands. (b) Keep accepting, and correct every document that states the private-only premise (criterion 9). (a) instead makes those documents true for every row created after it deploys.
1. **Rows already stored (the same owners, under either option).** Rows written before the refusal deploys keep `public` or `internal`. Under (b), new ones keep arriving until a read path consults the column. The owners record on this issue the count of active rows stored as `public` or `internal` in production, measured with ADR-007's visibility-audit query widened from `visibility = 0` to `visibility IN (0, 2)`. Under (a), they take the count after the refusal deploys, so it is final. Under (b), they take it while writing the ADR-021 amendment for GA. A count of zero settles this criterion. Otherwise they pick one fate. (i) Reset the rows to `private` in a data migration. The management API then returns `private` for them, npm serves them with the `private` directives, and the reset overwrites a value a customer set. (ii) Keep them. The management API keeps returning `public` or `internal`, npm keeps serving `public` rows with the `public` directives, and the views monolith/S04 and monolith/S05 specify render them as Private. The ADR-021 amendment for GA then names their fate as a precondition for any read path that consults the column.
1. **Create refuses `public` and `internal`.** For a caller holding `create_repository`, `POST /api/v1/:slug/repositories` with `visibility` `public` or `internal` answers the status decision 1 picks on every format and kind, and writes no row. Its message lists neither value as accepted. `private` and an omitted `visibility` still answer `201` with `"visibility": "private"`.
1. **Update refuses them on every kind.** For a caller holding `update_repository`, `PATCH /api/v1/:slug/repositories/:repository_name` with `visibility` `public` or `internal` answers the same status and changes nothing, including a `description` in the same body. A `PATCH` setting `private` on a row stored as `public` answers `200` and reads back `private`.
1. **The refusal keeps S17's validation order.** A virtual create or update carrying `visibility: public` beside more than 20 `upstream_repository_ids` answers the refusal, not `422 limit_exceeded`, the order S17's criterion 151 sets for an invalid `visibility`.
1. **Stored values still read back.** The detail `GET`, the list, and every upstream summary that carries `visibility` answer `200` for a row stored as `public` or `internal`, with the stored value. Narrowing `visibilityStrings` instead of the request lookup fails this criterion with a `500`.
1. **The contract and S17 state the refusal.** `api/openapi/v1.yaml` matches decision 1's status. Under `400`, `CreateRepositoryRequest` and `UpdateRepositoryRequest` accept only `private`. Under `422`, both operations name the `422`. Either way, `Repository` and `UpstreamRepositorySummary` keep all three values. S17's Repository resource, Create, Update, Error Cases, Resolutions item 5, and criteria 4 and 10 say the same.
1. **Tests and the e2e docs follow the refusal.** The `internal/managementapi` tests that send `public` or `internal` as an accepted value assert the refusal instead. The e2e tests that create or patch those values through the API move to `private`. What they assert about a stored `public` or `internal` row moves to tests that write the row without the API. While decision 2 keeps stored rows, one of those tests shows the registry denies a member with no role on a `public` row, the assertion `TestVisibilityIsNotAnAuthorizationExemption` makes today. The `docs/testing/e2e/limitations.md` entry and the public-fixture note in `e2e/README.md` describe the refusal.
1. **S09 and the monolith specs describe the stored data.** S09's References and Data Model say the column can hold `public` and `internal`, no authorization decision reads them, and npm's `Cache-Control` does. This applies always under (b), and under (a) unless decision 2 resets the rows or counts zero. Under (b), monolith/S04 and monolith/S05 also drop "closed beta creates no other value" and say how a stored `public` or `internal` row renders.
1. **The user docs and S11 match the shipped behavior.** `## Visibility` in `docs/user/repositories/_index.md` says what the API does with `public` and `internal` during beta. S11's Authentication and authorization list and the `Auth` rows of its four read routes agree with S09's Anonymous callers: none says a read of a non-private repository needs no credential during closed beta.
## Specs and ADRs
- S09, References: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/S09-authorization.md#references
- S09, Data Model: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/S09-authorization.md#data-model
- S09, Anonymous callers: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/S09-authorization.md#anonymous-callers
- S17, Repository resource: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/S17-rest-management-api.md#repository-resource
- S17, Create: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/S17-rest-management-api.md#create
- S17, Update: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/S17-rest-management-api.md#update
- S17, Acceptance Criteria (4, 10, and 151 at `f771c7325`): https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/S17-rest-management-api.md#acceptance-criteria
- S17, Error Cases: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/S17-rest-management-api.md#error-cases
- S17, Resolutions (item 5, Visibility): https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/S17-rest-management-api.md#resolutions
- S11, Authentication and authorization: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/S11-npm-hosted.md#authentication-and-authorization
- monolith/S07, Resolutions (Visibility levels): https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/monolith/S07-repository-crud.md#resolutions
- monolith/S04, Frontend / UX: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/monolith/S04-repositories-list.md#frontend--ux
- monolith/S05, Header: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/monolith/S05-repository-detail.md#header
- ADR-021, Repository visibility: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/adr/021_authorization.md#repository-visibility
- ADR-021, Public and internal visibility: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/adr/021_authorization.md#public-and-internal-visibility
- ADR-007, Repositories, the visibility codes and the visibility-audit query: https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/adr/007_database_schema.md#repositories
## Dependencies
- Nothing blocks this issue.
- https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1180 comes after this issue if its decision 3 makes `repositories.visibility = public` the grant. Its read path then consults the column only after decision 2 here settles the stored rows, because every row stored as `public` turns world-readable at that moment. Under its decision 3 (b), a separate grant, the order lapses.
- https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/707, the audit event for hosted and virtual visibility changes, can land before or after this issue. If the refusal here lands first and covers `PATCH`, its tests write `description` or `private`.
- The gate is the first read path that consults the column. `AR-Blocks::GA` is its proxy. If that work moves past GA, the label moves with it.
## First step
The S09 and S17 spec owners answer decision 1 on this issue. Under (a), the first MR amends S17 (Repository resource, Create, Update, Error Cases, criteria 4 and 10, and Resolutions item 5) and S11, ahead of the implementation MR for criteria 3 to 8 and 10. Under (b), the first MR corrects S09, S11, monolith/S04, monolith/S05, and `docs/user/repositories/_index.md`, and decision 2 moves into the ADR-021 amendment that https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1180 opens.
## Original description
## :mag: Problem
`POST /api/v1/:slug/repositories` accepts and persists `visibility: public` (and `internal`), but [ADR-021](https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/adr/021_authorization.md) scopes closed beta to `private` only, and [S09](https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/S09-authorization.md) states as a premise that the column cannot hold anything else.
The two specs are each locally correct and jointly inconsistent:
- **S09 §23** — "the `visibility` column; **closed beta stores `private` only**."
- **S09 §53** — "The `repositories.visibility` column (ADR-007) is **stored but not consulted**: closed beta is `private`-only (ADR-021), so every decision path in this spec treats every repository as private."
- **S17 §406** — the request enum is `public`, `private`, `internal`.
- **S17 §1612** — "Accept and persist on create and update … Enforcement arrives with the authorization integration (ADR-021). Reason: a private default cannot accidentally expose a repository, and making the field required later would be a breaking change."
S17's behaviour wins, so S09's premise is false in practice.
## :repeat: Reproduce
Verified on a local `caproni` rig running **AR v1.453.0** with the real S33 JWT + `iam-data-access` + GLAZ stack (not the fakes), as `Artifact Admin` on the namespace:
```shell
curl -X POST "$AR/api/v1/$SLUG/repositories" \
-H "Authorization: Bearer $JWT" -H 'Content-Type: application/json' \
--data '{"name":"npm-pub","format":"npm","visibility":"public"}'
# 201 {"id":"01a05d9b-82f9-7850-8e7f-4b4c4e24f883","name":"npm-pub",...,"visibility":"public",...}
```
The row persists as public — `0` per [ADR-007 §157](https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/adr/007_database_schema.md) (`0=public, 1=private, 2=internal`):
```
slug | name | format | visibility
------------+---------+--------+------------
gitlab-org | npm-pub | 2 | 0 <-- public
gitlab-org | npm-a | 2 | 1
gitlab-org | maven-a | 1 | 1
```
Authorization behaviour today is correct and matches ADR-021 §135 ("Write and management operations always require the corresponding permission from an assigned role, regardless of visibility"): a principal with zero role assignments is denied **every** operation on `npm-pub`, reads included, and AR logs `decision_reason: "no role assignment"` — `evaluate`'s zero-tuple deny fires before visibility is ever consulted.
## :boom: Why it matters
**1. S09 §53 is safe for the wrong reason.** The safety comes from the column *not being consulted*, not from the data being `private`. The stated justification does not hold, so the invariant is incidental rather than guaranteed — and it is the kind of premise a future reader would reasonably trust.
**2. The transition is unspecified, and that is the actual risk.** When visibility is first consulted, every row already persisted as `public` becomes readable by anyone including unauthenticated callers (ADR-021 §133). Nothing in ADR-021's [Public and internal visibility](https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/adr/021_authorization.md) section, ADR-007, S09, or S17 specifies a migration, a reset, or an audit gate for pre-existing rows.
This is **latent, not exploitable today** — no decision path consults the column, so there is no live exposure. It is filed because the trigger is a future configuration change made by someone who was not part of this analysis.
Note that **ADR-007 §241 already anticipates public rows existing**: it defines the audit query ("list every public repository in a namespace", `WHERE visibility = 0`) and a dedicated partial index on `(namespace_id, visibility) WHERE soft_deleted_at IS NULL` to serve it. The tooling exists; nothing requires its use before visibility is enabled — and its existence is itself further evidence against S09's "stores `private` only".
## :wrench: Proposal
**Preferred — reject the unsupported values at the API.** Return `400` `bad_request` for `visibility: public|internal` while closed beta is `private`-only, reusing the error path S17 already defines (§1276, §1412: "Invalid name, format, or visibility → `400` `bad_request`"). This makes the data match S09 §23, keeps the column clean, and removes the transition problem instead of scheduling it.
S17 §1612's reasoning does not block this: it argues that *making the field required* later would be breaking, but rejecting a **value** is not requiring the **field**. The compatibility direction is also favourable — *widening* an accepted enum when visibility ships is backwards compatible, whereas the alternative eventually needs the breaking direction (narrowing) to clean up.
**Alternative — keep accepting, and close the gap in the docs.** Correct S09 §23 and §53 to say the column may hold non-`private` values that are ignored, and add an explicit precondition to ADR-021's GA section requiring the ADR-007 §241 audit plus a decision on pre-existing `public` rows before visibility is consulted.
Either way the docs need a follow-up, since S09 §23/§53 are inaccurate as written today.
## :hourglass: On the milestone label
The true gate is **"before visibility is ever consulted"**, not GA as such — ADR-021 §302 defers `public`/`internal` *to* GA for a decision ("requires additional discussion … not yet decided"), which is not the same as shipping them at GA. `AR-Blocks::GA` is the closest available proxy and is where that discussion is scheduled. If the visibility work moves past GA, the label should move with it rather than the constraint being dropped.
Worth recording the one asymmetry: the **prevention** half (stop accepting the values) gets cheaper the earlier it lands, because every repository created in the meantime is one more row to remediate; the **remediation** half (decide what happens to rows already marked public) is what genuinely gates enabling visibility. If prevention lands before beta traffic accumulates, remediation is moot.
## :book: Context
Found while verifying [S09 authorization enforcement](https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/S09-authorization.md) steps 13 (npm) and 17 (management API) end to end on a local rig. **Both surfaces enforce correctly** — the full acceptance matrix passed across four principal states, and an adversarial pass found no bypass (ten encoded-separator/traversal/double-encoding variants on writes, all denied; the `//` path-cleaning `307` sits after authentication; service-token and user-JWT surfaces are isolated in both directions). This is the only substantive finding, and it is documentary rather than behavioural.
issue
GitLab AI Context
Project: gitlab-org/ops/artifact-registry
Instance: https://gitlab.com
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://gitlab.com/gitlab-org/ops/artifact-registry/-/raw/main/CONTRIBUTING.md — contribution guidelines
- https://gitlab.com/gitlab-org/ops/artifact-registry/-/raw/main/README.md — project overview and setup
- https://gitlab.com/gitlab-org/ops/artifact-registry/-/raw/main/AGENTS.md — AI agent instructions
- https://gitlab.com/gitlab-org/ops/artifact-registry/-/raw/main/CLAUDE.md — Claude Code instructions
Repository: https://gitlab.com/gitlab-org/ops/artifact-registry
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD