Loading
Add validity checks for the remaining OpenAI token types
This merge request extends OpenAI coverage to three more of the four token types GitLab detects.
Resolves #628281 (closed).
Gap
- GitLab detects four OpenAI token types, but validity checks only verified the project key (
sk_proj_). - The following token types had no verifier:
Fix
- We split the single flat
OpenaiClientintoOpenai::BaseandOpenai::ProjectKey. This is the layout ADR-006 prescribes. - We pin the metrics label
partnerto openai in theOpenai::Baseclass. This means all verifiers use the same label. - We add three new validity checks, each only enabled for GSS findings:
OpenAiServiceAccountKey– validated usingGET /v1/models.OpenAiServiceAdminKey– validated usingGET /v1/organization/admin_api_keys.open ai token– validated usingGET /v1/models.
- Every endpoint choice was test against a real key of that type, not inferred.
- We also updated handling for
403status code as OpenAI uses403for permissions refusal:- Those missing scopes map to
active, because OpenAI returns that only after resolving the key. - The "Country, region, or territory not supported" error, stays
unknown, because that cause does not depend on the key.
- Those missing scopes map to
Notes
- The existing
401handling is unchanged:- We return
inactiveonly for OpenAI'sinvalid_api_keycode. - We return
unknownfor the other three documented 401 causes, which describe a live key the request cannot use.
- We return
MR acceptance checklist
I have evaluated this MR against the MR acceptance checklist.
Edited by Ahmed Hemdan