Skip to content

Commit 8ccd1d7

Browse files
authored
including GitHub Actions to schedule daily audits and Add documentati… (#39116)
* including GitHub Actions to schedule daily audits and Add documentation for the changes made to manage keys created outside of the Google Cloud Secret Manager key rotation system * correcting a typo in the file name * Fix PreCommit GHA and PreCommit Whitespace, and preparing the test of the action from the pull request * Testing the GitHub action from the PR * Remove the pull request configuration from the github Action
1 parent 6984200 commit 8ccd1d7

3 files changed

Lines changed: 79 additions & 3 deletions

File tree

.github/workflows/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,4 @@ PostCommit Jobs run in a schedule against master branch and generally do not get
545545
| [ Infrastructure Policy Enforcer ](https://github.com/apache/beam/actions/workflows/beam_Infrastructure_PolicyEnforcer.yml) | N/A | [![.github/workflows/beam_Infrastructure_PolicyEnforcer.yml](https://github.com/apache/beam/actions/workflows/beam_Infrastructure_PolicyEnforcer.yml/badge.svg?event=schedule)](https://github.com/apache/beam/actions/workflows/beam_Infrastructure_PolicyEnforcer.yml?query=event%3Aschedule) |
546546
| [ Modify the GCP User Roles according to the infra/users.yml file ](https://github.com/apache/beam/actions/workflows/beam_Infrastructure_UsersPermissions.yml) | N/A | [![.github/workflows/beam_Infrastructure_UsersPermissions.yml](https://github.com/apache/beam/actions/workflows/beam_Infrastructure_UsersPermissions.yml/badge.svg?event=schedule)](https://github.com/apache/beam/actions/workflows/beam_Infrastructure_UsersPermissions.yml?query=event%3Aschedule) |
547547
| [ Service Account Keys Management ](https://github.com/apache/beam/actions/workflows/beam_Infrastructure_ServiceAccountKeys.yml) | N/A | [![.github/workflows/beam_Infrastructure_ServiceAccountKeys.yml](https://github.com/apache/beam/actions/workflows/beam_Infrastructure_ServiceAccountKeys.yml/badge.svg?event=schedule)](https://github.com/apache/beam/actions/workflows/beam_Infrastructure_ServiceAccountKeys.yml?query=event%3Aschedule) |
548+
| [ Unmanaged Service Accounts Keys Audit ](https://github.com/apache/beam/actions/workflows/beam_Infrastructure_AuditUnmanagedKeys.yml) | N/A | [![.github/workflows/beam_Infrastructure_AuditUnmanagedKeys.yml](https://github.com/apache/beam/actions/workflows/beam_Infrastructure_AuditUnmanagedKeys.yml/badge.svg?event=schedule)](https://github.com/apache/beam/actions/workflows/beam_Infrastructure_AuditUnmanagedKeys.yml?query=event%3Aschedule) |
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# This workflow works with the GCP security log analyzer to
19+
# generate weekly security reports and initialize log sinks
20+
21+
name: Unmanaged Service Accounts Keys Audit
22+
23+
on:
24+
workflow_dispatch:
25+
schedule:
26+
# Every day at 00:00 UTC
27+
- cron: '0 0 * * *'
28+
29+
concurrency:
30+
group: ${{ github.workflow }}
31+
cancel-in-progress: false
32+
33+
permissions:
34+
contents: read
35+
issues: write
36+
id-token: write
37+
38+
jobs:
39+
beam_UnmanagedKeysAudit:
40+
name: Audit Unmanaged Service Account Keys
41+
runs-on: [self-hosted, ubuntu-24.04, main]
42+
timeout-minutes: 30
43+
steps:
44+
- uses: actions/checkout@v6
45+
46+
- name: Setup gcloud
47+
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db
48+
49+
- name: Setup Python
50+
uses: actions/setup-python@v4
51+
with:
52+
python-version: '3.13'
53+
54+
- name: Install Python dependencies
55+
working-directory: ./infra/enforcement
56+
run: |
57+
python -m pip install --upgrade pip
58+
pip install -r requirements.txt
59+
60+
- name: Run Unmanaged Service Account Keys Audit
61+
working-directory: ./infra/enforcement
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
GITHUB_REPOSITORY: ${{ github.repository }}
65+
run: python account_keys.py --action announce
66+
67+
68+
69+

infra/enforcement/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ The enforcement tools are integrated with GitHub Actions to provide automated co
134134

135135
### Workflow Configuration
136136

137-
The GitHub Actions workflow (`.github/workflows/beam_Infrastructure_PolicyEnforcer.yml`) runs:
138-
- **Schedule**: Weekly on Mondays at 9:00 AM UTC
137+
The repository includes workflows for different security domains:
138+
- **IAM Policy Enforcer** (`.github/workflows/beam_Infrastructure_PolicyEnforcer.yml`): Runs weekly on Mondays at 9:00 AM UTC.
139+
- **Unmanaged Keys Audit** (`.github/workflows/beam_Infrastructure_AuditUnmanagedKeys.yml`): Runs daily at 00:00 UTC. It manages the continuous execution of the `account_keys.py` script to swiftly detect rogue service account keys generated outside the official rotation system.
139140
- **Manual trigger**: Can be triggered manually via `workflow_dispatch`
140141
- **Actions**: Runs both IAM and Account Keys enforcement with the `announce` action
141142

@@ -170,7 +171,9 @@ python account_keys.py --action generate
170171
### Actions
171172

172173
- **check**: Validates service account keys and their permissions against defined policies and reports any differences (default behavior)
173-
- **announce**: Creates or updates a GitHub issue and sends an email notification when service account keys policies differ from the defined ones. If no open issue exists, creates a new one; if an open issue exists, updates the issue body with current violations
174+
- **announce**: Creates or updates a GitHub issue and sends an email notification when service account keys policies differ from the defined ones.
175+
- For general configuration errors, it updates the main compliance issue.
176+
- **For unmanaged/rogue keys (Security Alerts)**, it consolidates alerts into a dedicated `[SECURITY]` issue acting as a live dashboard. It updates the issue by placing the newest audit report at the top and moving the previous reports into a collapsed `<details>` history section. If the keys are revoked and the infrastructure becomes healthy, the system automatically resolves and closes the issue.
174177
- **print**: Prints announcement details for testing purposes without creating actual GitHub issues or sending emails
175178
- **generate**: Updates the compliance file to match the current GCP service account keys and Secret Manager permissions
176179

@@ -183,6 +186,9 @@ The Account Keys enforcement tool provides the following capabilities:
183186
- **Permission Validation**: Ensures that Secret Manager permissions match the declared authorized users
184187
- **Compliance Reporting**: Identifies missing service accounts, undeclared managed secrets, and permission mismatches
185188
- **Automatic Remediation**: Can automatically update the compliance file to match current infrastructure state
189+
- **Unmanaged Key Detection**: Identifies physical keys in IAM that were created outside the automated rotation system by comparing them against the legal, managed keys registered in Google Cloud Secret Manager.
190+
- **Stateful Security Alerts**: Consolidates security violations into a single, dynamically updated GitHub issue, keeping a collapsed `<details>` history of past scans to prevent alert fatigue.
191+
- **Self-Healing Resolution**: Automatically closes the security GitHub issue when all unmanaged keys have been successfully revoked.
186192

187193
### Configuration
188194

0 commit comments

Comments
 (0)