Skip to content
Snippets Groups Projects
Commit 134bc228 authored by Václav Bartoš's avatar Václav Bartoš
Browse files

user cert is now revoked when user is deleted

parent 4097f905
No related branches found
No related tags found
No related merge requests found
...@@ -123,11 +123,17 @@ def revoke_certificate(cn: str): ...@@ -123,11 +123,17 @@ def revoke_certificate(cn: str):
:param cn: CN (common name) identifying the certificate :param cn: CN (common name) identifying the certificate
""" """
_check_cn(cn) _check_cn(cn)
raise NotImplementedError # Revoke the certificate
# cmd = [{EASYRSA}, "TODO", cn] cmd = [EASYRSA, "revoke", cn]
# result = subprocess.run(cmd, env=EASYRSA_ENV, stderr=subprocess.PIPE) result = subprocess.run(cmd, env=EASYRSA_ENV, stderr=subprocess.PIPE)
# if result.returncode != 0: if result.returncode != 0:
# raise CertError(f"Can't revoke the certificate for '{cn}': {result.stderr[:500]}") raise CertError(f"Can't revoke the certificate for '{cn}': {result.stderr[:500]}")
# Refresh the CRL list
cmd = [EASYRSA, "gen-crl"]
result = subprocess.run(cmd, env=EASYRSA_ENV, stderr=subprocess.PIPE)
if result.returncode != 0:
raise CertError(f"Certificate revoked, but there was an error during generating CRL: {result.stderr[:500]}")
# TODO check that Keycloak really looks into the CRL during user authentication
def get_pem_files(cn: str): def get_pem_files(cn: str):
......
...@@ -374,8 +374,6 @@ def add_user(): ...@@ -374,8 +374,6 @@ def add_user():
try: try:
certificates.generate_certificate(user.cn) certificates.generate_certificate(user.cn)
flash(f'Certificate for user "{user.username}" was successfully created.', "success") flash(f'Certificate for user "{user.username}" was successfully created.', "success")
except certificates.CertError as e: except certificates.CertError as e:
flash(str(e), "error") flash(str(e), "error")
return redirect_to_main_page() # don't continue creating user accounts in services return redirect_to_main_page() # don't continue creating user accounts in services
...@@ -531,12 +529,16 @@ def delete_user(username: str): ...@@ -531,12 +529,16 @@ def delete_user(username: str):
flash(f"Error: Can't get user info from KeyCloak: {e}", "error") flash(f"Error: Can't get user info from KeyCloak: {e}", "error")
return redirect_to_main_page() return redirect_to_main_page()
# TODO revoke certificate try:
certificates.revoke_certificate(user_spec.cn)
flash(f'Certificate for "{user_spec.cn}" revoked.', "success")
except certificates.CertError as e:
flash(f"Error: {e}", "error")
# Keycloak # Keycloak
try: try:
kc_delete_user(user_spec.kcid) kc_delete_user(user_spec.kcid)
flash('User successfully deleted from KeyCloak.', "success") flash(f'User "{user_spec.username}" successfully deleted from KeyCloak.', "success")
except KeycloakError as e: except KeycloakError as e:
flash(f'Error when deleting user from KeyCloak: {e}', "error") flash(f'Error when deleting user from KeyCloak: {e}', "error")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment