Copilot commented on code in PR #10967:
URL: https://github.com/apache/gravitino/pull/10967#discussion_r3193854383
##########
server-common/src/main/java/org/apache/gravitino/server/authentication/AuthenticatorFactory.java:
##########
@@ -37,6 +37,8 @@ public class AuthenticatorFactory {
ImmutableMap.of(
AuthenticatorType.SIMPLE.name().toLowerCase(),
SimpleAuthenticator.class.getCanonicalName(),
+ AuthenticatorType.BASIC.name().toLowerCase(),
+ BasicAuthenticator.class.getCanonicalName(),
Review Comment:
The new `basic` entry in `AUTHENTICATORS` is not covered by a unit test.
Please add a test that configures `gravitino.authenticators=basic` and asserts
`AuthenticatorFactory.createAuthenticators(...)` returns a `BasicAuthenticator`
instance (and consider covering ordering behavior when multiple authenticators
are configured).
##########
server-common/src/main/java/org/apache/gravitino/server/authentication/BasicAuthenticator.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.server.authentication;
+
+import java.nio.charset.StandardCharsets;
+import java.security.Principal;
+import java.util.Base64;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.UserPrincipal;
+import org.apache.gravitino.auth.AuthConstants;
+import org.apache.gravitino.exceptions.BadRequestException;
+import org.apache.gravitino.exceptions.UnauthorizedException;
+
+/**
+ * Basic authenticator wiring for the local authentication module.
+ *
+ * <p>The credential verification flow will be implemented in follow-up
subtasks. For now, keep the
+ * current Basic header parsing behavior so the module can be loaded safely
when {@code
+ * gravitino.authenticators=basic}.
+ */
+public class BasicAuthenticator implements Authenticator {
+ private static final String BASIC_AUTH_CHALLENGE = "Basic";
+
+ @Override
+ public boolean isDataFromToken() {
+ return true;
+ }
+
+ @Override
+ public Principal authenticateToken(byte[] tokenData) {
+ if (tokenData == null) {
+ throw new UnauthorizedException("Empty token authorization header",
BASIC_AUTH_CHALLENGE);
+ }
+
+ String authData = new String(tokenData, StandardCharsets.UTF_8);
+ if (authData.trim().isEmpty()) {
+ throw new UnauthorizedException("Empty token authorization header",
BASIC_AUTH_CHALLENGE);
+ }
+
+ if (!authData.startsWith(AuthConstants.AUTHORIZATION_BASIC_HEADER)) {
+ throw new UnauthorizedException("Invalid token authorization header",
BASIC_AUTH_CHALLENGE);
+ }
+
+ String credential =
authData.substring(AuthConstants.AUTHORIZATION_BASIC_HEADER.length());
+ if (credential.trim().isEmpty()) {
+ throw new BadRequestException("Malformed Basic authorization header:
missing credentials");
+ }
+
+ try {
+ String decodedCredential =
+ new String(Base64.getDecoder().decode(credential),
StandardCharsets.UTF_8);
+ int separatorIndex = decodedCredential.indexOf(':');
+ if (separatorIndex < 0) {
+ throw new BadRequestException(
+ "Malformed Basic authorization header: credentials must be in
username:password format");
+ }
+
+ String userName = decodedCredential.substring(0, separatorIndex);
+ if (userName.isEmpty()) {
+ throw new BadRequestException(
+ "Malformed Basic authorization header: username must not be
empty");
+ }
+
+ return new UserPrincipal(userName, authData);
Review Comment:
`BasicAuthenticator` currently accepts any non-empty `username:password`
Basic credential and immediately returns a `UserPrincipal` without validating
the password. With `gravitino.authenticators=basic`, this allows arbitrary user
impersonation (effectively no authentication). Please either implement
credential verification before returning a principal, or fail closed (e.g.,
always return 401/throw) until verification is implemented.
##########
common/src/main/java/org/apache/gravitino/auth/AuthenticatorType.java:
##########
@@ -27,6 +27,9 @@ public enum AuthenticatorType {
/** Simple authentication. */
SIMPLE,
+ /** Authentication that uses local basic auth. */
+ BASIC,
+
/** Authentication that uses OAuth. */
OAUTH,
Review Comment:
End-user authentication documentation still lists `simple`, `oauth`, and
`kerberos` as the supported values for `gravitino.authenticators`. Since this
PR introduces `basic`, please update the relevant docs (for example
`docs/security/how-to-authenticate.md` and Web UI authentication docs) to
include `basic` and its expected behavior/status codes.
--
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]