You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "HansMarcus01 (via GitHub)" <gi...@apache.org> on 2026/06/30 19:46:32 UTC

[PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

HansMarcus01 opened a new pull request, #39177:
URL: https://github.com/apache/beam/pull/39177

   This pull request fixes a runtime error in the GitHub action "Unmanaged Service Account Keys". It adds a new report for unauthorized service accounts and prompts users to comply with compliance policies.
   
   Currently the keys.yaml file is empty, which indicates that the service accounts have been created manually, thus preventing secure management of them.
   
   Output expected:
   <img width="1250" height="162" alt="image" src="https://github.com/user-attachments/assets/b50b2b2e-1f79-4031-8da1-458c15984e68" />
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "HansMarcus01 (via GitHub)" <gi...@apache.org>.
HansMarcus01 commented on PR #39177:
URL: https://github.com/apache/beam/pull/39177#issuecomment-5222192968

   @Amar3tto PTAL
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "pabloem (via GitHub)" <gi...@apache.org>.
pabloem commented on code in PR #39177:
URL: https://github.com/apache/beam/pull/39177#discussion_r3786068750


##########
.github/workflows/beam_Infrastructure_PolicyEnforcer.yml:
##########
@@ -82,4 +83,4 @@ jobs:
           EMAIL_ADDRESS: ${{ secrets.ISSUE_REPORT_SENDER_EMAIL_ADDRESS }}
           EMAIL_PASSWORD: ${{ secrets.ISSUE_REPORT_SENDER_EMAIL_PASSWORD }}
           EMAIL_RECIPIENT: "dev@beam.apache.org"

Review Comment:
   if we do not need the email recipient, please create an issue to track removing this (no need to fix in this pull request)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC-273] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "pabloem (via GitHub)" <gi...@apache.org>.
pabloem commented on PR #39177:
URL: https://github.com/apache/beam/pull/39177#issuecomment-5337907063

   lgtm


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39177:
URL: https://github.com/apache/beam/pull/39177#issuecomment-4847930127

   Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment `assign set of reviewers`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "pabloem (via GitHub)" <gi...@apache.org>.
pabloem commented on code in PR #39177:
URL: https://github.com/apache/beam/pull/39177#discussion_r3787711333


##########
infra/enforcement/account_keys.py:
##########
@@ -406,23 +410,44 @@ def print_announcement(self, recipient: str) -> None:
         """
         if not self.sending_client:
             raise ValueError("SendingClient is required for printing announcements")
-            
+
         diff = self.check_compliance()
 
         if not diff:
             self.logger.info("No compliance issues found, no announcement will be printed.")
             return
 
-        title = f"Account Keys Compliance Issue Detected"
-        body = f"Account keys for project {self.project_id} are not compliant with the defined policies on {self.service_account_keys_file}\n\n"
-        for issue in diff:
-            body += f"- {issue}\n"
+        unmanaged_keys_issues = [issue for issue in diff if "SECURITY ALERT" in issue]
+        general_issues = [issue for issue in diff if "SECURITY ALERT" not in issue]

Review Comment:
   SECURITY ALERT is too general to differentiate issues. We need something more specific. Let's add a specific string for this. Let's say 'iac_drift_for_iam' - this refers to the difference between the IaC config and the real state ('drift'). Use that string to match. And do not write SECURITY ALERT, because it seems like a more serious problem than it currently is.



##########
infra/enforcement/iam.py:
##########
@@ -247,51 +248,86 @@ def create_announcement(self, recipient: str) -> None:
         """
         if not self.sending_client:
             raise ValueError("SendingClient is required for creating announcements")
-            
         diff = self.check_compliance()
 
         if not diff:
             self.logger.info("No compliance issues found, no announcement will be created.")
             return
 
-        title = f"IAM Policy Non-Compliance Detected"
-        body = f"IAM policy for project {self.project_id} is not compliant with the defined policies on {self.users_file}\n\n"
-        for issue in diff:
-            body += f"- {issue}\n"
+        security_alerts = [issue for issue in diff if "SECURITY ALERT" in issue]
+        general_issues = [issue for issue in diff if "SECURITY ALERT" not in issue]

Review Comment:
   SECURITY ALERT is too general to differentiate issues. We need something more specific. Let's add a specific string for this. Let's say 'iac_drift_for_iam' - this refers to the difference between the IaC config and the real state ('drift'). Use that string to match. And do not write SECURITY ALERT, because it seems like a more serious problem than it currently is.



##########
infra/enforcement/iam.py:
##########
@@ -247,51 +248,86 @@ def create_announcement(self, recipient: str) -> None:
         """
         if not self.sending_client:
             raise ValueError("SendingClient is required for creating announcements")
-            
         diff = self.check_compliance()
 
         if not diff:
             self.logger.info("No compliance issues found, no announcement will be created.")
             return
 
-        title = f"IAM Policy Non-Compliance Detected"
-        body = f"IAM policy for project {self.project_id} is not compliant with the defined policies on {self.users_file}\n\n"
-        for issue in diff:
-            body += f"- {issue}\n"
+        security_alerts = [issue for issue in diff if "SECURITY ALERT" in issue]
+        general_issues = [issue for issue in diff if "SECURITY ALERT" not in issue]
+
+        if general_issues:
+            self.logger.info(f"Found {len(general_issues)} general IAM compliance issues. Triggering announcement...")
+            title = f"IAM Policy Non-Compliance Detected"
+            body = f"IAM policy for project {self.project_id} is not compliant with the defined policies on {self.users_file}\n\n"
+            for issue in general_issues:
+                body += f"- {issue}\n"
+
+            announcement = f"Dear team,\n\nThis is an automated notification about compliance issues detected in the IAM policy for project {self.project_id}.\n\n"
+            announcement += f"We found {len(general_issues)} compliance issue(s) that need your attention.\n"
+            announcement += f"\nPlease check the GitHub issue for detailed information and take appropriate action to resolve these compliance violations."
+
+            self.sending_client.create_announcement(title, body, recipient, announcement)
 
-        announcement = f"Dear team,\n\nThis is an automated notification about compliance issues detected in the IAM policy for project {self.project_id}.\n\n"
-        announcement += f"We found {len(diff)} compliance issue(s) that need your attention.\n"
-        announcement += f"\nPlease check the GitHub issue for detailed information and take appropriate action to resolve these compliance violations."
+        if security_alerts:
+            self.logger.info(f"Found {len(security_alerts)} critical IAM security alerts. Dispatching to GitHub security issue...")
+            title = f"[SECURITY] Action Required: Unauthorized IAM Users Detected"
+            body = f"Critical security violations detected in IAM policies for project {self.project_id}:\n\n"
+            for issue in security_alerts:
+                body += f"- {issue}\n"
 
-        self.sending_client.create_announcement(title, body, recipient, announcement)
+            announcement = f"URGENT: Dear team,\n\nThis is an automated security alert regarding unauthorized IAM access in project {self.project_id}.\n\n"
+            announcement += f"We found {len(security_alerts)} critical security alert(s) that require IMMEDIATE attention.\n"
+            announcement += f"\nPlease check the GitHub issue for detailed information and revoke unauthorized access immediately."
+
+            self.sending_client.create_announcement(title, body, recipient, announcement)
 
     def print_announcement(self, recipient: str) -> None:
         """
         Prints announcement details instead of sending them (for testing purposes).
-        
+
         Args:
             recipient (str): The email address of the announcement recipient.
         """
         if not self.sending_client:
             raise ValueError("SendingClient is required for printing announcements")
-            
+
         diff = self.check_compliance()
 
         if not diff:
             self.logger.info("No compliance issues found, no announcement will be printed.")
             return
 
-        title = f"IAM Policy Non-Compliance Detected"
-        body = f"IAM policy for project {self.project_id} is not compliant with the defined policies on {self.users_file}\n\n"
-        for issue in diff:
-            body += f"- {issue}\n"
+        security_alerts = [issue for issue in diff if "SECURITY ALERT" in issue]
+        general_issues = [issue for issue in diff if "SECURITY ALERT" not in issue]

Review Comment:
   SECURITY ALERT is too general to differentiate issues. We need something more specific. Let's add a specific string for this. Let's say 'iac_drift_for_iam' - this refers to the difference between the IaC config and the real state ('drift'). Use that string to match. And do not write SECURITY ALERT, because it seems like a more serious problem than it currently is.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #39177:
URL: https://github.com/apache/beam/pull/39177#discussion_r3501437875


##########
infra/enforcement/account_keys.py:
##########
@@ -405,23 +405,44 @@
         """
         if not self.sending_client:
             raise ValueError("SendingClient is required for printing announcements")
-            
+
         diff = self.check_compliance()
 
         if not diff:
             self.logger.info("No compliance issues found, no announcement will be printed.")
             return
 
-        title = f"Account Keys Compliance Issue Detected"
-        body = f"Account keys for project {self.project_id} are not compliant with the defined policies on {self.service_account_keys_file}\n\n"
-        for issue in diff:
-            body += f"- {issue}\n"
+        unmanaged_keys_issues = [issue for issue in diff if "SECURITY ALERT" in issue]
+        general_issues = [issue for issue in diff if "SECURITY ALERT" not in issue]
+
+        if general_issues:
+            self.logger.info("Printing general compliance announcement...")
+            title = f"[SECURITY] Action Required: Unauthorized Service Accounts Detected"
+            body = f"Unauthorized Service Accounts Report\n\n"
+            body += f"Account keys for project {self.project_id} are not compliant with the defined policies on {self.service_account_keys_file}\n\n"
+            for issue in general_issues:
+                body += f"- {issue}\n"
+
+            announcement = f"Dear team,\n\nThis is an automated notification about compliance issues detected in the Account Keys policy for project {self.project_id}.\n\n"
+            announcement += f"We found {len(general_issues)} compliance issue(s) that need your attention.\n"
+            announcement += f"\nPlease check the GitHub issue for detailed information and take appropriate action to resolve these compliance violations."
 
-        announcement = f"Dear team,\n\nThis is an automated notification about compliance issues detected in the Account Keys policy for project {self.project_id}.\n\n"
-        announcement += f"We found {len(diff)} compliance issue(s) that need your attention.\n"
-        announcement += f"\nPlease check the GitHub issue for detailed information and take appropriate action to resolve these compliance violations."
+            self.sending_client.print_announcement(title, body, recipient, announcement)
 
-        self.sending_client.print_announcement(title, body, recipient, announcement)
+        if unmanaged_keys_issues:
+            self.logger.info("Printing security dashboard update for unmanaged keys...")
+            timestamp = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
+            print("\n" + "="*60)
+            print("SIMULATING GITHUB SECURITY ISSUE CREATION/UPDATE")
+            print("="*60)
+            print("Title: [SECURITY] Action Required: Unmanaged Service Account Keys Detected\n")
+            print(f"Body:\n### Unmanaged Keys Audit Report ({timestamp})")
+            print(f"The following unauthorized or unmanaged keys were detected in `{self.project_id}`:\n")
+            for issue in unmanaged_keys_issues:
+                print(f"- {issue}")

Review Comment:
   ## CodeQL / Clear-text logging of sensitive information
   
   This expression logs [sensitive data (secret)](1) as clear text.
   This expression logs [sensitive data (secret)](2) as clear text.
   This expression logs [sensitive data (secret)](3) as clear text.
   
   [Show more details](https://github.com/apache/beam/security/code-scanning/1801)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39177:
URL: https://github.com/apache/beam/pull/39177#issuecomment-5296748984

   Assigning reviewers:
   
   R: @Abacn for label build.
   
   
   Note: If you would like to opt out of this review, comment `assign to next reviewer`.
   
   Available commands:
   - `stop reviewer notifications` - opt out of the automated review tooling
   - `remind me after tests pass` - tag the comment author after tests pass
   - `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
   
   The PR bot will only process comments in the main thread (not review comments).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "pabloem (via GitHub)" <gi...@apache.org>.
pabloem commented on code in PR #39177:
URL: https://github.com/apache/beam/pull/39177#discussion_r3672172663


##########
.github/workflows/beam_Infrastructure_PolicyEnforcer.yml:
##########
@@ -24,7 +24,7 @@ on:
   workflow_dispatch:
   schedule:
     # Once a week at 9:00 AM on Monday
-    - cron: '0 9 * * 1'

Review Comment:
   why are you changing this? this is no longer "Once a week at 9:00 AM on Monday" - but rather, "every day at midnight"



##########
.github/workflows/beam_Infrastructure_UsersPermissions.yml:
##########
@@ -52,7 +52,7 @@ jobs:
       - name: Setup gcloud
         uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db
       - name: Install Terraform
-        uses: hashicorp/setup-terraform@v4
+        uses: hashicorp/setup-terraform@dfe3c3f87815947d99a8997f908cb6525fc44e9e

Review Comment:
   this change seems unrelated. why is it included here? is it necessary?
   if not necessary, please revert.



##########
.github/workflows/beam_Infrastructure_AuditUnmanagedKeys.yml:
##########
@@ -1,71 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one

Review Comment:
   why do we need to remove this file?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "pabloem (via GitHub)" <gi...@apache.org>.
pabloem commented on code in PR #39177:
URL: https://github.com/apache/beam/pull/39177#discussion_r3786090828


##########
infra/enforcement/account_keys.py:
##########
@@ -316,18 +317,17 @@ def check_compliance(self) -> List[str]:
                 msg = f"Service account '{service_account}' is not declared in the service account keys file."
                 compliance_issues.append(msg)
                 self.logger.warning(msg)
-            else:
                 iam_keys = self._get_user_managed_keys_from_iam(service_account)
-                if iam_keys:
-                    secret_name = f"{self._denormalize_account_email(service_account)}-key"
-                    legal_keys = []
-                    if secret_name in managed_secrets:
-                        legal_keys = self._get_verified_keys_from_secret_manager(secret_name)
-                    unmanaged_keys = set(iam_keys) - set(legal_keys)
-                    for unmanaged_key in unmanaged_keys:
-                        msg = f"SECURITY ALERT: Unmanaged key '{unmanaged_key}' detected on account '{service_account}'. This key was created outside of Beam's service account management system. "
-                        compliance_issues.append(msg)
-                        self.logger.warning(msg)
+            if iam_keys:

Review Comment:
   there could be an undefined variable here. How do we fix?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "HansMarcus01 (via GitHub)" <gi...@apache.org>.
HansMarcus01 commented on PR #39177:
URL: https://github.com/apache/beam/pull/39177#issuecomment-5259998738

   Note: The "Clear-text logging of sensitive information" warning flagged on this file is a false positive.CodeQL's heuristics flagged the variables secret, secret_name, and managed_secrets. However, these variables exclusively store the GCP Secret Manager resource identifiers (names/IDs), not the actual cryptographic payloads or sensitive data. The actual secret payloads are securely handled in a separate method (_get_verified_keys_from_secret_manager) and are never passed to the logger.  Logging resource names is standard practice and strictly necessary for infrastructure auditing and debugging. Since no sensitive data is being exposed in plain text, I suggest we dismiss or ignore this specific alert.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC-273] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "pabloem (via GitHub)" <gi...@apache.org>.
pabloem merged PR #39177:
URL: https://github.com/apache/beam/pull/39177


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #39177:
URL: https://github.com/apache/beam/pull/39177#discussion_r3609547503


##########
infra/enforcement/sending.py:
##########
@@ -319,6 +345,13 @@
         print(f"Recipient: {recipient}")
         print(f"Announcement: {announcement}")
 
-        print("\nSimulating GitHub issue creation...")
-        print(f"Title: {title}")
-        print(f"Body: {body}")
+        timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
+
+        print("\n" + "="*60)
+        print("SIMULATING GITHUB GENERAL ISSUE CREATION/UPDATE")
+        print("="*60)
+        print(f"Title: {title}\n")
+        print(f"Body:\n### Compliance Audit Report ({timestamp})")
+        print(body)

Review Comment:
   ## CodeQL / Clear-text logging of sensitive information
   
   This expression logs [sensitive data (secret)](1) as clear text.
   This expression logs [sensitive data (secret)](2) as clear text.
   This expression logs [sensitive data (secret)](3) as clear text.
   
   [Show more details](https://github.com/apache/beam/security/code-scanning/1893)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #39177:
URL: https://github.com/apache/beam/pull/39177#discussion_r3501433319


##########
infra/enforcement/sending.py:
##########
@@ -248,18 +248,36 @@ def create_announcement(self, title: str, body: str, recipient: str, announcemen
         """
         open_issues = self._get_open_issues(title)
         open_issues.sort(key=lambda x: x.updated_at, reverse=True)
+
+        timestamp = __import__("datetime").datetime.now(__import__("datetime").timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
+        new_report = f"### Compliance Audit Report ({timestamp})\n{body}"
+
         if open_issues:
-            self.logger.info(f"Issue with title '{title}' already exists: #{open_issues[0].number}")
-            announcement += f"\n\nRelated GitHub Issue: {open_issues[0].html_url}"
+            target_issue = open_issues[0]
+            self.logger.info(f"Issue with title '{title}' already exists: #{target_issue.number}")
+            announcement += f"\n\nRelated GitHub Issue: {target_issue.html_url}"
+
+            old_body = target_issue.body or ""
+            history_marker = "### History\n<details>\n<summary>Click to expand</summary>\n\n"
 
-            if open_issues[0].body != body:
-                self.logger.info(f"Updating body of issue #{open_issues[0].number}")
-                self.update_issue_body(open_issues[0].number, body)
+            if history_marker in old_body:
+                # If history already exists, append the new report to it
+                headed = old_body.split(history_marker)
+                last_report = headed[0].strip()
+                old_history = headed[1].replace("</details>", "").strip()
+                combined_history = f"{last_report}\n\n---\n\n{old_history}"

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   **Correctness/Robustness**: Using `.replace("</details>", "")` is risky because it will remove *all* occurrences of `</details>` within the history, which will corrupt the Markdown rendering if there are other collapsed sections or nested HTML details blocks. Additionally, `split(history_marker)` should limit the split to 1 to prevent issues if the marker appears elsewhere.
   
   Instead, split with `maxsplit=1` and safely strip only the trailing `</details>` tag.
   
   ```suggestion
                   headed = old_body.split(history_marker, 1)
                   last_report = headed[0].strip()
                   old_history = headed[1].rstrip()
                   if old_history.endswith("</details>"):
                       old_history = old_history[:-10].rstrip()
                   combined_history = f"{last_report}\n\n---\n\n{old_history}"
   ```



##########
infra/enforcement/sending.py:
##########
@@ -273,6 +291,13 @@ def print_announcement(self, title: str, body: str, recipient: str, announcement
         print(f"Recipient: {recipient}")
         print(f"Announcement: {announcement}")
 
-        print("\nSimulating GitHub issue creation...")
-        print(f"Title: {title}")
-        print(f"Body: {body}")
+        timestamp = __import__("datetime").datetime.now(__import__("datetime").timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   **Style/Maintainability**: Using inline `__import__("datetime")` is non-idiomatic and violates PEP 8 guidelines.
   
   Please import `datetime` and `timezone` at the top of the file and simplify this line.
   
   ```suggestion
           timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
   ```
   
   <details>
   <summary>References</summary>
   
   1. Imports should be placed at the top of the file, as per PEP 8 guidelines. <sup>([link](https://github.com/apache/beam/blob/master/.gemini/styleguide.md))</sup>
   </details>



##########
infra/enforcement/account_keys.py:
##########
@@ -405,23 +405,44 @@ def print_announcement(self, recipient: str) -> None:
         """
         if not self.sending_client:
             raise ValueError("SendingClient is required for printing announcements")
-            
+
         diff = self.check_compliance()
 
         if not diff:
             self.logger.info("No compliance issues found, no announcement will be printed.")
             return
 
-        title = f"Account Keys Compliance Issue Detected"
-        body = f"Account keys for project {self.project_id} are not compliant with the defined policies on {self.service_account_keys_file}\n\n"
-        for issue in diff:
-            body += f"- {issue}\n"
+        unmanaged_keys_issues = [issue for issue in diff if "SECURITY ALERT" in issue]
+        general_issues = [issue for issue in diff if "SECURITY ALERT" not in issue]
+
+        if general_issues:
+            self.logger.info("Printing general compliance announcement...")
+            title = f"[SECURITY] Action Required: Unauthorized Service Accounts Detected"
+            body = f"Unauthorized Service Accounts Report\n\n"
+            body += f"Account keys for project {self.project_id} are not compliant with the defined policies on {self.service_account_keys_file}\n\n"
+            for issue in general_issues:
+                body += f"- {issue}\n"
+
+            announcement = f"Dear team,\n\nThis is an automated notification about compliance issues detected in the Account Keys policy for project {self.project_id}.\n\n"
+            announcement += f"We found {len(general_issues)} compliance issue(s) that need your attention.\n"
+            announcement += f"\nPlease check the GitHub issue for detailed information and take appropriate action to resolve these compliance violations."
 
-        announcement = f"Dear team,\n\nThis is an automated notification about compliance issues detected in the Account Keys policy for project {self.project_id}.\n\n"
-        announcement += f"We found {len(diff)} compliance issue(s) that need your attention.\n"
-        announcement += f"\nPlease check the GitHub issue for detailed information and take appropriate action to resolve these compliance violations."
+            self.sending_client.print_announcement(title, body, recipient, announcement)
 
-        self.sending_client.print_announcement(title, body, recipient, announcement)
+        if unmanaged_keys_issues:
+            self.logger.info("Printing security dashboard update for unmanaged keys...")
+            timestamp = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   **Potential Runtime Error**: Ensure that `datetime` is imported at the top of the file. If it is not imported, this line will raise a `NameError` at runtime.
   
   If `datetime` is not imported, please add `from datetime import datetime, timezone` at the top of the file and update this line to use them directly.
   
   ```suggestion
               timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
   ```



##########
infra/enforcement/sending.py:
##########
@@ -248,18 +248,36 @@ def create_announcement(self, title: str, body: str, recipient: str, announcemen
         """
         open_issues = self._get_open_issues(title)
         open_issues.sort(key=lambda x: x.updated_at, reverse=True)
+
+        timestamp = __import__("datetime").datetime.now(__import__("datetime").timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   **Style/Maintainability**: Using inline `__import__("datetime")` is non-idiomatic and violates PEP 8 guidelines regarding imports being at the top of the file.
   
   Please import `datetime` and `timezone` at the top of the file:
   ```python
   from datetime import datetime, timezone
   ```
   And simplify this line.
   
   ```suggestion
           timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
   ```
   
   <details>
   <summary>References</summary>
   
   1. Imports should be placed at the top of the file, as per PEP 8 guidelines. <sup>([link](https://github.com/apache/beam/blob/master/.gemini/styleguide.md))</sup>
   </details>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC 2026] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #39177:
URL: https://github.com/apache/beam/pull/39177#issuecomment-4847353688

   ## Summary of Changes
   
   Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
   
   This pull request enhances the 'Unmanaged Service Account Keys' GitHub action by improving how compliance issues are reported and tracked. It introduces a more robust system for logging unauthorized service accounts and compliance violations, ensuring that security alerts are distinct from general issues and that historical audit data is preserved within GitHub issues instead of being lost during updates.
   
   ### Highlights
   
   * **Enhanced Compliance Reporting**: Implemented a structured audit report format for GitHub issues, including timestamped entries and a collapsible history section for better tracking of compliance violations.
   * **Security Alert Differentiation**: Separated unmanaged service account keys from general compliance issues, ensuring security-critical alerts are prioritized and clearly identified.
   * **Improved Issue Management**: Updated the logic for creating and updating GitHub issues to append new reports to existing threads rather than overwriting them, preserving audit trails.
   
   <details>
   <summary><b>New Features</b></summary>
   
   🧠 You can now enable **Memory** (public preview) to help **Gemini Code Assist** learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. **Click [here](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
   </details>
   
   <details>
   <summary><b>Ignored Files</b></summary>
   
   *   **Ignored by pattern:** `.github/workflows/**` (1)
       *   .github/workflows/beam_Infrastructure_AuditUnmanagedKeys.yml
   </details>
   
   <details>
   <summary><b>Using Gemini Code Assist</b></summary>
   <br>
   
   The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
   
   <b>Invoking Gemini</b>
   
   You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page.
   
   Feature | Command | Description
   --- | --- | ---
   Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
   Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
   Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
   Help | `/gemini help` | Displays a list of available commands.
   
   <b>Customization</b>
   
   To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
   
   <b>Limitations & Feedback</b>
   
   Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
   </details>
   
   
   [^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [GSoC-273] Fixing the github action Unmanaged Service Account Keys [beam]

Posted by "pabloem (via GitHub)" <gi...@apache.org>.
pabloem commented on code in PR #39177:
URL: https://github.com/apache/beam/pull/39177#discussion_r3807011103


##########
infra/enforcement/account_keys.py:
##########
@@ -376,13 +379,14 @@ def create_announcement(self, recipient: str) -> None:
             self.logger.info("No compliance issues found, no announcement will be created.")
             return
 
-        unmanaged_keys_issues = [issue for issue in diff if "SECURITY ALERT" in issue]
-        general_issues = [issue for issue in diff if "SECURITY ALERT" not in issue]
+        unmanaged_keys_issues = [issue for issue in diff if "IAC_DRIFT_SA_KEY" in issue]
+        general_issues = [issue for issue in diff if "IAC_DRIFT_SA_KEY" not in issue]
 
         if general_issues:
             self.logger.info(f"Found {len(general_issues)} general compliance issues. Triggering announcement...")
-            title = f"Account Keys Compliance Issue Detected"
-            body = f"Account keys for project {self.project_id} are not compliant with the defined policies on {self.service_account_keys_file}\n\n"
+            title = f"[SECURITY] Action Required: Unauthorized Service Accounts Detected"

Review Comment:
   change the title too to include `IAC_DRIFT_SA_KEY` - also, create a constant at the top of the file for `IAC_DRIFT_SA_KEY`. Even better if we have a central place for all the constants.



##########
infra/enforcement/iam.py:
##########
@@ -247,51 +248,86 @@ def create_announcement(self, recipient: str) -> None:
         """
         if not self.sending_client:
             raise ValueError("SendingClient is required for creating announcements")
-            
         diff = self.check_compliance()
 
         if not diff:
             self.logger.info("No compliance issues found, no announcement will be created.")
             return
 
-        title = f"IAM Policy Non-Compliance Detected"
-        body = f"IAM policy for project {self.project_id} is not compliant with the defined policies on {self.users_file}\n\n"
-        for issue in diff:
-            body += f"- {issue}\n"
+        iam_drift_issues = [issue for issue in diff if "IAC_DRIFT_IAM_USER" in issue]
+        general_issues = [issue for issue in diff if "IAC_DRIFT_IAM_USER" not in issue]

Review Comment:
   is it okay if general_issues only filters out `IAC_DRIFT_IAM_USER` but not `IAC_DRIFT_SA_KEY`



##########
infra/enforcement/iam.py:
##########
@@ -247,51 +248,86 @@ def create_announcement(self, recipient: str) -> None:
         """
         if not self.sending_client:
             raise ValueError("SendingClient is required for creating announcements")
-            
         diff = self.check_compliance()
 
         if not diff:
             self.logger.info("No compliance issues found, no announcement will be created.")
             return
 
-        title = f"IAM Policy Non-Compliance Detected"
-        body = f"IAM policy for project {self.project_id} is not compliant with the defined policies on {self.users_file}\n\n"
-        for issue in diff:
-            body += f"- {issue}\n"
+        iam_drift_issues = [issue for issue in diff if "IAC_DRIFT_IAM_USER" in issue]
+        general_issues = [issue for issue in diff if "IAC_DRIFT_IAM_USER" not in issue]
+
+        if general_issues:
+            self.logger.info(f"Found {len(general_issues)} general IAM compliance issues. Triggering announcement...")
+            title = f"IAM Policy Non-Compliance Detected"
+            body = f"IAM policy for project {self.project_id} is not compliant with the defined policies on {self.users_file}\n\n"
+            for issue in general_issues:
+                body += f"- {issue}\n"
+
+            announcement = f"Dear team,\n\nThis is an automated notification about compliance issues detected in the IAM policy for project {self.project_id}.\n\n"
+            announcement += f"We found {len(general_issues)} compliance issue(s) that need your attention.\n"
+            announcement += f"\nPlease check the GitHub issue for detailed information and take appropriate action to resolve these compliance violations."
+
+            self.sending_client.create_announcement(title, body, recipient, announcement)
 
-        announcement = f"Dear team,\n\nThis is an automated notification about compliance issues detected in the IAM policy for project {self.project_id}.\n\n"
-        announcement += f"We found {len(diff)} compliance issue(s) that need your attention.\n"
-        announcement += f"\nPlease check the GitHub issue for detailed information and take appropriate action to resolve these compliance violations."
+        if iam_drift_issues:
+            self.logger.info(f"Found {len(iam_drift_issues)} critical IAM security alerts. Dispatching to GitHub security issue...")
+            title = f"[SECURITY] Action Required: Unauthorized IAM Users Detected"
+            body = f"Critical security violations detected in IAM policies for project {self.project_id}:\n\n"
+            for issue in iam_drift_issues:
+                body += f"- {issue}\n"
 
-        self.sending_client.create_announcement(title, body, recipient, announcement)
+            announcement = f"URGENT: Dear team,\n\nThis is an automated security alert regarding unauthorized IAM access in project {self.project_id}.\n\n"
+            announcement += f"We found {len(iam_drift_issues)} critical security alert(s) that require IMMEDIATE attention.\n"
+            announcement += f"\nPlease check the GitHub issue for detailed information and revoke unauthorized access immediately."
+
+            self.sending_client.create_announcement(title, body, recipient, announcement)
 
     def print_announcement(self, recipient: str) -> None:
         """
         Prints announcement details instead of sending them (for testing purposes).
-        
+
         Args:
             recipient (str): The email address of the announcement recipient.
         """
         if not self.sending_client:
             raise ValueError("SendingClient is required for printing announcements")
-            
+
         diff = self.check_compliance()
 
         if not diff:
             self.logger.info("No compliance issues found, no announcement will be printed.")
             return
 
-        title = f"IAM Policy Non-Compliance Detected"
-        body = f"IAM policy for project {self.project_id} is not compliant with the defined policies on {self.users_file}\n\n"
-        for issue in diff:
-            body += f"- {issue}\n"
+        iam_drift_issues = [issue for issue in diff if "IAC_DRIFT_IAM_USER" in issue]
+        general_issues = [issue for issue in diff if "IAC_DRIFT_IAM_USER" not in issue]

Review Comment:
   use a coinstant here please and make sure filtering is correct (do we only filter out `IAC_DRIFT_IAM_USER` ? or should we filter out other IAC_DRIFT constants?



##########
infra/enforcement/iam.py:
##########
@@ -223,7 +224,7 @@ def check_compliance(self) -> List[str]:
             existing_user = existing_users.get(email)
 
             if current_user and not existing_user:
-                differences.append(f"User {email} not found in existing policy.")
+                differences.append(f"IAC_DRIFT_IAM_USER: Unauthorized user '{email}' detected in GCP but not found in existing policy.")

Review Comment:
   create a constant for `IAC_DRIFT_IAM_USER`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org