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

feat: pass-throughs for specific non-authz service endpoints #12

Merged
merged 6 commits into from
Mar 19, 2024
Merged
Changes from 3 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
26 changes: 24 additions & 2 deletions src/proxy_auth_v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ local err_500_and_log = function(detail, err)
end
-- END FUNCTION DEFINITIONS -----–-----–-----–-----–-----–-----–-----–-----–-----–-------

local req = ngx.req
local req_method = req.get_method()
local req_uri = ngx.var.request_uri -- pre-rewrite URI
local uri = ngx.var.uri -- post-rewrite URI

-- BEGIN OPEN ENDPOINT LOGIC ------------------------------------------------------------

-- Pass through all endpoint calls which used to be proxied by bento_public
-- TODO: replace this with properly authorization-compatible services

if req_method == "GET" and (
uri == "/service-info" or
req_uri == "/api/metadata/api/projects" or
req_uri == "/api/metadata/api/public" or
davidlougheed marked this conversation as resolved.
Show resolved Hide resolved
req_uri == "/api/metadata/api/public_overview" or
req_uri == "/api/metadata/api/public_search_fields" or
req_uri == "/api/metadata/api/public_dataset"
) then
goto script_end
v-rocheleau marked this conversation as resolved.
Show resolved Hide resolved
end

-- END OPEN ENDPOINT LOGIC --------------------------------------------------------------

-- BEGIN AUTHORIZATION LOGIC ------------------------------------------------------------

local bento_debug = os.getenv("BENTO_DEBUG")
Expand All @@ -54,11 +77,10 @@ local user_role

-- Check bearer token if set
-- Adapted from https://github.com/zmartzone/lua-resty-openidc/issues/266#issuecomment-542771402
local req = ngx.req
local auth_header = req.get_headers()["Authorization"]

-- Tokens can also be passed in the form of POST body form data
if req.get_method() == "POST" then
if req_method == "POST" then
req.read_body()
local req_body = req.get_post_args()
if req_body ~= nil and req_body["token"] then
Expand Down