Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
dashboardv3
inventory-provider
Commits
322fa06f
Unverified
Commit
322fa06f
authored
2 months ago
by
Adeel Ahmad
Browse files
Options
Downloads
Patches
Plain Diff
Add route based authorisation for services
parent
158a3313
No related branches found
No related tags found
1 merge request
!50
Dboard3 1142/token auth
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/__init__.py
+19
-2
19 additions, 2 deletions
inventory_provider/__init__.py
inventory_provider/auth.py
+2
-1
2 additions, 1 deletion
inventory_provider/auth.py
with
21 additions
and
3 deletions
inventory_provider/__init__.py
+
19
−
2
View file @
322fa06f
...
...
@@ -3,7 +3,7 @@ automatically invoked app factory
"""
import
logging
import
os
from
flask
import
Flask
from
flask
import
g
,
Flask
,
request
,
jsonify
from
flask_cors
import
CORS
from
inventory_provider
import
environment
...
...
@@ -54,7 +54,24 @@ def create_app(setup_logging=True):
@auth.login_required
def
secure_before_request
():
"""
Enforces authentication for all routes
"""
pass
client
=
g
.
get
(
"
auth_service
"
)
if
not
client
:
# This allows clients to access any resource without providing an API key
# TODO: Only for testing, should be removed in Production
return
# return jsonify({"error": "Unauthorized"}), 403
CLIENT_PERMISSIONS
=
{
"
serviceA
"
:
[
"
msr
"
],
"
serviceB
"
:
[
"
testing
"
],
}
allowed_routes
=
CLIENT_PERMISSIONS
.
get
(
client
,
[])
route
=
request
.
path
.
strip
(
"
/
"
).
split
(
"
/
"
)[
0
]
if
route
not
in
allowed_routes
:
return
jsonify
({
"
error
"
:
"
Forbidden
"
}),
403
# IMS based routes
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/auth.py
+
2
−
1
View file @
322fa06f
from
flask
import
Blueprint
,
current_app
from
flask
import
Blueprint
,
current_app
,
g
from
flask_httpauth
import
HTTPTokenAuth
auth
=
HTTPTokenAuth
(
scheme
=
"
ApiKey
"
)
...
...
@@ -12,6 +12,7 @@ def verify_api_key(api_key):
for
service
,
details
in
config
[
'
api-keys
'
].
items
():
if
details
.
get
(
'
api-key
'
)
==
api_key
:
g
.
auth_service
=
service
return
service
return
None
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment