Skip to content

Commit 966e8d8

Browse files
AOSM CLI - Fixing a zip-slip security bug for code that was using tar.extractall() on nfd build command (#9234)
* AOSM CLI - Fixing a zip-slip security bug for code that was using tar.extractall() on `nfd build` command * fixing tests * fixing tests * review updates --------- Co-authored-by: Daniel Steven <[email protected]>
1 parent dcfe66b commit 966e8d8

File tree

302 files changed

+17834
-47961
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

302 files changed

+17834
-47961
lines changed

src/aosm/HISTORY.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22
33
Release History
44
===============
5+
6+
2.0.0b3
7+
++++++++
8+
* Fixing a zip-slip security bug for code that was using tar.extractall() on `nfd build` command.
9+
* This version requires a minimum of 2.70.0 Azure core CLI. See install instructions: https://github.com/MicrosoftDocs/azure-docs-cli/blob/main/docs-ref-conceptual/Latest-version/install-azure-cli.md
10+
511
2.0.0b2
612
++++++++
7-
* Remove msrestazure dependency
13+
* Added sns generate-config, build and deploy commands.
14+
* Added a check to make sure resource type used in ARM template are in allowed list.
15+
* Fixed multi NF RETs issue in nsdvs.
16+
* Fixed: Better exception messages for Azure permissions problems.
17+
* Fixed: skip-steps help text to reflect current implementation.
18+
* Added finetuning of parameter exposure with yaml comments for CNF
819

920
2.0.0b1
1021
++++++++

src/aosm/README.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Microsoft Azure CLI 'aosm' Extension
22

3-
This package is for the 'aosm' extension to support Azure Operator Service Manager
3+
This package is for the 'aosm' extension to support Azure Operator Service Manager
44
functions.
55
i.e. `az aosm`
66

@@ -23,16 +23,18 @@ These commands help with the publishing of Network Function Definition and Netwo
2323
Service Design resources.
2424

2525
## Overview of function
26+
2627
A generic workflow of using the tool would be:
28+
2729
- Find the pre-requisite items you require for your use-case
2830
- Run a `generate-config` command to output an example JSON config file for subsequent commands
2931
- Fill in the config file
3032
- Run a `build` command to output one or more bicep templates for your Network Function Definition or Network Service Design
3133
- Review the output of the build command, edit the output as necessary for your requirements
3234
- Run a `publish` command to:
33-
* Create all pre-requisite resources such as Resource Group, Publisher, Artifact Stores, Groups
34-
* Deploy those bicep templates
35-
* Upload artifacts to the artifact stores
35+
- Create all pre-requisite resources such as Resource Group, Publisher, Artifact Stores, Groups
36+
- Deploy those bicep templates
37+
- Upload artifacts to the artifact stores
3638

3739
### Pre-requisites
3840

@@ -45,14 +47,16 @@ image that would be used for the VNF Virtual Machine.
4547
#### CNFs
4648

4749
For CNFs you must have these packages installed on the machine you are running the CLI from:
48-
- `helm` package installed . Instructions on how to do this can be found [here](https://helm.sh/docs/intro/install/).
49-
- `docker` installed only in some circumstances, those being if the source image is in your local docker repository, or you do not have subscription-wide permissions required to push charts and images. See the remainder of this section for further details. Docker provides packages that easily configure docker on [Windows](https://docs.docker.com/docker-for-windows/), or [Linux](https://docs.docker.com/engine/install/#supported-platforms) systems.
50+
51+
- `helm` package installed . Instructions on how to do this can be found [here](https://helm.sh/docs/intro/install/).
52+
- `docker` installed only in some circumstances, those being if the source image is in your local docker repository, or you do not have subscription-wide permissions required to push charts and images. See the remainder of this section for further details. Docker provides packages that easily configure docker on [Windows](https://docs.docker.com/docker-for-windows/), or [Linux](https://docs.docker.com/engine/install/#supported-platforms) systems.
5053

5154
For CNFs, you must provide:
52-
* Helm packages with an associated schema. These files must be on your disk and will be referenced in the `cnf-input.jsonc` config file.
53-
* A reference to an existing Azure Container Registry which contains the images for your CNF. Currently, only one ACR and namespace is supported per CNF. The images to be copied from this ACR are populated automatically based on the helm package schema. You must have Reader/AcrPull permissions on this ACR. To use this, fill in `source_registry` and optionally `source_registry_namespace` in the cnf-input.jsonc file.
54-
* Optionally, you can provide a file (on disk) path_to_mappings which is a copy of values.yaml with your chosen values replaced by deployment parameters, thus exposing them as parameters to the CNF.
55-
* When filling in the cnf-input.jsonc file, you must list helm packages in the order they are to be deployed. For example, if A must be deployed before B, your cnf-input.jsonc should look something like this:
55+
56+
- Helm packages with an associated schema. These files must be on your disk and will be referenced in the `cnf-input.jsonc` config file.
57+
- A reference to an existing Azure Container Registry which contains the images for your CNF. Currently, only one ACR and namespace is supported per CNF. The images to be copied from this ACR are populated automatically based on the helm package schema. You must have Reader/AcrPull permissions on this ACR. To use this, fill in `source_registry` and optionally `source_registry_namespace` in the cnf-input.jsonc file.
58+
- Optionally, you can provide a file (on disk) path_to_mappings which is a copy of values.yaml with your chosen values replaced by deployment parameters, thus exposing them as parameters to the CNF.
59+
- When filling in the cnf-input.jsonc file, you must list helm packages in the order they are to be deployed. For example, if A must be deployed before B, your cnf-input.jsonc should look something like this:
5660

5761
"helm_packages": [
5862
{
@@ -73,19 +77,21 @@ For CNFs, you must provide:
7377
},
7478

7579
##### Permissions for publishing CNFs
80+
7681
If sourcing the CNF images from an existing ACR, you need to have `Reader`/`AcrPull` permissions
77-
from this ACR, and ideally, `Contributor` role + `AcrPush` role (or a custom role that allows the `importImage` action and `AcrPush`) over the whole subscription in order to be able to import to the new Artifact store. If you have these, you
82+
from this ACR, and ideally, `Contributor` role + `AcrPush` role (or a custom role that allows the `importImage` action and `AcrPush`) over the whole subscription in order to be able to import to the new Artifact store. If you have these, you
7883
do not need docker to be installed locally, and the image copy is very quick.
7984

8085
If you do not have the subscription-wide permissions then you can run the `az aosm nfd publish` command using the `--no-subscription-permissions` flag to pull the image to your local machine and then push it to the Artifact Store using manifest credentials scoped only to the store. This requires docker to be installed locally.
8186

8287
#### NSDs
83-
For NSDs, you will need to have a Resource Group with a deployed Publisher, Artifact Store, Network Function Definition and Network Function Definition Version. You can use the `az aosm nfd` commands to create all of these resources.
8488

89+
For NSDs, you will need to have a Resource Group with a deployed Publisher, Artifact Store, Network Function Definition and Network Function Definition Version. You can use the `az aosm nfd` commands to create all of these resources.
8590

8691
### Command examples
8792

8893
#### Before you start
94+
8995
`az login` to login to the Azure CLI.
9096
`az account set --subscription <subscription>` to choose the subscription you will work on.
9197

@@ -104,7 +110,7 @@ Create an example config file for building a definition
104110

105111
`az aosm nfd generate-config`
106112

107-
This will output a file called `cnf-input.jsonc` which must be filled in.
113+
This will output a file called `cnf-input.jsonc` which must be filled in.
108114
Once the config file has been filled in the following commands can be run.
109115

110116
Build an nfd definition locally
@@ -115,7 +121,6 @@ Publish a pre-built definition
115121

116122
`az aosm nfd publish --build-output-folder cnf-cli-output`
117123

118-
119124
#### NSDs
120125

121126
Get help on command arguments
@@ -129,7 +134,7 @@ Create an example config file for building a definition
129134

130135
`az aosm nsd generate-config`
131136

132-
This will output a file called `nsd-input.jsonc` which must be filled in.
137+
This will output a file called `nsd-input.jsonc` which must be filled in.
133138
Once the config file has been filled in the following commands can be run.
134139

135140
Build an nsd locally
@@ -140,12 +145,11 @@ Publish a pre-built design
140145

141146
`az aosm nsd publish --build-output-folder nsd-cli-output`
142147

143-
144148
## Bug Reporting
145149

146150
It would be much appreciated if you could report these so that we're aware of them!
147151

148-
Please see [Logging](#logging) for how to view and collect logs.
152+
Please see [Logging](#logging) for how to view and collect logs.
149153

150154
Please describe what you are doing and if possible provide the input and output files.
151155

@@ -157,20 +161,25 @@ CLI issues should be tagged and triaged as UX bugs.
157161
## Logging
158162

159163
The CLI uses the standard Azure CLI logging mechanism. To enable logging to the console, you can use the following flags depending on the desired level of logging:
164+
160165
- `--verbose` - This flag changes the logging level to Info and above.
161166
- `--debug` - This flag changes the logging level to Debug and above.
162167
- `--only-show-errors` - This flag changes the logging level to Error only, suppressing Warning.
163168

164169
It is also possible to enable logging to file by running the following command:
170+
165171
```
166172
az config set logging.enable_log_file=true
167173
```
168-
This will create a log file in the `~/.azure/logs` directory.
174+
175+
This will create a log file in the `~/.azure/logs` directory.
169176

170177
**Note:** The above command will enable logging for all Azure CLI commands until the logging is disabled again by the user. Not disabling file logging could slow down the performance of the CLI. To disable file logging, run the following command:
178+
171179
```
172180
az config set logging.enable_log_file=false
173181
```
174182

175183
## Development
184+
176185
Information about setting up and maintaining a development environment for this extension can be found [here](https://eng.ms/docs/strategic-missions-and-technologies/strategic-missions-and-technologies-organization/azure-for-operators/aiops/aiops-orchestration/aosm-product-docs/processes/cli_contributing).

src/aosm/azext_aosm/_help.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,26 @@
121121
- name: Publish a Network Service Design.
122122
text: az aosm nsd publish --build-output-folder my-nsd-output-folder
123123
"""
124+
125+
helps[
126+
"aosm sns"
127+
] = """
128+
type: group
129+
short-summary: Manage AOSM Site Network Services.
130+
long-summary: |
131+
A Site Network Service (SNS) is a collection of network functions along with platform that come together to offer a service..
132+
"""
133+
134+
helps[
135+
"aosm sns generate-config"
136+
] = """
137+
type: command
138+
short-summary: Generate configuration file for building an AOSM SNS.
139+
long-summary: |
140+
Generates a configuration file that you can use to build an AOSM Site Network Service (SNS). The configuration file is a JSONC file that contains the required parameters for building the SNS. You must complete the configuration file with your specific values before building the SNS.
141+
examples:
142+
- name: Generate a configuration file for a Site Network Service.
143+
text: az aosm sns generate-config
144+
- name: Generate a configuration file for a Site Network Service and write to a specific file.
145+
text: az aosm sns generate-config --output-file my-sns-input-config.jsonc
146+
"""

src/aosm/azext_aosm/_params.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ def load_arguments(self: AzCommandsLoader, _):
2828
nf_skip_steps = get_enum_type(
2929
[BICEP_PUBLISH, ARTIFACT_UPLOAD, IMAGE_UPLOAD, HELM_TEMPLATE]
3030
)
31-
ns_skip_steps = get_enum_type([BICEP_PUBLISH, ARTIFACT_UPLOAD])
3231

3332
# Set the argument context so these options are only available when this specific command
3433
# is called.
35-
3634
with self.argument_context("aosm nfd") as c:
3735
c.argument(
3836
"definition_type",
@@ -77,11 +75,10 @@ def load_arguments(self: AzCommandsLoader, _):
7775
"skip",
7876
arg_type=nf_skip_steps,
7977
help=(
80-
"Optional skip steps. 'bicep-publish' will skip deploying the bicep "
81-
"template; 'artifact-upload' will skip uploading any artifacts; "
82-
"'image-upload' will skip uploading the VHD image (for VNFs) or the "
83-
"container images (for CNFs); 'helm-template' will skip templating the "
84-
"helm charts (for CNFs)."
78+
"Optional skip step. Providing the string 'helm-template' will skip "
79+
"templating the helm charts (for CNFs), but is very likely to result in "
80+
"a broken deployment as image versions will not be parsed. Intended only for "
81+
"temporarily unblocking during development."
8582
),
8683
)
8784
c.argument(
@@ -118,7 +115,9 @@ def load_arguments(self: AzCommandsLoader, _):
118115
" the required parameters for building the NSD."
119116
),
120117
)
121-
c.argument("skip", arg_type=ns_skip_steps, help="Optional skip steps")
118+
# NSD skip steps are not currently implemented. This is a record of how to add them.
119+
# You also need to add the `skip` parameter in the relevant function in custom.py.
120+
# c.argument("skip", arg_type=ns_skip_steps, help="Optional skip steps")
122121
c.argument(
123122
"clean",
124123
arg_type=get_three_state_flag(),
@@ -145,3 +144,41 @@ def load_arguments(self: AzCommandsLoader, _):
145144
"Requires Docker to be installed locally."
146145
),
147146
)
147+
148+
with self.argument_context("aosm sns") as c:
149+
c.argument(
150+
"output_file",
151+
options_list=["--output-file"],
152+
help="The name of the output file to write the generated config text to.",
153+
required=False,
154+
)
155+
c.argument(
156+
"config_file",
157+
options_list=["--config-file", "-f"],
158+
type=file_type,
159+
completer=FilesCompleter(allowednames="*.jsonc"),
160+
help=(
161+
"The path to the configuration file. This is a JSONC file that contains"
162+
" the required parameters for building the NSD."
163+
),
164+
)
165+
c.argument(
166+
"build_output_folder",
167+
options_list=["--build-output-folder", "-b"],
168+
type=file_type,
169+
completer=FilesCompleter(allowednames="*.json"),
170+
help="Path to the folder to deploy, created by the build command.",
171+
)
172+
c.argument(
173+
"no_subscription_permissions",
174+
options_list=["--no-subscription-permissions", "-u"],
175+
completer=FilesCompleter(allowednames="*.json"),
176+
help=(
177+
"Pass this flag if you do not have permission to import to the "
178+
"Publisher subscription (Contributor role + AcrPush role, or a "
179+
"custom role that allows the importImage action and AcrPush over the "
180+
"whole subscription). This means that the image artifacts will be "
181+
"pulled to your local machine and then pushed to the Artifact Store. "
182+
"Requires Docker to be installed locally."
183+
),
184+
)

src/aosm/azext_aosm/_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def example_name_or_id_validator(cmd, namespace):
99
# See:
1010
# https://github.com/Azure/azure-cli/blob/dev/doc/authoring_command_modules/authoring_commands.md#supporting-name-or-id-parameters
1111
from azure.cli.core.commands.client_factory import get_subscription_id
12-
from azure.mgmt.core.tools import is_valid_resource_id, resource_id
12+
from msrestazure.tools import is_valid_resource_id, resource_id # pylint: disable=import-error
1313

1414
if namespace.storage_account:
1515
if not is_valid_resource_id(namespace.RESOURCE):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"azext.isPreview": true,
3-
"azext.minCliCoreVersion": "2.54.0"
3+
"azext.minCliCoreVersion": "2.70.0"
44
}

0 commit comments

Comments
 (0)