|
| 1 | +--- |
| 2 | +title: Provisioned credentials |
| 3 | +sdk: ruby |
| 4 | +kind: guide |
| 5 | +order: 22 |
| 6 | +spec_sections: [§9.7, §9.8] |
| 7 | +--- |
| 8 | + |
| 9 | +# Provisioned credentials |
| 10 | + |
| 11 | +Provisioned credentials let a runtime mint short-lived upstream keys for a |
| 12 | +job after the lease is finalized. The key is returned only on |
| 13 | +`job.accepted`, scoped by the lease, and revoked when the job terminates. |
| 14 | + |
| 15 | +## Configure the runtime |
| 16 | + |
| 17 | +```ruby |
| 18 | +provisioner = Arcp::Credentials::InMemoryProvisioner.new( |
| 19 | + endpoint: 'https://llm-gateway.example/v1', |
| 20 | + profile: 'openai' |
| 21 | +) |
| 22 | + |
| 23 | +runtime = Arcp::Runtime::Runtime.new( |
| 24 | + auth_verifier: auth, |
| 25 | + credential_provisioner: provisioner, |
| 26 | + credential_store: Arcp::Credentials::InMemoryStore.new |
| 27 | +) |
| 28 | +``` |
| 29 | + |
| 30 | +When a provisioner is configured, the runtime advertises the |
| 31 | +`model.use` and `provisioned_credentials` features during capability |
| 32 | +negotiation. Without a provisioner, both features are omitted. |
| 33 | + |
| 34 | +## Request model access |
| 35 | + |
| 36 | +```ruby |
| 37 | +handle = client.submit_job( |
| 38 | + agent: 'gateway-caller', |
| 39 | + lease_request: Arcp::Lease::LeaseRequest.new( |
| 40 | + capabilities: ['cost.spend'], |
| 41 | + budget: Arcp::Lease::CostBudget.parse(['USD:1.00']), |
| 42 | + model_use: ['tier-fast/*'] |
| 43 | + ) |
| 44 | +) |
| 45 | + |
| 46 | +credential = handle.credential_for(endpoint: 'https://llm-gateway.example/v1') |
| 47 | +``` |
| 48 | + |
| 49 | +The runtime copies `cost.budget`, `model.use`, and `expires_at` into the |
| 50 | +credential constraints so an upstream gateway can enforce the same bounds. |
| 51 | + |
| 52 | +## Implement a provisioner |
| 53 | + |
| 54 | +```ruby |
| 55 | +class LiteLLMProvisioner |
| 56 | + include Arcp::CredentialProvisioner |
| 57 | + |
| 58 | + def issue(lease:, job_id:, agent:, principal_id:) |
| 59 | + response = generate_litellm_key( |
| 60 | + budget: lease.budget&.to_a, |
| 61 | + models: lease.model_use, |
| 62 | + expires_at: lease.expires_at |
| 63 | + ) |
| 64 | + |
| 65 | + [ |
| 66 | + Arcp::Credential.new( |
| 67 | + id: response.fetch('key_alias'), |
| 68 | + scheme: Arcp::Credential::SCHEME_BEARER, |
| 69 | + value: response.fetch('key'), |
| 70 | + endpoint: 'https://llm-gateway.example/v1', |
| 71 | + profile: 'openai', |
| 72 | + constraints: { |
| 73 | + 'cost.budget' => lease.budget&.to_a, |
| 74 | + 'model.use' => lease.model_use, |
| 75 | + 'expires_at' => lease.expires_at |
| 76 | + }.compact |
| 77 | + ) |
| 78 | + ] |
| 79 | + end |
| 80 | + |
| 81 | + def revoke(credential_id:) |
| 82 | + delete_litellm_key(credential_id) |
| 83 | + end |
| 84 | +end |
| 85 | +``` |
| 86 | + |
| 87 | +Vendor-specific HTTP clients should live outside the core gem. The SDK only |
| 88 | +defines the interface and value objects. |
| 89 | + |
| 90 | +When an upstream gateway reports budget exhaustion, map it back to the ARCP |
| 91 | +error boundary: |
| 92 | + |
| 93 | +```ruby |
| 94 | +begin |
| 95 | + call_gateway(credential) |
| 96 | +rescue StandardError => e |
| 97 | + raise Arcp::Credentials.translate_upstream_error(e) |
| 98 | +end |
| 99 | +``` |
| 100 | + |
| 101 | +## Rotation and revocation |
| 102 | + |
| 103 | +Agents can rotate a credential value mid-job: |
| 104 | + |
| 105 | +```ruby |
| 106 | +ctx.rotate_credential(id: 'cred_job_123_0', new_value: 'sk-new-value') |
| 107 | +``` |
| 108 | + |
| 109 | +That emits a `status` event with `phase: 'credential_rotated'` and a |
| 110 | +`fields` hash containing the new `{ id, value }`. Treat this event as |
| 111 | +secret-bearing data. |
| 112 | + |
| 113 | +The runtime revokes outstanding credential ids on success, error, |
| 114 | +cancellation, and timeout. `CredentialRegistry` retries transient revoke |
| 115 | +failures once and keeps any failed id in the configured store for later |
| 116 | +reconciliation. |
| 117 | + |
| 118 | +## Security notes |
| 119 | + |
| 120 | +`Credential#to_h` is the wire representation and includes `value`. |
| 121 | +Use `Credential#to_redacted_h` for logs, metrics, and examples. |
| 122 | +`session.list_jobs` summaries never include credentials. |
0 commit comments