.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
http_util
AcceptEntry
dataclass
AcceptEntry(content_type: str, profile: str | None = None, quality: float = 1.0)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content_type
|
str
|
|
required |
profile
|
str | None
|
|
None
|
quality
|
float
|
|
1.0
|
Source code in cattle_grid/auth/http_util.py
ContentType
parse_accept_header
>>> header = 'application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams", text/html;q=0.1'
>>> parse_accept_header(header)
[AcceptEntry(content_type='application/activity+json', profile=None, quality=1.0),
AcceptEntry(content_type='application/ld+json', profile='https://www.w3.org/ns/activitystreams', quality=1.0),
AcceptEntry(content_type='text/html', profile=None, quality=0.1)]
Source code in cattle_grid/auth/http_util.py
should_serve
should_serve(header: str | None) -> List[ContentType]
Determines what content to serve
>>> should_serve("application/activity+json")
[<ContentType.activity_pub: 'activity_pub'>]
>>> should_serve("text/html")
[<ContentType.html: 'html'>]
Source code in cattle_grid/auth/http_util.py
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
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()
],
) -> 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