feat(auth): support OAuth 2.0 client credentials - #135
Open
galpgustavoflor wants to merge 1 commit into
Open
Conversation
Organisations whose Collibra instance is fronted by SSO (SAML/OIDC) have no local password for federated users, so both existing authentication modes (server-wide Basic credentials and client-supplied Authorization headers) fail with "Failed to authenticate request through basic credentials". Collibra itself issues Bearer tokens through the OAuth 2.0 client credentials grant at /rest/oauth/v2/token, but chip had no way to use them. Add a third authentication mode. When api.oauth.client-id and api.oauth.client-secret are configured, chip obtains a token from the Collibra token endpoint (credentials sent as HTTP Basic, as Collibra expects), caches it, refreshes it before expiry, and sends "Authorization: Bearer <token>" on every outgoing Collibra API request. The token request reuses the base transport so proxy and TLS settings apply to it as well. OAuth takes precedence over Basic auth; the two existing branches keep their order and behaviour, and with no OAuth configuration the code path is unchanged. Misconfiguration (only one of id/secret, OAuth combined with username/password, or a non-absolute token URL) fails at startup with an actionable message. Token endpoint response bodies are stripped from errors so neither the client secret nor a token can reach logs or tool results. No new dependency is added: golang.org/x/oauth2 was already an indirect requirement and is promoted to a direct one. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of your changes
Adds a third authentication mode: OAuth 2.0 client credentials.
Organisations whose Collibra instance is fronted by SSO (SAML/OIDC) have no local password for federated users, so both existing modes (server-wide Basic credentials and client-supplied
Authorizationheaders) fail withauthenticationFailed. Collibra issues Bearer tokens through theclient_credentialsgrant at/rest/oauth/v2/token; this change lets chip use them.When
api.oauth.client-idandapi.oauth.client-secretare set (env:COLLIBRA_MCP_API_OAUTH_CLIENT_ID/COLLIBRA_MCP_API_OAUTH_CLIENT_SECRET, flags:--api-oauth-client-id/--api-oauth-client-secret), chip:clientcredentials.Config.TokenSource, which already returns aReuseTokenSource);Authorization: Bearer <token>on every outgoing Collibra API request, in both stdio and HTTP modes;api.proxyandapi.skip-tls-verifyapply to it as well.The token endpoint defaults to
<api.url>/rest/oauth/v2/tokenand can be overridden withapi.oauth.token-url.Precedence in
RoundTripis OAuth, then server-wide Basic, then the client-supplied header; the two existing branches keep their order and behaviour.Startup validation fails with a message when only one of client-id/client-secret is set, when OAuth and username/password are both set, or when the token URL is not absolute. Token endpoint response bodies are stripped from returned errors so neither the client secret nor a token can reach logs or tool results. A warning is logged that all actions are attributed to the OAuth client's account, mirroring the existing Basic-auth warning.
Files:
cmd/chip/config.go,cmd/chip/http.go,cmd/chip/main.go, newcmd/chip/http_test.go,go.mod,README.md,docs/CONFIG.md,docs/mcp.yaml.example. The two Go files already touched were also run throughgofmt, which realigned two struct literals that were previously misaligned.Tests (
cmd/chip/http_test.go, table-driven withhttptest) cover: Bearer header sent and token endpoint called once across two requests; Basic auth with no token call; client header pass-through; token endpoint 401 returns an error that does not contain the secret and no request reaches the API; token URL derivation with and without trailing slash, with a path prefix, and with an explicit override; and the config validation rules.Manual verification against a real instance: register a client with
POST /rest/auth/v1/clientsand body{"client_name": "mcp-chip", "grant_types": ["client_credentials"]}(the secret is returned once), confirmcurl -u "<client_id>:<client_secret>" -d grant_type=client_credentials https://<instance>/rest/oauth/v2/tokenreturns a token, then run chip with the two env vars and calllist_asset_types.Impact Analysis
RoundTripfollows the same two branches as before and existing tests pass untouched.golang.org/x/oauth2moves from the indirect to the direct require block (viago mod tidy); no new module enters the dependency graph andgo.sumis unchanged.pkg/clients, or the tool registry.go build -v ./...,go test -race ./...,golangci-lint run(v2.4.0),gofmt -lon the changed files. The only test failures on this Windows machine are four pre-existing path-handling tests inpkg/skillsthat fail identically onmainand are unrelated.Checklist
🤖 Generated with Claude Code