ansible: enhance ceos image discovery to detect pre-pulled registry images#23299
Merged
StormLiangMS merged 1 commit intosonic-net:masterfrom Mar 25, 2026
Merged
Conversation
…mages When ceos_registry is not defined, use 'docker images | grep' to discover ceos_image from any registry cached locally (e.g. pre-pulled during VMSS provisioning). This avoids building a local image that would trigger S360 security alerts. The consolidated grep matches both plain local images (ceosimage:4.32.5M-1) and registry-prefixed images (any-registry/ceosimage:4.32.5M-1) in one step. When ceos_registry IS defined, the existing explicit registry check is preserved unchanged. Co-authored-by: Copilot <[email protected]> Signed-off-by: Xin Wang <[email protected]>
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
wangxinbot
pushed a commit
to wangxinbot/sonic-mgmt
that referenced
this pull request
Mar 25, 2026
…image discovery Cherry-pick of sonic-net#22794 and sonic-net#23299 to 202411 branch. Original PRs: - sonic-net#22794 - sonic-net#23299 Includes enhanced ceos image discovery: when ceos_registry is not defined, a consolidated 'docker images | grep' discovers pre-pulled registry images locally, avoiding unnecessary local image builds that trigger S360 alerts. Co-authored-by: Copilot <[email protected]> Signed-off-by: Xin Wang <[email protected]>
wangxinbot
pushed a commit
to wangxinbot/sonic-mgmt
that referenced
this pull request
Mar 25, 2026
…image discovery Cherry-pick of sonic-net#22794 and sonic-net#23299 to 202505 branch. Original PRs: - sonic-net#22794 - sonic-net#23299 Includes enhanced ceos image discovery: when ceos_registry is not defined, a consolidated 'docker images | grep' discovers pre-pulled registry images locally, avoiding unnecessary local image builds that trigger S360 alerts. Co-authored-by: Copilot <[email protected]> Signed-off-by: Xin Wang <[email protected]>
wangxinbot
pushed a commit
to wangxinbot/sonic-mgmt.msft
that referenced
this pull request
Mar 25, 2026
…image discovery Cherry-pick of sonic-net/sonic-mgmt#22794 and #23299 to 202412 branch. Original PRs: - sonic-net/sonic-mgmt#22794 - sonic-net/sonic-mgmt#23299 Includes enhanced ceos image discovery: when ceos_registry is not defined, a consolidated 'docker images | grep' discovers pre-pulled registry images locally, avoiding unnecessary local image builds that trigger S360 alerts. Co-authored-by: Copilot <[email protected]> Signed-off-by: Xin Wang <[email protected]>
wangxinbot
pushed a commit
to wangxinbot/sonic-mgmt.msft
that referenced
this pull request
Mar 25, 2026
…image discovery Cherry-pick of sonic-net/sonic-mgmt#22794 and #23299 to 202503 branch. Original PRs: - sonic-net/sonic-mgmt#22794 - sonic-net/sonic-mgmt#23299 Includes enhanced ceos image discovery: when ceos_registry is not defined, a consolidated 'docker images | grep' discovers pre-pulled registry images locally, avoiding unnecessary local image builds that trigger S360 alerts. Co-authored-by: Copilot <[email protected]> Signed-off-by: Xin Wang <[email protected]>
wangxinbot
pushed a commit
to wangxinbot/sonic-mgmt.msft
that referenced
this pull request
Mar 25, 2026
…image discovery Cherry-pick of sonic-net/sonic-mgmt#22794 and #23299 to 202506 branch. Original PRs: - sonic-net/sonic-mgmt#22794 - sonic-net/sonic-mgmt#23299 Includes enhanced ceos image discovery: when ceos_registry is not defined, a consolidated 'docker images | grep' discovers pre-pulled registry images locally, avoiding unnecessary local image builds that trigger S360 alerts. Co-authored-by: Copilot <[email protected]> Signed-off-by: Xin Wang <[email protected]>
wangxinbot
pushed a commit
to wangxinbot/sonic-mgmt.msft
that referenced
this pull request
Mar 25, 2026
…image discovery Cherry-pick of sonic-net/sonic-mgmt#22794 and #23299 to 202509 branch. Original PRs: - sonic-net/sonic-mgmt#22794 - sonic-net/sonic-mgmt#23299 Includes enhanced ceos image discovery: when ceos_registry is not defined, a consolidated 'docker images | grep' discovers pre-pulled registry images locally, avoiding unnecessary local image builds that trigger S360 alerts. Co-authored-by: Copilot <[email protected]> Signed-off-by: Xin Wang <[email protected]>
This was referenced Mar 25, 2026
wangxinbot
pushed a commit
to wangxinbot/sonic-mgmt
that referenced
this pull request
Mar 25, 2026
…image discovery Cherry-pick of sonic-net#22794 and sonic-net#23299 to 202511 branch. Original PRs: - sonic-net#22794 - sonic-net#23299 Includes enhanced ceos image discovery: when ceos_registry is not defined, a consolidated 'docker images | grep' discovers pre-pulled registry images locally, avoiding unnecessary local image builds that trigger S360 alerts. Co-authored-by: Copilot <[email protected]> Signed-off-by: Xin Wang <[email protected]>
StormLiangMS
approved these changes
Mar 25, 2026
Collaborator
StormLiangMS
left a comment
There was a problem hiding this comment.
Review: Looks good to merge 👍
Summary: Clean solution for detecting pre-pulled registry images when ceos_registry is not defined, preventing unnecessary local builds that trigger S360 alerts.
Positives:
- Well-scoped fix with clear problem statement
- Good defensive coding:
ignore_errors,changed_when: no, properis not skipped+rc == 0+stdout != ''guards {% raw %}...{% endraw %}is much more readable than{{ '{{' }}escaping- Backward compatible —
ceos_registrydefined path unchanged - 3-tier fallback logic in
ceos_effective_imageis sound
Minor observations (non-blocking):
- Regex dot in grep:
grep -m1 '{{ ceos_image }}$'— the.in version strings like4.32.5M-1is a regex wildcard. Extremely low risk in practice, butgrep -Fwould be theoretically safer if an end-anchor isn't needed. -m1ordering: Multiple matching images return whicheverdocker imageslists first (newest). Acceptable since any match beats none in theceos_registry is not definedcase.- Duplicated discovery task across both files follows existing pattern — could be extracted to a shared task file in a future cleanup.
vmittal-msft
pushed a commit
that referenced
this pull request
Mar 25, 2026
…image discovery (#23300) Cherry-pick of #22794 and #23299 to 202511 branch. Original PRs: - #22794 - #23299 Includes enhanced ceos image discovery: when ceos_registry is not defined, a consolidated 'docker images | grep' discovers pre-pulled registry images locally, avoiding unnecessary local image builds that trigger S360 alerts. Signed-off-by: Xin Wang <[email protected]> Co-authored-by: Xin Wang <[email protected]> Co-authored-by: Copilot <[email protected]>
wangxin
added a commit
to Azure/sonic-mgmt.msft
that referenced
this pull request
Mar 26, 2026
…registry and enhance image discovery (#1084) Cherry-pick of sonic-net/sonic-mgmt#22794 and #23299 to 202509 branch. Original PRs: - sonic-net/sonic-mgmt#22794 (registry support) - sonic-net/sonic-mgmt#23299 (enhanced image discovery) Combined changes include: 1. Support for pulling ceos_image from a configured docker registry (ceos_registry) 2. Enhanced image discovery: when ceos_registry is not defined, discovers pre-pulled registry images locally via `docker images | grep`, avoiding unnecessary local image builds that trigger S360 alerts Conflicts resolved in ansible/roles/vm_set/tasks/add_ceos_list.yml.
wangxin
added a commit
to Azure/sonic-mgmt.msft
that referenced
this pull request
Mar 26, 2026
…registry and enhance image discovery (#1083) Cherry-pick of sonic-net/sonic-mgmt#22794 and #23299 to 202506 branch. Original PRs: - sonic-net/sonic-mgmt#22794 (registry support) - sonic-net/sonic-mgmt#23299 (enhanced image discovery) Combined changes include: 1. Support for pulling ceos_image from a configured docker registry (ceos_registry) 2. Enhanced image discovery: when ceos_registry is not defined, discovers pre-pulled registry images locally via `docker images | grep`, avoiding unnecessary local image builds that trigger S360 alerts Conflicts resolved in ansible/roles/vm_set/tasks/add_ceos_list.yml.
StormLiangMS
added a commit
to Azure/sonic-mgmt.msft
that referenced
this pull request
Mar 26, 2026
…registry and enhance image discovery (#1082) Cherry-pick of sonic-net/sonic-mgmt#22794 and #23299 to 202503 branch. Original PRs: - sonic-net/sonic-mgmt#22794 (registry support) - sonic-net/sonic-mgmt#23299 (enhanced image discovery) Combined changes include: 1. Support for pulling ceos_image from a configured docker registry (ceos_registry) 2. Enhanced image discovery: when ceos_registry is not defined, discovers pre-pulled registry images locally via `docker images | grep`, avoiding unnecessary local image builds that trigger S360 alerts Conflicts resolved in ansible/roles/vm_set/tasks/add_ceos_list.yml.
StormLiangMS
added a commit
to Azure/sonic-mgmt.msft
that referenced
this pull request
Mar 26, 2026
…registry and enhance image discovery (#1081) Cherry-pick of sonic-net/sonic-mgmt#22794 and #23299 to 202412 branch. Original PRs: - sonic-net/sonic-mgmt#22794 (registry support) - sonic-net/sonic-mgmt#23299 (enhanced image discovery) Combined changes include: 1. Support for pulling ceos_image from a configured docker registry (ceos_registry) 2. Enhanced image discovery: when ceos_registry is not defined, discovers pre-pulled registry images locally via `docker images | grep`, avoiding unnecessary local image builds that trigger S360 alerts Conflicts resolved in ansible/roles/vm_set/tasks/add_ceos_list.yml.
ravaliyel
pushed a commit
to ravaliyel/sonic-mgmt
that referenced
this pull request
Mar 27, 2026
…mages (sonic-net#23299) When ceos_registry is not defined, use 'docker images | grep' to discover ceos_image from any registry cached locally (e.g. pre-pulled during VMSS provisioning). This avoids building a local image that would trigger S360 security alerts. The consolidated grep matches both plain local images (ceosimage:4.32.5M-1) and registry-prefixed images (any-registry/ceosimage:4.32.5M-1) in one step. When ceos_registry IS defined, the existing explicit registry check is preserved unchanged. Signed-off-by: Xin Wang <[email protected]> Co-authored-by: Xin Wang <[email protected]> Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of PR
Summary:
Enhance ceos image discovery logic so that pre-pulled registry images are detected even when
ceos_registryis not defined. This prevents unnecessary local image builds that trigger S360 security alerts.This is a follow-up improvement to PR #22794 which added registry support for ceos images.
Type of change
Back port request
Approach
What is the motivation for this PR?
PR #22794 added support for pulling ceos images from a configured registry (
ceos_registry). However, whenceos_registryis not defined (e.g. in public code where the registry URL should not be exposed), pre-pulled registry images are not discovered. The code falls through to the download-and-build path, creating a local image that triggers S360 security alerts.This is problematic for PR testing where ceos images are pre-pulled from a registry during VMSS instance provisioning, but
ceos_registryis not defined in public configuration.How did you do it?
Added a consolidated
docker images | grepdiscovery task that runs whenceos_registryis not defined. The grep matchesceos_imageat the end of the image name, so it discovers both:ceosimage:4.32.5M-1any-registry/ceosimage:4.32.5M-1Changes are made in two files:
ansible/roles/vm_set/tasks/add_ceos_list.yml— controls whether to download/build the imageansible/roles/eos/tasks/ceos.yml— setsceos_effective_imagefor container creationWhen
ceos_registryIS defined, the existing explicit registry check is preserved unchanged.Used
{% raw %}...{% endraw %}Jinja2 blocks for Go template syntax in docker format strings, improving readability over the previous{{ '{{' }}escaping.How did you verify/test it?
Manually tested on testbed with:
ceos_registryundefined — image discovered correctlyceos_registryundefined — image discovered correctlyceos_registrydefined — existing behavior preservedAny platform specific information?
N/A
Supported testbed topology if it's a new test case?
N/A — this is an infrastructure/provisioning change, not a test case.
Documentation
N/A — internal infrastructure improvement.