You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "bharos (via GitHub)" <gi...@apache.org> on 2026/01/21 07:42:54 UTC

[I] [Improvement] Allow regex pattern to filter the Gravitino OAuth principal [gravitino]

bharos opened a new issue, #9767:
URL: https://github.com/apache/gravitino/issues/9767

   ### What would you like to be improved?
   
   The principal from OAuth token (for example from Azure AD) contains the email like
   username@company.com
   and there might not be other fields that map to the username (without @company). It will be useful in general to support patterns to extract username from principal string.
   
   ### How should we improve?
   
   We can add a parameter similar to what Trino server has:
   https://trino.io/docs/current/security/oauth2.html#trino-server-configuration
   `http-server.authentication.oauth2.user-mapping.pattern`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Allow regex pattern to filter the Gravitino OAuth principal [gravitino]

Posted by "bharos (via GitHub)" <gi...@apache.org>.
bharos commented on issue #9767:
URL: https://github.com/apache/gravitino/issues/9767#issuecomment-3787582692

   @jerqi @yangyuxia Thanks for the feedback! After reviewing the discussion and existing code, I'd like to propose keeping this PR **focused on OAuth only**. Here's my reasoning:
   
   **For this PR (OAuth user mapping):**
   - OAuth currently has no user mapping - adding pattern with default `^(.*)$` is non-breaking ✅
   - Solves the immediate issue (Azure AD email → username extraction)
   
   **For Kerberos (future PR/issue):**
   - Current behavior: `user/instance@REALM` → returns `user/instance`
   - Adding a default pattern would change this behavior (potential breaking change)
   - Should have its own config: `gravitino.authenticator.kerberos.userMappingPattern`
   - Regex pattern would work alongside KerberosPrincipal (pattern for display name, KerberosPrincipal for delegation tokens)
   - Needs proper discussion on defaults and backward compatibility
   
   **Recommendation:** Keep this PR OAuth-only and file a separate issue for Kerberos user mapping with KerberosPrincipal enhancement. This addresses the immediate OAuth use case while allowing proper consideration for Kerberos requirements.
   
   Does this approach work?
   
   Unless you think we should have the same config work for both OAuth and Kerberos?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Allow regex pattern to filter the Gravitino OAuth principal [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on issue #9767:
URL: https://github.com/apache/gravitino/issues/9767#issuecomment-3782999004

   Is it better that we can extract more information from Kerberos string. so I prefer
   ```
   Principal map(String principal)
   ```
   We can create a `KerberosPrincipal` to store some important information
   For example
   ```
   class KerberosPrincipal {
   String username;
   Option<String> hostname;
   Option<String> realm;
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Allow regex pattern to filter the Gravitino OAuth principal [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on issue #9767:
URL: https://github.com/apache/gravitino/issues/9767#issuecomment-3776681651

   > I'll create a PR in a day or two for this. cc [@jerqi](https://github.com/jerqi)
   
   Maybe we can have a common abstraction. There are similar issues about Kerberos Authenticator. You can see https://github.com/apache/gravitino/pull/9112#event-22180205653 
   
   Is it better that we can have a more common abstraction. All the authencators can reuse similar logic.
   Regrex expression may be not easy to maintain. Is it better that we can define some interfaces. But I am not sure whether regrex expression will be better or not. This is a point which I want to discuss with u.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Allow regex pattern to filter the Gravitino OAuth principal [gravitino]

Posted by "bharos (via GitHub)" <gi...@apache.org>.
bharos commented on issue #9767:
URL: https://github.com/apache/gravitino/issues/9767#issuecomment-3776619941

   I'll create a PR in a day or two for this.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Allow regex pattern to filter the Gravitino OAuth principal [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on issue #9767:
URL: https://github.com/apache/gravitino/issues/9767#issuecomment-3782339371

   @yangyuxia Do u have any suggestion?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Allow regex pattern to filter the Gravitino OAuth principal [gravitino]

Posted by "yangyuxia (via GitHub)" <gi...@apache.org>.
yangyuxia commented on issue #9767:
URL: https://github.com/apache/gravitino/issues/9767#issuecomment-3782965933

   > [@yangyuxia](https://github.com/yangyuxia) Do u have any suggestion?
   
   I think regular expressions are enough. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Allow regex pattern to filter the Gravitino OAuth principal [gravitino]

Posted by "bharos (via GitHub)" <gi...@apache.org>.
bharos commented on issue #9767:
URL: https://github.com/apache/gravitino/issues/9767#issuecomment-3780358289

   To address the need for a common user mapping abstraction (for OAuth/JWT, Kerberos, and potentially other authentication methods), we could use the following design:
   
   1. UserMapping Interface
   ```
   /**
    * Interface for mapping principals to usernames.
    * Different authentication providers can use different mapping strategies.
    */
   public interface UserMapping {
       /**
        * Maps a principal to a username.
        * @param principal the principal to map
        * @return the mapped username, or the original principal if no mapping applies
        */
       String map(String principal);
   }
   ```
   
   . Implementations
   RegexUserMapping - Flexible pattern-based mapping (works for OAuth, Kerberos, email, etc.):
   
   ```
   public class RegexUserMapping implements UserMapping {
       private final Pattern pattern;
       
       public RegexUserMapping(String patternStr) {
           this.pattern = Pattern.compile(patternStr);
       }
       
       @Override
       public String map(String principal) {
           if (principal == null) return null;
           Matcher matcher = pattern.matcher(principal);
           if (matcher.find() && matcher.groupCount() >= 1) {
               String extracted = matcher.group(1);
               return (extracted != null && !extracted.isEmpty()) ? extracted : principal;
           }
           return principal;
       }
   }
   ```
   
   KerberosUserMapping - Dedicated parser for Kerberos principals:
   ```
   public class KerberosUserMapping implements UserMapping {
       @Override
       public String map(String principal) {
           if (principal == null) return null;
           // Kerberos principal format: user[/instance][@REALM]
           // Extract user before '/' or '@'
           int slash = principal.indexOf('/');
           int at = principal.indexOf('@');
           int end = (slash >= 0) ? slash : (at >= 0 ? at : principal.length());
           return principal.substring(0, end);
       }
   }
   ```
   
   Config will then look like
   ```
    For regex-based mapping (default, works for most cases)
   gravitino.authenticator.oauth.user-mapping.type=regex
   gravitino.authenticator.oauth.user-mapping.pattern=([^/@]+).*
   
   # For Kerberos-specific mapping (if desired)
   gravitino.authenticator.kerberos.user-mapping.type=kerberos
   ```
   
   
   Questions:
   - Is this abstraction preferred, or is it over-engineering for our current needs?
   - I feel regex mapping is usually sufficient for Kerberos, do we really need a dedicated parser? (Regex like ([^/@]+).* works for most Kerberos cases)
   
   Wondering if we should keep it simple with just regex for now, or implement the interface-based approach for future extensibility?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Allow regex pattern to filter the Gravitino OAuth principal [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on issue #9767:
URL: https://github.com/apache/gravitino/issues/9767#issuecomment-3787826601

   > [@jerqi](https://github.com/jerqi) [@yangyuxia](https://github.com/yangyuxia) Thanks for the feedback! After reviewing the discussion and existing code, I'd like to propose keeping this PR **focused on OAuth only**. Here's my reasoning:
   > 
   > **For this PR (OAuth user mapping):**
   > 
   > * OAuth currently has no user mapping - adding pattern with default `^(.*)$` is non-breaking
   > * Solves the immediate issue (Azure AD email → username extraction)
   > 
   > **For Kerberos (future PR/issue):**
   > 
   > * Current behavior: `user/instance@REALM` → returns `user/instance`
   > * Adding a default pattern would change this behavior (potential breaking change)
   > * Should have its own config: `gravitino.authenticator.kerberos.userMappingPattern`
   > * Regex pattern would work alongside KerberosPrincipal (pattern for display name, KerberosPrincipal for delegation tokens)
   > * Needs proper discussion on defaults and backward compatibility
   > 
   > **Recommendation:** Keep this PR OAuth-only and file a separate issue for Kerberos user mapping with KerberosPrincipal enhancement. This addresses the immediate OAuth use case while allowing proper consideration for Kerberos requirements.
   > 
   > Does this approach work?
   > 
   > Unless you think we should have the same config work for both OAuth and Kerberos?
   
   The approach is ok for me. Just two points:
   1.  The OAuth authenticator and Kerberos authenticator should reuse the same `UserMapping` interface, they can implement their UserMapping class.
   2. The map method should return Principal object instead of String object.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Allow regex pattern to filter the Gravitino OAuth principal [gravitino]

Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi closed issue #9767: [Improvement] Allow regex pattern to filter the Gravitino OAuth principal
URL: https://github.com/apache/gravitino/issues/9767


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org