Skip to content

Commit fc81e13

Browse files
Move security exclusion from .bandit.ini to the corresponding code line
To avoid global security exclusions, the bandit check skips have been moved to the line of the issue. Signed-off-by: Francesco Giordano <[email protected]>
1 parent 8449c12 commit fc81e13

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

.bandit.ini

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
# B105 checks for potentially hard-coded passwords/API tokens.
2-
# It's disabled because it seems to have a high rate of false failures.
3-
# B404 checks for imports of the subprocess module.
4-
# It's disabled because we make use of that module.
5-
skips: ['B105', 'B404']
1+
skips: []

.isort.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ known_third_party=assertpy,boto3,botocore,dcv,gnupg,jinja2,jsonschema,pytest,req
1010
# )
1111
multi_line_output=3
1212
include_trailing_comma=true
13+
profile=black

cookbooks/aws-parallelcluster-config/files/default/dcv/pcluster_dcv_authenticator.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
import re
2020
import ssl
2121
import string
22-
import subprocess
22+
23+
# A nosec comment is appended to the following line in order to disable the B404 check.
24+
# In this file the input of the module subprocess is trusted.
25+
import subprocess # nosec
2326
import sys
2427
import time
2528
from collections import OrderedDict, namedtuple
@@ -130,7 +133,9 @@ class IncorrectRequestError(Exception):
130133

131134
USER_REGEX = r"^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$"
132135
SESSION_ID_REGEX = r"^([a-zA-Z0-9_-]{0,128})$"
133-
TOKEN_REGEX = r"^([a-zA-Z0-9_-]{256})$"
136+
# A nosec comment is appended to the following line in order to disable the B105 check.
137+
# Since the TOKEN_REGEX is not a hardcoded password
138+
TOKEN_REGEX = r"^([a-zA-Z0-9_-]{256})$" # nosec
134139

135140
MAX_NUMBER_OF_REQUEST_TOKENS = 500
136141
MAX_NUMBER_OF_SESSION_TOKENS = 100

cookbooks/aws-parallelcluster-install/files/default/clusterstatusmgtd/clusterstatusmgtd.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
import logging
1616
import os
1717
import shlex
18-
import subprocess
18+
19+
# A nosec comment is appended to the following line in order to disable the B404 check.
20+
# In this file the input of the module subprocess is trusted.
21+
import subprocess # nosec
1922
import time
2023
from configparser import ConfigParser
2124
from datetime import datetime, timezone

test/unit/dcv/test_dcv_authenticator.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ def test_get_request_token_parameter(parameters, keys, result):
161161

162162
def test_get_request_token(mocker):
163163
"""Verify the first step of the authentication process, the retrieval of the Request Token."""
164-
token_value = "1234abcd_-"
164+
# A nosec comment is appended to the following line in order to disable the B105 check.
165+
# Since the session token is not a hardcoded password
166+
token_value = "1234abcd_-" # nosec
165167
user = "centos"
166168
session_id = "mysession"
167169

@@ -288,7 +290,9 @@ def test_get_session_token(mocker):
288290
# working
289291
mock_os(mocker, user, obtain_timestamp(datetime.utcnow()))
290292
mock_verify_session_existence(mocker, exists=True)
291-
session_token = "1234"
293+
# A nosec comment is appended to the following line in order to disable the B105 check.
294+
# Since the session token is not a hardcoded password
295+
session_token = "1234" # nosec
292296
mock_generate_random_token(mocker, session_token)
293297
DCVAuthenticator.request_token_manager.add_token(
294298
request_token, DCVAuthenticator.RequestTokenInfo(user, session_id, datetime.utcnow(), access_file)

0 commit comments

Comments
 (0)