Fixes for issues found by tests.

This commit is contained in:
Dmitry Kuzmenko 2020-08-28 17:18:26 +03:00 committed by Daniel Wozniak
parent af185d74eb
commit a522bcfdaf
3 changed files with 11 additions and 50 deletions

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Beacon to fire events at failed login of users
@ -91,26 +90,14 @@ Match the event like so in the master config file:
on how to set up a bot user.
"""
# Import python libs
from __future__ import absolute_import, unicode_literals
import datetime
import logging
import os
import struct
# Import 3rd-party libs
import salt.ext.six
import salt.utils.files
# Import Salt Libs
import salt.utils.stringutils
# pylint: disable=import-error
from salt.ext.six.moves import map
# pylint: enable=import-error
__virtualname__ = "btmp"
BTMP = "/var/log/btmp"
FMT = b"hi32s4s32s256shhiii4i20x"
@ -131,7 +118,6 @@ LOC_KEY = "btmp.loc"
log = logging.getLogger(__name__)
# pylint: disable=import-error
try:
import dateutil.parser as dateutil_parser
@ -295,7 +281,7 @@ def beacon(config):
event = {}
for ind, field in enumerate(FIELDS):
event[field] = pack[ind]
if isinstance(event[field], salt.ext.six.string_types):
if isinstance(event[field], (str, bytes)):
if isinstance(event[field], bytes):
event[field] = salt.utils.stringutils.to_unicode(event[field])
event[field] = event[field].strip("\x00")

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Beacon to fire events at login of users as registered in the wtmp file
@ -117,27 +116,14 @@ Match the event like so in the master config file:
on how to set up a bot user.
"""
# Import Python libs
from __future__ import absolute_import, unicode_literals
import datetime
import logging
import os
import struct
import salt.utils.files
# Import salt libs
import salt.utils.stringutils
# Import 3rd-party libs
from salt.ext import six
# pylint: disable=import-error
from salt.ext.six.moves import map
# pylint: enable=import-error
__virtualname__ = "wtmp"
WTMP = "/var/log/wtmp"
FMT = b"hi32s4s32s256shhiii4i20x"
@ -161,7 +147,6 @@ LOGOUT_TYPE = 8
log = logging.getLogger(__name__)
# pylint: disable=import-error
try:
import dateutil.parser as dateutil_parser
@ -338,7 +323,7 @@ def beacon(config):
event = {}
for ind, field in enumerate(FIELDS):
event[field] = pack[ind]
if isinstance(event[field], six.string_types):
if isinstance(event[field], (str, bytes)):
if isinstance(event[field], bytes):
event[field] = salt.utils.stringutils.to_unicode(event[field])
event[field] = event[field].strip("\x00")
@ -346,14 +331,14 @@ def beacon(config):
if event["type"] == login_type:
event["action"] = "login"
# Store the tty to identify the logout event
__context__["{0}{1}".format(TTY_KEY_PREFIX, event["line"])] = event[
__context__["{}{}".format(TTY_KEY_PREFIX, event["line"])] = event[
"user"
]
elif event["type"] == logout_type:
event["action"] = "logout"
try:
event["user"] = __context__.pop(
"{0}{1}".format(TTY_KEY_PREFIX, event["line"])
"{}{}".format(TTY_KEY_PREFIX, event["line"])
)
except KeyError:
pass

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
r"""
.. _`AWS KMS Envelope Encryption`: https://docs.aws.amazon.com/kms/latest/developerguide/workflow.html
@ -63,18 +62,11 @@ data like so:
a-secret: gAAAAABaj5uzShPI3PEz6nL5Vhk2eEHxGXSZj8g71B84CZsVjAAtDFY1mfjNRl-1Su9YVvkUzNjI4lHCJJfXqdcTvwczBYtKy0Pa7Ri02s10Wn1tF0tbRwk=
"""
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
import base64
import logging
# Import salt libs
import salt.utils.stringio
# Import 3rd-party libs
from salt.ext import six
try:
import botocore.exceptions
import boto3
@ -149,14 +141,14 @@ def _session():
profile_name or "default"
)
config_error = salt.exceptions.SaltConfigurationError(err_msg)
six.raise_from(config_error, orig_exc)
raise config_error from orig_exc
except botocore.exceptions.NoRegionError as orig_exc:
err_msg = (
"Boto3 was unable to determine the AWS "
"endpoint region using the {} profile."
).format(profile_name or "default")
config_error = salt.exceptions.SaltConfigurationError(err_msg)
six.raise_from(config_error, orig_exc)
raise config_error from orig_exc
def _kms():
@ -181,7 +173,7 @@ def _api_decrypt():
raise
err_msg = "aws_kms:data_key is not a valid KMS data key"
config_error = salt.exceptions.SaltConfigurationError(err_msg)
six.raise_from(config_error, orig_exc)
raise config_error from orig_exc
def _plaintext_data_key():
@ -227,7 +219,7 @@ def _decrypt_ciphertext(cipher, translate_newlines=False):
plain_text = fernet.Fernet(data_key).decrypt(cipher)
if hasattr(plain_text, "decode"):
plain_text = plain_text.decode(__salt_system_encoding__)
return six.text_type(plain_text)
return str(plain_text)
def _decrypt_object(obj, translate_newlines=False):
@ -239,14 +231,14 @@ def _decrypt_object(obj, translate_newlines=False):
"""
if salt.utils.stringio.is_readable(obj):
return _decrypt_object(obj.getvalue(), translate_newlines)
if isinstance(obj, six.string_types):
if isinstance(obj, (str, bytes)):
try:
return _decrypt_ciphertext(obj, translate_newlines=translate_newlines)
except (fernet.InvalidToken, TypeError):
return obj
elif isinstance(obj, dict):
for key, value in six.iteritems(obj):
for key, value in obj.items():
obj[key] = _decrypt_object(value, translate_newlines=translate_newlines)
return obj
elif isinstance(obj, list):
@ -257,9 +249,7 @@ def _decrypt_object(obj, translate_newlines=False):
return obj
def render(
data, saltenv="base", sls="", argline="", **kwargs
): # pylint: disable=unused-argument
def render(data, saltenv="base", sls="", argline="", **kwargs):
"""
Decrypt the data to be rendered that was encrypted using AWS KMS envelope encryption.
"""