Signers#
A signer mediates between a STAC consumer and the three auth boundaries a
cloud-hosted STAC archive can have: the search request, the returned
Item (asset-href rewrite), and the asset read (GDAL env). Every signer
satisfies the Signer protocol — name plus sign_request,
sign_item, sign_href, and gdal_env — so a custom signer need not subclass
anything.
Pick by where the credential lives:
| Signer | Credential boundary | Needs |
|---|---|---|
AnonymousSigner |
none (public catalogs) | — |
AWSRequesterPaysSigner |
asset read (AWS_REQUEST_PAYER=requester) |
— |
BearerTokenSigner |
request + asset read (Authorization: Bearer) |
a token (or a callable) |
PlanetaryComputerSigner |
item / href (Azure SAS in the URL) | stdlib only (no SDK) |
EarthdataSigner |
asset read (EDL bearer) | env creds / token |
CDSESigner |
asset read (Keycloak bearer) | env creds |
Wire a signer into open_client(..., signer=...) (request + item), into
DatasetCollection.from_stac(..., signer=...) / build_vrt_from_stac(..., signer=...)
(href + read), or into load_asset(item, key, signer=...) (href + read).
Bearer tokens and cross-host redirects
BearerTokenSigner / EarthdataSigner / CDSESigner put the token in
GDAL's GDAL_HTTP_HEADERS, which GDAL forwards across HTTP redirects —
including to a different host. For catalogs that redirect asset reads
cross-host, prefer a URL-signing signer (PlanetaryComputerSigner, which
puts a SAS token in the query string) so the credential is scoped to the
signed URL.
pyramids.stac.signers
#
Generic signing abstraction for STAC consumers.
A signer mediates between a STAC consumer (an external client or pyramids'
own from_stac) and the three distinct auth boundaries a cloud-hosted STAC
archive can have:
- search-time — the outgoing
GET/POST/searchHTTP request may need credentials (a bearer token, a signed header). - item-rewrite — returned STAC Items' asset hrefs may need a token grafted on or the URL rewritten.
- asset-read — when GDAL opens the asset, it may need extra environment
(
AWS_REQUEST_PAYER=requester, anAuthorizationheader).
This module ships the generic, dependency-light signers
(:class:AnonymousSigner, :class:AWSRequesterPaysSigner,
:class:BearerTokenSigner) plus :class:PlanetaryComputerSigner, a native
Microsoft Planetary Computer SAS signer that mints tokens over stdlib
urllib — it requires no planetary-computer SDK, so it keeps pyramids
dependency-light. Provider signers that would require a heavyweight remote-
sensing SDK or live token-refresh service (e.g. NASA Earthdata's
earthaccess) remain out of scope here; implement the :class:Signer
protocol downstream (or pass a token callable to :class:BearerTokenSigner)
for those.
Signer
#
Bases: Protocol
Three-boundary signing protocol for STAC consumers.
Any object exposing name plus the four methods below satisfies the
protocol structurally — concrete signers need not subclass it.
Source code in src/pyramids/stac/signers.py
sign_request(request)
#
Modify an outgoing STAC-API HTTP request before it is sent.
Matches pystac_client.Client.open(request_modifier=...). Return
None to signal "mutated in place, send as-is", or return the
(modified) request.
Source code in src/pyramids/stac/signers.py
sign_item(item)
#
Mutate a returned STAC Item / ItemCollection in place.
Matches pystac_client.Client.open(modifier=...) and must return
None (pystac-client warns on a non-None return).
AnonymousSigner
#
Bases: _BaseSigner
Signer that adds no credentials anywhere — for public catalogs.
Examples:
- It is a complete no-op across every boundary:
Source code in src/pyramids/stac/signers.py
AWSRequesterPaysSigner
#
Bases: _BaseSigner
Signer for assets in AWS Requester-Pays buckets.
Adds only the GDAL environment needed to read from buckets such as
s3://usgs-landsat or s3://sentinel-1-grd; no request or href rewrite
is required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str | None
|
Optional AWS region of the bucket. Stored for callers that wire their own boto3/s3fs handles; pin it to avoid cross-region egress. |
None
|
Examples:
- The GDAL env opts into Requester-Pays and trims redundant calls:
Source code in src/pyramids/stac/signers.py
__init__(region=None)
#
Store the optional bucket region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str | None
|
AWS region of the Requester-Pays bucket, or |
None
|
gdal_env()
#
Return the GDAL config that opts into Requester-Pays reads.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A mapping setting |
dict[str, str]
|
cloud-read knobs that avoid extra billable HEAD/list calls. |
Source code in src/pyramids/stac/signers.py
BearerTokenSigner
#
Bases: _BaseSigner
Signer that injects an Authorization: Bearer header.
The token may be a static string or a zero-argument callable resolved on every use — pass a callable to plug in a provider-specific token cache / refresh routine without coupling pyramids to that provider's SDK.
Security note
gdal_env() carries the token in GDAL's process-wide
GDAL_HTTP_HEADERS config. :func:pyramids.stac.load_asset installs
it only for the duration of the asset open (via CloudConfig) and
tears it down afterwards, so it does not persist globally. However, GDAL
forwards that Authorization header across HTTP redirects, including
redirects to a different host (common with signed-URL / blob-storage
STAC assets) — so the token can be sent to the redirect target. Prefer a
URL-signing signer (rewriting the href via sign_href, e.g. a SAS
token in the query string) for catalogs that redirect cross-host, and
reserve this signer for catalogs that authenticate the asset host
directly with a bearer header.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str | Callable[[], str]
|
A bearer token string, or a callable returning one. |
required |
Examples:
- A static token is injected into the request and the GDAL env:
- A callable token is resolved on each use (e.g. an auto-refresher):
Source code in src/pyramids/stac/signers.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__init__(token)
#
Store the bearer token or token-provider callable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str | Callable[[], str]
|
A static token string or a zero-arg callable returning one. |
required |
sign_request(request)
#
Set the Authorization header on an outgoing request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Any
|
An object with a mutable |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The same |
Source code in src/pyramids/stac/signers.py
gdal_env()
#
Return the GDAL config carrying the bearer header for asset reads.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A mapping with |
Source code in src/pyramids/stac/signers.py
PlanetaryComputerSigner
#
Bases: _BaseSigner
Native Microsoft Planetary Computer SAS signer (no SDK dependency).
PC hosts Sentinel / Landsat / many collections behind short-lived Shared
Access Signature (SAS) tokens. This signer mints a token per
(account, container) from the PC token endpoint and appends it to the
blob href's query string — the same algorithm as planetary_computer.sign
but implemented over the standard library (urllib), so pyramids gains PC
support without taking the planetary-computer SDK as a dependency.
Because the credential rides the URL, :meth:gdal_env is empty: a signed
https://<account>.blob.core.windows.net/...?<sas> href is read directly
through GDAL /vsicurl/ with no extra config. Wire it in via
open_client(..., signer=PlanetaryComputerSigner()) (its sign_item
rewrites returned Items) or from_stac(..., signer=PlanetaryComputerSigner()).
Non-PC hrefs, the public ai4edatasetspublicassets bucket, and
already-signed URLs pass through unchanged. Tokens are cached until
refresh_window seconds before their advertised expiry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sas_url
|
str | None
|
SAS token endpoint. Defaults to |
None
|
subscription_key
|
str | None
|
Optional PC subscription key (raises rate limits),
sent as the |
None
|
refresh_window
|
float
|
Refetch a cached token when it is within this many seconds of expiry (default 60). |
60.0
|
timeout
|
float
|
Per-request timeout, in seconds, for the token GET. |
30.0
|
Examples:
- A non-PC href passes through untouched:
- An already-signed blob href is left as-is:
- The public assets bucket is never signed:
Source code in src/pyramids/stac/signers.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
__init__(*, sas_url=None, subscription_key=None, refresh_window=60.0, timeout=30.0)
#
Store endpoint / auth settings and initialise the token cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sas_url
|
str | None
|
SAS token endpoint (env |
None
|
subscription_key
|
str | None
|
Optional PC subscription key (env
|
None
|
refresh_window
|
float
|
Seconds-before-expiry at which a cached token is refetched. |
60.0
|
timeout
|
float
|
Token-request timeout in seconds. |
30.0
|
Source code in src/pyramids/stac/signers.py
sign_href(href)
#
Append a SAS token to a PC blob href; pass non-PC hrefs through.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
href
|
str
|
The asset href. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The href with |
str
|
blob URL, otherwise |
Source code in src/pyramids/stac/signers.py
sign_item(item)
#
Rewrite every asset href on an Item / ItemCollection in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
A STAC Item, an ItemCollection (iterable of Items), or the raw-dict equivalent. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None (pystac-client's |
Source code in src/pyramids/stac/signers.py
EarthdataSigner
#
Bases: _BearerProviderSigner
NASA Earthdata (EDL) bearer signer — native, no earthaccess SDK.
Uses a pre-minted token when given (or $EARTHDATA_TOKEN / $EARTHDATA_PAT),
otherwise mints one from the EDL find_or_create_token endpoint with HTTP
Basic auth ($EARTHDATA_USERNAME / $EARTHDATA_PASSWORD). The token is sent
as a GDAL Authorization: Bearer header for /vsicurl/ reads of EDL-gated
DAAC assets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str | None
|
EDL username (env |
None
|
password
|
str | None
|
EDL password (env |
None
|
token
|
str | None
|
A pre-minted bearer token (env |
None
|
refresh_window
|
float
|
Seconds-before-expiry at which to refetch a minted token. |
300.0
|
timeout
|
float
|
Token-request timeout in seconds. |
30.0
|
Examples:
- A pre-minted token is used directly in the GDAL header:
Source code in src/pyramids/stac/signers.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |
__init__(*, username=None, password=None, token=None, refresh_window=300.0, timeout=30.0)
#
Store EDL credentials / static token; init the token cache.
Source code in src/pyramids/stac/signers.py
CDSESigner
#
Bases: _BearerProviderSigner
Copernicus Data Space Ecosystem (CDSE) bearer signer via Keycloak OAuth2.
Mints an access token from the CDSE Keycloak token endpoint with a password
grant ($CDSE_USERNAME / $CDSE_PASSWORD, public client cdse-public), then
refreshes it with the refresh-token grant. The access token is sent as a
GDAL Authorization: Bearer header for /vsicurl/ reads of CDSE HTTPS/OData
assets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str | None
|
CDSE username (env |
None
|
password
|
str | None
|
CDSE password (env |
None
|
client_id
|
str
|
Keycloak client id (default |
'cdse-public'
|
refresh_window
|
float
|
Seconds-before-expiry at which to refresh (CDSE access tokens live ~600 s). |
30.0
|
timeout
|
float
|
Token-request timeout in seconds. |
30.0
|
Source code in src/pyramids/stac/signers.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | |
__init__(*, username=None, password=None, client_id='cdse-public', refresh_window=30.0, timeout=30.0)
#
Store CDSE credentials; init the token + refresh-token cache.