-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kafka: do authorization on produce (0)
- Loading branch information
Showing
3 changed files
with
132 additions
and
57 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
50 changes: 50 additions & 0 deletions
50
hstream-kafka/HStream/Kafka/Server/Security/AuthorizeHelper.hs
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,50 @@ | ||
module HStream.Kafka.Server.Security.AuthorizeHelper where | ||
|
||
import Control.Monad | ||
import Data.Maybe | ||
import Data.Text (Text) | ||
import qualified Data.Text as T | ||
|
||
import HStream.Kafka.Common.Acl | ||
import HStream.Kafka.Common.Authorizer.Class | ||
import HStream.Kafka.Common.Resource | ||
import HStream.Kafka.Common.Security | ||
import qualified Kafka.Protocol.Service as K | ||
|
||
toAuthorizableReqCtx :: K.RequestContext -> AuthorizableRequestContext | ||
toAuthorizableReqCtx reqCtx = | ||
AuthorizableRequestContext (T.pack reqCtx.clientHost) | ||
(Principal "User" (fromMaybe "" (join reqCtx.clientId))) | ||
|
||
-- FIXME: configuable | ||
defaultLogIfAllowed :: Bool | ||
defaultLogIfAllowed = False | ||
|
||
-- FIXME: configuable | ||
defaultLogIfDenied :: Bool | ||
defaultLogIfDenied = True | ||
|
||
-- | Do a | ||
simpleAuthorize :: Authorizer s | ||
=> AuthorizableRequestContext | ||
-> s | ||
-> ResourceType | ||
-> Text | ||
-> AclOperation | ||
-> IO Bool | ||
simpleAuthorize ctx authorizer resType resName op = do | ||
let resPat = ResourcePattern | ||
{ resPatResourceType = resType | ||
, resPatResourceName = resName | ||
, resPatPatternType = Pat_LITERAL -- FIXME: support extended? | ||
} | ||
action = AclAction | ||
{ aclActionResPat = resPat | ||
, aclActionOp = op | ||
, aclActionLogIfAllowed = defaultLogIfAllowed | ||
, aclActionLogIfDenied = defaultLogIfDenied | ||
} | ||
authorize ctx authorizer [action] >>= \case | ||
[Authz_ALLOWED] -> return True | ||
[Authz_DENIED] -> return False | ||
_ -> error "what happened?" -- FIXME: error |
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