Table of Contents

krb5

Examples

   [realms]
       EXAMPLE.COM = {
           kdc = kdc.example.com
           admin_server = kdc.example.com
       }
   [domain_realm]
       .example.com = EXAMPLE.COM
       example.com = EXAMPLE.COM
   ```

Python Examples

 def get_ticket(username, password, realm='EXAMPLE.COM', kdc='kdc.example.com'):
     # Initialize Kerberos context
     context = krbV.default_context()
     # Create a principal for the user
     principal = krbV.Principal(name=username, context=context)
     # Set up credentials cache
     ccache = krbV.CCache(name=krbV.CCache().generate(), context=context)
     # Get Ticket Granting Ticket (TGT)
     tgt = krbV.TGT(principal=principal, password=password, realm=realm, kdc=kdc, context=context)
     # Store the TGT in the credentials cache
     ccache.init(principal=principal)
     ccache.store(tgt)
     print(f"Successfully obtained TGT for {username}")
     return ccache
 # Example usage
 ccache = get_ticket('myusername', 'mypassword')
 ```

 url = 'http://example.com/protected/resource'
 # Set up Kerberos authentication
 auth = HTTPKerberosAuth(mutual_authentication=REQUIRED)
 # Make a request to the protected resource
 response = requests.get(url, auth=auth)
 if response.status_code == 200:
     print("Authenticated successfully!")
     print(response.content)
 else:
     print(f"Failed to authenticate. Status code: {response.status_code}")
 ```

Summary