Open
Conversation
9bf93dd to
c5dd566
Compare
71c69d3 to
30d306a
Compare
c5dd566 to
d6e95ea
Compare
7d0c198 to
b1c6f3f
Compare
d6e95ea to
b6a01e9
Compare
e1e15df to
b6a01e9
Compare
| if cfg.BYOKBearerToken != "" { | ||
| credHint = intercept.MaskCredential(cfg.BYOKBearerToken) | ||
| } | ||
| interceptor.SetCredential(credKind, credHint) |
Contributor
Author
There was a problem hiding this comment.
Consider moving it to constructors instead of SetCredential?
messages.NewStreamingInterceptor(NewCredentialFields(credKind, credHint), ...)messages.NewBlockingInterceptor(NewCredentialFields(credKind, credHint), ...)- ...
?
a610090 to
d3e5994
Compare
| return nil, UnknownRoute | ||
| } | ||
|
|
||
| interceptor.SetCredential(intercept.CredentialKindSubscription, utils.MaskSecret(key)) |
Contributor
Author
There was a problem hiding this comment.
CredentialKindSubscription makes sense for Copilot?
| credKind := intercept.CredentialKindCentralized | ||
| if token := utils.ExtractBearerToken(r.Header.Get("Authorization")); token != "" { | ||
| cfg.Key = token | ||
| credKind = intercept.CredentialKindPersonalAPIKey |
Contributor
Author
There was a problem hiding this comment.
This is a bit tricky, it can be either CredentialKindPersonalAPIKey or CredentialKindSubscription.
We can rely on some hacks to determine it:
- Presence of
Chatgpt-Account-Idheader - Check is it
JWT TokenorAPI KEY - Rely on URL (openai vs chatgpt)
See more details here: #227 (comment)
Alternatively we can introduce new enum value, smth like: CredentialKindPersonal
| suffix := string(runes[len(runes)-reveal:]) | ||
| masked := len(runes) - reveal*2 | ||
| return prefix + strings.Repeat("*", masked) + suffix | ||
| return prefix + fmt.Sprintf("...(%d)...", masked) + suffix |
Contributor
Author
There was a problem hiding this comment.
This approach preserves the length of the secret, but doesn't generate huge strings which we need to log and store in DB.
d3e5994 to
ec6ae45
Compare
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.
Summary
Records credential metadata on each AI Bridge interception, enabling admins to see how requests were authenticated and identify which credential was used.
Each provider's
CreateInterceptornow captures two new fields on the interceptor:credential_kind:centralized,personal_api_key, orsubscriptioncredential_hint: masked credential for audit (e.g.sk-a...(13)...efgh)Changes
Interceptorinterface withSetCredential,CredentialKind, andCredentialHint, backed by an embeddableCredentialFieldshelperCreateInterceptor:centralized(admin key) orpersonal(Bearer token)centralized,personal_api_key(X-Api-Key), orsubscription(Bearer token)subscriptionMaskSecretto embed hidden character count (e.g.sk-a...(13)...efghinstead ofsk-a*************efgh)Relates to coder/coder#23808