--- title: "ADR 0054: Trusted provider hosts are administrator configured or controller managed" --- * Status: accepted * Code: [`pkg/hostpolicy/hostpolicy.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/hostpolicy/hostpolicy.go), [`pkg/params/settings/config.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/params/settings/config.go) ## Context The controller derives the Git provider API host from data that originates, directly or indirectly, from a webhook payload or a Repository CR. Without a check, whoever can reach the controller endpoint could make it send provider credentials to a host they control. [`pkg/hostpolicy`](https://github.com/tektoncd/pipelines-as-code/tree/main/pkg/hostpolicy) is the gate, and its policy is stored in the controller ConfigMap. ## Decision * The policy has two values under two keys: the administrator allowlist (`settings.TrustedProviderHostnamesKey`) and the learned hosts in the `keys.AutoTrustedProviderHostnames` annotation. `policyFrom` reads both. * A non-empty allowlist selects administrator configured mode (`administratorConfigured`). `check` then trusts only listed hosts, public SaaS hosts included, so "never talk to github.com" can be expressed. * An empty allowlist selects controller managed mode. Public hosts (`vcshost.IsPublic`) and hosts in the annotation are trusted; everything else is refused with `NotTrustedError`. * A corrupted annotation is forgotten (`autoTrusted = nil`) rather than failing, so it can only narrow the policy to the public defaults. A corrupted allowlist fails with `InvalidAllowlistError`. * With no Kubernetes client the policy cannot be read, and `readPolicy` and `TrustOnFirstUse` return `noKubeClientError`; they never fall back to permissive. * `ControllerConfigMap` uses the ConfigMap named by `run.Info.Controller.Configmap`, falling back to `info.DefaultPipelinesAscodeConfigmapName`, so each controller has its own policy. * The gate reads the ConfigMap live through the Kubernetes client, not the parsed `settings.Config` field. The code gives no recorded reason beyond what the field's former comment stated: the informer cache may lag an administrator narrowing the list, and trust on first use needs a read-modify-write it can retry on conflict. ## Consequences * Each value has one owner; ownership is never inferred by comparing the two lists. * Learned hosts are kept but ignored while an administrator list exists, and apply again if the list is emptied. * The settings field is validated on ConfigMap change but is not what enforces the policy; reading it in the gate would reintroduce the cache lag. * Callers that choose the host themselves (the end-to-end harness via `github.Provider.UsePreauthenticatedClient`) never reach this package.