fix bug in keycloak cron not writing newline speparators to authorized_keys
All checks were successful
Build Container / Build Container (push) Successful in 4m29s

This commit is contained in:
lilly 2026-07-21 21:48:01 +02:00
commit 14730ecb47
Signed by: lilly
SSH key fingerprint: SHA256:y9T5GFw2A20WVklhetIxG1+kcg/Ce0shnQmbu1LQ37g

View file

@ -11,6 +11,9 @@ from simple_openid_connect.data import TokenErrorResponse
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
CRON_INTERVAL_MIN = 13.37
class ClientCredentialsAuth: class ClientCredentialsAuth:
def __init__(self, oidc_client: OpenidClient): def __init__(self, oidc_client: OpenidClient):
self.oidc_client = oidc_client self.oidc_client = oidc_client
@ -65,7 +68,7 @@ class KeycloakClient:
except Exception as e: except Exception as e:
logger.exception(f"Error in Keycloak cron task: {e}") logger.exception(f"Error in Keycloak cron task: {e}")
finally: finally:
await asyncio.sleep(15 * 60) # 15 minutes await asyncio.sleep(CRON_INTERVAL_MIN * 60)
async def fetch_ssh_keys(self): async def fetch_ssh_keys(self):
logger.info("Fetching ssh keys from keycloak") logger.info("Fetching ssh keys from keycloak")
@ -80,7 +83,7 @@ class KeycloakClient:
async def write_authorized_keys(self): async def write_authorized_keys(self):
logger.info(f"Writing authorized keys to {self.authorized_keys_file.absolute()}") logger.info(f"Writing authorized keys to {self.authorized_keys_file.absolute()}")
with self.authorized_keys_file.open(mode="wt", encoding="UTF-8") as f: with self.authorized_keys_file.open(mode="wt", encoding="UTF-8") as f:
f.writelines(self.ssh_keys) f.writelines([f"{i}\n" for i in self.ssh_keys])
self.authorized_keys_file.chmod(stat.S_IWUSR | stat.S_IRUSR) self.authorized_keys_file.chmod(stat.S_IWUSR | stat.S_IRUSR)