Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ContainerRegistry] <DO NOT MERGE> Add 'acrcssc' extension for public preview #8530

Draft
wants to merge 189 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 188 commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
d9e88db
add code for cssc
pwalecha Jun 5, 2024
cdb363c
# Correct the Delete repository method - it is only deleting Tag
pwalecha Jun 5, 2024
b1f89dc
update new yamls
pwalecha Jun 6, 2024
a898153
add support for streaming logging as well
pwalecha Jun 6, 2024
5a0ce0d
add support for logging
pwalecha Jun 6, 2024
7b86532
add support for streamed logs only giving acr-cli logs
pwalecha Jun 6, 2024
5c783c9
Delete old files
pwalecha Jun 10, 2024
968fafd
fix dry run
pwalecha Jun 10, 2024
d7538ba
remove redundant files
pwalecha Jun 10, 2024
add2048
simplify print code
pwalecha Jun 10, 2024
71680a3
add user confirmation before deletion
cegraybl Jun 10, 2024
dbd5113
Merge branch 'users/puwalech/acrcssc' of https://github.com/pwalecha/…
cegraybl Jun 10, 2024
be52009
allow update to be done on cadence or config (or both)
cegraybl Jun 10, 2024
1848240
fix:
pwalecha Jun 10, 2024
8a72e2d
merge latest
pwalecha Jun 10, 2024
94403bb
remove redundant code
pwalecha Jun 10, 2024
69788e2
add template file paths to the extension build
cegraybl Jun 10, 2024
8919cb8
Merge branch 'users/puwalech/acrcssc' of https://github.com/pwalecha/…
cegraybl Jun 10, 2024
2bfad35
fix minor bugs:
pwalecha Jun 11, 2024
e04fd35
fix update issue
pwalecha Jun 11, 2024
63cd2f9
update from warning to print
pwalecha Jun 11, 2024
13b1373
fix:
pwalecha Jun 12, 2024
84fc89e
fix minor issues, supress stderror from acr login
cegraybl Jun 12, 2024
d9360b3
add logging for better experience
pwalecha Jun 12, 2024
01667f2
Merge branch 'users/puwalech/acrcssc' of https://github.com/pwalecha/…
pwalecha Jun 12, 2024
f535211
remove redundant line
pwalecha Jun 12, 2024
f0e71c3
fix minor bugs:
pwalecha Jun 12, 2024
d48e9d7
update yaml for trigger task to 0.11, update filter parameter for dryrun
cegraybl Jun 13, 2024
ffa4998
fix acr-cli version and env variable for dryrun yaml
cegraybl Jun 13, 2024
e87f0ec
fix alot of style checks, some pylint issues
cegraybl Jun 13, 2024
f96a295
fix linter issue with missing help
cegraybl Jun 13, 2024
6dcbbbd
use download logs for dry_run
pwalecha Jun 14, 2024
90147ea
Merge branch 'users/puwalech/acrcssc_v2' of https://github.com/pwalec…
pwalecha Jun 14, 2024
081dda3
Fix temporary directory creation
pwalecha Jun 14, 2024
12e5bc4
add more unit test cases
pwalecha Jun 15, 2024
b1b8603
add a sample scenario test
pwalecha Jun 16, 2024
5d9834a
fix minor verbiage issues
pwalecha Jun 17, 2024
abb0683
fix issue where the 'supply-chain' section is not marked as 'preview'…
cegraybl Jun 17, 2024
cea7d4f
use the Task client to get values for OS & platform from the centrali…
cegraybl Jun 17, 2024
a028585
fix another handful of lint and style issues
cegraybl Jun 17, 2024
6570d07
add a scenario test.
pwalecha Jun 18, 2024
4537b3e
Merge branch 'users/puwalech/acrcssc_v2' of https://github.com/pwalec…
pwalecha Jun 18, 2024
946ab51
fix pylint issues
pwalecha Jun 21, 2024
51b795b
update task yaml files, update version to use latest cssc acr-cli image
cegraybl Jun 24, 2024
22d0d4d
fix per review comments:
pwalecha Jun 25, 2024
ad12541
merge latest
pwalecha Jun 25, 2024
7cefb1b
update to initial version
pwalecha Jun 27, 2024
32fb023
update to the same initial version
pwalecha Jun 27, 2024
b5b2f86
fix the build issues
pwalecha Jul 1, 2024
1d81086
Fix style issue
pwalecha Jul 1, 2024
4bbc6b5
comment failing test case
pwalecha Jul 1, 2024
ef073ad
fix the style issue
pwalecha Jul 1, 2024
0080d77
fix breaking unit test cases
pwalecha Jul 1, 2024
49df558
fix the dry-run yaml
pwalecha Jul 2, 2024
b7c1cde
fix 28610631, improve output message to list a specific cli command t…
cegraybl Jul 9, 2024
537eac6
fix 28610548: create with dry run will now check if the workflow alre…
cegraybl Jul 9, 2024
caea45f
add timeout for 60 minutes
pwalecha Jul 9, 2024
38e1a8e
fix 28610649, re-running workflow delete after a failed deletion shou…
cegraybl Jul 10, 2024
507d8be
standardize string replacement in the extension
cegraybl Jul 10, 2024
f1e4209
Multiple bug fixes in yamls related to patch failing with repos havin…
Jul 16, 2024
b2706a4
Changes to skip patching if image has eosl=true and fixed some other …
Jul 19, 2024
d422e09
Merge branch 'users/puwalech/acrcssc_v2' of https://github.com/pwalec…
pwalecha Jul 19, 2024
8d51d2a
fix breaking test case
pwalecha Jul 19, 2024
f664af9
Remove help for dry-run
pwalecha Jul 19, 2024
d93502f
fix style issues
pwalecha Jul 19, 2024
f1adf73
fix linter and style issues
pwalecha Jul 19, 2024
f1aa1b0
increase copatimeout to 30 m
pwalecha Jul 19, 2024
d553231
Update help for cadence.
pwalecha Jul 25, 2024
641705d
Update recommendation message to reflect max value of cadence
pwalecha Jul 25, 2024
2b107e2
Merge pull request #1 from pwalecha/users/puwalech/acrcssc_v2
cegraybl Aug 22, 2024
faaa49a
adding another echo in scan yaml with standard output for list comman…
Aug 29, 2024
4f7f1ab
feat(phase 1.5): WI 29146137 (#3)
cegraybl Sep 4, 2024
f700cf1
Added implementation for incremental patch tags
Sep 12, 2024
837dd80
Fixed the task yaml to default to floating tag convention when tag co…
Sep 19, 2024
529454b
Removed extra line
Sep 19, 2024
e93501a
Removed extra white spaces
Sep 19, 2024
d1784b5
Skip checking the new patch tag to be greate than 999 when value is p…
Sep 19, 2024
63ece18
Removed old comment
Sep 19, 2024
910afb3
Update output to include both found and not found repos and tags
Sep 20, 2024
9384ced
Add extended scope commands to base CSSC extension (#4)
cegraybl Sep 20, 2024
2e62ddc
bump extension version to 1.1.0, reflect changes in configuration and…
cegraybl Sep 20, 2024
97525cc
fix the return values for 'list' command, allows output to be transfo…
cegraybl Sep 26, 2024
0e2c3cf
Merge pull request #1 from cegraybl/cssc_v2
cegraybl Sep 26, 2024
108e612
Merge pull request #2 from cegraybl/cssc_v3
cegraybl Sep 26, 2024
2b93e84
improve reading for validation error
cegraybl Oct 2, 2024
1f1aeb8
fix typo on constant name
cegraybl Oct 2, 2024
7dcfd21
Updated cssc image versions containing the changed default behavior f…
Oct 30, 2024
9e412ae
fix(doc): update help text to indicate change in config defaults, bum…
cegraybl Oct 30, 2024
20913fd
Multiple db support added for trivy + fixed a bug with default tag co…
Nov 25, 2024
3e0d634
bump extension version ot indicate change
cegraybl Nov 25, 2024
abf9a8d
Merge branch 'cegraybl/cssc_phase_1.5' of https://github.com/AzureCR/…
cegraybl Nov 25, 2024
1f6ae0e
fix bug 30839968, 'show' command does not filter non-cssc tasks befor…
cegraybl Jan 13, 2025
e16ef40
add a nextOccurrence field to the task trigger task, calculated on cl…
cegraybl Jan 14, 2025
ede46dc
fix issue during 'list' with status filtering
cegraybl Jan 15, 2025
2363454
fix data type issue when filtering via status, fixes 30942760
cegraybl Jan 21, 2025
7fc946f
Merge branch 'cegraybl/cssc_phase_1.5' of https://github.com/AzureCR/…
cegraybl Jan 21, 2025
70ef5b1
rename key skipped_patch_reason to patch_skipped_reason
cegraybl Jan 23, 2025
fd15160
split the task state 'canceled' from 'failed', so it is its own posib…
cegraybl Jan 23, 2025
32b2760
Added retries for dependency calls
Jan 24, 2025
10ea0d5
Merge pull request #7 from AzureCR/cegraybl/cssc_31038071
cegraybl Jan 24, 2025
4358214
Added timeout in copa patch
Jan 27, 2025
13480c3
Added a missing slash
Jan 28, 2025
4bf877f
Merge pull request #9 from AzureCR/ruchi/BugFixForTrivyIntermittentIs…
Ruchii-27 Jan 28, 2025
a7b0007
Merge pull request #6 from AzureCR/cegraybl/cssc_30943055
cegraybl Jan 28, 2025
006ca61
Adding a max limit of 100 images allowed for continuous patching
Jan 31, 2025
b808ee4
Merge pull request #10 from AzureCR/ruchi/LimitMaxConcurrentScans
Ruchii-27 Feb 3, 2025
7432f7d
add initial support for patch and scan errors
cegraybl Feb 3, 2025
1f28380
Removed unwanted vuln upload step and list output file step, also mov…
Feb 4, 2025
a43de4b
A few more cleanups and updates to make the message consistent
Feb 4, 2025
be4f1ba
Removed comments and increased retry delay
Feb 4, 2025
d4be7b8
retrieve multiple line of unique errors
cegraybl Feb 4, 2025
5a17af6
sort error messages to make the output depeterministic
cegraybl Feb 4, 2025
06f2789
add comments and rename structure for clarity
cegraybl Feb 5, 2025
6e07dbb
making "and patch" optional to ensure both old and new logs continue …
Feb 5, 2025
d13a7f5
Merge pull request #11 from AzureCR/ruchi/CleanUpPatchTask
Ruchii-27 Feb 5, 2025
5672f53
Trigger Task updated to perform scans in batches of 10
Feb 5, 2025
e872fac
retrieve task run via runId when not found on original list of retrie…
cegraybl Feb 6, 2025
a6f6f3e
Merge pull request #12 from AzureCR/cegraybl/cssc_31196178_error_reason
cegraybl Feb 7, 2025
746318c
add unittests for schedule converters, fix some corner cases
cegraybl Jan 30, 2025
951d5ba
fix the mock for the 'get_logs' unit test, work still pending
cegraybl Feb 3, 2025
af48958
Merge pull request #14 from AzureCR/ruchi/BatchSchedulingScanTasks
Ruchii-27 Feb 7, 2025
4ed84ad
Updated the error message as per the PRD
Feb 7, 2025
aa71ff9
minor update to error message
Feb 7, 2025
8279bcb
fix a set of style and lint issues
cegraybl Feb 7, 2025
4c49e89
fix remaining style issues
cegraybl Feb 7, 2025
777c4bb
Merge pull request #15 from AzureCR/ruchi/UpdateErrorMessage
Ruchii-27 Feb 10, 2025
382bebd
Updated cssc image version to enable WF to use latest copa and trivy …
Feb 10, 2025
093ce3b
Merge pull request #16 from AzureCR/ruchi/UpdateCsscImgVersion
Ruchii-27 Feb 11, 2025
29b8462
saving changes, tests not done yet
cegraybl Feb 11, 2025
9c9ff52
save more changes, most of the test cases work now
cegraybl Feb 12, 2025
790d91b
add more variations to 'test_from_taskrun'
cegraybl Feb 13, 2025
8ccc275
fix asserts for test_generate_logs
cegraybl Feb 14, 2025
009888c
save work for unit tests
cegraybl Feb 14, 2025
7eeebb5
add an option to update all tasks yamls throught an ARM redeploy
cegraybl Feb 5, 2025
d6cb7e6
switch the feature to silently check and redeploy the tasks if the de…
cegraybl Feb 14, 2025
2919af7
remove incorrect parameter from deployment's LongRunningOperation
cegraybl Feb 14, 2025
da4b689
address review comments
cegraybl Feb 20, 2025
3657b4e
Update src/acrcssc/azext_acrcssc/helper/_taskoperations.py
cegraybl Feb 20, 2025
6078314
move extension entry tests to future PR
cegraybl Feb 21, 2025
daf93b2
address issues found by copilot
cegraybl Feb 21, 2025
3c4a383
remove information from compare log
cegraybl Feb 21, 2025
be2b3c0
Added retries for intermittent auth issues observed from ARM during a…
Feb 25, 2025
4a2e72e
Refreshing credentials on retries to handle intermittent authz issues…
Feb 26, 2025
71de8b8
Merge pull request #22 from AzureCR/AddRetriesForARMIssue
Ruchii-27 Feb 27, 2025
af00989
cssc image update to use source policy
Feb 28, 2025
07151fe
Merge pull request #23 from AzureCR/SourcePolicyPoc
Ruchii-27 Feb 28, 2025
7b7a949
Changes to pull buildkit from cached image in buildhost instead of do…
Feb 28, 2025
c2e5160
Merge pull request #24 from AzureCR/PullBuildkitFromMCR
Ruchii-27 Feb 28, 2025
cf8d3c2
change update/override task behavior away from ARM deployment to use …
cegraybl Mar 3, 2025
4d05050
update _update* functions signature, use LongRunningOperation for cli…
cegraybl Mar 4, 2025
d15e270
remove decieving debug message
cegraybl Mar 4, 2025
30c1ba4
Merge pull request #21 from AzureCR/cegraybl/cssc_30926545_unittest
cegraybl Mar 4, 2025
d19a752
add an option to update all tasks yamls throught an ARM redeploy
cegraybl Feb 5, 2025
1587015
switch the feature to silently check and redeploy the tasks if the de…
cegraybl Feb 14, 2025
59cd4c3
remove incorrect parameter from deployment's LongRunningOperation
cegraybl Feb 14, 2025
2eebe33
address review comments
cegraybl Feb 20, 2025
f9a1b11
Update src/acrcssc/azext_acrcssc/helper/_taskoperations.py
cegraybl Feb 20, 2025
4ac41e6
change update/override task behavior away from ARM deployment to use …
cegraybl Mar 3, 2025
71c2456
update _update* functions signature, use LongRunningOperation for cli…
cegraybl Mar 4, 2025
526a0c9
remove decieving debug message
cegraybl Mar 4, 2025
4a05db4
Merge branch 'feature/cssc_ext' into cegraybl/cssc_31231619_update_ta…
cegraybl Mar 4, 2025
a0a213a
add fix for bug 31646863
cegraybl Mar 4, 2025
7f2a44e
Merge branch 'cegraybl/cssc_31231619_update_task_yaml' of https://git…
cegraybl Mar 4, 2025
b29e2ff
Merge pull request #13 from AzureCR/cegraybl/cssc_31231619_update_tas…
cegraybl Mar 5, 2025
7054886
add initial check up for image limit using dryrun task
cegraybl Feb 15, 2025
6659821
fix log message, remove post fix log from dry-run execution
cegraybl Feb 19, 2025
bcf4508
remove dryrun statements from error when image limit is reached, atte…
cegraybl Feb 20, 2025
5fc0eb4
change log error to exception, remove duplicate call
cegraybl Feb 20, 2025
f7247cb
add additional check for temp file management
cegraybl Feb 20, 2025
dff903a
address review comments
cegraybl Feb 20, 2025
03eb29c
add additional error checking when modifying the logger level
cegraybl Feb 20, 2025
3c83455
Add log message when retrieving configuration from registry
cegraybl Feb 20, 2025
d5e1639
fix issues with configuration handling, make image limit check to ru…
cegraybl Mar 3, 2025
af6f182
remove dots from validation message, spinner already includes them
cegraybl Mar 3, 2025
dbfb3fd
resolve comment on possible using acr_archive_utils_logger_level befo…
cegraybl Mar 3, 2025
dafed5b
remove debug comment
cegraybl Mar 3, 2025
b9814a5
Merge pull request #20 from AzureCR/cegraybl/cssc_31229526_image_limi…
cegraybl Mar 5, 2025
9f20733
remove LongRunningOperation wrapper around task update to avoid polle…
cegraybl Mar 6, 2025
e68da31
Merge pull request #26 from AzureCR/cegraybl/cssc_31670277_remove_lon…
cegraybl Mar 6, 2025
9294174
added validation for tag-convention allowed values
Mar 7, 2025
8035585
Moved version validation check to schema validation and fixed the tag…
Mar 7, 2025
a007578
Taking copilots suggestion for exact match
Mar 7, 2025
37788cc
Merge pull request #28 from AzureCR/ruchi/FixCLIBugForTagConvention
Ruchii-27 Mar 7, 2025
49e9d97
When no matching images are found, inform the user instead of continu…
Mar 7, 2025
44cc40d
Merge pull request #30 from AzureCR/ruchi/FixCLIBugWhen0MatchingImages
Ruchii-27 Mar 10, 2025
9c7761b
test(cssc): 30926545 add Scenario test for extension, fix style issue…
cegraybl Mar 10, 2025
5ba93fa
fix(cssc): 31695069 Enhanced repositories schema validation + added t…
Ruchii-27 Mar 10, 2025
9deef45
fix(cssc): 31694510, 31694600 Check for existence of cssc tasks befor…
Ruchii-27 Mar 11, 2025
aaa3d7e
fix(cssc): 31694592 Added validations to ensure dry run and run immed…
Ruchii-27 Mar 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/acrcssc/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. :changelog:

Release History
===============

1.1.1
++++++
* Release for Public Preview
* Added `list`and `cancel-run` commands for workflows
* `list` command provide output on the scan and patch status of the registry
* `cancel-run` command allows to canceling all running scan and patch tasks


1.1.0
++++++
* Initial release for Private Preview
103 changes: 103 additions & 0 deletions src/acrcssc/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
Microsoft Azure CLI 'acrcssc' Extension
==========================================

Azure Container Registry - Container Secure Supply Chain (Continuous Patching)
==========================================

Overview
========
The `acrcssc` extension for Azure CLI provides continuous patching capabilities for Azure Container Registry (ACR). This extension helps automate the process of scanning and patching container images to ensure they are up-to-date with the latest security patches. Scans your configured list of images for vulnerabilities (CVEs) using Trivy and patch them using Copacetic.

Preview Limitations
===================
Continuous Patching is currently in preview. The following limitations apply:

- Windows-based container images aren’t supported
- Only "OS-level" vulnerabilities will be patched. This includes packages in the image managed by a package manager such as “apt” and “yum”. Vulnerabilities at the “application level” are unable to be patched, such as compiled languages like Go, Python, NodeJS
- Patching is only supported in Public regions, not in Sovereign regions

Features
========
- **Continuous Patching Workflow**: Automates the process of scanning and patching container images.
- **Task Management**: Create, update, delete, show, and cancel continuous patch tasks in the registry.
- **Dry Run Mode**: Validate the configuration without making any changes.
- **Immediate Run**: Trigger the patching workflow immediately.
- **Run Status**: Monitor the status of the scanning and patching tasks.

Commands
========
- `az acr supply-chain workflow create`: Create a continuous patch task in the registry.
- `az acr supply-chain workflow update`: Update an existing continuous patch task.
- `az acr supply-chain workflow delete`: Delete a continuous patch task.
- `az acr supply-chain workflow list`: List all continuous patch tasks in the registry.
- `az acr supply-chain workflow show`: Show details of a specific continuous patch task.
- `az acr supply-chain workflow cancel-run`: Cancel all running scan and patch tasks.

Usage
=====
1. **Create a Continuous Patch Task**:
```sh
az acr supply-chain workflow create --resource-group <resource-group> --registry <registry-name> --type continuouspatchv1 --schedule <schedule> --config <config-file>
```

1. **Update a Continuous Patch Task**:
```sh
az acr supply-chain workflow update --resource-group <resource-group> --registry <registry-name> --type continuouspatchv1 --schedule <schedule> --config <config-file>
```

1. **Update with dryrun to test configuration changes**:
```sh
az acr supply-chain workflow update --resource-group <resource-group> --registry <registry-name> --type continuouspatchv1 --config <config-file> --dryrun
```

1. **Delete a Continuous Patch Task**:
```sh
az acr supply-chain workflow delete --resource-group <resource-group> --registry <registry-name> --type continuouspatchv1
```

1. **List Continuous Patch Tasks**:
```sh
az acr supply-chain workflow list --resource-group <resource-group> --registry <registry-name> --type continuouspatchv1 --run-status <status>
```

1. **Show a Continuous Patch Task**:
```sh
az acr supply-chain workflow show --resource-group <resource-group> --registry <registry-name> --type continuouspatchv1
```

1. **Cancel all Scan and Patch Running Tasks**:
```sh
az acr supply-chain workflow cancel-run --resource-group <resource-group> --registry <registry-name> --type continuouspatchv1
```

Configuration
=============
The configuration file for the continuous patch task should define the repositories to be scanned and patched, the schedule for the task, and any other relevant settings.

Example Configuration:

```JSON
{
"repositories": [
{
"repository": "alpine",
"tags": ["tag1", "tag2"],
"enabled": true
},
{
"repository": "python",
"tags": ["*"],
"enabled": false
}
],
"version": "v1",
"tag-convention": "floating"
}
```

Tag Convention
==============
The `tag-convention` property in the configuration file determines how the tags for patched images are managed. It can have the following values:

- **incremental**: This is the default behavior. It increases the patch version of the tag. For example, if the original tag is `1.0`, the patched tags will be `1.0-1`, `1.0-2`, etc.
- **floating**: This reuses the tag postfix `patched` for patching. For example, if the original tag is `1.0`, the patched tag will be `1.0-patched`.
32 changes: 32 additions & 0 deletions src/acrcssc/azext_acrcssc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader

from azext_acrcssc._help import helps # pylint: disable=unused-import


class AcrcsscCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from azext_acrcssc._client_factory import cf_acr
acrcssc_custom = CliCommandType(
operations_tmpl='azext_acrcssc.custom#{}',
client_factory=cf_acr)
super(AcrcsscCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=acrcssc_custom)

def load_command_table(self, args):
from azext_acrcssc.commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_acrcssc._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = AcrcsscCommandsLoader
61 changes: 61 additions & 0 deletions src/acrcssc/azext_acrcssc/_client_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.cli.core.profiles import ResourceType
from azure.mgmt.containerregistry import ContainerRegistryManagementClient
from .helper._constants import (
ACR_API_VERSION_2023_01_01_PREVIEW,
ACR_API_VERSION_2019_06_01_PREVIEW
)

from azure.mgmt.authorization import AuthorizationManagementClient


def cf_acr(cli_ctx, *_) -> ContainerRegistryManagementClient:
return get_mgmt_service_client(cli_ctx,
ResourceType.MGMT_CONTAINERREGISTRY,
api_version=ACR_API_VERSION_2023_01_01_PREVIEW)


def cf_acr_registries(cli_ctx, *_) -> ContainerRegistryManagementClient:
return get_mgmt_service_client(cli_ctx,
ResourceType.MGMT_CONTAINERREGISTRY,
api_version=ACR_API_VERSION_2023_01_01_PREVIEW).registries


def cf_acr_tasks(cli_ctx, *_):
return get_mgmt_service_client(cli_ctx,
ResourceType.MGMT_CONTAINERREGISTRY,
api_version=ACR_API_VERSION_2019_06_01_PREVIEW).tasks


def cf_acr_registries_tasks(cli_ctx, *_):
return get_mgmt_service_client(cli_ctx,
ResourceType.MGMT_CONTAINERREGISTRY,
api_version=ACR_API_VERSION_2019_06_01_PREVIEW).registries


def cf_acr_taskruns(cli_ctx, *_):
return get_mgmt_service_client(cli_ctx,
ResourceType.MGMT_CONTAINERREGISTRY,
api_version=ACR_API_VERSION_2019_06_01_PREVIEW).task_runs


def cf_acr_runs(cli_ctx, *_):
return get_mgmt_service_client(cli_ctx,
ResourceType.MGMT_CONTAINERREGISTRY,
api_version=ACR_API_VERSION_2019_06_01_PREVIEW).runs


def cf_resources(cli_ctx, subscription_id=None):
return get_mgmt_service_client(cli_ctx,
ResourceType.MGMT_RESOURCE_RESOURCES,
subscription_id=subscription_id)


def cf_authorization(cli_ctx, subscription_id=None) -> AuthorizationManagementClient:
return get_mgmt_service_client(cli_ctx,
ResourceType.MGMT_AUTHORIZATION,
subscription_id=subscription_id, api_version="2022-04-01")
66 changes: 66 additions & 0 deletions src/acrcssc/azext_acrcssc/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# coding=utf-8
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.help_files import helps # pylint: disable=unused-import

helps['acr supply-chain'] = """
type: group
short-summary: Commands to manage acr supply chain resources.
"""

helps['acr supply-chain workflow'] = """
type: group
short-summary: Commands to manage acr supply chain workflows.
"""

helps['acr supply-chain workflow create'] = """
type: command
short-summary: Create acr supply chain workflow.
examples:
- name: Create acr supply chain workflow
text: az acr supply-chain workflow create -r $MyRegistry -g $MyResourceGroup \
--type continuouspatchv1 --schedule 1d --config path-to-config-file
"""
helps['acr supply-chain workflow update'] = """
type: command
short-summary: Update acr supply chain workflow.
examples:
- name: Updates acr supply chain workflow
text: az acr supply-chain workflow update -r $MyRegistry -g $MyResourceGroup --type \
continuouspatchv1 --schedule 1d --config path-to-config-file
"""

helps['acr supply-chain workflow show'] = """
type: command
short-summary: Show acr supply chain workflow tasks.
examples:
- name: Show all acr supply chain workflow
text: az acr supply-chain workflow show -r $MyRegistry -g $MyResourceGroup --type continuouspatchv1
"""

helps['acr supply-chain workflow delete'] = """
type: command
short-summary: Delete acr supply chain workflow.
examples:
- name: Delete acr supply chain workflow and associated configuration files
text: az acr supply-chain workflow delete -r $MyRegistry -g $MyResourceGroup --type continuouspatchv1
"""

helps['acr supply-chain workflow cancel-run'] = """
type: command
short-summary: Cancel currently running supply chain workflow.
examples:
- name: Cancel currently running acr supply chain workflow scans/patch
text: az acr supply-chain workflow cancel-run -r $MyRegistry -g $MyResourceGroup --type continuouspatchv1
"""

helps['acr supply-chain workflow list'] = """
type: command
short-summary: List status of acr supply chain workflow images.
examples:
- name: List all acr supply chain workflow images based on the status provided
text: az acr supply-chain workflow list -r $MyRegistry -g $MyResourceGroup --type continuouspatchv1 --run-status Failed
"""
37 changes: 37 additions & 0 deletions src/acrcssc/azext_acrcssc/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long
from azure.cli.command_modules.acr._constants import REGISTRY_RESOURCE_TYPE
from azure.cli.command_modules.acr._validators import validate_registry_name
from azure.cli.core import AzCommandsLoader
from azure.cli.core.commands.parameters import (get_resource_name_completion_list, get_three_state_flag, get_enum_type)


def load_arguments(self: AzCommandsLoader, _):
from .helper._constants import CSSCTaskTypes
from .helper._workflow_status import WorkflowTaskState

with self.argument_context("acr supply-chain workflow") as c:
c.argument('resource_group', options_list=['--resource-group', '-g'], help='Name of resource group.You can configure the default group using `az configure --defaults group=<name>`', completer=get_resource_name_completion_list(REGISTRY_RESOURCE_TYPE), configured_default='acr', validator=validate_registry_name)
c.argument('registry_name', options_list=['--registry', '-r'], help='The name of the container registry. It should be specified in lower case. You can configure the default registry name using `az configure --defaults acr=<registry name>`', completer=get_resource_name_completion_list(REGISTRY_RESOURCE_TYPE), configured_default='acr', validator=validate_registry_name)
c.argument("workflow_type", arg_type=get_enum_type(CSSCTaskTypes), options_list=['--type', '-t'], help="Type of workflow task.", required=True)

with self.argument_context("acr supply-chain workflow create") as c:
c.argument("config", options_list=["--config"], help="Configuration file path containing the json schema for the list of repositories and tags to filter within the registry. Schema example:{\"repositories\":[{\"repository\":\"alpine\",\"tags\":[\"tag1\",\"tag2\"],\"enabled\":true},{\"repository\":\"python\",\"tags\":[\"*\"],\"enabled\":false}], \"version\": \"v1\", \"tag-convention\": \"floating\"}. \"tag-convention\" is an optional property, values can be \"incremental\" (the default behavior, will increase the patch version of the tag, for example \"{repository}:{original-tag}-1\", \"{repository}:{original-tag}-2\", etc), or \"floating\" (will reuse the tag \"{repository}:{original-tag}-patched\" for patching)", required=True)
c.argument("schedule", options_list=["--schedule"], help="schedule to run the scan and patching task. E.g. `<n>d` where <n> is the number of days between each run. Max value is 30d.", required=True)
c.argument("run_immediately", options_list=["--run-immediately"], help="Set this flag to trigger the immediate run of the selected workflow task. Default value: false.", arg_type=get_three_state_flag(), required=False)
c.argument("dryrun", options_list=["--dry-run"], help="Use this flag to see the qualifying repositories and tags that would be affected by the workflow. Default value: false. 'config' parameter is mandatory to provide with dry-run", arg_type=get_three_state_flag(), required=False)

with self.argument_context("acr supply-chain workflow update") as c:
c.argument("config", options_list=["--config"], help="Configuration file path containing the json schema for the list of repositories and tags to filter within the registry. Schema example:{\"repositories\":[{\"repository\":\"alpine\",\"tags\":[\"tag1\",\"tag2\"],\"enabled\":true},{\"repository\":\"python\",\"tags\":[\"*\"],\"enabled\":false}], \"version\": \"v1\", \"tag-convention\": \"floating\"}}. \"tag-convention\" is an optional property, values can be \"incremental\" (the default behavior, will increase the patch version of the tag, for example \"{repository}:{original-tag}-1\", \"{repository}:{original-tag}-2\", etc), or \"floating\" (will reuse the tag \"{repository}:{original-tag}-patched\" for patching)", required=False)
c.argument("schedule", options_list=["--schedule"], help="schedule to run the scan and patching task. E.g. `<n>d` where n is the number of days between each run. Max value is 30d.", required=False)
c.argument("run_immediately", options_list=["--run-immediately"], help="Set this flag to trigger the immediate run of the selected workflow task. Default value: false.", arg_type=get_three_state_flag(), required=False)
c.argument("dryrun", options_list=["--dry-run"], help="Use this flag to see the qualifying repositories and tags that would be affected by the workflow. Default value: false. 'config' parameter is mandatory to provide with dry-run", arg_type=get_three_state_flag(), required=False)

with self.argument_context("acr supply-chain workflow list") as c:
c.argument("status", arg_type=get_enum_type(WorkflowTaskState), options_list=["--run-status"], help="Status to filter the supply-chain workflow image status.", required=False)

with self.argument_context("acr supply-chain workflow delete") as c:
c.argument("yes", options_list=["--yes", "-y"], help="Proceed with the deletion without user confirmation", required=False)
Loading
Loading