Ë
    tPêj<  ã                   óˆ   — U d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ  eh d£«      Zeee      ed<   d	ed
e	fd„Zy)é    )ÚMapping)ÚFinal)ÚRequest)Úverbose_proxy_logger)ÚUserAPIKeyAuth)Úrequire_trusted_proxy_request>   ÚmodelsÚorg_idÚteam_idÚuser_idÚ
team_aliasÚ
user_emailÚALLOWED_OAUTH2_PROXY_FIELDSÚrequestÚreturnc              ƒ   ó:  K  — ddl m} t        j                  d«       t	        | |d¬«       |j                  d«      xs i }t        j                  d|«       |st        d«      ‚t        t        |j                  «       «      t        z
  «      }|rt        d	|› d
t        t        «      › d�«      ‚|j                  «       D ���ci c]W  \  }}| j                  j                  |«      x}r5||dk(  r-|j                  d«      D �cg c]  }|j                  «       ‘Œ c}n|“ŒY }}}}t        j                  dt        |j                  «       «      «       t!        j"                  |«      }	t        j                  dt        |	j$                  «      «       |	S c c}w c c}}}w ­w)u[  
    Resolve a ``UserAPIKeyAuth`` from request headers per the admin-set
    ``oauth2_config_mappings``.

    The auth model assumes the proxy is deployed behind a trusted OAuth2
    reverse proxy that injects authenticated identity headers (e.g.
    oauth2-proxy, Authelia).

    **Identity-only allowlist.** ``oauth2_config_mappings`` maps header
    names to ``UserAPIKeyAuth`` fields. Without an allowlist, an admin
    who maps the wrong header to ``user_role`` lets any caller send
    ``X-User-Role: proxy_admin`` and gain full admin privileges
    (Pydantic coerces the string into the enum). Only fields in
    ``ALLOWED_OAUTH2_PROXY_FIELDS`` (identity assertion only â€” see the
    constant's comment) may be mapped; any other mapping is rejected at
    request time so the misconfiguration surfaces loudly rather than as
    a silent privesc.
    r   )Úgeneral_settingszHandling oauth2 proxy requestzOAuth2 proxy auth)r   r   Úfeature_nameÚoauth2_config_mappingszOauth2 config mappings: %sz4Oauth2 config mappings not found in general_settingszZOauth2 proxy auth refuses to map non-identity UserAPIKeyAuth fields from request headers: z%. Only identity fields are accepted (a  ); anything else (privileges, budgets, rate limits, metadata) would let a caller forge enforcement parameters by spoofing the matching header. If you need a trusted upstream to assert anything beyond identity, use JWT auth (signature-validated) instead of header-trust.r	   ú,z8Auth data before creating UserAPIKeyAuth object: keys=%sz+UserAPIKeyAuth object created with keys: %s)Úlitellm.proxy.proxy_serverr   r   Údebugr   ÚgetÚ
ValueErrorÚsortedÚsetÚkeysr   ÚitemsÚheadersÚsplitÚstripÚlistr   Úmodel_validateÚ__fields_set__)
r   r   r   Ú
disallowedÚkeyÚheaderÚmodelÚvalueÚ	auth_dataÚuser_api_key_auths
             úi/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/auth/oauth2_proxy_hook.pyÚhandle_oauth2_proxy_requestr-   (   s–  è ø€ õ& <ä×ÑÐ>Ô?Ü!ØØ)Ø(õð 5E×4HÑ4HÐIaÓ4bÒ4hÐfhÐÜ×ÑÐ;Ð=SÔTá!ÜÐOÓPÐPäœsÐ#9×#>Ñ#>Ó#@ÓAÔD_Ñ_Ó`€JÙÜð,Ø,6¨<ð 8$Ü$*Ô+FÓ$GÐ#Hð I=ð=ó	
ð 		
ð 2×7Ñ7Ó9÷7ð 7áˆC�Ø—_‘_×(Ñ(¨Ó0Ð0ˆEÐ0ð 	¸cÀXºo¨¯©°SÓ)9Ö: ˆe�k‰k�mÓ:ÐSXÑXð7€Iò 7ô ×ÑØBÜˆY�^‰^ÓÓôô  .×<Ñ<¸YÓGÐÜ×ÑØ5ÜÐ×-Ñ-Ó.ôð Ðùò ;ùô7ùs+   ‚C FÃ>FÄ FÄFÄA1FÆFÆFN)Úcollections.abcr   Útypingr   Úfastapir   Úlitellm._loggingr   Úlitellm.proxy._typesr   Ú&litellm.proxy.auth.trusted_proxy_utilsr   Ú	frozensetr   ÚstrÚ__annotations__r-   © ó    r,   ú<module>r9      sL   ðÞ #Ý å å 1Ý /Ý Pñ( 6?òó	6Ð ˜U 9¨S¡>Ñ2ó 	ð>¨wð >¸>ô >r8   