Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory RBAC in Krakend service #270

Merged
merged 1 commit into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions config/krakend/scripts/inventory_rbac.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


function getenv(key, fallback)
value = os.getenv(key)
if value == nil then
return fallback
end
return value
end

function user_group_auth(request)
-- set variables from request
local headers_group = request:headers('X-Auth-User-Groups')
local headers_role = request:headers('X-Auth-User-Roles')
local headers_all = headers_group .. "," .. headers_role

-- inventory RBAC settings
local permited_groups=getenv('INVENTORY_ADMIN_GROUP')

-- remove white spaces in groups
headers_all = headers_all:gsub("%s+", "")
headers_all = headers_all:lower()
permited_groups = permited_groups:gsub("%s+", "")
permited_groups = permited_groups:lower()

-- if graphql query contain mutation, then check if user is admin
local query=string.match(request:body(), "mutation")

if query ~= nil then
for header_group in string.gmatch(headers_all, '([^,]+)') do
for permited_group in string.gmatch(permited_groups, '([^,]+)') do
if header_group == permited_group then
return
end
end
end
print("User has no permissions for executing request, bad group")
custom_error("No permissions group", 427)
end
end
3 changes: 3 additions & 0 deletions config/secrets/frinx_rbac
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ UNISTORE_NETWORK_NODE=network
RM_ADMIN_GROUPS=network-admin
RM_ADMIN_ROLES=''

# INVENTORY RBAC SETTINGS
INVENTORY_ADMIN_GROUP=network-admin

# WORKFLOW-PROXY RBAC SETTINGS
ADMIN_ACCESS_ROLE=network-admin

Expand Down