forked from apache/incubator-livy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR propose to improve current Livy's access control mechanism with fine-grained control: 1. If `livy.server.access-control.enabled` is disabled, which means ACLs is disabled, any user could send any request to Livy. 2. If `livy.server.access-control.enabled` is enabled, then this ACL mechanism divides users into 3 groups: 1. view accessible users: users could get session, statement data, but cannot POST any queries. 2. modify accessible users: users could submit new statements, kill sessions. 3. super users: this is the same as previous, super user could impersonate any user. In the meanwhile, modify accessible users automatically have the view accessibility, and super user has all the permissions. Also add new configuration `livy.server.access-control.allowed-users`, this is the same as previous `livy.server.access-control.users`, when ACLs is enabled only users in the allowed list could issue REST queries to Livy server, other users will get 403. Please review and comment. Author: jerryshao <[email protected]> Closes apache#15 from jerryshao/LIVY-348.
- Loading branch information
Showing
16 changed files
with
434 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
server/src/main/scala/org/apache/livy/server/AccessManager.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
*/ | ||
|
||
package org.apache.livy.server | ||
|
||
import org.apache.livy.{LivyConf, Logging} | ||
|
||
private[livy] class AccessManager(conf: LivyConf) extends Logging { | ||
private val aclsOn = conf.getBoolean(LivyConf.ACCESS_CONTROL_ENABLED) | ||
|
||
private val WILDCARD_ACL = "*" | ||
|
||
private val superUsers = conf.configToSeq(LivyConf.SUPERUSERS) | ||
private val modifyUsers = conf.configToSeq(LivyConf.ACCESS_CONTROL_MODIFY_USERS) | ||
private val viewUsers = conf.configToSeq(LivyConf.ACCESS_CONTROL_VIEW_USERS) | ||
private val allowedUsers = conf.configToSeq(LivyConf.ACCESS_CONTROL_ALLOWED_USERS).toSet | ||
|
||
private val viewAcls = (superUsers ++ modifyUsers ++ viewUsers).toSet | ||
private val modifyAcls = (superUsers ++ modifyUsers).toSet | ||
private val superAcls = superUsers.toSet | ||
private val allowedAcls = (superUsers ++ modifyUsers ++ viewUsers ++ allowedUsers).toSet | ||
|
||
info(s"AccessControlManager acls ${if (aclsOn) "enabled" else "disabled"};" + | ||
s"users with view permission: ${viewUsers.mkString(", ")};" + | ||
s"users with modify permission: ${modifyUsers.mkString(", ")};" + | ||
s"users with super permission: ${superUsers.mkString(", ")};" + | ||
s"other allowed users: ${allowedUsers.mkString(", ")}") | ||
|
||
/** | ||
* Check whether the given user has view access to the REST APIs. | ||
*/ | ||
def checkViewPermissions(user: String): Boolean = { | ||
debug(s"user=$user aclsOn=$aclsOn viewAcls=${viewAcls.mkString(", ")}") | ||
if (!aclsOn || user == null || viewAcls.contains(WILDCARD_ACL) || viewAcls.contains(user)) { | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
/** | ||
* Check whether the give user has modification access to the REST APIs. | ||
*/ | ||
def checkModifyPermissions(user: String): Boolean = { | ||
debug(s"user=$user aclsOn=$aclsOn modifyAcls=${modifyAcls.mkString(", ")}") | ||
if (!aclsOn || user == null || modifyAcls.contains(WILDCARD_ACL) || modifyAcls.contains(user)) { | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
/** | ||
* Check whether the give user has super access to the REST APIs. This will always be checked | ||
* no matter acls is on or off. | ||
*/ | ||
def checkSuperUser(user: String): Boolean = { | ||
debug(s"user=$user aclsOn=$aclsOn superAcls=${superAcls.mkString(", ")}") | ||
if (user == null || superUsers.contains(WILDCARD_ACL) || superUsers.contains(user)) { | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
/** | ||
* Check whether the given user has the permission to access REST APIs. | ||
*/ | ||
def isUserAllowed(user: String): Boolean = { | ||
debug(s"user=$user aclsOn=$aclsOn, allowedAcls=${allowedAcls.mkString(", ")}") | ||
if (!aclsOn || user == null || allowedAcls.contains(WILDCARD_ACL) || | ||
allowedAcls.contains(user)) { | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
/** | ||
* Check whether access control is enabled or not. | ||
*/ | ||
def isAccessControlOn: Boolean = aclsOn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.