Skip to content

Commit

Permalink
Blacklist on account level (cont.)
Browse files Browse the repository at this point in the history
  • Loading branch information
steffenrost committed Sep 26, 2023
1 parent 7c9ec1b commit ed68b4e
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import spray.json.JsString

object BasicAuthenticationDirective extends AuthenticationDirectiveProvider {

private val allAccounts = sys.env.getOrElse("ALL_ACCOUNTS", "")
private val wlAccountPfx = sys.env.getOrElse("WL_ACCOUNT_PFX", "??")
private val iamNamespaceRegEx = sys.env.getOrElse("IAM_NAMESPACE_REGEX", "")
var namespaceBlacklist: Option[NamespaceBlacklist] = None
def getOrCreateBlacklist()(implicit transid: TransactionId,
system: ActorSystem,
Expand Down Expand Up @@ -82,9 +85,17 @@ object BasicAuthenticationDirective extends AuthenticationDirectiveProvider {
logging.info(this, s"authenticate: ${authkey.uuid}")
val future = Identity.get(authStore, authkey) map { result =>
val blacklist = getOrCreateBlacklist
val account = Try(result.authkey.asInstanceOf[BasicAuthenticationAuthKey].account).getOrElse("")
val identity =
if (!blacklist.isEmpty && blacklist.isBlacklisted(
Try(result.authkey.asInstanceOf[BasicAuthenticationAuthKey].account).getOrElse(""))) {
if (blacklist.isBlacklisted(allAccounts) && !blacklist.isBlacklisted(wlAccountPfx + account)) {
Identity(
subject = result.subject,
namespace = result.namespace,
authkey = result.authkey,
rights = result.rights,
limits =
UserLimits(invocationsPerMinute = Some(0), concurrentInvocations = Some(0), firesPerMinute = Some(0)))
} else if (blacklist.isBlacklisted(account)) {
Identity(
subject = result.subject,
namespace = result.namespace,
Expand Down Expand Up @@ -142,10 +153,20 @@ object BasicAuthenticationDirective extends AuthenticationDirectiveProvider {
//Identity.get(authStore, namespace)
implicit val ec = authStore.executionContext
implicit val logging = authStore.logging
logging.info(this, s"authentication for namespace $namespace")
Identity.get(authStore, namespace) map { result =>
val blacklist = getOrCreateBlacklist
if (!blacklist.isEmpty && blacklist.isBlacklisted(
Try(result.authkey.asInstanceOf[BasicAuthenticationAuthKey].account).getOrElse(""))) {
val account = Try(result.authkey.asInstanceOf[BasicAuthenticationAuthKey].account).getOrElse("")
if ((!iamNamespaceRegEx.isEmpty && !namespace.name.matches(iamNamespaceRegEx)) && blacklist.isBlacklisted(
allAccounts) && !blacklist
.isBlacklisted(wlAccountPfx + account)) {
Identity(
subject = result.subject,
namespace = result.namespace,
authkey = result.authkey,
rights = result.rights,
limits = UserLimits(invocationsPerMinute = Some(0), concurrentInvocations = Some(0), firesPerMinute = Some(0)))
} else if (blacklist.isBlacklisted(account)) {
Identity(
subject = result.subject,
namespace = result.namespace,
Expand Down

0 comments on commit ed68b4e

Please sign in to comment.