-
Notifications
You must be signed in to change notification settings - Fork 43
[OCPERT-437] Port blocking sec-alerts check command to main for Konflux release flow #1147
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
Open
jhuttana
wants to merge
3
commits into
openshift:main
Choose a base branch
from
jhuttana:OCPERT-437
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
0131bf3
[OCPERT-437] Port blocking sec-alerts check command to main for Konfl…
jhuttana f7fe1d5
Resolve stale StateBox blockers on re-run and handle partial check fa…
jhuttana 9ca1b56
Resolve stale StateBox blockers on re-run and handle partial check fa…
jhuttana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import logging | ||
|
|
||
| import click | ||
|
|
||
| from oar.core.advisory import AdvisoryManager | ||
| from oar.core.const import ( | ||
| TASK_CHECK_BLOCKING_SEC_ALERTS, | ||
| TASK_STATUS_FAIL, | ||
| TASK_STATUS_INPROGRESS, | ||
| TASK_STATUS_PASS, | ||
| ) | ||
| from oar.core.statebox import StateBox | ||
| from oar.core.exceptions import StateBoxException | ||
| from oar.core import util | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.pass_context | ||
| def check_blocking_sec_alerts(ctx): | ||
| """ | ||
| Check for blocking security alerts across all RHSA advisories. | ||
| Reports blocking alerts and updates StateBox task status. | ||
| """ | ||
| cs = ctx.obj["cs"] | ||
|
|
||
| try: | ||
| util.log_task_status(TASK_CHECK_BLOCKING_SEC_ALERTS, TASK_STATUS_INPROGRESS) | ||
|
|
||
| am = AdvisoryManager(cs) | ||
| statebox = StateBox(cs) | ||
| advisories = am.get_advisories() | ||
|
|
||
| rhsa_advisories = [ad for ad in advisories if ad.errata_type == "RHSA"] | ||
| if not rhsa_advisories: | ||
| logger.info("No RHSA advisories found, skipping security alert check") | ||
| util.log_task_status(TASK_CHECK_BLOCKING_SEC_ALERTS, TASK_STATUS_PASS) | ||
| return | ||
|
|
||
| logger.info(f"Found {len(rhsa_advisories)} RHSA advisory(ies) to check: " | ||
| f"{', '.join(str(ad.errata_id) for ad in rhsa_advisories)}") | ||
|
|
||
| blocking_advisories = [] | ||
| check_errors = {} | ||
|
|
||
| for advisory in rhsa_advisories: | ||
| try: | ||
| if advisory.has_blocking_security_alert(): | ||
| blocking_advisories.append(advisory) | ||
| except Exception as e: | ||
| check_errors[advisory.errata_id] = str(e) | ||
| logger.error(f"Error checking advisory {advisory.errata_id}: {e}") | ||
|
|
||
| existing_issues = statebox.get_issues( | ||
| unresolved_only=True, task_name=TASK_CHECK_BLOCKING_SEC_ALERTS | ||
| ) | ||
|
|
||
| if blocking_advisories: | ||
| logger.warning("BLOCKING SECURITY ALERTS FOUND:") | ||
| advisory_details = [] | ||
| for advisory in blocking_advisories: | ||
| link = util.get_advisory_link(str(advisory.errata_id)) | ||
| logger.warning(f" RHSA advisory {advisory.errata_id} - {link}") | ||
| advisory_details.append(f"- RHSA advisory {advisory.errata_id}: {link}") | ||
|
|
||
| issue_description = ( | ||
| f"Found blocking security alerts in {len(blocking_advisories)} RHSA advisory(ies)\n\n" | ||
| f"Affected advisories:\n" + "\n".join(advisory_details) | ||
| ) | ||
|
|
||
| existing_blocker = next( | ||
| (i for i in existing_issues if i.get("blocker", False)), None | ||
| ) | ||
| if existing_blocker and existing_blocker["issue"].strip().lower() == issue_description.strip().lower(): | ||
| logger.info("Blocking security alerts unchanged from previous check") | ||
| else: | ||
| if existing_blocker: | ||
| statebox.resolve_issue( | ||
| issue=existing_blocker["issue"], | ||
| resolution="Replaced with updated blocking security alert findings", | ||
| ) | ||
| try: | ||
| statebox.add_issue( | ||
| issue=issue_description, | ||
| blocker=True, | ||
| related_tasks=[TASK_CHECK_BLOCKING_SEC_ALERTS], | ||
| auto_save=True, | ||
| ) | ||
| logger.info(f"Created blocking issue in StateBox for {len(blocking_advisories)} RHSA advisory(ies)") | ||
| except StateBoxException as e: | ||
| logger.warning(f"Could not add StateBox issue: {e}") | ||
|
|
||
| util.log_task_status(TASK_CHECK_BLOCKING_SEC_ALERTS, TASK_STATUS_FAIL) | ||
| elif check_errors: | ||
| error_details = "; ".join(f"{eid}: {err}" for eid, err in check_errors.items()) | ||
| logger.warning(f"Security-alert checks failed for: {error_details}") | ||
| util.log_task_status(TASK_CHECK_BLOCKING_SEC_ALERTS, TASK_STATUS_FAIL) | ||
| else: | ||
| for issue in existing_issues: | ||
| statebox.resolve_issue( | ||
| issue=issue["issue"], | ||
| resolution="No blocking security alerts found on re-check", | ||
| ) | ||
| logger.info(f"Resolved previous StateBox issue: {issue['issue'][:80]}") | ||
| logger.info("No blocking security alerts found") | ||
| util.log_task_status(TASK_CHECK_BLOCKING_SEC_ALERTS, TASK_STATUS_PASS) | ||
|
|
||
| except Exception as e: | ||
| logger.exception("check blocking sec-alerts failed") | ||
| util.log_task_status(TASK_CHECK_BLOCKING_SEC_ALERTS, TASK_STATUS_FAIL) | ||
| raise | ||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.