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

policies/geoip: distance + impossible travel #12541

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

BeryJu
Copy link
Member

@BeryJu BeryJu commented Jan 2, 2025

Details

Add options to the GeoIP policy for distance checks and impossible travel checks


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema has been updated (make gen-build)

If changes to the frontend have been made

  • The code has been formatted (make web)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make website)

@BeryJu BeryJu requested review from a team as code owners January 2, 2025 20:30
Copy link

netlify bot commented Jan 2, 2025

Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 7ac0d30
🔍 Latest deploy log https://app.netlify.com/sites/authentik-storybook/deploys/6785c2a19e68df00088f76c0
😎 Deploy Preview https://deploy-preview-12541--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 2, 2025

Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 7ac0d30
🔍 Latest deploy log https://app.netlify.com/sites/authentik-docs/deploys/6785c2a1c9b9e90008f08b25
😎 Deploy Preview https://deploy-preview-12541--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.77%. Comparing base (5da0297) to head (7ac0d30).

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12541      +/-   ##
==========================================
+ Coverage   92.76%   92.77%   +0.01%     
==========================================
  Files         769      769              
  Lines       38879    38934      +55     
==========================================
+ Hits        36067    36122      +55     
  Misses       2812     2812              
Flag Coverage Δ
e2e 48.60% <18.46%> (-0.04%) ⬇️
integration 24.63% <18.46%> (-0.01%) ⬇️
unit 90.40% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BeryJu BeryJu force-pushed the policies/geoip/distance branch from a2cc87e to bec9606 Compare January 2, 2025 21:07
Copy link
Contributor

github-actions bot commented Jan 2, 2025

authentik PR Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-bec96066e44fabf7f7a68a72487a655241197a2c
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

For arm64, use these values:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-bec96066e44fabf7f7a68a72487a655241197a2c-arm64
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
    image:
        repository: ghcr.io/goauthentik/dev-server
        tag: gh-bec96066e44fabf7f7a68a72487a655241197a2c

For arm64, use these values:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
    image:
        repository: ghcr.io/goauthentik/dev-server
        tag: gh-bec96066e44fabf7f7a68a72487a655241197a2c-arm64

Afterwards, run the upgrade commands from the latest release notes.

Signed-off-by: Jens Langhammer <[email protected]>
Signed-off-by: Jens Langhammer <[email protected]>
Signed-off-by: Jens Langhammer <[email protected]>
Signed-off-by: Jens Langhammer <[email protected]>
Signed-off-by: Jens Langhammer <[email protected]>
Signed-off-by: Jens Langhammer <[email protected]>
@BeryJu BeryJu force-pushed the policies/geoip/distance branch from bec9606 to 7ac0d30 Compare January 14, 2025 01:49
Copy link

<ak-form-group>
<span slot="header"> ${msg("Distance settings")} </span>
<div slot="body" class="pf-c-form">
<ak-form-element-horizontal name="checkHistoryDistance">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ak-switch-input could be used here

)}
</p>
</ak-form-element-horizontal>
<ak-form-element-horizontal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ak-number-input though, it doesn't support min yet. cc. @kensternberg-authentik for awareness

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -37,21 +52,27 @@ def passes(self, request: PolicyRequest) -> PolicyResult:
- the client IP is advertised by an autonomous system with ASN in the `asns`
- the client IP is geolocated in a country of `countries`
"""
results: list[PolicyResult] = []
static_results: list[PolicyResult] = []
dynamic_results: list[PolicyResult] = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any advantage in having two separate lists here?

if not geoip_data:
return PolicyResult(False)
for previous_login in previous_logins:
previous_login_geoip: GeoIPDict = previous_login.context.get("geo")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
previous_login_geoip: GeoIPDict = previous_login.context.get("geo")
previous_login_geoip: GeoIPDict = previous_login.context["geo"]

We've checked previously. I'd rather it fails on that line if something went wrong, than a None error later on

# than max distance per hour times the amount of hours since the previous login
# (round down to the lowest closest time of hours)
# clamped to be at least 1 hour
rel_time_hours = max(int((_now - previous_login.created).total_seconds() / 86400), 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rel_time_hours = max(int((_now - previous_login.created).total_seconds() / 86400), 1)
rel_time_hours = max(int((_now - previous_login.created).total_seconds() / 3600), 1)

an hour is 60 secs * 60 mins = 3600 seconds, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants