zhoujinsong commented on code in PR #4118: URL: https://github.com/apache/amoro/pull/4118#discussion_r2993236849
########## amoro-ams/src/main/resources/authorization/privilege_mapping.yaml: ########## @@ -0,0 +1,97 @@ +# 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. + +mappings: + - prefixes: + - /api/ams/v1/overview + methods: + - GET + resource-type: SYSTEM + privilege: VIEW_SYSTEM + + - prefixes: + - /api/ams/v1/catalogs + methods: + - GET + resource-type: CATALOG + privilege: VIEW_CATALOG + + - prefixes: + - /api/ams/v1/catalogs + methods: + - POST + - PUT + - DELETE + resource-type: CATALOG + privilege: MANAGE_CATALOG + + - prefixes: + - /api/ams/v1/tables + methods: + - GET + resource-type: TABLE + privilege: VIEW_TABLE + + - prefixes: + - /api/ams/v1/tables + methods: + - POST + - PUT + - DELETE + resource-type: TABLE + privilege: MANAGE_TABLE + + - paths: + - /api/ams/v1/upgrade/properties + methods: + - POST + - PUT + - DELETE + resource-type: TABLE + privilege: MANAGE_TABLE + + - prefixes: + - /api/ams/v1/optimize + methods: + - GET + resource-type: OPTIMIZER + privilege: VIEW_OPTIMIZER + + - prefixes: + - /api/ams/v1/optimize + methods: + - POST + - PUT + - DELETE + resource-type: OPTIMIZER + privilege: MANAGE_OPTIMIZER + + - prefixes: + - /api/ams/v1/terminal + methods: + - GET + - POST + - PUT + resource-type: TERMINAL + privilege: EXECUTE_SQL + + - prefixes: + - /api/ams/v1/files + - /api/ams/v1/settings Review Comment: **[Bug] `MANAGE_PLATFORM` mapping has no `methods` filter** The last mapping entry for `/api/ams/v1/files`, `/api/ams/v1/settings`, and `/api/ams/v1/api/token` omits the `methods` field. Per `DashboardPrivilegeMappingRule`, an empty method set means _all_ HTTP methods match. This causes GET requests to `/api/ams/v1/settings` to require `MANAGE_PLATFORM`, which is too strict — a read request should only need `VIEW_SYSTEM` or similar. Add explicit `methods` to distinguish read vs. write access. ########## amoro-ams/src/main/java/org/apache/amoro/server/authorization/RoleResolver.java: ########## @@ -0,0 +1,87 @@ +/* + * 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.amoro.server.authorization; + +import org.apache.amoro.config.Configurations; +import org.apache.amoro.server.AmoroManagementConf; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; + +public class RoleResolver { + private static final Logger LOG = LoggerFactory.getLogger(RoleResolver.class); + + private final boolean authorizationEnabled; + private final String defaultRole; + private final String adminUsername; + private final LdapGroupRoleResolver ldapGroupRoleResolver; + + public RoleResolver(Configurations serviceConfig) { + this(serviceConfig, createLdapGroupRoleResolver(serviceConfig)); + } + + RoleResolver(Configurations serviceConfig, LdapGroupRoleResolver ldapGroupRoleResolver) { + this.authorizationEnabled = serviceConfig.get(AmoroManagementConf.AUTHORIZATION_ENABLED); + this.defaultRole = + serviceConfig + .getOptional(AmoroManagementConf.AUTHORIZATION_DEFAULT_ROLE) + .map(String::trim) + .filter(role -> !role.isEmpty()) + .orElse(null); + this.adminUsername = serviceConfig.get(AmoroManagementConf.ADMIN_USERNAME); + this.ldapGroupRoleResolver = ldapGroupRoleResolver; + } + + private static LdapGroupRoleResolver createLdapGroupRoleResolver(Configurations serviceConfig) { + boolean authorizationEnabled = serviceConfig.get(AmoroManagementConf.AUTHORIZATION_ENABLED); + boolean ldapRoleMappingEnabled = + serviceConfig.get(AmoroManagementConf.AUTHORIZATION_LDAP_ROLE_MAPPING_ENABLED); + if (!authorizationEnabled && ldapRoleMappingEnabled) { + LOG.warn( + "Ignore http-server.authorization.ldap-role-mapping configuration because http-server.authorization.enabled is false"); + } + return authorizationEnabled + ? new LdapGroupRoleResolver(serviceConfig) + : LdapGroupRoleResolver.disabled(); + } + + public boolean isAuthorizationEnabled() { + return authorizationEnabled; + } + + public Set<String> resolve(String username) { + if (!authorizationEnabled) { + return Collections.singleton(Role.SERVICE_ADMIN); + } + + Set<String> roles = new LinkedHashSet<>(); + if (adminUsername.equals(username)) { Review Comment: **[Minor] Admin username comparison is case-sensitive** `adminUsername.equals(username)` — if `LdapPasswdAuthenticationProvider.normalizeUsername` strips the domain but the configured `admin-username` was set to `Admin` (capital A), the bootstrap admin will not get `SERVICE_ADMIN` role. Consider using `equalsIgnoreCase` or at least documenting the case-sensitivity requirement. -- 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]
