Skip to content

Commit

Permalink
feat: enable/disable Ahjo IP restriction, allow multiple IPs (#2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke authored Dec 12, 2023
1 parent 7939f5e commit e78e1be
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .env.benefit-backend.example
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ AHJO_CLIENT_ID=
AHJO_CLIENT_SECRET=
AHJO_TOKEN_URL=
AHJO_REST_API_URL=
AHJO_REDIRECT_URL=
AHJO_REDIRECT_URL=
DISABLE_AHJO_SAFE_LIST_CHECK=True
2 changes: 1 addition & 1 deletion backend/benefit/common/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class SafeListPermission(permissions.BasePermission):

def has_permission(self, request, view):
remote_addr = request.META["REMOTE_ADDR"]
if settings.NEXT_PUBLIC_MOCK_FLAG:
if settings.NEXT_PUBLIC_MOCK_FLAG or settings.DISABLE_AHJO_SAFE_LIST_CHECK:
# disable safe list check in mock mode
return True

Expand Down
6 changes: 4 additions & 2 deletions backend/benefit/helsinkibenefit/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@
AHJO_TOKEN_URL=(str, "https://johdontyopoytahyte.hel.fi/ids4/connect/token"),
AHJO_REST_API_URL=(str, "https://ahjohyte.hel.fi:9802/ahjorest/v1"),
AHJO_REDIRECT_URL=(str, "https://helsinkilisa/dummyredirect.html"),
AHJO_ALLOWED_IP=(str, ""),
AHJO_ALLOWED_IP=(list, ["*"]),
DISABLE_AHJO_SAFE_LIST_CHECK=(bool, False),
)
if os.path.exists(env_file):
env.read_env(env_file)
Expand Down Expand Up @@ -518,4 +519,5 @@
AHJO_REST_API_URL = env("AHJO_REST_API_URL")
AHJO_REDIRECT_URL = env("AHJO_REDIRECT_URL")

REST_SAFE_LIST_IPS = (env("AHJO_ALLOWED_IP"),)
REST_SAFE_LIST_IPS = env.list("AHJO_ALLOWED_IP")
DISABLE_AHJO_SAFE_LIST_CHECK = env.bool("DISABLE_AHJO_SAFE_LIST_CHECK")

0 comments on commit e78e1be

Please sign in to comment.