--- title: "ADR 0034: Inherited provider secret is resolved before the global Repository is merged" --- * Status: accepted * Code: [`pkg/gitclient/client_setup.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/gitclient/client_setup.go), [`pkg/secrets/inherit.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/secrets/inherit.go) ## Context `SetupAuthenticatedClient` merges the global Repository spec into the local one with `repo.Spec.Merge`. After that merge, a local Repository that sets no `git_provider.url` carries the global one, so the question "did this Repository choose its own endpoint while inheriting the shared secret?" can no longer be answered from the merged object. GitHub Apps do not use the Repository `git_provider` section at all: they take the webhook secret of the controller namespace and keep `event.InstallationID > 0`. ## Decision * For events without an installation ID, `secrets.ResolveInheritedSecret(repo, globalRepo, event)` runs first, on the unmerged local Repository. It returns the namespace holding the secret and whether the global secret is inherited, or an error. * Only then is the global spec merged into the local Repository, and the secret is read from the namespace that was resolved. * For GitHub App events the resolution is skipped, since Repository credential inheritance does not apply to them. * A Repository that inherits the global secret must not also choose the endpoint it is sent to. This is the rule enforced in `ResolveInheritedSecret`, and `TestSetupAuthenticatedClientRefusesInheritedSecretWithOwnProviderURL` covers it (other host, cleartext downgrade, other path on a shared host refused; same host, API entry point of the same deployment and an own secret allowed). ## Why The global Repository lives in the controller namespace and its token is shared. If anyone able to create a Repository in any namespace could inherit that token and set their own `git_provider.url`, they could redirect it to a host of their choosing. Resolving before the merge keeps a local endpoint visible instead of hiding it behind the global defaults. ## Consequences * Moving the merge above `ResolveInheritedSecret` silently disables the check. * Every path resolving a provider secret must go through `ResolveInheritedSecret`; `pkg/secrets/inherit.go` records that the adapter and the watcher each used to have their own copy.