apm icon indicating copy to clipboard operation
apm copied to clipboard

[FEATURE] Configurable policy source that replaces git-remote-based auto-discovery

Open Leon4ever2802 opened this issue 5 days ago • 1 comments

Proposals are welcome before implementation. For substantive changes, wait for a responsible human maintainer to approve the scope and identify a review contact. An automated recommendation, label alone, or silence is not approval. See Contributing.

Is your feature request related to a problem? Please describe.

Org policy auto-discovery derives the policy host from the project's git remote (git remote get-url origin) and then calls https://<remote-host>/api/v4/.... This assumes the git transport host and the HTTPS/API host are the same machine and reachable on the same network path.

In our self-managed GitLab setup they are not:

  • gitlab-ssh.example.com — SSH only (port 22 open, port 443 closed)
  • gitlab.example.com — HTTPS only (port 443 open)

Developers clone via SSH, so origin is [email protected]:group/repo.git. APM then tries to fetch the org policy from https://gitlab-ssh.example.com/..., which is unreachable. Discovery fails and falls through to policy.fetch_failure_default (warn, or a blocked install if set to block). The org policy that actually lives at gitlab.example.com/group/apm-policy is never applied by auto-discovery.

apm install --policy <source> (#1925, #4001, v0.38.0) helps, but does not fully solve this:

  1. It must be passed on every apm install / apm update invocation by every developer, which is easy to forget and defeats install-time enforcement as a default.
  2. Auto-discovery still runs alongside it against the unreachable remote host and produces a fetch failure on every run. --policy cannot be combined with --no-policy / APM_POLICY_DISABLE=1, so there is no way to say "use this source instead of discovery".

The only current workaround is forcing HTTPS clones / rewriting origin to the HTTPS host, which we cannot mandate (SSH is our standard transport).

Describe the solution you'd like

A persistent, configurable policy source that replaces remote-based auto-discovery, without passing a CLI flag each time. For example (any of these would work for us):

  • An environment variable, e.g. APM_POLICY_SOURCE=gitlab.example.com/group/apm-policy (or an https:// URL / local path), accepting the same source forms as --policy.
  • An apm config setting (user/machine scope), e.g. apm config set policy.source <ref>.
  • Optionally a project-level field in apm.yml (I'm aware this is deferred to the #3297 design per the #1925 scope note; env/config would already unblock us).

Expected behavior when set:

  • Remote-based auto-discovery is skipped entirely (no request to the remote host).
  • The configured source is fetched with the normal host auth chain and enforced with the same fail-closed semantics as an explicit --policy source.
  • extends: inheritance from that source keeps working (tighten-only, same-host rules unchanged).
  • apm policy status, apm install, apm update and apm audit --ci report the configured source as the effective policy source.
  • An explicit --policy on the command line still composes tighten-only on top.

Done when: a project whose origin points at an SSH-only host enforces the org policy from a separate HTTPS host on apm install with no extra CLI flags and no failed discovery request.

Describe alternatives you've considered

  • apm install --policy <ref> on every invocation: works, but per-invocation, easy to skip, and discovery still fails against the SSH host on each run.
  • Cloning via HTTPS / rewriting origin: not acceptable as an org-wide requirement.
  • url.<base>.insteadOf git config: doesn't help, because git remote get-url applies the rewrite, so APM still sees the SSH host.
  • A host mapping (e.g. APM_GITLAB_API_HOST_MAP=gitlab-ssh.example.com=gitlab.example.com) for discovery: would also solve our case, but a directly configured policy source is simpler and works for any host type.
  • --no-policy / APM_POLICY_DISABLE=1: disables enforcement, not an option.

Additional context

  • Related: #1925 (explicit --policy on install/update, shipped in v0.38.0 via #4001), #2933 (GitLab auto-discovery), discussion #3159 (referencing one central policy by URL), #3297 (private distribution design).
  • Happy to help test on a self-managed GitLab with split SSH/HTTPS hosts.

Leon4ever2802 avatar Nov 27 '26 15:11 Leon4ever2802

Thanks for the thorough request and for describing the split SSH/HTTPS setup so clearly. The gap is real: --policy (#1925/#4001) must be passed on every run, and discovery still hits the unreachable remote host.

Suggested next step: design discussion with a maintainer on a persistent source (env var and/or apm config) that replaces discovery. Open questions: precedence against --policy/--no-policy/APM_POLICY_DISABLE, fail-closed semantics, extends: same-host rules, and how apm policy status/audit --ci report the source. This is security-sensitive, since it changes where org policy is fetched from, so it needs maintainer review of trust boundaries. The project-level apm.yml field stays deferred to #3297.

This is a recommendation only. Scope, review contact and priority are a human maintainer's call.

Generated by Triage Panel · copilot · auto · 27.8 AIC · ⌖ 0.728 AIC · ⊞ 12.5K · ◷

github-actions[bot] avatar Nov 28 '26 12:11 github-actions[bot]