Skip to content

Commit

Permalink
Merge branch 'bug_24394/autoprovisioned_users_don_t_have_access_to_an…
Browse files Browse the repository at this point in the history
…y_nodes_pr' into 8.1-next
  • Loading branch information
clarktsiory committed Mar 12, 2024
2 parents 153d4fb + 8853de2 commit 9416aa3
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import com.normation.rudder.api.ApiAuthorization
import com.normation.rudder.domain.eventlog.RudderEventActor
import com.normation.rudder.domain.logger.ApplicationLoggerPure
import com.normation.rudder.domain.logger.PluginLogger
import com.normation.rudder.facts.nodes.NodeSecurityContext
import com.normation.rudder.rest.RoleApiMapping
import com.normation.rudder.users._
import com.normation.zio._
Expand Down Expand Up @@ -527,8 +528,15 @@ trait RudderUserServerMapping[R <: OAuth2UserRequest, U <: OAuth2User, T <: Rudd
rudderUserDetailsService.loadUserByUsername(user.getName)
}
}
// for now, tenants are not configurable by OIDC
val tenants = rudderUserDetailsService.authConfigProvider.getUserByName(user.getName) match {
// when the user is not defined in rudder-users.xml, we give it the whole perm on nodes for compatibility
case Left(_) => NodeSecurityContext.All
// if the user is defined in rudder-users.xml, we get whatever is defined there.
case Right(u) => u.nodePerms
}

buildUser(optReg, userRequest, user, roleApiMapping, rudderUser, newUserDetails)
buildUser(optReg, userRequest, user, roleApiMapping, rudderUser, newUserDetails, tenants)
}

def buildUser(
Expand All @@ -537,7 +545,8 @@ trait RudderUserServerMapping[R <: OAuth2UserRequest, U <: OAuth2User, T <: Rudd
user: U,
roleApiMapping: RoleApiMapping,
rudder: RudderUserDetail,
userBuilder: (U, RudderUserDetail) => T
userBuilder: (U, RudderUserDetail) => T,
tenants: NodeSecurityContext
): T = {
val roles = {
optReg match {
Expand Down Expand Up @@ -644,8 +653,7 @@ trait RudderUserServerMapping[R <: OAuth2UserRequest, U <: OAuth2User, T <: Rudd
.toList

val apiAuthz = ApiAuthorization.ACL(acls)
val userDetails = rudder
.copy(roles = roles, apiAuthz = apiAuthz)
val userDetails = rudder.copy(roles = roles, apiAuthz = apiAuthz, nodePerms = tenants)
AuthBackendsLogger.debug(
s"Principal '${rudder.getUsername}' final roles: [${roles.map(_.name).mkString(", ")}], and API authz: ${apiAuthz.debugString}"
)
Expand Down

0 comments on commit 9416aa3

Please sign in to comment.