Documentation
¶
Overview ¶
Package openai is the OpenAI credential provider: project, service account, admin and legacy user API keys.
Every OpenAI key embeds the marker `T3BlbkFJ` ("OpenAI" in base64) at a fixed position, so the scan looks for the marker and checks the exact shape around it; the marker is not a checksum but it removes random look-alikes. Verification is one request that lists models, or the organization's admin keys for an admin key. OpenAI's API cannot revoke a key by itself: revocation goes through the Admin API with an admin key of the organization the leaked key belongs to, which the operator supplies in OPENAI_ADMIN_KEY. With one, patty finds the key in the organization's projects by the redacted value OpenAI shows for each key and deletes it.
Index ¶
- Constants
- type Provider
- func (p *Provider) Configure(env func(string) string)
- func (p *Provider) DryRunRevoke(ctx context.Context, tok detect.Token) error
- func (*Provider) Find(content []byte) []detect.Token
- func (p *Provider) Kinds() []detect.KindInfo
- func (*Provider) LocalSources() detect.LocalSources
- func (*Provider) Name() string
- func (p *Provider) Revoke(ctx context.Context, tokens []detect.Token) error
- func (p *Provider) Verify(ctx context.Context, tok detect.Token) detect.Verification
Constants ¶
const ( // KindProject is a project-scoped key (sk-proj-), the kind the platform issues by default. KindProject detect.Kind = "openai-project-key" // KindServiceAccount is the key of a project's service account (sk-svcacct-). KindServiceAccount detect.Kind = "openai-service-account-key" // KindAdmin is an organization admin key (sk-admin-), which manages the // organization rather than calling models. KindAdmin detect.Kind = "openai-admin-key" // KindLegacy is a user key from before projects (sk- and 20 characters // on either side of the marker). KindLegacy detect.Kind = "openai-legacy-key" )
const (
// AdminKeyEnv is the environment variable Configure reads AdminKey from.
AdminKeyEnv = "OPENAI_ADMIN_KEY"
)
const Marker = "T3BlbkFJ"
Marker is what every OpenAI key contains at a fixed position: "OpenAI" in base64. The scan looks for it and checks the shape around it.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct {
// BaseURL is the API root, https://api.openai.com by default.
BaseURL string
Client *http.Client
// AdminKey is an admin key of the operator's organization. It enables
// deletion of that organization's keys and lets the report name them.
// Configure reads it from OPENAI_ADMIN_KEY.
AdminKey string
// contains filtered or unexported fields
}
Provider implements detect.Provider for OpenAI.
func (*Provider) Configure ¶
Configure implements detect.Configurable: the admin key comes from OPENAI_ADMIN_KEY.
func (*Provider) DryRunRevoke ¶
DryRunRevoke implements detect.DryRunRevoker: it finds the key in the organization exactly as Revoke would, and stops there.
func (*Provider) Find ¶
Find implements detect.Provider. One substring pass for the marker, then the exact shape around each occurrence: a run of one of the documented lengths on each side, the family prefix before the left run, and no continuation into a longer word on either end.
func (*Provider) Kinds ¶
Kinds implements detect.Provider. Project, service account and admin keys are revocable only while an admin key is configured; legacy user keys are not managed by the Admin API at all.
func (*Provider) LocalSources ¶
func (*Provider) LocalSources() detect.LocalSources
LocalSources implements detect.Provider: the environment variables the SDKs read, Codex's credential file (which holds a sign-in as well as a key) and opencode's credential store.
func (*Provider) Revoke ¶
Revoke implements detect.Revoker by deleting each key through the Admin API, which needs the operator's admin key: OpenAI has no endpoint for reporting a leaked key. Admin keys are found in the organization's admin key list, project and service account keys in the key lists of every project, by the redacted value OpenAI shows for each key. A key no entry matches belongs to another organization and is reported as such, not as revoked. Deletion is final.
func (*Provider) Verify ¶
Verify implements detect.Provider with one request: listing models, which every key may do, or listing the organization's admin keys for an admin key, which is the only thing such a key is for and also names it. Only OpenAI's invalid_api_key answer counts as revoked. A 429 is reported as unknown, because a key whose quota is exhausted answers 429 just like a rate-limited one and is still very much live.