@@ -1206,7 +1206,7 @@ def create_ingress_controller(v1: CoreV1Api, apps_v1_api: AppsV1Api, cli_argumen
1206
1206
1207
1207
1208
1208
def create_ingress_controller_wafv5 (
1209
- v1 : CoreV1Api , apps_v1_api : AppsV1Api , cli_arguments , namespace , reg_secret , args = None
1209
+ v1 : CoreV1Api , apps_v1_api : AppsV1Api , cli_arguments , namespace , reg_secret , args = None , rorfs = False
1210
1210
) -> str :
1211
1211
"""
1212
1212
Create an Ingress Controller according to the params.
@@ -1225,6 +1225,9 @@ def create_ingress_controller_wafv5(
1225
1225
dep ["spec" ]["replicas" ] = int (cli_arguments ["replicas" ])
1226
1226
dep ["spec" ]["template" ]["spec" ]["containers" ][0 ]["image" ] = cli_arguments ["image" ]
1227
1227
dep ["spec" ]["template" ]["spec" ]["containers" ][0 ]["imagePullPolicy" ] = cli_arguments ["image-pull-policy" ]
1228
+ if "readOnlyRootFilesystem" not in dep ["spec" ]["template" ]["spec" ]["containers" ][0 ]["securityContext" ]:
1229
+ dep ["spec" ]["template" ]["spec" ]["containers" ][0 ]["securityContext" ]["readOnlyRootFilesystem" ] = rorfs
1230
+
1228
1231
template_spec = dep ["spec" ]["template" ]["spec" ]
1229
1232
if "imagePullSecrets" not in template_spec :
1230
1233
template_spec ["imagePullSecrets" ] = []
@@ -1233,43 +1236,109 @@ def create_ingress_controller_wafv5(
1233
1236
if "volumes" not in template_spec :
1234
1237
template_spec ["volumes" ] = []
1235
1238
1236
- template_spec ["volumes" ].extend (
1237
- [
1238
- {
1239
- "name" : "app-protect-bd-config" ,
1240
- "emptyDir" : {},
1241
- },
1242
- {
1243
- "name" : "app-protect-config" ,
1244
- "emptyDir" : {},
1245
- },
1246
- {
1247
- "name" : "app-protect-bundles" ,
1248
- "emptyDir" : {},
1249
- },
1250
- ]
1251
- )
1239
+ if rorfs and "initContainers" not in template_spec :
1240
+ template_spec ["initContainers" ] = []
1241
+ template_spec ["initContainers" ].extend (
1242
+ [
1243
+ {
1244
+ "name" : "init-nginx-ingress" ,
1245
+ "image" : cli_arguments ["image" ],
1246
+ "imagePullPolicy" : "IfNotPresent" ,
1247
+ "command" : ["cp" , "-vdR" , "/etc/nginx/." , "/mnt/etc" ],
1248
+ "securityContext" : {
1249
+ "allowPrivilegeEscalation" : False ,
1250
+ "readOnlyRootFilesystem" : True ,
1251
+ "runAsUser" : 101 , # nginx
1252
+ "runAsNonRoot" : True ,
1253
+ "capabilities" : {"drop" : ["ALL" ]},
1254
+ },
1255
+ "volumeMounts" : [{"mountPath" : "/mnt/etc" , "name" : "nginx-etc" }],
1256
+ }
1257
+ ]
1258
+ )
1259
+
1260
+ if rorfs :
1261
+ template_spec ["volumes" ].extend (
1262
+ [
1263
+ {
1264
+ "name" : "app-protect-bd-config" ,
1265
+ "emptyDir" : {},
1266
+ },
1267
+ {
1268
+ "name" : "app-protect-config" ,
1269
+ "emptyDir" : {},
1270
+ },
1271
+ {
1272
+ "name" : "app-protect-bundles" ,
1273
+ "emptyDir" : {},
1274
+ },
1275
+ {"name" : "nginx-etc" , "emptyDir" : {}},
1276
+ {"name" : "nginx-log" , "emptyDir" : {}},
1277
+ {"name" : "nginx-cache" , "emptyDir" : {}},
1278
+ {"name" : "nginx-lib" , "emptyDir" : {}},
1279
+ ]
1280
+ )
1281
+ else :
1282
+ template_spec ["volumes" ].extend (
1283
+ [
1284
+ {
1285
+ "name" : "app-protect-bd-config" ,
1286
+ "emptyDir" : {},
1287
+ },
1288
+ {
1289
+ "name" : "app-protect-config" ,
1290
+ "emptyDir" : {},
1291
+ },
1292
+ {
1293
+ "name" : "app-protect-bundles" ,
1294
+ "emptyDir" : {},
1295
+ },
1296
+ ]
1297
+ )
1252
1298
1253
1299
container = dep ["spec" ]["template" ]["spec" ]["containers" ][0 ]
1254
1300
if "volumeMounts" not in container :
1255
1301
container ["volumeMounts" ] = []
1256
1302
1257
- container ["volumeMounts" ].extend (
1258
- [
1259
- {
1260
- "name" : "app-protect-bd-config" ,
1261
- "mountPath" : "/opt/app_protect/bd_config" ,
1262
- },
1263
- {
1264
- "name" : "app-protect-config" ,
1265
- "mountPath" : "/opt/app_protect/config" ,
1266
- },
1267
- {
1268
- "name" : "app-protect-bundles" ,
1269
- "mountPath" : "/etc/app_protect/bundles" ,
1270
- },
1271
- ]
1272
- )
1303
+ if rorfs :
1304
+ container ["volumeMounts" ].extend (
1305
+ [
1306
+ {
1307
+ "name" : "app-protect-bd-config" ,
1308
+ "mountPath" : "/opt/app_protect/bd_config" ,
1309
+ },
1310
+ {
1311
+ "name" : "app-protect-config" ,
1312
+ "mountPath" : "/opt/app_protect/config" ,
1313
+ },
1314
+ {
1315
+ "name" : "app-protect-bundles" ,
1316
+ "mountPath" : "/etc/app_protect/bundles" ,
1317
+ },
1318
+ {"name" : "nginx-etc" , "mountPath" : "/etc/nginx" },
1319
+ {"name" : "nginx-log" , "mountPath" : "/var/log/nginx" },
1320
+ {"name" : "nginx-cache" , "mountPath" : "/var/cache/nginx" },
1321
+ {"name" : "nginx-lib" , "mountPath" : "/var/lib/nginx" },
1322
+ ]
1323
+ )
1324
+ else :
1325
+ container ["volumeMounts" ].extend (
1326
+ [
1327
+ {
1328
+ "name" : "app-protect-bd-config" ,
1329
+ "mountPath" : "/opt/app_protect/bd_config" ,
1330
+ },
1331
+ {
1332
+ "name" : "app-protect-config" ,
1333
+ "mountPath" : "/opt/app_protect/config" ,
1334
+ },
1335
+ {
1336
+ "name" : "app-protect-bundles" ,
1337
+ "mountPath" : "/etc/app_protect/bundles" ,
1338
+ },
1339
+ ]
1340
+ )
1341
+
1273
1342
dep ["spec" ]["template" ]["spec" ]["containers" ][0 ]["args" ].extend (
1274
1343
[
1275
1344
f"-default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret" ,
@@ -1281,7 +1350,11 @@ def create_ingress_controller_wafv5(
1281
1350
"name" : "waf-config-mgr" ,
1282
1351
"image" : f"{ NGX_REG } /nap/waf-config-mgr:{ WAF_V5_VERSION } " ,
1283
1352
"imagePullPolicy" : "IfNotPresent" ,
1284
- "securityContext" : {"allowPrivilegeEscalation" : False , "capabilities" : {"drop" : ["all" ]}},
1353
+ "securityContext" : {
1354
+ "allowPrivilegeEscalation" : False ,
1355
+ "capabilities" : {"drop" : ["all" ]},
1356
+ "readOnlyRootFilesystem" : rorfs ,
1357
+ },
1285
1358
"volumeMounts" : [
1286
1359
{
1287
1360
"name" : "app-protect-bd-config" ,
@@ -1301,6 +1374,11 @@ def create_ingress_controller_wafv5(
1301
1374
"name" : "waf-enforcer" ,
1302
1375
"image" : f"{ NGX_REG } /nap/waf-enforcer:{ WAF_V5_VERSION } " ,
1303
1376
"imagePullPolicy" : "IfNotPresent" ,
1377
+ "securityContext" : {
1378
+ "allowPrivilegeEscalation" : False ,
1379
+ "capabilities" : {"drop" : ["all" ]},
1380
+ "readOnlyRootFilesystem" : rorfs ,
1381
+ },
1304
1382
"env" : [{"name" : "ENFORCER_PORT" , "value" : "50000" }],
1305
1383
"volumeMounts" : [
1306
1384
{
0 commit comments