Render the registry configuration without a shell script
## Problem
The registry Deployment and its migrations Job run a `configure` init container with `args: ["sh", "/config/configure"]` ([deployment.yaml:76](https://gitlab.com/gitlab-org/charts/gitlab/-/blob/53e3d35bd44/charts/registry/templates/deployment.yaml#L76), [migrations-job.yaml:45](https://gitlab.com/gitlab-org/charts/gitlab/-/blob/53e3d35bd44/charts/registry/templates/migrations-job.yaml#L45)). The script is the `registry.init.script` default ([values.yaml:162](https://gitlab.com/gitlab-org/charts/gitlab/-/blob/53e3d35bd44/charts/registry/values.yaml#L162)). It splices secrets into the rendered `config.yml` as text:
- `sed -i -e 's@PLACEHOLDER@'"$(cat /config/<secret>)"'@'` for the HTTP secret, the S3 access and secret keys, every notification header secret (the file name is the placeholder), the database password, and the Redis cache, rate-limiting and load-balancing passwords.
- The `storage` secret is indented with `sed 's/^/ /'` and inserted after `storage:` with `sed '/^storage:/ r file'`. A `delete.enabled: true` default is appended when `egrep -A1 '^delete:\s*$' | egrep -q '\s{2,4}enabled:'` finds none.
- `cp`, `cat`, `mkdir` and `chmod` copy the storage files, `middleware.storage`, the certificate, the profiling key, and the database and TLS key material.
### Secrets with some characters are corrupted or silently dropped
The secret becomes part of the sed expression, so sed interprets it. With the database password, tested with GNU sed:
| Password | Result in `config.yml` |
|---|---|
| `abc&def` | `password: abcDB_PASSWORD_FILEdef` (`&` is the matched text) |
| `abc@def` | sed fails (`unknown option to 's'`); `password: DB_PASSWORD_FILE` |
| `abc\1def` | sed fails (`invalid reference \1`); `password: DB_PASSWORD_FILE` |
| `a\nb` | the value is split across two lines |
The script has no `set -e`, so when sed fails the init container still succeeds and the registry starts with the literal placeholder as the password. The placeholders also sit inside double quotes in the YAML ([_database.tpl:14](https://gitlab.com/gitlab-org/charts/gitlab/-/blob/53e3d35bd44/charts/registry/templates/_database.tpl#L14), [_redis.tpl:116](https://gitlab.com/gitlab-org/charts/gitlab/-/blob/53e3d35bd44/charts/registry/templates/_redis.tpl#L116), [configmap.yaml:55](https://gitlab.com/gitlab-org/charts/gitlab/-/blob/53e3d35bd44/charts/registry/templates/configmap.yaml#L55)), so a `"` or `\` produces invalid YAML or a different value.
### The script defines what the init image must contain
The init container uses `gitlab-base`, so `gitlab-base` has to ship a shell, sed, grep and coreutils for this script. A minimal or distroless `gitlab-base` cannot run it. That is the case for the hardened CNG images (https://gitlab.com/gitlab-org/software-supply-chain-security/hardened-builds/-/work_items/35), where every other `configure` script needs only `mkdir`, `cp` and `chmod`.
## Proposal
Render `config.yml` with gomplate, which the Debian and UBI `gitlab-base` images already ship, and mount files instead of copying them.
1. **Template.** The ConfigMap carries `config.yml` as a gomplate template (`{%` `%}` delimiters, as the chart already uses for `sentinelpassword` in [_redis.tpl:96](https://gitlab.com/gitlab-org/charts/gitlab/-/blob/53e3d35bd44/charts/registry/templates/_redis.tpl#L96)). Every secret is read as data, never as template or sed text:
- Scalar secrets (HTTP secret, database password, Redis cache, rate-limiting and load-balancing passwords): `{% file.Read "/config/<secret>" | strings.TrimRight "\n" | data.ToJSON %}`. A JSON string is valid YAML for any content. `TrimRight` strips all trailing newlines, as `$(cat)` does today; `TrimSuffix` would strip only one. The S3 access and secret key substitution is dropped: no template mounts `/config/accesskey` or emits those placeholders.
- Notification headers: Helm already knows each secret header's name, Secret and key ([_helpers.tpl:62-67](https://gitlab.com/gitlab-org/charts/gitlab/-/blob/53e3d35bd44/charts/registry/templates/_helpers.tpl#L62-67)), so it renders the header name followed by the mounted `notifications/SECRET_<secret>_<key>` file, indented with `strings.Indent`. The file is inserted as YAML text, as the sed splice did, so a flow list and a multi-line block list both work. No placeholder substitution, no loop.
- `storage`: inserted under `storage:` as indented YAML text (`file.Read | strings.TrimRight "\n" | strings.Indent 2`), not parsed and re-emitted. A `data.YAML | data.ToYAML` round trip uses YAML 1.2, so it quotes `secure: yes` and `v4auth: on`, which the S3 driver then rejects, and turns `0123` into `83`. The `delete.enabled: true` default is added when the Secret has no top-level `delete` key, checked with `regexp.Match "(?m)^delete[ \t]*:"`. Parsing the Secret for that check would fail on input the registry accepts, such as duplicate keys. `delete: {}` counts as present and suppresses the default.
2. **Init container.** `command: [gomplate, --left-delim, "{%", --right-delim, "%}", --file, /templates/config.yml.tpl, --out, /registry/config.yml]`. No shell. `/templates` is already mounted in the Deployment and the migrations Job. `command:` bypasses the `gitlab-base` entrypoint, so the template is rendered once.
3. **Files.** A projected `registry-files` volume carries the certificate, the storage `extraKey`, `middleware.storage`, the profiling key, and the TLS and database SSL material. Each is mounted with `subPath` at the path `config.yml` names, next to `config.yml` from the emptyDir; directory mounts inside a read-only volume fail in runc. Key files use mode `0440` when `securityContext.fsGroup` is set and `0444` when it is not, so the registry user can read them either way. The `configure` container mounts only the Secrets the template reads.
### Custom `registry.init.script`
Change the default of `registry.init.script` to empty.
- Empty: the gomplate path above.
- Set: today's behaviour, unchanged. Render the legacy `config.yml` with placeholders, the same `/config` layout, and run `sh /config/configure`. A custom script almost certainly runs its own `sed` on those placeholders, so keeping only the `sh` call would break it silently.
A custom script still needs an init image with a shell. The Debian and UBI `gitlab-base` images have one. With a shell-free `gitlab-base`, the init container fails at the first unsupported command, and `registry.init.image` can point at an image with a shell. Document this.
Do not deprecate `registry.init.script`. The init step stays; only its interpreter changes from `sh` to gomplate, so a user hook into it is still coherent. Deprecation would make sense if the init container went away, as with registry environment overrides. The cost is keeping the legacy placeholder render next to the gomplate one. Retiring the shell form needs a gomplate-native extension point first, most likely for extra secrets, which needs its own issue.
### Things to check
- **TLS and database key permissions.** Mounted Secret files are root-owned, not `600` files owned by the registry user. Result: with `fsGroup`, the kubelet sets the group, and `0440` is readable by the registry user. Without `fsGroup`, `0444` is needed. pgx v5 reads `sslkey` with `os.ReadFile` and Go `crypto/tls` loads keys the same way; neither checks permissions.
- **Template syntax in values.** gomplate interprets any `{%` that Helm renders into the template from a value. Secret contents are data and are never parsed. Result: each chart-emitted gomplate action is rendered as a NUL-delimited placeholder, every `{%` in the rendered text is escaped, and the placeholders are then replaced with their actions. A value can never become an action, and a value containing NUL fails rendering. This changes one behaviour: on the old path, the `gitlab-base` entrypoint rendered `{% %}` in values, and now it is literal. That needs an upgrade note.
- **Sentinel passwords.** `sentinelpassword` is already rendered as `{% file.Read ... %}` ([_redis.tpl:96](https://gitlab.com/gitlab-org/charts/gitlab/-/blob/53e3d35bd44/charts/registry/templates/_redis.tpl#L96)). Result: they already reach the registry. The `configure` container sets only `args:`, so the `gitlab-base` entrypoint runs `set-config`, which renders `/templates/*.tpl` with gomplate before `sh /config/configure`. No changelog entry is needed.
- **Init image contract.** `gomplate` must be on `PATH` in the init image. Document it with the certificates contract in https://gitlab.com/gitlab-org/charts/gitlab/-/work_items/6729. Result: the Debian and UBI images have it. The hardened `gitlab-base` ships gomplate in its store but sets no `PATH`, so the init container fails with `exec: "gomplate": executable file not found in $PATH`. It needs a hardened-builds change before this ships to the nix variant.
- **Volume layout.** The `registry-server-config` volume now holds only `config.yml`. Extra mounts or sidecars that read other files from it need an upgrade note.
### Alternatives considered
- **Registry environment overrides** (`REGISTRY_<PATH>` from `secretKeyRef`). These remove the init container for most keys, but header secrets are awkward: the parser lowercases map keys, a header set in both `config.yml` and the environment is sent twice, and header names with `_` cannot be expressed. Values are also parsed as YAML, so a password can change type.
- **File references in the registry** (`passwordfile`, a secret-headers map). The cleanest long-term option, but it needs registry releases before the chart can use it.
## Acceptance criteria
- [ ] With default values, the registry `configure` init container runs `gomplate` with no shell, in the Deployment and the migrations Job.
- [ ] The registry starts and uses secrets containing `&`, `@`, `\`, `"`, `#` and newlines as given, including notification headers.
- [ ] A set `registry.init.script` behaves as before, documented as requiring an init image with a shell.
- [ ] Existing installs upgrade without changes to their values or Secrets.
- [ ] Specs cover each secret type, the storage `delete` default and the custom-script path.
## Related
- https://gitlab.com/gitlab-org/charts/gitlab/-/work_items/6717: the same approach for shared-secrets.
- https://gitlab.com/gitlab-org/charts/gitlab/-/work_items/6729: the init image contract.
- https://gitlab.com/gitlab-org/software-supply-chain-security/hardened-builds/-/work_items/35: the hardened `gitlab-base` image that cannot run this script.
issue
GitLab AI Context
Project: gitlab-org/charts/gitlab
Instance: https://gitlab.com
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://gitlab.com/gitlab-org/charts/gitlab/-/raw/master/CONTRIBUTING.md — contribution guidelines
- https://gitlab.com/gitlab-org/charts/gitlab/-/raw/master/README.md — project overview and setup
- https://gitlab.com/gitlab-org/charts/gitlab/-/raw/master/AGENTS.md — AI agent instructions
Repository: https://gitlab.com/gitlab-org/charts/gitlab
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