deepstack-api-v2-contracts / schemas /api-key.schema.json
mcauduro's picture
DeepStack API v2 contracts, package 7726f3ef2d6c (CC-BY-4.0)
1e3bc19 verified
Raw History Blame
6.87 kB
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "api-key.schema.json",
"title": "ApiKeyRecord",
"description": "One API key of a tenant as the server stores it (INT-007/APP-10, R4). The secret is never stored: only a salted PBKDF2-HMAC-SHA256 digest, with its own random salt. Scopes are 'route:purpose' pairs from a closed list; a key is never a forecasting machine, never trains, retains or publishes. rights is the ceiling of the rights_scope a request may claim. phase is always pre_lock: a key cannot attest a lock. The public view ($defs/public_view) is what /v2/keys/self answers and has no salt and no digest.",
"type": "object",
"additionalProperties": false,
"required": [
"schema_version",
"key_id",
"tenant_id",
"label",
"scopes",
"rights",
"quota",
"status",
"phase",
"hash",
"created_at",
"expires_at",
"rotated_from",
"rotated_to",
"grace_until",
"revoked_at",
"revoked_reason"
],
"properties": {
"schema_version": {
"$ref": "common.schema.json#/$defs/schema_version"
},
"key_id": {
"$ref": "#/$defs/key_id"
},
"tenant_id": {
"$ref": "#/$defs/tenant_id"
},
"label": {
"$ref": "#/$defs/label"
},
"scopes": {
"$ref": "#/$defs/scopes"
},
"rights": {
"$ref": "#/$defs/rights"
},
"quota": {
"$ref": "#/$defs/quota"
},
"status": {
"$ref": "#/$defs/status"
},
"phase": {
"const": "pre_lock"
},
"hash": {
"type": "object",
"additionalProperties": false,
"required": [
"algorithm",
"iterations",
"salt",
"digest"
],
"properties": {
"algorithm": {
"const": "pbkdf2-hmac-sha256"
},
"iterations": {
"type": "integer",
"minimum": 10000,
"maximum": 10000000
},
"salt": {
"type": "string",
"pattern": "^[0-9a-f]{32}$"
},
"digest": {
"$ref": "common.schema.json#/$defs/sha256"
}
}
},
"created_at": {
"$ref": "common.schema.json#/$defs/utc"
},
"expires_at": {
"type": [
"string",
"null"
],
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,6})?(Z|\\+00:00)$"
},
"rotated_from": {
"type": [
"string",
"null"
],
"pattern": "^key_[0-9a-f]{16}$"
},
"rotated_to": {
"type": [
"string",
"null"
],
"pattern": "^key_[0-9a-f]{16}$"
},
"grace_until": {
"type": [
"string",
"null"
],
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,6})?(Z|\\+00:00)$"
},
"revoked_at": {
"type": [
"string",
"null"
],
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,6})?(Z|\\+00:00)$"
},
"revoked_reason": {
"type": [
"string",
"null"
],
"enum": [
null,
"owner_revoked",
"rotated",
"compromised",
"tenant_closed"
]
}
},
"$defs": {
"key_id": {
"type": "string",
"pattern": "^key_[0-9a-f]{16}$"
},
"tenant_id": {
"description": "tenant:<slug>. Locally only tenant:deepstack-internal (dogfood) and, in tests, tenant:qa-*.",
"type": "string",
"pattern": "^tenant:[a-z0-9][a-z0-9-]{1,62}$"
},
"label": {
"type": "string",
"pattern": "^[a-z0-9][a-z0-9 ._-]{0,63}$"
},
"scopes": {
"type": "array",
"minItems": 1,
"maxItems": 8,
"uniqueItems": true,
"items": {
"enum": [
"answers:analyst",
"answers:resolution_explainer",
"search:analyst",
"scenarios:analyst",
"trackrecord:read"
]
}
},
"rights": {
"type": "object",
"additionalProperties": false,
"required": [
"policy_version",
"purposes"
],
"properties": {
"policy_version": {
"$ref": "common.schema.json#/$defs/id"
},
"purposes": {
"type": "array",
"minItems": 1,
"maxItems": 3,
"uniqueItems": true,
"items": {
"enum": [
"read",
"process",
"external_provider"
]
}
}
}
},
"quota": {
"type": "object",
"additionalProperties": false,
"required": [
"per_minute",
"per_day",
"concurrency"
],
"properties": {
"per_minute": {
"type": "integer",
"minimum": 1,
"maximum": 600
},
"per_day": {
"type": "integer",
"minimum": 1,
"maximum": 100000
},
"concurrency": {
"type": "integer",
"minimum": 1,
"maximum": 16
}
}
},
"status": {
"enum": [
"active",
"rotating",
"revoked",
"expired"
]
},
"public_view": {
"description": "What a key holder may read about its own key: no salt, no digest, no other key of the tenant.",
"type": "object",
"additionalProperties": false,
"required": [
"schema_version",
"key_id",
"tenant_id",
"label",
"scopes",
"rights",
"quota",
"status",
"phase",
"principal_scope",
"expires_at",
"grace_until"
],
"properties": {
"schema_version": {
"$ref": "common.schema.json#/$defs/schema_version"
},
"key_id": {
"$ref": "#/$defs/key_id"
},
"tenant_id": {
"$ref": "#/$defs/tenant_id"
},
"label": {
"$ref": "#/$defs/label"
},
"scopes": {
"$ref": "#/$defs/scopes"
},
"rights": {
"$ref": "#/$defs/rights"
},
"quota": {
"$ref": "#/$defs/quota"
},
"status": {
"$ref": "#/$defs/status"
},
"phase": {
"const": "pre_lock"
},
"principal_scope": {
"$ref": "common.schema.json#/$defs/principal_scope"
},
"expires_at": {
"type": [
"string",
"null"
],
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,6})?(Z|\\+00:00)$"
},
"grace_until": {
"type": [
"string",
"null"
],
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,6})?(Z|\\+00:00)$"
}
}
}
}
}