bobbai00 commented on code in PR #9043:
URL: https://github.com/apache/texera/pull/9043#discussion_r4619500832
##########
access-control-service/src/main/scala/org/apache/texera/service/resource/AccessControlResource.scala:
##########
@@ -125,6 +129,60 @@ object AccessControlResource extends LazyLogging {
}
}
+ // Extract the bearer token from the access-token query param, the
+ // Authorization header, or a "token" field in the body (in that order).
+ private def extractBearerToken(
+ uriInfo: UriInfo,
+ headers: HttpHeaders,
+ bodyOpt: Option[String]
+ ): String = {
+ val qToken = Option(uriInfo.getQueryParameters().getFirst("access-token"))
+ .map(_.trim)
+ .filter(_.nonEmpty)
+ val hToken = Option(headers.getRequestHeader("Authorization"))
+ .flatMap(_.asScala.headOption)
+ .map(_.replaceFirst("(?i)^Bearer\\s+", "")) // case-insensitive "Bearer "
+ .map(_.trim)
+ .filter(_.nonEmpty)
+ val bToken = bodyOpt.flatMap(extractTokenFromBody)
+ qToken.orElse(hToken).orElse(bToken).getOrElse("")
+ }
+
+ // Phase 1 agent authorization: authenticate the JWT and require a
+ // REGULAR/ADMIN role. Any such user may reach any agent for now; per-agent
+ // ownership is deferred (see #5302 / #5561). On success, return the user
+ // identity headers for future per-agent authorization in agent-service.
+ private def checkAgentAccess(
+ uriInfo: UriInfo,
+ headers: HttpHeaders,
+ bodyOpt: Option[String]
+ ): Response = {
+ val token = extractBearerToken(uriInfo, headers, bodyOpt)
+ val userSession: Optional[SessionUser] =
+ try parseToken(token)
+ catch {
+ case e: Exception =>
+ logger.error(s"Failed parsing token for agent request: $e")
+ Optional.empty()
+ }
+
+ if (userSession.isEmpty) {
+ return Response.status(Response.Status.UNAUTHORIZED).build()
Review Comment:
Partly there. [Lines
319-322](https://github.com/apache/texera/blob/ff51a5d02f9c41e2f08394427ac4d387717d860a/access-control-service/src/main/scala/org/apache/texera/service/resource/AccessControlResource.scala#L319-L322)
now say the proxy returns `401 on missing/invalid tokens, and 403 for
unauthorized roles`. `checkComputingUnitAccess` still answers 403 for a missing
or invalid token ([lines
224-225](https://github.com/apache/texera/blob/ff51a5d02f9c41e2f08394427ac4d387717d860a/access-control-service/src/main/scala/org/apache/texera/service/resource/AccessControlResource.scala#L224-L225)
and
[232-234](https://github.com/apache/texera/blob/ff51a5d02f9c41e2f08394427ac4d387717d860a/access-control-service/src/main/scala/org/apache/texera/service/resource/AccessControlResource.scala#L232-L234)),
so the sentence is now wrong for the computing-unit routes instead. Naming
both would fix it, for example: `(the /api/agents branch returns 401 for a
missing or invalid token and 403 for a dis
allowed role; the computing-unit branches return 403 for both)`.
--
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]