MCPcopy Create free account
hub / github.com/saltstack/salt / authenticate_key

Method authenticate_key

salt/auth/__init__.py:533–595  ·  view source on GitHub ↗

Authenticate a user by the key passed in load. Return the effective user id (name) if it's different from the specified one (for sudo). If the effective user id is the same as the passed one, return True on success or False on failure.

(self, load, key)

Source from the content-addressed store, hash-verified

531 return True
532
533 def authenticate_key(self, load, key):
534 """
535 Authenticate a user by the key passed in load.
536 Return the effective user id (name) if it's different from the specified one (for sudo).
537 If the effective user id is the same as the passed one, return True on success or False on
538 failure.
539 """
540 error_msg = 'Authentication failure of type "user" occurred.'
541
542 auth_key = load.pop("key", None)
543 if auth_key is None:
544 log.warning(error_msg)
545 return False
546
547 if "user" in load:
548 auth_user = AuthUser(load["user"])
549 if auth_user.is_sudo():
550 for check_key in key:
551 if auth_key == key[check_key]:
552 return auth_user.sudo_name()
553 return False
554 elif (
555 load["user"] == self.opts.get("user", "root") or load["user"] == "root"
556 ):
557 for check_key in key:
558 if auth_key == key[check_key]:
559 return True
560 log.warning(
561 "Master runs as %r, but user in payload is %r",
562 self.opts.get("user", "root"),
563 load["user"],
564 )
565 log.warning(error_msg)
566 return False
567
568 elif auth_user.is_running_user():
569 if auth_key != key.get(load["user"]):
570 log.warning(error_msg)
571 return False
572 elif auth_key == key.get("root"):
573 pass
574 elif auth_key == key.get("salt"):
575 # there is nologin for salt
576 pass
577 else:
578 if load["user"] in key:
579 # User is authorised, check key and check perms
580 if auth_key != key[load["user"]]:
581 log.warning(error_msg)
582 return False
583 return load["user"]
584 else:
585 log.warning(error_msg)
586 return False
587 else:
588 for check_key in key:
589 if auth_key == key[check_key]:
590 return True

Callers 1

check_authenticationMethod · 0.95

Calls 7

is_sudoMethod · 0.95
sudo_nameMethod · 0.95
is_running_userMethod · 0.95
AuthUserClass · 0.85
warningMethod · 0.80
popMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected