-
Notifications
You must be signed in to change notification settings - Fork 0
Add randkey for krb api 1225 #924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
284429d
d4962a4
0d54a13
d08f664
77d0720
888fe0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Чет не понял. А ручка reset_principal_pw остается ? Почему теперь две ручки могут изменить пароль принципалу ? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,12 @@ | |
| DomainErrorTranslator, | ||
| ) | ||
| from api.main.adapters.kerberos import KerberosFastAPIAdapter | ||
| from api.main.schema import KerberosSetupRequest | ||
| from api.main.schema import ( | ||
| KerberosSetupRequest, | ||
| KtaddRequest, | ||
| PrincipalAddRequest, | ||
| PrincipalPutRequest, | ||
| ) | ||
| from api.utils import require_master_db | ||
| from enums import DomainCodes | ||
| from ldap_protocol.dialogue import LDAPSession | ||
|
|
@@ -149,15 +154,15 @@ async def setup_kdc( | |
| error_map=error_map, | ||
| ) | ||
| async def ktadd( | ||
| names: Annotated[LIMITED_LIST, Body()], | ||
| kerberos_adapter: FromDishka[KerberosFastAPIAdapter], | ||
| request: KtaddRequest, | ||
| ) -> StreamingResponse: | ||
| """Create keytab from kadmin server. | ||
|
|
||
| :param Annotated[LDAPSession, Depends ldap_session: ldap | ||
| :return bytes: file | ||
| """ | ||
| return await kerberos_adapter.ktadd(names) | ||
| return await kerberos_adapter.ktadd(request) | ||
|
|
||
|
|
||
| @krb5_router.get( | ||
|
|
@@ -178,13 +183,12 @@ async def get_krb_status( | |
|
|
||
|
|
||
| @krb5_router.post( | ||
| "/principal/add", | ||
| "/principal", | ||
| dependencies=[Depends(verify_auth), Depends(require_master_db)], | ||
| error_map=error_map, | ||
| ) | ||
| async def add_principal( | ||
| primary: Annotated[LIMITED_STR, Body()], | ||
| instance: Annotated[LIMITED_STR, Body()], | ||
| request: PrincipalAddRequest, | ||
| kerberos_adapter: FromDishka[KerberosFastAPIAdapter], | ||
| ) -> None: | ||
| """Create principal in kerberos with given name. | ||
|
|
@@ -194,31 +198,19 @@ async def add_principal( | |
| :param Annotated[LDAPSession, Depends ldap_session: ldap | ||
| :raises HTTPException: on failed kamin request. | ||
| """ | ||
| await kerberos_adapter.add_principal(primary, instance) | ||
| await kerberos_adapter.add_principal(request) | ||
|
|
||
|
|
||
| @krb5_router.patch( | ||
| "/principal/rename", | ||
| @krb5_router.put( | ||
| "/principal", | ||
| dependencies=[Depends(verify_auth), Depends(require_master_db)], | ||
| error_map=error_map, | ||
| ) | ||
| async def rename_principal( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename - > modify |
||
| principal_name: Annotated[LIMITED_STR, Body()], | ||
| principal_new_name: Annotated[LIMITED_STR, Body()], | ||
| request: PrincipalPutRequest, | ||
| kerberos_adapter: FromDishka[KerberosFastAPIAdapter], | ||
| ) -> None: | ||
| """Rename principal in kerberos with given name. | ||
|
|
||
| \f | ||
| :param Annotated[str, Body principal_name: upn | ||
| :param Annotated[LIMITED_STR, Body principal_new_name: _description_ | ||
| :param Annotated[LDAPSession, Depends ldap_session: ldap | ||
| :raises HTTPException: on failed kamin request. | ||
| """ | ||
| await kerberos_adapter.rename_principal( | ||
| principal_name, | ||
| principal_new_name, | ||
| ) | ||
| await kerberos_adapter.rename_principal(request) | ||
|
|
||
|
|
||
| @krb5_router.patch( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,8 +153,9 @@ async def setup( | |
| @abstractmethod | ||
| async def add_principal( | ||
| self, | ||
| name: str, | ||
| password: str | None, | ||
| principal_name: str, | ||
| password: str | None = None, | ||
| algorithms: list[str] | None = None, | ||
| timeout: int | float = 1, | ||
| ) -> None: ... | ||
|
|
||
|
|
@@ -179,7 +180,13 @@ async def create_or_update_principal_pw( | |
| ) -> None: ... | ||
|
|
||
| @abstractmethod | ||
| async def rename_princ(self, name: str, new_name: str) -> None: ... | ||
| async def rename_princ( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename -> modify |
||
| self, | ||
| name: str, | ||
| new_name: str, | ||
| algorithms: list[str] | None = None, | ||
| password: str | None = None, | ||
| ) -> None: ... | ||
|
|
||
| @backoff.on_exception( | ||
| backoff.constant, | ||
|
|
@@ -202,7 +209,11 @@ async def get_status(self, wait_for_positive: bool = False) -> bool: | |
| return status | ||
|
|
||
| @abstractmethod | ||
| async def ktadd(self, names: list[str]) -> httpx.Response: ... | ||
| async def ktadd( | ||
| self, | ||
| names: list[str], | ||
| is_rand_key: bool, | ||
| ) -> httpx.Response: ... | ||
|
|
||
| @abstractmethod | ||
| async def lock_principal(self, name: str) -> None: ... | ||
|
|
@@ -221,14 +232,17 @@ async def ldap_principal_setup(self, name: str, path: str) -> None: | |
| if response.status_code == 200: | ||
| return | ||
|
|
||
| response = await self.client.post("/principal", json={"name": name}) | ||
| response = await self.client.post( | ||
| "/principal", | ||
| json={"principal_name": name}, | ||
| ) | ||
| if response.status_code != 201: | ||
| log.error(f"Error creating ldap principal: {response.text}") | ||
| return | ||
|
|
||
| response = await self.client.post( | ||
| "/principal/ktadd", | ||
| json=[name], | ||
| json={"names": [name], "is_rand_key": True}, | ||
| ) | ||
| if response.status_code != 200: | ||
| log.error(f"Error getting keytab: {response.text}") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,12 +20,17 @@ async def add_principal( | |
| self, | ||
| name: str, | ||
| password: str | None, | ||
| timeout: int = 1, | ||
| algorithms: list[str] | None = None, | ||
| timeout: int | float = 1, | ||
| ) -> None: | ||
| """Add request.""" | ||
| response = await self.client.post( | ||
| "principal", | ||
| json={"name": name, "password": password}, | ||
| json={ | ||
| "name": name, | ||
| "password": password, | ||
| "algorithms": algorithms, | ||
| }, | ||
| timeout=timeout, | ||
| ) | ||
|
|
||
|
|
@@ -89,17 +94,32 @@ async def create_or_update_principal_pw( | |
| raise krb_exc.KRBAPIChangePasswordError(response.text) | ||
|
|
||
| @logger_wraps() | ||
| async def rename_princ(self, name: str, new_name: str) -> None: | ||
| async def rename_princ( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename -> modify |
||
| self, | ||
| name: str, | ||
| new_name: str, | ||
| algorithms: list[str] | None, | ||
| password: str | None, | ||
| ) -> None: | ||
| """Rename request.""" | ||
| response = await self.client.put( | ||
| "principal", | ||
| json={"name": name, "new_name": new_name}, | ||
| json={ | ||
| "name": name, | ||
| "new_name": new_name, | ||
| "algorithms": algorithms, | ||
| "password": password, | ||
| }, | ||
| ) | ||
| if response.status_code != 202: | ||
| raise krb_exc.KRBAPIRenamePrincipalError(response.text) | ||
|
|
||
| @logger_wraps() | ||
| async def ktadd(self, names: list[str]) -> httpx.Response: | ||
| async def ktadd( | ||
| self, | ||
| names: list[str], | ||
| is_rand_key: bool, | ||
| ) -> httpx.Response: | ||
| """Ktadd build request for stream and return response. | ||
|
|
||
| :param list[str] names: principals | ||
|
|
@@ -108,7 +128,7 @@ async def ktadd(self, names: list[str]) -> httpx.Response: | |
| request = self.client.build_request( | ||
| "POST", | ||
| "/principal/ktadd", | ||
| json=names, | ||
| json={"names": names, "is_rand_key": is_rand_key}, | ||
| ) | ||
|
|
||
| response = await self.client.send(request, stream=True) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename -> modify