fix(mcp): read a provider's bearer where provisioning writes it

Discovery resolved applications[role].credentials, the address from
before f713ba8350 moved every credential under secrets.credentials. The
run's own inventory shows which one is real: twelve applications carry
secrets.credentials, none carries the top-level key. So every provider
declaring credential.source: credentials - fifteen of the twenty - handed
back an empty mapping, and reconciliation aborted on a secret that had
been provisioned all along:

  mcp_servers: 1 authorized MCP server(s) cannot be rendered.
  web-app-prometheus: credential_missing: web-app-prometheus declares
  owner 'mcp-web-app-prometheus' but no secret resolved

The five providers on token_store read through users and were never
affected, which is why only some clients broke.

Provider and client were reading the same secret at two addresses:
web-app-prometheus/vars/main.yml:32 renders its bearer from
secrets.credentials.mcp_bearer. Without the strict assert this would have
surfaced as a 401 at runtime rather than a failed deploy.

The lookup was correct when 6881ac5132 wrote it - the rename landed on a
branch it was not an ancestor of, and arrived here through the main
merges of 08-15. Its own message notes that no regex over lookup('config')
could see an access path like this one; a .get("credentials") split across
two lines in a Python plugin is equally invisible to it.

The address now comes from credential_key's constants, which is where the
module already claims a credential is addressed by exactly one string.

resolve_credential was always handed a fabricated mapping directly, so the
function was covered and its caller's address was not. The new tests close
that seam, one of them end to end over the shape provisioning produces.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5 committed 2026-08-29 20:57:07 +02:00
1 parent f4b1ccadd7
commit 8e3fe04d72
2 files changed
+68 -4

No files matched your search

@@ -15,6 +15,7 @@ plugin_module = importlib.import_module("plugins.lookup.mcp_servers")
build_mcp_discovery = plugin_module.build_mcp_discovery
resolve_credential = plugin_module.resolve_credential
resolve_consumer_id = plugin_module.resolve_consumer_id
role_credentials_of = plugin_module.role_credentials_of
CONSUMER = "web-app-openwebui"
@@ -275,6 +276,49 @@ class TestResolveCredential(unittest.TestCase):
resolve_credential(server, {}, {"mcp_token": "v"}), ("v", "mcp-web-app-x")
)
def test_the_role_secret_is_read_where_the_inventory_writes_it(self):
"""The function was tested; the address its caller used was not.
Provisioning writes `<role>.secrets.credentials.<key>`, which is also
how the roles' own vars address it. Discovery read the top-level
`credentials` and therefore found nothing for all fifteen providers
whose source is `credentials`, aborting the deploy on a secret that
had been generated and vaulted all along.
"""
applications = {
"web-app-prometheus": {
"secrets": {"credentials": {"mcp_bearer": "resolved"}}
}
}
self.assertEqual(
{"mcp_bearer": "resolved"},
role_credentials_of(applications, "web-app-prometheus"),
)
def test_a_top_level_credentials_block_is_not_the_address(self):
applications = {"web-app-x": {"credentials": {"mcp_bearer": "wrong-place"}}}
self.assertEqual({}, role_credentials_of(applications, "web-app-x"))
def test_an_absent_role_yields_an_empty_mapping(self):
self.assertEqual({}, role_credentials_of({}, "web-app-missing"))
def test_the_extraction_feeds_resolve_credential(self):
"""End to end: the payload shape provisioning produces must resolve."""
applications = {
"web-app-prometheus": {
"secrets": {"credentials": {"mcp_bearer": "resolved"}}
}
}
server = self._server(
owner="mcp-web-app-prometheus", source="credentials", key="mcp_bearer"
)
self.assertEqual(
("resolved", "mcp-web-app-prometheus"),
resolve_credential(
server, {}, role_credentials_of(applications, "web-app-prometheus")
),
)
def test_administrator_owner_resolves_to_nothing(self):
server = self._server(
owner="administrator", source="token_store", key="web-app-baserow"