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