Skip to content

Commit

Permalink
Merge branch 'goauthentik:main' into feature/source_ldap_lookup_group…
Browse files Browse the repository at this point in the history
…s_from_user
  • Loading branch information
krejcar25 authored Feb 3, 2025
2 parents a66dc73 + e4b6df3 commit f62efb2
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 61 deletions.
7 changes: 4 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"recommendations": [
"bashmish.es6-string-css",
"bpruitt-goddard.mermaid-markdown-syntax-highlighting",
"charliermarsh.ruff",
"dbaeumer.vscode-eslint",
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode",
Expand All @@ -10,12 +11,12 @@
"Gruntfuggly.todo-tree",
"mechatroner.rainbow-csv",
"ms-python.black-formatter",
"charliermarsh.ruff",
"ms-python.black-formatter",
"ms-python.debugpy",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.black-formatter",
"redhat.vscode-yaml",
"Tobermory.es6-string-html",
"unifiedjs.vscode-mdx"
"unifiedjs.vscode-mdx",
]
}
66 changes: 58 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,76 @@
"version": "0.2.0",
"configurations": [
{
"name": "Python: PDB attach Server",
"type": "python",
"name": "Debug: Attach Server Core",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 6800
"port": 9901
},
"justMyCode": true,
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/"
}
],
"django": true
},
{
"name": "Python: PDB attach Worker",
"type": "python",
"name": "Debug: Attach Worker",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 6900
"port": 9901
},
"justMyCode": true,
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/"
}
],
"django": true
},
{
"name": "Debug: Start Server Router",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/server",
"cwd": "${workspaceFolder}"
},
{
"name": "Debug: Start LDAP Outpost",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/ldap",
"cwd": "${workspaceFolder}"
},
{
"name": "Debug: Start Proxy Outpost",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/proxy",
"cwd": "${workspaceFolder}"
},
{
"name": "Debug: Start RAC Outpost",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/rac",
"cwd": "${workspaceFolder}"
},
{
"name": "Debug: Start Radius Outpost",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/radius",
"cwd": "${workspaceFolder}"
}
]
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ docker: ## Build a docker image of the current source tree
DOCKER_BUILDKIT=1 docker build . --progress plain --tag ${DOCKER_IMAGE}

test-docker:
./scripts/test_docker.sh
BUILD=true ./scripts/test_docker.sh

#########################
## CI
Expand Down
2 changes: 2 additions & 0 deletions authentik/core/management/commands/dev_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from daphne.management.commands.runserver import Command as RunServer
from daphne.server import Server

from authentik.lib.debug import start_debug_server
from authentik.root.signals import post_startup, pre_startup, startup


Expand All @@ -13,6 +14,7 @@ class SignalServer(Server):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
start_debug_server()

def ready_callable():
pre_startup.send(sender=self)
Expand Down
6 changes: 2 additions & 4 deletions authentik/core/management/commands/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from structlog.stdlib import get_logger

from authentik.lib.config import CONFIG
from authentik.lib.debug import start_debug_server
from authentik.root.celery import CELERY_APP

LOGGER = get_logger()
Expand All @@ -28,10 +29,7 @@ def add_arguments(self, parser):
def handle(self, **options):
LOGGER.debug("Celery options", **options)
close_old_connections()
if CONFIG.get_bool("remote_debug"):
import debugpy

debugpy.listen(("0.0.0.0", 6900)) # nosec
start_debug_server()
worker: Worker = CELERY_APP.Worker(
no_color=False,
quiet=True,
Expand Down
2 changes: 1 addition & 1 deletion authentik/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,4 @@ def django_db_config(config: ConfigLoader | None = None) -> dict:
if len(argv) < 2: # noqa: PLR2004
print(dumps(CONFIG.raw, indent=4, cls=AttrEncoder))
else:
print(CONFIG.get(argv[1]))
print(CONFIG.get(argv[-1]))
26 changes: 26 additions & 0 deletions authentik/lib/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from structlog.stdlib import get_logger

from authentik.lib.config import CONFIG

LOGGER = get_logger()


def start_debug_server(**kwargs) -> bool:
"""Attempt to start a debugpy server in the current process.
Returns true if the server was started successfully, otherwise false"""
if not CONFIG.get_bool("debug") and not CONFIG.get_bool("debugger"):
return
try:
import debugpy
except ImportError:
LOGGER.warning(
"Failed to import debugpy. debugpy is not included "
"in the default release dependencies and must be installed manually"
)
return False

listen: str = CONFIG.get("listen.listen_debug_py", "127.0.0.1:9901")
host, _, port = listen.rpartition(":")
debugpy.listen((host, int(port)), **kwargs) # nosec
LOGGER.debug("Starting debug server", host=host, port=port)
return True
3 changes: 2 additions & 1 deletion authentik/lib/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ listen:
listen_radius: 0.0.0.0:1812
listen_metrics: 0.0.0.0:9300
listen_debug: 0.0.0.0:9900
listen_debug_py: 0.0.0.0:9901
trusted_proxy_cidrs:
- 127.0.0.0/8
- 10.0.0.0/8
Expand Down Expand Up @@ -57,7 +58,7 @@ cache:
# transport_options: ""

debug: false
remote_debug: false
debugger: false

log_level: info

Expand Down
3 changes: 3 additions & 0 deletions authentik/providers/oauth2/tests/test_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def test_auth_code_view(self):
"id_token": provider.encode(
access.id_token.to_dict(),
),
"scope": "",
},
)
self.validate_jwt(access, provider)
Expand Down Expand Up @@ -242,6 +243,7 @@ def test_refresh_token_view(self):
"id_token": provider.encode(
access.id_token.to_dict(),
),
"scope": "offline_access",
},
)
self.validate_jwt(access, provider)
Expand Down Expand Up @@ -301,6 +303,7 @@ def test_refresh_token_view_invalid_origin(self):
"id_token": provider.encode(
access.id_token.to_dict(),
),
"scope": "offline_access",
},
)

Expand Down
4 changes: 4 additions & 0 deletions authentik/providers/oauth2/views/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ def create_code_response(self) -> dict[str, Any]:
response = {
"access_token": access_token.token,
"token_type": TOKEN_TYPE,
"scope": " ".join(access_token.scope),
"expires_in": int(
timedelta_from_string(self.provider.access_token_validity).total_seconds()
),
Expand Down Expand Up @@ -710,6 +711,7 @@ def create_refresh_response(self) -> dict[str, Any]:
"access_token": access_token.token,
"refresh_token": refresh_token.token,
"token_type": TOKEN_TYPE,
"scope": " ".join(access_token.scope),
"expires_in": int(
timedelta_from_string(self.provider.access_token_validity).total_seconds()
),
Expand All @@ -736,6 +738,7 @@ def create_client_credentials_response(self) -> dict[str, Any]:
return {
"access_token": access_token.token,
"token_type": TOKEN_TYPE,
"scope": " ".join(access_token.scope),
"expires_in": int(
timedelta_from_string(self.provider.access_token_validity).total_seconds()
),
Expand Down Expand Up @@ -767,6 +770,7 @@ def create_device_code_response(self) -> dict[str, Any]:
response = {
"access_token": access_token.token,
"token_type": TOKEN_TYPE,
"scope": " ".join(access_token.scope),
"expires_in": int(
timedelta_from_string(self.provider.access_token_validity).total_seconds()
),
Expand Down
2 changes: 1 addition & 1 deletion authentik/stages/authenticator_webauthn/mds/blob.jwt

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion internal/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
func EnableDebugServer() {
l := log.WithField("logger", "authentik.go_debugger")
if !config.Get().Debug {
l.Info("not enabling debug server, set `AUTHENTIK_DEBUG` to `true` to enable it.")
return
}
h := mux.NewRouter()
Expand Down
8 changes: 6 additions & 2 deletions lifecycle/ak
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ function cleanup {
}

function prepare_debug {
# Only attempt to install debug dependencies if we're running in a container
if [ ! -d /ak-root ]; then
return
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y --no-install-recommends krb5-kdc krb5-user krb5-admin-server libkrb5-dev gcc
Expand All @@ -63,7 +67,7 @@ function prepare_debug {
chown authentik:authentik /unittest.xml
}

if [[ "${AUTHENTIK_REMOTE_DEBUG}" == "true" ]]; then
if [[ "$(python -m authentik.lib.config debugger 2> /dev/null)" == "True" ]]; then
prepare_debug
fi

Expand Down Expand Up @@ -92,7 +96,7 @@ elif [[ "$1" == "test-all" ]]; then
elif [[ "$1" == "healthcheck" ]]; then
run_authentik healthcheck $(cat $MODE_FILE)
elif [[ "$1" == "dump_config" ]]; then
exec python -m authentik.lib.config
exec python -m authentik.lib.config $@
elif [[ "$1" == "debug" ]]; then
exec sleep infinity
else
Expand Down
7 changes: 2 additions & 5 deletions lifecycle/gunicorn.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from authentik import get_full_version
from authentik.lib.config import CONFIG
from authentik.lib.debug import start_debug_server
from authentik.lib.logging import get_logger_config
from authentik.lib.utils.http import get_http_session
from authentik.lib.utils.reflection import get_env
Expand Down Expand Up @@ -146,9 +147,5 @@ def post_worker_init(worker: DjangoUvicornWorker):
except Exception: # nosec
pass

if CONFIG.get_bool("remote_debug"):
import debugpy

debugpy.listen(("0.0.0.0", 6800)) # nosec

start_debug_server()
run_migrations()
50 changes: 25 additions & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f62efb2

Please sign in to comment.