From 3e49acf7ae87ca66a4314a5c580563c3b9c8dcc1 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 13 Dec 2020 17:10:56 +0100 Subject: [PATCH] outposts: regularly ensure that all outposts have a valid service account and token --- authentik/outposts/settings.py | 5 +++++ authentik/outposts/tasks.py | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/authentik/outposts/settings.py b/authentik/outposts/settings.py index d6820a777..f02d4fa2a 100644 --- a/authentik/outposts/settings.py +++ b/authentik/outposts/settings.py @@ -12,4 +12,9 @@ CELERY_BEAT_SCHEDULE = { "schedule": crontab(minute=0, hour="*"), "options": {"queue": "authentik_scheduled"}, }, + "outpost_token_ensurer": { + "task": "authentik.outposts.tasks.outpost_token_ensurer", + "schedule": crontab(minute="*/5"), + "options": {"queue": "authentik_scheduled"}, + }, } diff --git a/authentik/outposts/tasks.py b/authentik/outposts/tasks.py index e0e455529..d5246c83b 100644 --- a/authentik/outposts/tasks.py +++ b/authentik/outposts/tasks.py @@ -90,6 +90,16 @@ def outpost_pre_delete(outpost_pk: str): ProxyKubernetesController(outpost, service_connection).down() +@CELERY_APP.task(bind=True, base=MonitoredTask) +def outpost_token_ensurer(self: MonitoredTask): + """Periodically ensure that all Outposts have valid Service Accounts + and Tokens""" + all_outposts = Outpost.objects.all() + for outpost in all_outposts: + _ = outpost.token + self.set_status(TaskResult(TaskResultStatus.SUCCESSFUL, f"Successfully checked {len(all_outposts)} Outposts.")) + + @CELERY_APP.task() def outpost_post_save(model_class: str, model_pk: Any): """If an Outpost is saved, Ensure that token is created/updated