Run time_auth and create a token. Return False or the token
(self, load)
| 237 | return False |
| 238 | |
| 239 | def mk_token(self, load): |
| 240 | """ |
| 241 | Run time_auth and create a token. Return False or the token |
| 242 | """ |
| 243 | if not self.authenticate_eauth(load): |
| 244 | return {} |
| 245 | |
| 246 | if self._allow_custom_expire(load): |
| 247 | token_expire = load.pop("token_expire", self.opts["token_expire"]) |
| 248 | else: |
| 249 | _ = load.pop("token_expire", None) |
| 250 | token_expire = self.opts["token_expire"] |
| 251 | |
| 252 | tdata = { |
| 253 | "start": time.time(), |
| 254 | "expire": time.time() + token_expire, |
| 255 | "name": self.load_name(load), |
| 256 | "eauth": load["eauth"], |
| 257 | } |
| 258 | |
| 259 | if self.opts["keep_acl_in_token"]: |
| 260 | acl_ret = self.__get_acl(load) |
| 261 | tdata["auth_list"] = acl_ret |
| 262 | |
| 263 | groups = self.get_groups(load) |
| 264 | if groups: |
| 265 | tdata["groups"] = groups |
| 266 | |
| 267 | if self.opts["eauth_tokens.cache_driver"] == "rediscluster": |
| 268 | salt.utils.versions.warn_until( |
| 269 | 3010, |
| 270 | "The 'rediscluster' token backend has been deprecated, and will be removed " |
| 271 | "in the Calcium release. Please use the 'redis_cache' cache backend instead.", |
| 272 | ) |
| 273 | return self.tokens["{}.mk_token".format(self.opts["eauth_tokens"])]( |
| 274 | self.opts, tdata |
| 275 | ) |
| 276 | else: |
| 277 | hash_type = getattr(hashlib, self.opts.get("hash_type", "md5")) |
| 278 | new_token = str(hash_type(os.urandom(512)).hexdigest()) |
| 279 | tdata["token"] = new_token |
| 280 | try: |
| 281 | # ``Cache.store``'s ``expires`` is a *relative* duration in |
| 282 | # seconds, not an absolute epoch. Passing ``tdata["expire"]`` |
| 283 | # here -- which is ``time.time() + token_expire`` -- caused |
| 284 | # the envelope ``_expires`` to be set to ``now + (now + |
| 285 | # token_expire)`` (~ year 4090), and combined with the |
| 286 | # broken ``Cache.clean_expired`` fallback resulted in tokens |
| 287 | # being deleted within a single master loop interval. |
| 288 | # Issue #69307. |
| 289 | self.cache.store("tokens", new_token, tdata, expires=token_expire) |
| 290 | except salt.exceptions.SaltCacheError as err: |
| 291 | log.error( |
| 292 | "Cannot mk_token from tokens cache using %s: %s", |
| 293 | self.opts["eauth_tokens.cache_driver"], |
| 294 | err, |
| 295 | ) |
| 296 | return {} |