Skip to content

Commit b3a58b8

Browse files
committed
cisagov#869, allow malcolm to start even if htpasswd isn't set for no_authentication method
1 parent 35251d6 commit b3a58b8

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

scripts/control.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,23 @@ def checkWiseFile():
463463
shutil.copyfile(wiseExampleFile, wiseFile)
464464

465465

466+
def getNginxAuthMethod():
467+
global args
468+
global dotenvImported
469+
470+
authCommonEnvFile = os.path.join(args.configDir, 'auth-common.env')
471+
if args.authMode:
472+
nginxAuthMode = str(args.authMode).lower()
473+
else:
474+
nginxAuthMode = 'unknown'
475+
if os.path.isfile(authCommonEnvFile):
476+
nginxAuthMode = str(
477+
dotenvImported.dotenv_values(authCommonEnvFile).get('NGINX_AUTH_MODE', nginxAuthMode)
478+
).lower()
479+
480+
return nginxAuthMode
481+
482+
466483
def malcolm_iso_services_op(start):
467484
global args
468485
global orchMode
@@ -1381,12 +1398,16 @@ def start():
13811398
# make sure the auth files exist. if we are in an interactive shell and we're
13821399
# missing any of the auth files, prompt to create them now
13831400
if sys.__stdin__.isatty() and (
1384-
not MalcolmAuthFilesExist(configDir=args.configDir, run_profile=args.composeProfile)
1401+
not MalcolmAuthFilesExist(
1402+
configDir=args.configDir, run_profile=args.composeProfile, auth_method=getNginxAuthMethod()
1403+
)
13851404
):
13861405
authSetup()
13871406

13881407
# still missing? sorry charlie
1389-
if not MalcolmAuthFilesExist(configDir=args.configDir, run_profile=args.composeProfile):
1408+
if not MalcolmAuthFilesExist(
1409+
configDir=args.configDir, run_profile=args.composeProfile, auth_method=getNginxAuthMethod()
1410+
):
13901411
raise Exception(
13911412
'Files relating to authentication and/or secrets are missing, please run ./scripts/auth_setup to generate them'
13921413
)
@@ -1655,15 +1676,8 @@ def authSetup():
16551676
authCommonEnvFile = os.path.join(args.configDir, 'auth-common.env')
16561677
nginxEnvFile = os.path.join(args.configDir, 'nginx.env')
16571678
openSearchEnvFile = os.path.join(args.configDir, 'opensearch.env')
1679+
nginxAuthMode = getNginxAuthMethod()
16581680

1659-
if args.authMode:
1660-
nginxAuthMode = str(args.authMode).lower()
1661-
else:
1662-
nginxAuthMode = 'unknown'
1663-
if os.path.isfile(authCommonEnvFile):
1664-
nginxAuthMode = str(
1665-
dotenvImported.dotenv_values(authCommonEnvFile).get('NGINX_AUTH_MODE', nginxAuthMode)
1666-
).lower()
16671681
netboxMode = ''
16681682
if os.path.isfile(netboxCommonEnvFile):
16691683
netboxMode = str(dotenvImported.dotenv_values(netboxCommonEnvFile).get('NETBOX_MODE', '')).lower()

scripts/malcolm_common.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,16 +1463,22 @@ def AuthFileCheck(fileName, allowEmpty=False):
14631463
return False
14641464

14651465

1466-
def MalcolmAuthFilesExist(configDir=None, run_profile=PROFILE_MALCOLM):
1466+
def MalcolmAuthFilesExist(configDir=None, run_profile=PROFILE_MALCOLM, auth_method=None):
14671467
configDirToCheck = (
14681468
configDir if configDir is not None and os.path.isdir(configDir) else os.path.join(MalcolmPath, 'config')
14691469
)
14701470
return (
14711471
(
14721472
(run_profile == PROFILE_HEDGEHOG)
14731473
or (
1474-
AuthFileCheck(os.path.join(MalcolmPath, os.path.join('nginx', 'htpasswd')), allowEmpty=True)
1475-
and AuthFileCheck(os.path.join(MalcolmPath, os.path.join('nginx', 'nginx_ldap.conf')), allowEmpty=True)
1474+
AuthFileCheck(
1475+
os.path.join(MalcolmPath, os.path.join('nginx', 'htpasswd')),
1476+
allowEmpty=(auth_method == 'no_authentication'),
1477+
)
1478+
and AuthFileCheck(
1479+
os.path.join(MalcolmPath, os.path.join('nginx', 'nginx_ldap.conf')),
1480+
allowEmpty=(auth_method != 'ldap'),
1481+
)
14761482
and AuthFileCheck(
14771483
os.path.join(MalcolmPath, os.path.join('nginx', os.path.join('certs', 'cert.pem'))), allowEmpty=True
14781484
)

0 commit comments

Comments
 (0)