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

Method get_tok

salt/auth/__init__.py:300–422  ·  view source on GitHub ↗

Return the name associated with the token, or False if the token is not valid

(self, tok)

Source from the content-addressed store, hash-verified

298 return tdata
299
300 def get_tok(self, tok):
301 """
302 Return the name associated with the token, or False if the token is
303 not valid
304 """
305 if self.opts["eauth_tokens.cache_driver"] == "rediscluster":
306 salt.utils.versions.warn_until(
307 3010,
308 "The 'rediscluster' token backend has been deprecated, and will be removed "
309 "in the Calcium release. Please use the 'redis_cache' cache backend instead.",
310 )
311
312 tdata = {}
313 try:
314 tdata = self.tokens["{}.get_token".format(self.opts["eauth_tokens"])](
315 self.opts, tok
316 )
317 except salt.exceptions.SaltDeserializationError as exc:
318 # The on-disk / in-store token blob is corrupt and cannot
319 # be parsed. Removing it is the right call -- a corrupt
320 # token can never authenticate anyway, and leaving it
321 # around makes every subsequent ``get_tok`` for the same
322 # id keep failing. ``%r`` on the exception gives the
323 # operator the class and message inline (e.g. msgpack
324 # format error, truncated file) without spamming a full
325 # traceback into a hot-path WARNING; the full traceback is
326 # available via the companion ``log.debug`` for deeper
327 # investigation.
328 log.warning(
329 "Token %r could not be deserialized (%r); removing it from the store.",
330 tok,
331 exc,
332 )
333 log.debug("Token deserialization traceback:", exc_info=True)
334 rm_tok = True
335 except OSError as exc:
336 # Transient backend error (Redis connection blip, NFS hang,
337 # hung disk). The token itself is fine; do NOT delete it --
338 # that would log every authenticated user out on every
339 # backend hiccup. Return an empty dict so the caller treats
340 # this request as not-authenticated; the next request will
341 # retry against the backend and succeed once it recovers.
342 # Same logging pattern as above -- exception class + message
343 # at WARNING, full traceback at DEBUG so a flapping deploy
344 # stays diagnoseable without GB/hour of stack frames.
345 log.warning(
346 "Token store transient error reading %r (%r); treating as "
347 "not-authenticated for this request without removing the "
348 "token from the store.",
349 tok,
350 exc,
351 )
352 log.debug("Token store transient-error traceback:", exc_info=True)
353 return {}
354 else:
355 if not tdata:
356 return {}
357 rm_tok = False

Callers 15

clean_expired_tokensMethod · 0.95
authenticate_tokenMethod · 0.95
clean_expired_tokensFunction · 0.95
test_cve_2021_3244Function · 0.95
get_tokenMethod · 0.80
getMethod · 0.80
_verify_authMethod · 0.80
GETMethod · 0.80
get_tokenMethod · 0.80

Calls 8

rm_tokenMethod · 0.95
formatMethod · 0.80
warningMethod · 0.80
debugMethod · 0.80
timeMethod · 0.80
getMethod · 0.45
fetchMethod · 0.45
errorMethod · 0.45