.. versionadded:: 2018.3.0 Go through various checks to see if the token/eauth/user can be authenticated. Returns a dictionary containing the following keys: - auth_list - username - error If an error is encountered, return immediately wit
(self, load, auth_type, key=None, show_username=False)
| 641 | return auth_list |
| 642 | |
| 643 | def check_authentication(self, load, auth_type, key=None, show_username=False): |
| 644 | """ |
| 645 | .. versionadded:: 2018.3.0 |
| 646 | |
| 647 | Go through various checks to see if the token/eauth/user can be authenticated. |
| 648 | |
| 649 | Returns a dictionary containing the following keys: |
| 650 | |
| 651 | - auth_list |
| 652 | - username |
| 653 | - error |
| 654 | |
| 655 | If an error is encountered, return immediately with the relevant error dictionary |
| 656 | as authentication has failed. Otherwise, return the username and valid auth_list. |
| 657 | """ |
| 658 | auth_list = [] |
| 659 | username = load.get("username", "UNKNOWN") |
| 660 | ret = {"auth_list": auth_list, "username": username, "error": {}} |
| 661 | |
| 662 | # Authenticate |
| 663 | if auth_type == "token": |
| 664 | token = self.authenticate_token(load) |
| 665 | if not token: |
| 666 | ret["error"] = { |
| 667 | "name": "TokenAuthenticationError", |
| 668 | "message": 'Authentication failure of type "token" occurred.', |
| 669 | } |
| 670 | return ret |
| 671 | |
| 672 | # Update username for token |
| 673 | username = token["name"] |
| 674 | ret["username"] = username |
| 675 | auth_list = self.get_auth_list(load, token=token) |
| 676 | elif auth_type == "eauth": |
| 677 | if not self.authenticate_eauth(load): |
| 678 | ret["error"] = { |
| 679 | "name": "EauthAuthenticationError", |
| 680 | "message": 'Authentication failure of type "eauth" occurred for user {}.'.format( |
| 681 | username |
| 682 | ), |
| 683 | } |
| 684 | return ret |
| 685 | |
| 686 | auth_list = self.get_auth_list(load) |
| 687 | elif auth_type == "user": |
| 688 | auth_ret = self.authenticate_key(load, key) |
| 689 | msg = 'Authentication failure of type "user" occurred' |
| 690 | if not auth_ret: # auth_ret can be a boolean or the effective user id |
| 691 | if show_username: |
| 692 | msg = f"{msg} for user {username}." |
| 693 | ret["error"] = {"name": "UserAuthenticationError", "message": msg} |
| 694 | return ret |
| 695 | |
| 696 | # Verify that the caller has root on master |
| 697 | if auth_ret is not True: |
| 698 | if AuthUser(load["user"]).is_sudo(): |
| 699 | if not self.opts["sudo_acl"] or not self.opts["publisher_acl"]: |
| 700 | auth_ret = True |
no test coverage detected