Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ath default OIDC #651

Merged
merged 4 commits into from
Jan 17, 2025
Merged

Ath default OIDC #651

merged 4 commits into from
Jan 17, 2025

Conversation

spointu
Copy link
Contributor

@spointu spointu commented Jan 17, 2025

Summary by Sourcery

Implement authentication through OpenID Connect (OIDC) providers.

New Features:

  • Added support for authentication using OIDC providers.

Tests:

  • Updated tests to cover new authentication methods.

- If in the authproviders.ini.local configuration file for ldap mapping no value is entered we apply default values
- If the authproviders file does not contain any configuration or if it is empty, the list of providers is not displayed
- Retrieve OIDC roles to assign ACLs based on configuration
- Manage role priority to apply top ranked ACL in profile_order of configuration file
- Fixed complete destruction of the local session following disconnection from the provider upon disconnection
Copy link

sourcery-ai bot commented Jan 17, 2025

Reviewer's Guide by Sourcery

This pull request implements authentication against an OIDC provider. It introduces changes in web/index.php and web/providers.php to handle provider selection, authentication, and sign-out. The update also includes modifications to user data mapping and session management.

Sequence diagram for OIDC Authentication Flow

sequenceDiagram
    actor User
    participant Web as Web Interface
    participant OIDC as OIDC Provider
    participant MMC as MMC Agent

    User->>Web: Click OIDC provider button
    Web->>OIDC: Redirect to provider login
    OIDC-->>User: Display login form
    User->>OIDC: Enter credentials
    OIDC->>Web: Return with auth code
    Web->>OIDC: Exchange code for tokens
    OIDC-->>Web: Return tokens and user info
    Web->>MMC: Create/Update user account
    Note over Web,MMC: Map OIDC user data to local user
    Web->>MMC: Set user ACL based on roles
    MMC-->>Web: Confirm user setup
    Web-->>User: Redirect to dashboard
Loading

Sequence diagram for OIDC Sign-out Flow

sequenceDiagram
    actor User
    participant Web as Web Interface
    participant OIDC as OIDC Provider

    User->>Web: Request sign-out
    Web->>OIDC: Sign-out request with ID token
    OIDC-->>Web: Confirm sign-out
    Web->>Web: Destroy local session
    Web-->>User: Redirect to login page with sign-out message
Loading

Class diagram for User Authentication Components

classDiagram
    class AuthenticationHandler {
        +handleProviderSelection(providersConfig)
        +handleAuthentication(providerKey, providersConfig)
        +handleSignout()
        +getAclString(userInfo, providersConfig, providerKey)
        +updateUserMail(uid, mail)
    }

    class UserManager {
        +add_user(uid, password, firstName, lastName, homeDir, createHomeDir, ownHomeDir, primaryGroup)
        +setAcl(user, aclString)
        +auth_user(username, password, persist)
        +changeUserAttributes(uid, attribute, value)
    }

    class SessionManager {
        +handleSession()
        +generateStr(length)
    }

    AuthenticationHandler --> UserManager
    AuthenticationHandler --> SessionManager
Loading

File-Level Changes

Change Details Files
Adds OIDC provider selection and authentication.
  • Added a new section in index.php to display available OIDC providers.
  • Implemented provider selection logic in providers.php to handle user choices.
  • Integrated OIDC authentication flow in providers.php to redirect users to the selected provider.
  • Added session management in providers.php to store user information after successful authentication.
  • Improved user data mapping in providers.php to handle user attributes from the OIDC provider.
  • Added a sign-out redirect URL to ensure users are redirected to the MMC web interface after logging out from the OIDC provider.
  • Added logic to update the user's email address after successful authentication.
  • Added a function to retrieve the appropriate ACL string based on the user's roles from the OIDC provider.
  • Added logic to set the user's ACL upon successful authentication or user creation.
  • Updated the authproviders.ini.in file to include configuration options for OIDC providers.
  • Added input sanitization to prevent potential security vulnerabilities.
  • Improved error handling and logging for better debugging and troubleshooting.
  • Added a logout parameter to the redirect URL in index.php to handle logout requests from the OIDC provider.
  • Added a logout message display on successful logout from the OIDC provider.
web/index.php
web/providers.php
Enhances user experience during login and logout.
  • Improved the user interface for provider selection in index.php.
  • Added a logout message in index.php to inform users about successful logout.
  • Added a logout option in index.php to allow users to explicitly sign out from the application and the OIDC provider.
web/index.php
Improves security by sanitizing user inputs.
  • Sanitized user inputs in providers.php to prevent potential security vulnerabilities such as cross-site scripting (XSS) attacks.
  • Added HTML escaping to user-provided data to prevent XSS vulnerabilities.
web/providers.php

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

mergify bot commented Jan 17, 2025

⚠️ The sha of the head commit of this PR conflicts with #650. Mergify cannot evaluate rules on this PR. ⚠️

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @spointu - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider standardizing error handling across the codebase - some places use proper error handling with redirects while others just exit(). This could improve maintainability and user experience.
  • Please add documentation for the new ACL role mapping feature, including examples of how to configure the profiles_order and acl_ mappings in the config file.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

}
}

function updateUserMail($uid, $mail)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Consider adding email format validation before updating

Adding validation here would provide an additional security layer, even if validation exists elsewhere


return $providersConfig[$providerKey]['lmcACL'] ?? '';
}

// manages the Openid Connect authentication process (Auth + Return phase)
function handleAuthentication($providerKey, $providersConfig)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider extracting user management logic into a separate function

This would improve code organization and make the authentication flow easier to understand

Suggested implementation:

// Handles user-specific management operations
function handleUserManagement()
{
    if (isset($_POST['lang'])) {
        $lang = htmlspecialchars($_POST['lang'], ENT_QUOTES, 'UTF-8');
        $_SESSION['lang'] = $_POST['lang'];
    }
}

// manages the Openid Connect authentication process (Auth + Return phase)
function handleAuthentication($providerKey, $providersConfig)
{
    // Handle the authentication process
    handleUserManagement();

Since we can only see part of the code, you'll need to:

  1. Review and move any other user-related operations from handleAuthentication into handleUserManagement
  2. Make sure any necessary variables or parameters are passed between the functions
  3. Update any references to these functions elsewhere in the codebase

@spointu spointu merged commit 3d9169e into integration Jan 17, 2025
2 of 6 checks passed
@neoclust neoclust deleted the ath-default-oidc branch January 21, 2025 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants