Tag: Authorization

  • Kerberos

    Kerberos is a network authentication protocol that offers strong authentication for client/server applications using secret-key (symmetric) cryptography. It enables users, computers, and network services to securely verify each other’s identities over untrusted networks without the need to repeatedly transmit passwords.

    Developed at the Massachusetts Institute of Technology (MIT) as part of Project Athena, Kerberos is named after Cerberus, the three-headed dog from Greek mythology that guards the entrance to Hades. The name reflects its purpose of protecting access to network resources.

    Kerberos employs a trusted third party known as the Key Distribution Center (KDC) to manage authentication and issue encrypted tickets. Instead of sending user credentials every time someone accesses a network resource, Kerberos uses a ticket-based authentication mechanism to establish trust between clients and services.


    Kerberos Core Characteristics

    • Strong Authentication: This mechanism allows both clients and servers to securely verify each other’s identities using cryptographic methods, thereby preventing unauthorized access and impersonation.
    • Secret-Key Cryptography: This approach primarily uses symmetric encryption (secret-key cryptography) to secure authentication messages and tickets. Keys are typically derived from user passwords or securely managed for network services.
    • Ticket-Based System: After initial authentication, the user receives a Ticket Granting Ticket (TGT). This ticket enables the user to request service tickets for specific resources without the need to repeatedly transmit user credentials across the network.
    • Centralized Authentication: This system relies on a trusted central authority, known as the Key Distribution Center (KDC), which manages user identities, issues authentication tickets, and distributes session keys.
    • Time Synchronization: It is essential for client and server system clocks to be synchronized within an acceptable tolerance (usually a maximum difference of 5 minutes) to prevent replay attacks that exploit old timestamps.
    • Pre-authentication: Clients must provide cryptographic proof of their identity—such as a timestamp encrypted with their password hash—before the KDC issues a TGT. This step mitigates the risk of offline password-guessing dictionary attacks.
    • Mutual Authentication: This process allows both the client and the target server to verify each other’s identities, ensuring that the client is communicating with a legitimate service and not an imposter.

    Kerberos Components

    • Key Distribution Center (KDC): The central trust authority consisting of two logical sub-services:
      • Authentication Server (AS): Validates initial user credentials and issues Ticket Granting Tickets (TGTs).
      • Ticket Granting Service (TGS): Issues service tickets to clients presenting a valid TGT.
    • Client: The principal (user, workstation, or application) requesting access to a network service.
    • Server: The resource provider hosting the target service (e.g., file server, database, web application).
    • Ticket Granting Ticket (TGT): Issued by the AS after successful initial authentication. The KDC encrypts it with its internal master key for the TGS (historically known as the krbtgt account key). It proves the user’s authenticated identity to the TGS.
    • Service Ticket: Issued by the TGS and encrypted using the unique secret key shared exclusively between the KDC and the target service server. Presented by the client to access that specific service.
    • Session Key: Temporary cryptographic key used for secure communication

    Kerberos Workflow

    • Client Authentication (AS-REQ / AS-REP):
      • The client sends an initial authentication request to the Authentication Server (AS) containing its username (principal name) and pre-authentication data.
      • If valid, the AS responds with a TGT (encrypted with the TGS master key) and a client-TGS session key, with this response payload encrypted using a key derived from the user’s password.
    • Service Request (TGS-REQ):
      • When the client wants to access a service, it sends the TGT to the Ticket Granting Service (TGS) along with the target service’s principal name and an authenticator (a timestamp encrypted with the client-TGS session key to prove freshness).
    • Service Ticket Issuance (TGS-REP):
      • The TGS decrypts and validates the TGT and the authenticator.
      • If valid and the user is authorized, the TGS issues a Service Ticket (encrypted using the target service’s secret key) along with a new client-service session key.
    • Service Access & Mutual Authentication (AP-REQ / AP-REP):
      • The client presents the Service Ticket and a fresh authenticator to the destination application server.
      • The server decrypts the ticket using its own secret key, validates the authenticator, and grants access based on its access control policies.
      • Optionally, the server returns a reply to complete mutual authentication, proving to the client that it is the legitimate service.

    Real-world examples

    When an employee logs into a Windows domain computer, Active Directory authenticates the user and issues a Ticket Granting Ticket (TGT). Once the employee has the TGT, their computer can automatically use it to request a Service Ticket whenever they access network resources, such as a file share. This process enables secure, password-free Single Sign-On (SSO).

    1. Initial Login: The employee enters their username and password on their workstation.
    2. Authentication: Active Directory, acting as the Key Distribution Center (KDC), validates the credentials.
    3. TGT Issuance: The employee’s computer receives a Ticket Granting Ticket (TGT), which establishes a secure session.
    4. Resource Request: The employee tries to open a shared network folder hosted on a file server.
    5. Ticket Request: Behind the scenes, the computer uses the TGT to request a Service Ticket for the file server from the domain controller.
    6. Authorization: The file server decrypts and validates the ticket, granting access based on the employee’s permissions.

    John logs into his corporate workstation with his username and password, which the domain controller (Authentication Server) validates and uses to issue a Ticket Granting Ticket (TGT). When John tries to access the corporate email server, his computer presents the TGT to the Ticket Granting Service (TGS), which verifies his permissions and issues a service ticket, allowing him to access his email. Later, John attempts to access a restricted internal web server, but the TGS determines that he is not authorized to access that service and denies the request.

    1. Initial Login: John logs into his corporate workstation in the morning using his username (john) and password (123456).
    2. Authentication (AS): The domain controller validates John’s credentials and issues his Ticket Granting Ticket (TGT).
    3. Accessing the Email Server (Allowed):
      1. John opens his corporate email client.
      2. Behind the scenes, his computer presents his TGT to the Ticket Granting Service (TGS) and requests a service ticket for the emailserver.
      3. Because John is authorized for the email server, the TGS issues the ticket, and the email server authenticates him successfully.
    4. Accessing the Web Server (Denied):
      1. Later, John tries to access a restricted internal webserver (such as an administrative dashboard or secure portal).
      2. His computer requests a service ticket for the web server from the TGS using his TGT.
      3. The TGS checks John’s access control list, realizes he is not authorized for the web server, and denies the request ([Ticket Granting Service] Access Denied: User john is not authorized for webserver).

    import json # Used to serialize Python dictionaries into JSON and deserialize JSON back into dictionaries
    import secrets # Used to generate cryptographically secure random session keys
    import time # Used to manage ticket expiration timestamps
    from cryptography.fernet import Fernet # Provides symmetric encryption and decryption for Kerberos tickets

    class KerberosKDC:
        def __init__(self):
            self.users = {“john”: {“password”: “123456”}} # Simulated user database
            self.service_keys = {“emailserver”: Fernet.generate_key()} # Generate encryption key for the email server
            self.kdc_key = Fernet.generate_key() # Secret key used by the KDC to encrypt and decrypt TGTs

        def authenticate_user(self, username, password):
            if username not in self.users or self.users[username][“password”] != password: # Verify the user’s username and password
                print(“[Authentication Server] Invalid username or password”)
                return None
            session_key = secrets.token_hex(16) # Generate a random session key for the user
            tgt = {“username”: username, “session_key”: session_key, “expires”: time.time() + 3600} # Create a TGT containing user information, session key, and expiration time
            encrypted_tgt = self.encrypt_ticket(tgt, self.kdc_key) # Encrypt the TGT using the KDC secret key
            print(f”[Authentication Server] Issued TGT for {username}”)
            return encrypted_tgt # Return the encrypted TGT to the client

        def request_service_ticket(self, tgt, service):
            if tgt is None: # Check whether a TGT was provided
                return None
            tgt_data = self.decrypt_ticket(tgt, self.kdc_key) # Decrypt the TGT using the KDC secret key
            if tgt_data[“expires”] < time.time(): # Check whether the TGT has expired
                print(“[Ticket Granting Service] Ticket Granting Ticket (TGT) expired”)
                return None
            if service not in self.service_keys: # Verify that the requested service exists
                print(“[Ticket Granting Service] Service not found”)
                return None
            service_session_key = secrets.token_hex(16) # Generate a session key for communication with the requested service
            ticket = {“username”: tgt_data[“username”], “service”: service, “session_key”: service_session_key, “expires”: time.time() + 3600} # Create a service ticket with user information, session key, and expiration time
            encrypted_ticket = self.encrypt_ticket(ticket, self.service_keys[service]) # Encrypt the service ticket using the requested service’s secret key)
            print(f”[Ticket Granting Service] Issued service ticket for {service}”)
            return encrypted_ticket # Return the encrypted service ticket to the client

        def encrypt_ticket(self, data, key):
            cipher = Fernet(key) # Initialize Fernet encryption using the provided key
            serialized = json.dumps(data).encode(“utf-8”) # Convert the ticket dictionary into JSON and encode it as bytes
            return cipher.encrypt(serialized) # Encrypt the ticket and return the encrypted data

        def decrypt_ticket(self, ticket, key):
            cipher = Fernet(key) # Initialize Fernet decryption using the provided key
            decrypted = cipher.decrypt(ticket) # Decrypt the encrypted ticket
            return json.loads(decrypted.decode(“utf-8”)) # Decode the data and convert the JSON back into a Python dictionary

    class ServiceServer:
        def __init__(self, key):
            self.key = key # Store the secret key assigned to this service

        def authenticate(self, ticket):
            if ticket is None: # Check whether a service ticket was provided
                return False
            cipher = Fernet(self.key) # Initialize Fernet using the service’s secret key
            data = cipher.decrypt(ticket) # Decrypt the service ticket
            ticket_data = json.loads(data.decode(“utf-8”)) # Convert the decrypted JSON data into a Python dictionary
            if ticket_data[“expires”] < time.time(): # Verify that the service ticket has not expired
                print(“Service ticket expired”)
                return False
            print(f”Authenticated user: {ticket_data[‘username’]} for {ticket_data[‘service’]}”) # Display the authenticated username and requested service
            return True

    kdc = KerberosKDC() # Initialize the Key Distribution Center (KDC)
    print(“Accessing emailserver..”)
    tgt_john = kdc.authenticate_user(“john”, “123456”) # Authenticate John and obtain a Ticket Granting Ticket (TGT)
    ticket_john = kdc.request_service_ticket(tgt_john, “emailserver”) # Use the TGT to request a service ticket for the email server
    if ticket_john:
        email_server = ServiceServer(kdc.service_keys[“emailserver”]) # Initialize the email server with its secret key
        email_server.authenticate(ticket_john) # Validate the service ticket and authenticate John

    import json
    import secrets
    import time
    from cryptography.fernet import Fernet
    
    class KerberosKDC:
        def __init__(self):
            self.users = {"john": {"password": "123456"}}
            self.service_keys = {"emailserver": Fernet.generate_key()}
            self.kdc_key = Fernet.generate_key()
    
        def authenticate_user(self, username, password):
            if username not in self.users or self.users[username]["password"] != password:
                print("[Authentication Server] Invalid username or password")
                return None
            session_key = secrets.token_hex(16)
            tgt = {"username": username, "session_key": session_key, "expires": time.time() + 3600}
            encrypted_tgt = self.encrypt_ticket(tgt, self.kdc_key)
            print(f"[Authentication Server] Issued TGT for {username}")
            return encrypted_tgt
    
        def request_service_ticket(self, tgt, service):
            if tgt is None:
                return None
            tgt_data = self.decrypt_ticket(tgt, self.kdc_key)
            if tgt_data["expires"] < time.time():
                print("[Ticket Granting Service] Ticket Granting Ticket (TGT) expired")
                return None
            if service not in self.service_keys:
                print("[Ticket Granting Service] Service not found")
                return None
            service_session_key = secrets.token_hex(16)
            ticket = {"username": tgt_data["username"], "service": service, "session_key": service_session_key, "expires": time.time() + 3600}
            encrypted_ticket = self.encrypt_ticket(ticket, self.service_keys[service])
            print(f"[Ticket Granting Service] Issued service ticket for {service}")
            return encrypted_ticket
    
        def encrypt_ticket(self, data, key):
            cipher = Fernet(key)
            serialized = json.dumps(data).encode("utf-8")
            return cipher.encrypt(serialized)
    
        def decrypt_ticket(self, ticket, key):
            cipher = Fernet(key)
            decrypted = cipher.decrypt(ticket)
            return json.loads(decrypted.decode("utf-8"))
    
    class ServiceServer:
        def __init__(self, key):
            self.key = key
    
        def authenticate(self, ticket):
            if ticket is None:
                return False
            cipher = Fernet(self.key)
            data = cipher.decrypt(ticket)
            ticket_data = json.loads(data.decode("utf-8"))
            if ticket_data["expires"] < time.time():
                print("Service ticket expired")
                return False
            print(f"Authenticated user: {ticket_data['username']} for {ticket_data['service']}")
            return True
    
    kdc = KerberosKDC()
    print("Accessing emailserver..")
    tgt_john = kdc.authenticate_user("john", "123456")
    ticket_john = kdc.request_service_ticket(tgt_john, "emailserver")
    if ticket_john:
        email_server = ServiceServer(kdc.service_keys["emailserver"])
        email_server.authenticate(ticket_john)
  • Identification, Authentication, Authorization, and Accountability


    Identification

    Identification is the process of claiming or declaring an identity, where a person, system, or object presents information that indicates who or what they are. It is the first step in identity verification, often involving credentials such as a username, ID number, card, or biometric data that represent the claimed identity. Identification by itself does not prove authenticity; instead, it signals the intent of the entity to be recognized, which is later confirmed through authentication mechanisms. This process is essential in security systems, as it establishes the basis for determining access rights and privileges.

    • Username
    • SSN

    Example

    id # command that shows user identity information (UID, GID, groups)

    id

    whoami # command that prints the current logged-in username

    whoami

    Authentication

    Authentication is the process of verifying that a claimed identity is valid by confirming that the person, system, or object truly is who or what they assert to be. It typically follows identification and uses various methods such as passwords, PINs, security tokens, smart cards, or biometrics like fingerprints and facial recognition. Authentication can be implemented through single-factor, two-factor, or multi-factor approaches, depending on the required security level. By validating the authenticity of an identity before granting access, authentication helps prevent unauthorized use, strengthens trust, and protects sensitive systems and data.

    Authentication factors

    • Something you know
      • Password
        • A sequence of characters that identifies a user
      • Personal Identification Number (PIN)
        • A sequence of numbers that identifies a user
    • Something you have
      • Passport
        • A travel document issued by a government that verifies their identity and international travel
      • Smartphone
        • A cellular telephone with an integrated computer 
      • Smart Card
        • A physical plastic card with an embedded microprocessor that stores and processes data (It acts as a security token)
      • Token
        • A device that’s used to gain access to restricted resource (Might include name, password, key, certificate, group, privilege)
    • Something you are
      • Fingerprint
        • A unique pattern made by a person’s fingertip friction ridges
      • Facial recognition
        • A technology that identifies a user based on their faces
      • Iris Scan
        • A technology that identifies a user based on their iris
    • Somewhere you are
      • IP address
        • A logical network address that is used to locate the device
      • MAC Address
        • A physical network address that is used to locate the device
    • Something you do
      • Pattern unlock
        • A technology that identifies a user based on drawing a specific pattern 
      • Picture Password
        • A technology that identifies a user based on selection of images

    Example

    passwd # command used to set or change a user’s password in Linux

    passwd

    Authorization

    Authorization is the process of determining what actions, resources, or services a person, system, or object is permitted to access after their identity has been successfully verified through authentication. It defines the level of access granted, such as whether a user can read, modify, delete, or execute specific files, applications, or functions. Authorization is typically enforced through policies, access control lists, or role-based access control (RBAC), ensuring that users only perform actions aligned with their roles and responsibilities. This step is critical for enforcing the principle of least privilege, reducing security risks, and protecting sensitive information from misuse or unauthorized access.

    • Access Control
      • A security technique to protect a system against unauthorized access

    Example

    echo # command that prints text to the terminal or output stream
    “example” # the text string being displayed 
    > # output redirection operator 
    file # the file where the output will be written (created or overwritten)

    echo "QeeqBox" > file

    sudo # run the command with administrative (root) privileges
    groupadd # command used to create a new group in Linux
    sales # name of the group being created

    sudo groupadd sales

    chown # command to change ownership of a file
    john # user who will become the new owner
    file.txt # file whose ownership is being changed

    chown john file.txt

    chgrp # command to change group ownership of a file
    sales # group that will become the new group owner
    file.txt # file whose group is being changed

    chgrp sales file.txt

    Accountability (Auditing)

    Accountability (Auditing) is the ability to trace actions, events, or system changes back to a specific individual, system, or object, ensuring that every activity within an environment can be attributed to its source. It involves maintaining detailed logs, audit trails, and monitoring mechanisms that record who did what, when, and how. Accountability helps detect misuse, supports investigations, enforces compliance with policies and regulations, and promotes responsible behavior by making users aware that their actions are being tracked. By providing transparency and traceability, auditing strengthens overall security and trust within an organization’s systems.

    • Audit logs

    Example

    who # shows currently logged-in users on the system

    who

    last # shows history of user logins and system reboots

    last

    sudo # runs the command with root (admin) privileges
    cat # command used to display file contents
    /var/log/auth.log # system authentication log file (login, sudo, SSH events)

    sudo cat /var/log/auth.log

    Identity Management (IdM)

    Identity Management (IdM) is the process of managing and controlling digital identities within an organization or system. It involves creating, maintaining, and governing user accounts, as well as assigning appropriate access rights and permissions based on roles or responsibilities. IdM ensures that only authorized individuals can access specific resources, applications, or data, while also maintaining compliance and security. This process includes activities such as authentication, authorization, password management, and account lifecycle management, helping to protect sensitive information and streamline user access.

    Example

    sudo # run command with admin (root) privileges
    useradd # command to create a new user account
    john # username being created

    sudo useradd john

    sudo # run command with admin (root) privileges
    passwd # command to set/change a user password
    john # username whose password is being set

    sudo passwd john

    Access Management (AM)

    Access Management (AM) is the process of ensuring that people, systems, or objects have the appropriate level of access to resources, applications, and data based on their roles and responsibilities. It deals specifically with permissions and privileges, determining what a user or entity can do once authenticated. AM enforces policies such as granting, restricting, or revoking access, often using methods like role-based access control (RBAC), attribute-based access control (ABAC), or least privilege principles. By managing access effectively, organizations can reduce the risk of unauthorized activities, protect sensitive assets, and maintain compliance with security and regulatory requirements.

    Example

    echo # command that prints text to the terminal or output stream
    “example” # the text string being displayed 
    > # output redirection operator 
    file # the file where the output will be written (created or overwritten)

    echo "QeeqBox" > file

    sudo # run the command with administrative (root) privileges
    groupadd # command used to create a new group in Linux
    sales # name of the group being created

    sudo groupadd sales

    chown # command to change ownership of a file
    john # user who will become the new owner
    file.txt # file whose ownership is being changed

    chown john file.txt

    chgrp # command to change group ownership of a file
    sales # group that will become the new group owner
    file.txt # file whose group is being changed

    chgrp sales file.txt

    Identity and Access Management (IAM)

    Identity and Access Management (IAM) is the integrated framework of policies, processes, and technologies used to manage and control digital identities while ensuring that users, systems, or objects have the appropriate level of access to organizational resources. It combines Identity Management (IdM), which focuses on creating and maintaining digital identities, with Access Management (AM), which governs permissions and privileges. IAM solutions handle authentication, authorization, and account lifecycle management, enforcing security principles like least privilege and separation of duties. By implementing IAM, organizations can safeguard sensitive data, streamline user access, improve operational efficiency, and ensure compliance with industry regulations.