Skip to content

Commit de110ed

Browse files
authored
[confcom] Add a warning and path for default change for stdio (#9203)
* Add a warning and path for default change for stdio * Satisfy azdev style * Fix help string for --enable-stdio * Refactor resolving stdio into it's own function * Bump version * Bump minor version
1 parent b87bebe commit de110ed

File tree

5 files changed

+65
-15
lines changed

5 files changed

+65
-15
lines changed

src/confcom/HISTORY.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
Release History
44
===============
55

6-
1.2.8
6+
1.3.0
77
++++++
8-
* Made the default minimum SVN of the infrastructure fragment 4
8+
* Add a new --enable-stdio flag, with a warning if neither this or --disable-stdio is set
99

1010
1.2.7
1111
++++++

src/confcom/azext_confcom/_params.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
validate_fragment_json,
2424
validate_fragment_json_policy,
2525
validate_image_target,
26+
validate_stdio,
2627
validate_upload_fragment,
2728
validate_infrastructure_svn,
2829
)
@@ -105,9 +106,15 @@ def load_arguments(self, _):
105106
)
106107
c.argument(
107108
"disable_stdio",
108-
options_list=("--disable-stdio",),
109-
required=False,
109+
action="store_true",
110110
help="Disabling container stdio will disable the ability to see the output of the container in the terminal for Confidential ACI",
111+
validator=validate_stdio,
112+
)
113+
c.argument(
114+
"enable_stdio",
115+
action="store_true",
116+
help="Enable the standard io streams to leave the container",
117+
validator=validate_stdio,
111118
)
112119
c.argument(
113120
"diff",
@@ -290,9 +297,15 @@ def load_arguments(self, _):
290297
)
291298
c.argument(
292299
"disable_stdio",
293-
options_list=("--disable-stdio",),
294-
required=False,
300+
action="store_true",
295301
help="Disabling container stdio will disable the ability to see the output of the container in the terminal for Confidential ACI",
302+
validator=validate_stdio,
303+
)
304+
c.argument(
305+
"enable_stdio",
306+
action="store_true",
307+
help="Enable the standard io streams to leave the container",
308+
validator=validate_stdio,
296309
)
297310
c.argument(
298311
"debug_mode",

src/confcom/azext_confcom/_validators.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
# --------------------------------------------------------------------------------------------
55

66
from knack.util import CLIError
7+
from knack.log import get_logger
78
from azext_confcom.config import RESERVED_FRAGMENT_NAMES, SUPPORTED_ALGOS
89

910

11+
logger = get_logger(__name__)
12+
13+
1014
def validate_params_file(namespace):
1115
if namespace.arm_template_parameters and not namespace.arm_template:
1216
raise CLIError(
@@ -131,3 +135,27 @@ def validate_fragment_path(namespace):
131135
def validate_fragment_json(namespace):
132136
if namespace.fragments_json and not namespace.generate_import:
133137
raise CLIError("Must provide --fragment-path to place a fragment import into a file")
138+
139+
140+
def validate_stdio(namespace):
141+
if namespace.enable_stdio and namespace.disable_stdio:
142+
raise CLIError('Use only one of --enable-stdio or --disable-stdio.')
143+
144+
145+
def resolve_stdio(enable_stdio_flag, disable_stdio_flag, default=True):
146+
147+
stdio_enabled = default
148+
if enable_stdio_flag is None and disable_stdio_flag is None:
149+
logger.warning(
150+
"WARNING: Using default stdio setting (Enabled)\n"
151+
"For the most secure deployments, ensure stdio is disabled. "
152+
"Default behaviour may change in the future, you can set stdio with:\n"
153+
" --disable-stdio\n"
154+
" --enable-stdio\n"
155+
)
156+
elif enable_stdio_flag is not None:
157+
stdio_enabled = enable_stdio_flag
158+
elif disable_stdio_flag is not None:
159+
stdio_enabled = not disable_stdio_flag
160+
161+
return stdio_enabled

src/confcom/azext_confcom/custom.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
import os
77
import sys
8+
from typing import Optional
89

910
from azext_confcom import oras_proxy, os_util, security_policy
11+
from azext_confcom._validators import resolve_stdio
1012
from azext_confcom.config import (
1113
DEFAULT_REGO_FRAGMENTS, POLICY_FIELD_CONTAINERS_ELEMENTS_REGO_FRAGMENTS,
1214
REGO_IMPORT_FILE_STRUCTURE)
@@ -43,7 +45,8 @@ def acipolicygen_confcom(
4345
save_to_file: str = None,
4446
debug_mode: bool = False,
4547
print_policy_to_terminal: bool = False,
46-
disable_stdio: bool = False,
48+
disable_stdio: Optional[bool] = None,
49+
enable_stdio: Optional[bool] = None,
4750
print_existing_policy: bool = False,
4851
faster_hashing: bool = False,
4952
omit_id: bool = False,
@@ -61,6 +64,8 @@ def acipolicygen_confcom(
6164
"For additional information, see http://aka.ms/clisecrets. \n",
6265
)
6366

67+
stdio_enabled = resolve_stdio(enable_stdio, disable_stdio)
68+
6469
if print_existing_policy and arm_template:
6570
print_existing_policy_from_arm_template(arm_template, arm_template_parameters)
6671
return
@@ -112,7 +117,7 @@ def acipolicygen_confcom(
112117
input_path,
113118
debug_mode=debug_mode,
114119
infrastructure_svn=infrastructure_svn,
115-
disable_stdio=disable_stdio,
120+
disable_stdio=(not stdio_enabled),
116121
exclude_default_fragments=exclude_default_fragments,
117122
)
118123
elif arm_template:
@@ -121,21 +126,21 @@ def acipolicygen_confcom(
121126
arm_template,
122127
arm_template_parameters,
123128
debug_mode=debug_mode,
124-
disable_stdio=disable_stdio,
129+
disable_stdio=(not stdio_enabled),
125130
approve_wildcards=approve_wildcards,
126131
diff_mode=diff,
127132
rego_imports=fragments_list,
128133
exclude_default_fragments=exclude_default_fragments,
129134
)
130135
elif image_name:
131136
container_group_policies = security_policy.load_policy_from_image_name(
132-
image_name, debug_mode=debug_mode, disable_stdio=disable_stdio
137+
image_name, debug_mode=debug_mode, disable_stdio=(not stdio_enabled)
133138
)
134139
elif virtual_node_yaml_path:
135140
container_group_policies = security_policy.load_policy_from_virtual_node_yaml_file(
136141
virtual_node_yaml_path=virtual_node_yaml_path,
137142
debug_mode=debug_mode,
138-
disable_stdio=disable_stdio,
143+
disable_stdio=(not stdio_enabled),
139144
approve_wildcards=approve_wildcards,
140145
diff_mode=diff,
141146
rego_imports=fragments_list,
@@ -227,14 +232,18 @@ def acifragmentgen_confcom(
227232
fragment_path: str = None,
228233
omit_id: bool = False,
229234
generate_import: bool = False,
230-
disable_stdio: bool = False,
235+
disable_stdio: Optional[bool] = None,
236+
enable_stdio: Optional[bool] = None,
231237
debug_mode: bool = False,
232238
output_filename: str = "",
233239
outraw: bool = False,
234240
upload_fragment: bool = False,
235241
no_print: bool = False,
236242
fragments_json: str = "",
237243
):
244+
245+
stdio_enabled = resolve_stdio(enable_stdio, disable_stdio)
246+
238247
output_type = get_fragment_output_type(outraw)
239248

240249
if generate_import:
@@ -288,14 +297,14 @@ def acifragmentgen_confcom(
288297

289298
if image_name:
290299
policy = security_policy.load_policy_from_image_name(
291-
image_name, debug_mode=debug_mode, disable_stdio=disable_stdio
300+
image_name, debug_mode=debug_mode, disable_stdio=(not stdio_enabled)
292301
)
293302
else:
294303
# this is using --input
295304
if not tar_mapping:
296305
tar_mapping = os_util.load_tar_mapping_from_config_file(input_path)
297306
policy = security_policy.load_policy_from_json_file(
298-
input_path, debug_mode=debug_mode, disable_stdio=disable_stdio
307+
input_path, debug_mode=debug_mode, disable_stdio=(not stdio_enabled)
299308
)
300309
# get all of the fragments that are being used in the policy
301310
# and associate them with each container group

src/confcom/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
logger.warn("Wheel is not available, disabling bdist_wheel hook")
2121

22-
VERSION = "1.2.8"
22+
VERSION = "1.3.0"
2323

2424
# The full list of classifiers is available at
2525
# https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)