924060929 commented on code in PR #71078:
URL: https://github.com/apache/doris/pull/71078#discussion_r4748746722


##########
fe/fe-core/src/main/java/org/apache/doris/authentication/AuthenticationIntegrationRuntime.java:
##########
@@ -198,6 +204,9 @@ public AuthenticationOutcome 
authenticate(List<AuthenticationIntegrationMeta> ch
             if (!plugin.supports(request)) {
                 continue;
             }
+            if (!secureTransport && 
AuthenticationTransportPolicy.requiresSecureTransport(integration.getType())) {
+                throw new SecureTransportRequiredException();

Review Comment:
   [P1] Throwing `SecureTransportRequiredException` immediately aborts the 
`authentication_chain` loop. In a mixed chain like `corp_iam,corp_ldap` over 
plaintext (including current Flight SQL), if `corp_iam` returns 
`supports(request) == true` for `CLEAR_TEXT_PASSWORD`, `corp_ldap` is never 
tried — even though `corp_ldap,corp_iam` works and 
`requiresTlsForClearPasswordExchange()` intentionally allows mixed chains. 
Record the TLS failure and continue trying subsequent integrations, and only 
raise `SecureTransportRequiredException` if no later integration succeeds. 
Please also add a unit test for the `iam,ldap` ordering.



##########
fe/fe-core/src/main/java/org/apache/doris/mysql/authenticate/AuthenticatorManager.java:
##########
@@ -192,76 +194,145 @@ public boolean authenticate(ConnectContext context,
         }
         UserIdentity preferredUserIdentity = certDecision.isVerified() ? 
certDecision.getUserIdentity() : null;
 
+        LoginCredentials credentials = new 
LoginCredentials(channel.isSslMode(),
+                authenticator -> resolveAuthenticateRequest(authenticator, 
userName, context, channel, serializer,
+                        authPacket, handshakePacket),
+                (authenticator, primary) -> 
resolveAuthenticationChainRequest(authenticator, primary, context,
+                        userName, channel, serializer, authPacket, 
handshakePacket));
+        LoginResult result = authenticate(userName, remoteIp, 
preferredUserIdentity, credentials);
+        if (result.status() == LoginStatus.NO_REQUEST) {
+            return false;
+        }
+        if (result.status() == LoginStatus.AUTHENTICATOR_TLS_REQUIRED) {
+            
context.getState().setError(ErrorCode.ERR_SECURE_TRANSPORT_REQUIRED,
+                    AuthenticationTransportPolicy.SECURE_TRANSPORT_REQUIRED);
+            MysqlProto.sendResponsePacket(context);
+            return false;
+        }
+        if (result.status() == LoginStatus.TOKEN_TLS_REQUIRED) {
+            setInsecureOidcTransportError(context);
+        }
+        if (result.response() != null) {
+            return finishSuccessfulAuthentication(context, result.remoteIp(), 
result.response(),
+                    result.status() == LoginStatus.CHAIN_SUCCESS);
+        }
+        return reportAuthenticationFailure(context, userName, 
result.remoteIp(), result.password(), result.failures());
+    }
+
+    /**
+     * Authenticate a credential delivered by a single-step protocol. The 
secure transport flag
+     * describes the actual connection, and is supplied by the server's 
protocol adapter.
+     */
+    public AuthenticateResponse authenticate(AuthenticateRequest request, 
boolean secureTransport) throws IOException {
+        LoginCredentials credentials = new LoginCredentials(secureTransport,
+                authenticator -> singleStepRequest(authenticator, request), 
this::singleStepRequest);
+        LoginResult result = authenticate(request.getUserName(), 
request.getRemoteIp(), null, credentials);
+        if (result.status() == LoginStatus.AUTHENTICATOR_TLS_REQUIRED
+                || result.status() == LoginStatus.TOKEN_TLS_REQUIRED) {
+            return 
AuthenticateResponse.failed(AuthenticationFailureSummary.secureTransportRequired());
+        }
+        if (result.status() == LoginStatus.NO_REQUEST) {
+            return 
AuthenticateResponse.failed(AuthenticationFailureSummary.forClientVisibleFailure(
+                    AuthenticationFailureType.ACCESS_DENIED, "Authentication 
method is unavailable on this protocol",
+                    "Authentication method is unavailable on this protocol"));
+        }
+        AuthenticateResponse response = result.response();
+        if (response == null) {

Review Comment:
   [P2] Unlike the MySQL path (`reportAuthenticationFailure`), 
`authenticate(AuthenticateRequest, boolean)` never calls 
`logAuthenticationFailureSummary(...)` when `response == null`, nor logs 
rejections from `validateSuccessfulAuthentication` (`ACCOUNT_LOCK` / binding 
mismatch) or `requiresCertificateAuth`. Since 
`OPERATIONAL_AUTHENTICATION_FAILURE_MESSAGE` instructs users to check FE logs, 
Flight failures should log the failure summary / rejection reason as well.



##########
fe/fe-core/src/main/java/org/apache/doris/mysql/authenticate/DefaultAuthenticator.java:
##########
@@ -47,19 +49,16 @@ public AuthenticateResponse 
authenticate(AuthenticateRequest request) throws IOE
             LOG.debug("user:{} start to default authenticate.", 
request.getUserName());
         }
         Password password = request.getPassword();
-        if (!(password instanceof NativePassword)) {
-            return AuthenticateResponse.failedResponse;
-        }
-        NativePassword nativePassword = (NativePassword) password;
-
         List<UserIdentity> currentUserIdentity = Lists.newArrayList();
         try {
-            if (request.getUserIdentity() != null) {
-                
Env.getCurrentEnv().getAuth().checkPasswordForUserIdentity(request.getUserIdentity(),
-                        nativePassword.getRemotePasswd(), 
nativePassword.getRandomString(), currentUserIdentity);
+            if 
(CredentialType.CLEAR_TEXT_PASSWORD.equals(request.getCredentialType())
+                    && password instanceof ClearPassword) {
+                
Env.getCurrentEnv().getAuth().checkLocalPlainPassword(request.getUserName(), 
request.getRemoteIp(),

Review Comment:
   [P2] Unlike `checkNativePassword`, the `CLEAR_TEXT_PASSWORD` branch ignores 
`request.getUserIdentity()`. Routing `request.getUserIdentity() != null` to 
`Auth.checkPlainPasswordForUserIdentity(...)` keeps both branches symmetric and 
avoids a subtle bug once Flight TLS / certificate-assisted auth is introduced.



##########
fe/fe-core/src/main/java/org/apache/doris/mysql/authenticate/AuthenticatorManager.java:
##########
@@ -192,76 +194,145 @@ public boolean authenticate(ConnectContext context,
         }
         UserIdentity preferredUserIdentity = certDecision.isVerified() ? 
certDecision.getUserIdentity() : null;
 
+        LoginCredentials credentials = new 
LoginCredentials(channel.isSslMode(),
+                authenticator -> resolveAuthenticateRequest(authenticator, 
userName, context, channel, serializer,
+                        authPacket, handshakePacket),
+                (authenticator, primary) -> 
resolveAuthenticationChainRequest(authenticator, primary, context,
+                        userName, channel, serializer, authPacket, 
handshakePacket));
+        LoginResult result = authenticate(userName, remoteIp, 
preferredUserIdentity, credentials);
+        if (result.status() == LoginStatus.NO_REQUEST) {
+            return false;
+        }
+        if (result.status() == LoginStatus.AUTHENTICATOR_TLS_REQUIRED) {
+            
context.getState().setError(ErrorCode.ERR_SECURE_TRANSPORT_REQUIRED,
+                    AuthenticationTransportPolicy.SECURE_TRANSPORT_REQUIRED);
+            MysqlProto.sendResponsePacket(context);
+            return false;
+        }
+        if (result.status() == LoginStatus.TOKEN_TLS_REQUIRED) {
+            setInsecureOidcTransportError(context);
+        }
+        if (result.response() != null) {
+            return finishSuccessfulAuthentication(context, result.remoteIp(), 
result.response(),
+                    result.status() == LoginStatus.CHAIN_SUCCESS);
+        }
+        return reportAuthenticationFailure(context, userName, 
result.remoteIp(), result.password(), result.failures());

Review Comment:
   [P2] On the MySQL path, a `SecureTransportRequiredException` from 
`authentication_chain` is wrapped in 
`AuthenticationFailureSummary.secureTransportRequired()` and falls through to 
`ensureAuthenticationErrorReported`, returning `ERR_UNKNOWN_ERROR (1105)` 
instead of `ERR_SECURE_TRANSPORT_REQUIRED (3159)`. Consider mapping 
TLS-required failures consistently to `ERR_SECURE_TRANSPORT_REQUIRED`.



##########
fe/fe-core/src/main/java/org/apache/doris/authentication/AuthenticationTransportPolicy.java:
##########
@@ -14,30 +14,23 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-// This file is copied from
 
-package org.apache.doris.arrowflight.auth2;
+package org.apache.doris.authentication;
 
-import org.apache.doris.analysis.UserIdentity;
+/** Transport requirements of authentication integration types that handle 
bearer credentials. */
+public final class AuthenticationTransportPolicy {
+    public static final String SECURE_TRANSPORT_REQUIRED = "Authentication 
requires secure transport";
 
-import org.immutables.value.Value;
-
-/**
- * Result of Authentication.
- */
[email protected]
-public interface FlightAuthResult {
-    String getUserName();
-
-    UserIdentity getUserIdentity();
+    private AuthenticationTransportPolicy() {
+    }
 
-    String getRemoteIp();
+    public static boolean requiresSecureTransport(String integrationType) {

Review Comment:
   [P2] Hardcoding `"oidc"` and `"aws_iam"` in `fe-core` means future 
token-based plugins (e.g. `saml2` or custom plugins) will bypass this check 
unless `fe-core` is updated. Ideally this should live on the 
`AuthenticationPlugin` SPI (e.g. `default boolean requiresSecureTransport() { 
return false; }`, symmetric with `requiresClearPassword()`). If kept here to 
avoid changing the SPI surface in this PR, please add a brief note/TODO.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to