aicam commented on code in PR #6896: URL: https://github.com/apache/texera/pull/6896#discussion_r3991146509
########## access-control-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitMountResource.scala: ########## @@ -0,0 +1,221 @@ +/* + * 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.texera.service.resource + +import com.typesafe.scalalogging.LazyLogging +import io.dropwizard.auth.Auth +import jakarta.annotation.security.RolesAllowed +import jakarta.ws.rs._ +import jakarta.ws.rs.core.MediaType +import org.apache.texera.auth.JwtAuth.{jwtClaims, jwtToken} +import org.apache.texera.auth.SessionUser +import org.apache.texera.auth.util.ComputingUnitAccess +import org.apache.texera.common.config.{EnvironmentalVariable, KubernetesConfig} +import org.apache.texera.dao.SqlServer +import org.apache.texera.dao.SqlServer.withTransaction +import org.apache.texera.dao.jooq.generated.Tables.{DATASET_VERSION, MODEL_VERSION} +import org.apache.texera.dao.jooq.generated.enums.PrivilegeEnum +import org.apache.texera.dao.jooq.generated.tables.daos.{DatasetDao, ModelDao} +import org.apache.texera.service.resource.ComputingUnitMountResource._ +import org.apache.texera.service.util.{ + ComputingUnitNodeLocator, + MountRequestValidation, + MounterClient +} + +import scala.jdk.CollectionConverters._ + +/** + * The mount authority: this service decides whether a user may act on a computing unit, so + * it is where a mount request is authorized before being forwarded to that unit's node. + * + * Read access to the data is not decided here. file-service's S3 proxy authorizes every + * read, so a mount of a repository the user cannot read reads nothing. + * + * Not routed at the gateway — these endpoints are reached in-cluster, by the engine. + */ +@Path("/mounts") +@RolesAllowed(Array("REGULAR", "ADMIN")) +@Produces(Array(MediaType.APPLICATION_JSON)) +class ComputingUnitMountResource( + mounterEnabled: Boolean, + mounterPort: Option[Int], + fileServiceBaseUrl: Option[String], + nodeLocator: ComputingUnitNodeLocator, + mounter: MounterClient +) extends LazyLogging { + + // No-arg constructor for Jersey reflection. Tests use the param-ful form. + def this() = + this( + KubernetesConfig.mounterEnabled, + EnvironmentalVariable.get(MounterPortVariable).map(_.trim.toInt), + EnvironmentalVariable.get(FileServiceUrlVariable), + ComputingUnitNodeLocator, + MounterClient + ) + + @POST + @Path("/{cuid}") + @Consumes(Array(MediaType.APPLICATION_JSON)) + def mount( + @PathParam("cuid") cuid: Int, + request: MountRequest, + @Auth user: SessionUser + ): MountInfo = { + val (port, fileService) = requireMountConfiguration() + try MountRequestValidation.validate(cuid.toString, request.repositoryName, request.commitHash) + catch { case e: IllegalArgumentException => throw new BadRequestException(e.getMessage) } + requireComputingUnitAccess(cuid, user) + requireRepositoryReadAccess(request.repositoryName, request.commitHash, user.getUid) + val nodeIp = requireNodeIp(cuid) + + // A token minted here, after the access check: GeeseFS keeps presenting it for the life + // of the mount, so it must be one this service vouched for. + val mountPath = + try { + mounter.mount( + nodeIp, + port, + cuid.toString, + request.repositoryName, + request.commitHash, + jwtToken(jwtClaims(user.getUser)), Review Comment: The rule of thumb I follow is to tie everything to one token for simplicity so we have one single source of truth. That was the purpose of creating access control service. So the trade off here is: - Create new tokens: for different parts of applications, we should build different tokens carrying different information. We will be limited on tokens and they can not be used interchangeably. - Create a dedicated ACS: this service act as a guard for any purpose, it can read database, call K8s endpoints. This is a more flexible way, this solution support any authorization process with one single token. It is also worth to mention that ACS is not powerful by itself, the Envoy Gateway in K8s deployment gives it this flexibility because it can manage the network layer very advance so ACS can only focus on security. -- 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]
