karu v0.4.0

Stateless byte range transport

Configuration reference

Karu captures configuration when a client is created. The client keeps that snapshot for its entire lifetime, so later changes to the process environment do not change requests that are already using it.

karu_config_create() reads supported environment variables and records the home and cache directories used for credential discovery. karu_config_create_empty() starts without those implicit sources, which is useful for isolated applications and tests.

Global options replace values captured from the environment. Path options are more specific and win for the longest matching VSI prefix. A path scope includes the named resource and its descendants, but stops at a segment boundary.

Configuration priority Karu checks a matching path option, then a global option, then the captured environment, and finally the built in default. The first available value is used. FIRST MATCH WINS Longest path most specific option Global option client configuration Environment captured at creation Built in default final fallback Karu stops when it finds a value for the request

Option names ignore letter case and unknown names are rejected. Aliases are converted to their canonical names before priority is evaluated, so an alias cannot bypass a more specific path option.

AWS_DEFAULT_PROFILE, AWS_DEFAULT_REGION, AWS_ENDPOINT_URL_S3, AWS_ENDPOINT_URL, and HUGGING_FACE_HUB_TOKEN use their canonical AWS or Hugging Face names. SOURCE_PROXY_URL maps to SOURCE_ENDPOINT. CURL_CA_BUNDLE and SSL_CERT_FILE map to KARU_HTTP_CA_BUNDLE.

Runtime

Limits apply per client. With multiple worker processes, compare KARU_IO_THREADS=1 and 4 on the full workload, including decoding.

OptionDefaultPurpose
KARU_CONCURRENCY64maximum simultaneous remote transfers
KARU_IO_THREADS4libcurl event loops per client, each on its own thread; KARU_CONCURRENCY is split between them
KARU_COALESCE_GAP1048576largest gap, in bytes, considered for merging ranges; 0 disables merging
KARU_COALESCE_LIMIT67108864largest merged transfer span
KARU_COALESCE_PARTS1024largest number of requests in one merged transfer
KARU_COALESCE_AMPLIFICATION16largest ratio of transferred bytes to requested bytes in a merge
KARU_RANGE_FALLBACK_LIMIT8388608largest prefix Karu may discard when a server ignores Range; 0 disables nonzero-offset fallback
KARU_MAX_ATTEMPTS / KARU_MAX_RETRIES8total attempts for transient failures, subject to the request deadline; DNS resolution and connection failures get at most 3 attempts
KARU_REQUEST_TIMEOUT120total seconds for one remote transfer and each credential_process; 0 disables both deadlines
KARU_CONNECT_TIMEOUT30connection timeout in seconds
KARU_LOW_SPEED_TIME60seconds below the low-speed threshold before aborting
KARU_LOW_SPEED_LIMIT1024low-speed threshold in bytes per second

The four coalescing ceilings may be overridden for one batch through karu_client_submit_with(), karu_client_fetch_with(), or the C++ SubmitOptions type. Other runtime options are fixed when the client is created. Local files only merge overlapping or contiguous ranges.

AWS S3

OptionPurpose
AWS_ACCESS_KEY_IDstatic access key ID
AWS_SECRET_ACCESS_KEYstatic secret; must accompany the access key ID
AWS_SESSION_TOKENoptional temporary session token
AWS_PROFILE / AWS_DEFAULT_PROFILEshared profile name
AWS_SHARED_CREDENTIALS_FILEcredentials file path
AWS_CONFIG_FILEconfig file path
AWS_REGION / AWS_DEFAULT_REGIONSigV4 region; default us-east-1
AWS_S3_ENDPOINTservice-root host or URL
AWS_ENDPOINT_URL_S3 / AWS_ENDPOINT_URLaliases for AWS_S3_ENDPOINT
AWS_HTTPSadd https:// to a host-only endpoint; default YES
AWS_VIRTUAL_HOSTINGput the bucket before the host; defaults to YES for AWS and NO for a custom endpoint
AWS_REQUEST_PAYERrequester for requester-pays buckets
AWS_NO_SIGN_REQUESTexplicit anonymous access
AWS_ROLE_ARNrole used with web identity
AWS_WEB_IDENTITY_TOKEN_FILEOIDC token file
AWS_ROLE_SESSION_NAMEoptional web-identity session name
AWS_STS_ENDPOINTweb-identity STS endpoint
AWS_CONTAINER_CREDENTIALS_RELATIVE_URIECS credential endpoint path
AWS_CONTAINER_CREDENTIALS_FULL_URIHTTPS, loopback, or ECS credential endpoint
AWS_CONTAINER_AUTHORIZATION_TOKENECS credential endpoint authorization
AWS_CONTAINER_AUTHORIZATION_TOKEN_FILEfile containing that authorization value
AWS_EC2_METADATA_DISABLEDdisable IMDS discovery
AWS_METADATA_SERVICE_TIMEOUTIMDS connect timeout in seconds, 1–60

Static profiles, credential_process, and web-identity profiles are handled natively. Chained source-profile AssumeRole and IAM Identity Center should be provided by the application's AWS SDK through the callback API. A credential_process is terminated if it exceeds KARU_REQUEST_TIMEOUT.

AWS_S3_ENDPOINT is a service root. With virtual hosting enabled, an endpoint of https://objects.example.test becomes https://bucket.objects.example.test/key. With virtual hosting disabled it becomes https://objects.example.test/bucket/key.

Source Cooperative

source://account/product/key and /vsisource/account/product/key resolve to the Source Data Proxy. Public reads need no configuration and remain unsigned. Source credentials use their own namespace and callback kind, so Karu never forwards ambient AWS credentials to the proxy.

OptionPurpose
SOURCE_PROFILEAWS-format profile; defaults to source-coop when signed access is requested
SOURCE_CONFIG_FILEAWS-format config file; default ~/.aws/config
SOURCE_SHARED_CREDENTIALS_FILEAWS-format credentials file; default ~/.aws/credentials
SOURCE_ACCESS_KEY_IDexplicit Source access key ID
SOURCE_SECRET_ACCESS_KEYexplicit secret; must accompany the access key ID
SOURCE_SESSION_TOKENoptional temporary session token
SOURCE_REGIONSigV4 region; defaults to the profile region, then us-east-1
SOURCE_ENDPOINT / SOURCE_PROXY_URLproxy service root; default https://data.source.coop
SOURCE_NO_SIGN_REQUESTforce (YES) or disable (NO) anonymous access

Installing a Source credential option or a KARU_CREDENTIALS_SOURCE callback enables signed requests automatically. SOURCE_NO_SIGN_REQUEST=YES always wins; SOURCE_NO_SIGN_REQUEST=NO requests credentials explicitly and uses the source-coop profile when no profile is named.

The profile created for the Source CLI uses credential_process:

[profile source-coop]
credential_process = source-coop creds
endpoint_url = https://data.source.coop

Run source-coop login, then set SOURCE_PROFILE=source-coop in Karu. Karu executes the profile's credential process and refreshes its temporary result when needed. The process is terminated if it exceeds KARU_REQUEST_TIMEOUT; Karu does not implement the browser login or read the CLI keyring. The profile's endpoint_url is intentionally ignored because SOURCE_ENDPOINT owns endpoint selection for /vsisource/ paths.

Google Cloud Storage

OptionPurpose
GCS_ACCESS_TOKENstatic bearer token
GCS_HMAC_ACCESS_KEY_IDinteroperable HMAC access ID
GCS_HMAC_SECRET_ACCESS_KEYinteroperable HMAC secret
GOOGLE_APPLICATION_CREDENTIALSADC JSON path
CLOUDSDK_CONFIGdirectory containing gcloud's ADC JSON
GCS_REFRESH_TOKENauthorized-user refresh token
GCS_CLIENT_IDauthorized-user client ID
GCS_CLIENT_SECRETauthorized-user client secret
GCS_PRIVATE_KEYinline service-account PEM key
GCS_PRIVATE_KEY_FILEPEM key file; alternative to the inline key
GCS_CLIENT_EMAILservice-account email used with a PEM key
GCS_SCOPEOAuth scope; defaults to read-only object access
GCS_USER_PROJECTrequester-pays billing project header
GCS_ENDPOINTXML API service-root URL
GCS_METADATA_ENDPOINTmetadata token endpoint
GCS_METADATA_DISABLEDdisable metadata discovery
GCS_NO_SIGN_REQUESTexplicit anonymous access

ADC supports service_account, authorized_user, and OIDC external_account sources backed by a file or a simple URL. Service-account impersonation is supported. Environment-specific external-account suppliers can use the callback API.

With environment discovery enabled, metadata credentials are attempted after ADC files. An explicit GCS_METADATA_ENDPOINT also enables that source for an otherwise empty configuration. GCS_METADATA_DISABLED=YES always disables it.

Azure Storage

OptionPurpose
AZURE_STORAGE_CONNECTION_STRINGaccount, endpoint, Shared Key, or SAS connection string
AZURE_STORAGE_ACCOUNTstorage account name
AZURE_STORAGE_ACCESS_KEYbase64 Shared Key
AZURE_STORAGE_SAS_TOKENencoded SAS query string
AZURE_STORAGE_ACCESS_TOKENstatic bearer token
AZURE_STORAGE_ENDPOINTBlob or DFS service-root URL
AZURE_TENANT_IDMicrosoft Entra tenant
AZURE_CLIENT_IDapplication or managed-identity client ID
AZURE_CLIENT_SECRETclient-secret credential
AZURE_FEDERATED_TOKEN_FILEworkload-identity assertion
AZURE_AUTHORITY_HOSTauthority root for public or sovereign clouds
AZURE_STORAGE_SCOPEOAuth v2 scope; default https://storage.azure.com/.default
AZURE_STORAGE_RESOURCEmanaged-identity resource; default https://storage.azure.com/
AZURE_IMDS_OBJECT_IDselect a managed identity by object ID
AZURE_IMDS_CLIENT_IDselect a managed identity by client ID
AZURE_IMDS_MSI_RES_IDselect a managed identity by Azure resource ID
IDENTITY_ENDPOINT / IDENTITY_HEADERApp Service managed identity
IMDS_ENDPOINTmanaged-identity endpoint override
AZURE_NO_SIGN_REQUESTexplicit anonymous access

Connection-string DefaultEndpointsProtocol, EndpointSuffix, BlobEndpoint, and DfsEndpoint values are honored. AZURE_AUTHORITY_HOST, AZURE_STORAGE_SCOPE, and AZURE_STORAGE_RESOURCE keep identity and storage endpoints explicit for sovereign clouds. AZURE_STORAGE_ENDPOINT is a convenience option; the standard endpoint fields in AZURE_STORAGE_CONNECTION_STRING are also supported.

HTTP and Hugging Face

KARU_HTTP_HEADERS accepts newline-separated Name: value entries. libcurl does not forward authorization to a different redirect origin. HF_ENDPOINT changes the Hugging Face service root.

OptionPurpose
KARU_HTTP_HEADERSnewline-separated request headers
KARU_HTTP_VERSION1.1 (default), 2TLS/2, 2PRIOR_KNOWLEDGE, or AUTO
KARU_HTTP_CA_BUNDLE / CURL_CA_BUNDLE / SSL_CERT_FILEexplicit CA bundle passed to libcurl
KARU_HTTP_CA_PATHdirectory containing CA certificates
KARU_HTTP_PROXYexplicit HTTP proxy
KARU_HTTP_PROXY_CREDENTIALSproxy credentials in user:password form
KARU_HTTP_USER_AGENTUser-Agent; defaults to karu/<version>, and an empty value disables it
HF_TOKEN / HUGGING_FACE_HUB_TOKENbearer token; takes precedence over token files
HF_TOKEN_PATHpath to the token written by Hugging Face tooling
HF_HOMEHugging Face state directory; the token is read from <HF_HOME>/token
HF_ENDPOINTHub service-root URL

With environment discovery enabled, Karu follows the Hugging Face CLI's default token location: $HF_TOKEN_PATH, then $HF_HOME/token, then ${XDG_CACHE_HOME:-~/.cache}/huggingface/token. A missing token file means anonymous access. karu_config_create_empty() does not inspect a default cache, but explicitly setting HF_TOKEN_PATH or HF_HOME opts into that one file.

The token file is read while each request attempt is materialized. Logging in or rotating the file therefore affects the next operation without putting a credential or cache inside an object. Karu trims surrounding whitespace and reports an existing but unreadable token file as a credential error.

Range and Host are always owned by Karu. Cloud and Hugging Face requests also reserve authentication and provider-signature headers. Use the dedicated credential options or callback instead of injecting those headers through KARU_HTTP_HEADERS.

Object transfers and their redirects are restricted to HTTP and HTTPS.

On Linux and macOS, Karu discovers a system CA bundle at runtime when no CA option is set. This avoids relying solely on the build machine's certificate path.

With OpenSSL and no CA option set, Karu prefers libcurl's hashed CA directory, as on Debian and Ubuntu. Only certificates in that directory are trusted. Otherwise, libcurl 7.87+ uses the available bundle without its default directory so it can cache the certificates. Set KARU_HTTP_CA_PATH to include a directory; other TLS backends keep their defaults.

The bundle cache lasts up to 24 hours. Bundle updates may not take effect until it expires.

Custom providers

karu_config_set_credentials_provider() installs one callback for AWS, GCS, Azure, or Source Cooperative. The callback receives the canonical VSI path. It returns strings that Karu copies immediately, an optional Unix expiry, and an optional canonical cache_prefix.

Use a prefix only when the credential is valid for that path and every object beneath it. For example, /vsis3/team-bucket/ shares one renewable value across that bucket. Without a prefix Karu calls the provider for every request, which is appropriate when the provider or vendor SDK owns its own cache.

Source uses KARU_CREDENTIALS_SOURCE and the same access-key, secret, and session-token fields as AWS, but its cache namespace is separate. A Source prefix therefore starts with /vsisource/, not /vsis3/.

Karu coalesces simultaneous callback refreshes for the same path. Refresh is lazy: the first request inside the refresh window obtains a new value while later requests for that same path wait for it. There is no background thread. Callbacks for different paths may run concurrently.

The callback must be thread-safe and must not re-enter that same client. Karu cannot interrupt caller code, so the callback must place its own deadline on any I/O.

Inside Karu

How configuration reaches a request

The client freezes configuration once. Each request then resolves its effective options from the canonical path before credentials are loaded and the transfer is prepared.

Karu configuration resolution Environment values, global overrides, and path overrides enter a frozen configuration snapshot. A canonical request path selects options by longest-prefix precedence. Provider credentials are cached by that scope and used to prepare the final transport request. BUILD CLIENT Environment captured at create() Global options config.set() Path options config.set_path() ConfigSnapshot validated · immutable per client EACH REQUEST Canonical path URI → VSI locator Option lookup longest path → global → env → default Provider scope backend + effective options Credentials callback or native cache PreparedRequest endpoint · auth headers · byte range Transport local read or HTTP transfer the same canonical path scopes option lookup and credential reuse