* '''Key Distribution Center (KDC)''': Centralized server responsible for authentication and ticket granting, consisting of the Authentication Server (AS) and the Ticket Granting Server (TGS). * '''Ticket Granting Ticket (TGT)''': A ticket issued by the AS used to request service tickets from the TGS. * '''Service Ticket''': A ticket issued by the TGS that allows a client to authenticate to a specific service. * '''Principal''': An entity (user or service) identified in the Kerberos system. * '''Realms''': Administrative domains that define the scope of authentication.
* '''Mutual Authentication''': Both the client and server verify each other's identity. * '''Single Sign-On (SSO)''': Users authenticate once to access multiple services without re-entering credentials. * '''Encrypted Communication''': Ensures data integrity and confidentiality during transmission. * '''Scalability''': Suitable for large, complex networks with multiple services and users.
* Install the krb5 packages: ```bash sudo apt-get install krb5-user krb5-config ```
* Edit the `/etc/krb5.conf` file to include the realm and KDC information: ```plaintext [libdefaults] default_realm = EXAMPLE.COM
[realms] EXAMPLE.COM = { kdc = kdc.example.com admin_server = kdc.example.com }
[domain_realm] .example.com = EXAMPLE.COM example.com = EXAMPLE.COM ```
```bash kinit username ```
```bash klist ```
```bash kdestroy ```
```python import krbV
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') ```
```python import requests from requests_kerberos import HTTPKerberosAuth, REQUIRED
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}") ```