Ankusa.BlobStore.OCI (ankusa v0.7.0)

Copy Markdown View Source

Ankusa.BlobStore backed by Oracle Cloud Infrastructure Object Storage, via Req.

OCI has no bearer-token or pre-signed-URL shortcut that covers arbitrary PUT/GET/DELETE/list against a bucket, so this adapter signs its own requests the way every OCI SDK does: Signature version 1, an RSA-SHA256 signature over the request's (request-target), date, and host headers (plus content-length/content-type/x-content-sha256 on PUT). The signing is implemented with OTP's :public_key — no dependency — and pinned against OCI's own test keys in test/ankusa/blob_store_oci_signing_test.exs.

opts:

  • :region — required, e.g. "us-ashburn-1"
  • :namespace — required; the OCI namespace (see the tenancy page)
  • :bucket — required
  • :key_id — optional; overrides the tenancy/user/fingerprint key
                     id the API-key opts derive. Instance principals and
                     session tokens sign with a `ST$<token>` key id — pass
                     that here alongside `:private_key`.
  • :tenancy_ocid — required for API-key auth
  • :user_ocid — required for API-key auth
  • :key_fingerprint — required for API-key auth; the signing key fingerprint
  • :private_key — required unless :key_provider is set; the PEM private key
                     (PKCS#1 or PKCS#8)
  • :key_provider — {module, fun, args} returning {:ok, %{key_id: key_id, private_key: pem}} | :error, applied per request, in place of
                     `:key_id`/`:private_key`: the identity of an instance principal
                     (`{Ankusa.BlobStore.OCI.InstancePrincipal, :credentials, [[region: …]]}`).
                     On a `401` the adapter calls the module's `invalidate/n` (same
                     arguments) and sends the request once more with fresh credentials
  • :endpoint — default "https://objectstorage.#{region}.oraclecloud.com"
  • :timeout_ms — default 10_000, for both connect and response of
                     one request that carries at most 1 MiB
  • :upload_timeout_ms, :op_deadline_ms, :multipart_threshold_bytes, :multipart_part_bytes, :breaker_*, :pool_* — one deadline per
                     operation, multipart above a size, a breaker per
                     bucket and a connection pool per endpoint. See
                     `Ankusa.BlobStore.Options`
  • :req_options — transport options for the HTTP client. See
                     `Ankusa.HttpClient` for the accepted keys
  • :retries — default 2: extra attempts after a transport error
                     or a `408`/`429`/`5xx`, each re-signed with a fresh
                     `date`. See `Ankusa.BlobStore.Retry`
  • :sse — %{type: :kms, key_id: vault_key_ocid}: every object is
                     encrypted with that Vault key (`opc-sse-kms-key-id`).
                     Object Storage encrypts everything at rest anyway;
                     this picks the key. See `Ankusa.BlobStore.SSE`

Identity

Two credential shapes:

  • API key — :tenancy_ocid/:user_ocid/:key_fingerprint/:private_key, the default. The right shape off-OCI (CI, laptops, another cloud).
  • Instance principal — on OCI compute or OKE, the best credential is the instance's own identity: key_provider: {Ankusa.BlobStore.OCI.InstancePrincipal, :credentials, [[region: "us-ashburn-1"]]} runs the certificate federation (IMDS leaf cert → auth.<region>.oraclecloud.com/v1/x509 → a short-lived ST$ session token plus a session key), caches it and refreshes it before it expires and on a 401. A session token from another source (the OCI SDK, a sidecar) still works as key_id: "ST$<token>" with its session key as :private_key; it is the caller's to renew.

put_if_absent/4 sends if-none-match: * (a 412 is :already_exists); every PUT carries Content-MD5 and a GET verifies opc-content-md5 (Ankusa.BlobStore.Checksum); a body over multipart_threshold_bytes is a multipart upload (create, parts each with Content-MD5, commit, abort on failure).

Local dev

config :ankusa,
  storage: %{
    blob_store:
      {Ankusa.BlobStore.OCI,
       region: "us-ashburn-1",
       namespace: System.get_env("OCI_NAMESPACE"),
       bucket: "ankusa-segments",
       tenancy_ocid: System.get_env("OCI_TENANCY"),
       user_ocid: System.get_env("OCI_USER"),
       key_fingerprint: System.get_env("OCI_KEY_FINGERPRINT"),
       private_key: File.read!(System.fetch_env!("OCI_KEY_FILE"))}
  }

The floci-oci emulator in docker-compose.integration.yml (:4599) parses but never verifies the signature, so local integration testing works with any locally generated key; the signing itself is proven by the reference vectors in test/ankusa/blob_store_oci_signing_test.exs.