Skip to content

[BUG] GitLab (self-hosted) org-policy auto-discovery is impossible: all candidate repo names are invalid GitLab project paths #2566

Description

Describe the bug
On self-hosted GitLab, APM org-policy auto-discovery can never resolve, because every candidate repository name in the discovery cascade is an invalid GitLab project path.

Per the Policy Files docs, discovery probes, in order: .github-private.github.apm_apm. GitLab rejects any project path that starts with ., _, or -:

Path can only include non-accented letters, digits, '', '-' and '.'. It must not start with '-', '', or '.', nor end with '-', '_', '.', '.git', or '.atom'.

So none of the four candidates can be created:

Candidate Valid on GitLab? Reason
.github-private leading .
.github leading .
.apm leading .
_apm leading _

This is stricter than Azure DevOps (#2429): ADO forbids a leading _ only on the project name, so PR #2450 could keep repository _apm inside project apm. On GitLab the _apm fallback is also invalid, so there is no working coordinate at all. Additionally, probing these paths on our host surfaces an HTTP 410, which prints a policy-fetch warning on every apm install / apm audit (inconsistent with the docs stating GitLab "falls through with no policy applied").

To Reproduce
Steps to reproduce the behavior:

  1. On a project whose origin is a self-hosted GitLab remote (git@gitlab.example.com:<group>/<repo>.git), run command apm audit --ci (without --no-policy), or apm install.
  2. With parameters: default org-policy auto-discovery (no explicit --policy).
  3. See error: a policy-fetch warning (HTTP 410 on our host) and no org policy applied. Then try to create the org policy repo under the group — GitLab rejects .github-private, .github, .apm, and _apm with the path error quoted above.

Expected behavior
A supported way to host and auto-discover org policy on self-hosted GitLab using a valid, configurable GitLab project path (e.g. apm-policy), plus a clean "no policy" outcome (not a 410 warning) when none is present — analogous to the ADO project-coordinate fix in PR #2450, but for GitLab where even _apm is an invalid path.

Environment:

  • OS: macOS
  • APM Version: 0.25.0
  • Git host: self-hosted GitLab (GitLab Enterprise), e.g. gitlab.example.com

Logs
The form contains the following errors:

  • Project namespace path can only include non-accented letters, digits, '', '-' and '.'. It must not start with '-', '', or '.', nor end with '-', '_', '.', '.git', or '.atom'.
  • Path can only include non-accented letters, digits, '', '-' and '.'. It must not start with '-', '', or '.', nor end with '-', '_', '.', '.git', or '.atom'.

Additional context
Current mitigation is apm audit --ci --no-policy, which disables policy enforcement entirely.

Proposed direction:

  1. Configurable / host-valid policy repo name (default e.g. apm-policy), mirroring PR fix(policy): use valid ADO project coordinate #2450's ADO project-coordinate fix but for GitLab (where _apm is invalid too).
  2. A GitLab auto-discovery code path (currently documented as "not auto-discovered / falls through with no policy").
  3. apm install --policy <path-or-url> for install-time enforcement on non-GitHub remotes (tracked more broadly in [FEATURE] Support policy enforcement on non-GitHub remotes: add --policy to apm install (and/or auto-discovery for GitLab/ADO/plain git) #1925).
  4. Treat a missing policy repo as a clean "no policy" outcome instead of emitting an HTTP 410 warning.

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/audit-policyapm-policy.yml schema, custom_checks, install-time enforcement.area/enterpriseAir-gapped/GHE configurability, registry proxy, rulesets, adoption playbook.priority/highShips in current or next milestonestatus/triagedInitial agentic triage complete; pending maintainer ratification (silence = approval).theme/governanceGoverned by policy. apm-policy, audit, enforcement, enterprise rollout.type/bugSomething does not work as documented.

    Type

    No type

    Projects

    Status
    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions