.auth¶
cattle_grid.auth ¶
create_app ¶
Allows running just the auth endpoint
Source code in cattle_grid/auth/__init__.py
dependencies ¶
AuthConfig
module-attribute
¶
AuthConfig = Annotated[
AuthConfig, Depends(provide_auth_config)
]
Provides the configuration for the auth module
BovineActor
module-attribute
¶
BovineActor = Annotated[
BovineActor, Depends(create_bovine_actor)
]
Returns the bovine actor
public_key_cache ¶
PublicKeyCache
dataclass
¶
Caches public keys in the database and fetches them using bovine_actor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bovine_actor
|
BovineActor
|
used to fetch the public key |
required |
session_maker
|
Callable[list, AsyncSession] | None
|
sql session maker |
None
|
Source code in cattle_grid/auth/public_key_cache.py
session_maker
class-attribute
instance-attribute
¶
session_maker: Callable[[], AsyncSession] | None = None
sql session maker
cryptographic_identifier
async
¶
cryptographic_identifier(
key_id: str,
) -> CryptographicIdentifier | Literal["gone"] | None
Returns “gone” if Tombstone
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_id
|
str
|
URI of the public key to fetch |
required |
Returns:
| Type | Description |
|---|---|
CryptographicIdentifier | Literal['gone'] | None
|
|
Source code in cattle_grid/auth/public_key_cache.py
find_with_item ¶
Given a list of dictionaries, finds the dictionary with id = key_id
public_key_owner_from_dict ¶
Given an actor and key_id returns the public_key and the owner. This method directly checks the key publicKey
Source code in cattle_grid/auth/public_key_cache.py
router ¶
ReverseProxyHeaders ¶
Bases: BaseModel
Headers set by the reverse proxy
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_original_method
|
str
|
The original used method |
'get'
|
x_original_uri
|
str | None
|
The original request uri |
None
|
x_original_host
|
str | None
|
The original used host |
None
|
x_forwarded_proto
|
str
|
The protocol being used |
'http'
|
Source code in cattle_grid/auth/router.py
handle_get_actor
async
¶
Returns the actor profile of the fetch actor used to retrieve public keys, e.g.
Source code in cattle_grid/auth/router.py
verify_signature
async
¶
verify_signature(
request: Request,
response: Response,
config: AuthConfig,
signature_checker: SignatureCheckWithCache,
reverse_proxy_headers: Annotated[
ReverseProxyHeaders, Header()
],
servable_content_types: ShouldServe,
) -> str
Takes the request and checks signature. If signature check fails a 401 is returned. If the domain the public key belongs to is blocked, a 403 is returned.
If the request is valid. The controller corresponding to
the signature is set in the response header X-CATTLE-GRID-REQUESTER.
The header X-CATTLE-GRID-SHOULD-SERVE is set to html
if one should redirect to the HTML resource. It is set to other if the resource to serve cannot be determined.
This is only used for unsigned requests.
Note: More headers than the ones listed below can be used to verify a signature.
Source code in cattle_grid/auth/router.py
webfinger
async
¶
webfinger(resource: str, config: AuthConfig) -> JrdData
If resource is the actor corresponding to the actor fetching public keys, returns the corresponding Jrd. Otherwise returns not found
Source code in cattle_grid/auth/router.py
util ¶
check_block ¶
Checks if a controller’s domain is in block list
>>> check_block({"blocked.example"}, "http://actor.example/path")
False
>>> check_block({"blocked.example"}, "http://blocked.example/path")
True