You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: infra/enforcement/README.md
+68-9Lines changed: 68 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,12 @@
19
19
20
20
# Infrastructure rules enforcement
21
21
22
-
This module is used to check that the infrastructure rules are being used.
22
+
This module is used to check that the infrastructure rules are being used and provides automated notifications for compliance violations.
23
+
24
+
The enforcement tools support multiple notification methods:
25
+
-**GitHub Issues**: Automatically create GitHub issues with detailed compliance reports
26
+
-**Email Notifications**: Send email alerts via SMTP for compliance violations
27
+
-**Console Output**: Print detailed reports to console for manual review
23
28
24
29
## IAM Policies
25
30
@@ -34,8 +39,11 @@ You can specify the action either through the configuration file (`config.yml`)
34
39
# Check compliance and report issues (default)
35
40
python iam.py --action check
36
41
37
-
# Create GitHub issue if compliance violations are found
38
-
python iam.py --action issue
42
+
# Create/update GitHub issue and send email if compliance violations are found
43
+
python iam.py --action announce
44
+
45
+
# Print announcement details for testing purposes (no actual issue created)
46
+
python iam.py --action print
39
47
40
48
# Generate new compliance file based on current IAM policy
41
49
python iam.py --action generate
@@ -44,7 +52,8 @@ python iam.py --action generate
44
52
### Actions
45
53
46
54
-**check**: Validates IAM policies against defined policies and reports any differences (default behavior)
47
-
-**issue**: Creates a GitHub issue when IAM policies differ from the defined ones, including detailed permission discrepancies
55
+
-**announce**: Creates or updates a GitHub issue and sends an email notification when IAM 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
56
+
-**print**: Prints announcement details for testing purposes without creating actual GitHub issues or sending emails
48
57
-**generate**: Updates the compliance file to match the current GCP IAM policy, creating a new baseline from existing permissions
49
58
50
59
### Features
@@ -58,16 +67,31 @@ The IAM Policy enforcement tool provides the following capabilities:
58
67
-**Sorted Output**: Provides consistent, sorted output for easy comparison and review
59
68
-**Detailed Reporting**: Comprehensive reporting of permission differences with clear before/after comparisons
60
69
-**GitHub Integration**: Automatic issue creation with detailed compliance violation reports
70
+
-**Email Notifications**: Optional email notifications for compliance issues via SMTP
71
+
-**Issue Management**: Smart issue handling - creates new issues when none exist, updates existing open issues with current violations
The `config.yml` file supports the following parameters for IAM policies:
65
77
66
78
-`project_id`: GCP project ID to check (default: `apache-beam-testing`)
67
79
-`users_file`: Path to the YAML file containing expected IAM policies (default: `../iam/users.yml`)
68
-
-`action`: Default action to perform (`check`, `issue`, or `generate`)
80
+
-`action`: Default action to perform (`check`, `announce`, `print`, or `generate`)
69
81
-`logging`: Logging configuration (level and format)
70
82
83
+
### Environment Variables (for announce action)
84
+
85
+
When using the `announce` action, the following environment variables are required:
86
+
87
+
-`GITHUB_TOKEN`: GitHub personal access token for creating issues
88
+
-`GITHUB_REPOSITORY`: Repository in format `owner/repo` (default: `apache/beam`)
89
+
-`SMTP_SERVER`: SMTP server for email notifications
90
+
-`SMTP_PORT`: SMTP port (default: 587)
91
+
-`EMAIL_ADDRESS`: Email address for sending notifications
92
+
-`EMAIL_PASSWORD`: Email password for authentication
93
+
-`EMAIL_RECIPIENT`: Email address to receive notifications
94
+
71
95
### IAM Policy File Format
72
96
73
97
The IAM policy file should follow this YAML structure:
@@ -98,9 +122,28 @@ Each user entry includes:
98
122
3. **Role Processing**: Processes all roles while filtering out conditional bindings
99
123
4. **Comparison**: Compares current permissions with expected permissions from the policy file
100
124
5. **Reporting**: Generates detailed reports of any discrepancies found
125
+
6. **Notification**: Sends notifications via GitHub issues and/or email when using announce action
126
+
127
+
The `print` action can be used for testing notification content without actually creating GitHub issues or sending emails.
101
128
102
129
Command-line arguments take precedence over configuration file settings.
103
130
131
+
## GitHub Actions Integration
132
+
133
+
The enforcement tools are integrated with GitHub Actions to provide automated compliance monitoring. The workflow is configured to run weekly and automatically create GitHub issues and send email notifications for any policy violations.
134
+
135
+
### Workflow Configuration
136
+
137
+
The GitHub Actions workflow (`.github/workflows/beam_Infrastructure_PolicyEnforcer.yml`) runs:
138
+
- **Schedule**: Weekly on Mondays at 9:00 AM UTC
139
+
- **Manual trigger**: Can be triggered manually via `workflow_dispatch`
140
+
- **Actions**: Runs both IAM and Account Keys enforcement with the `announce` action
141
+
142
+
**Note**:
143
+
- The email service is configured to use gmail
144
+
- The recipient email is set to `[email protected]` for Apache Beam project notifications
145
+
- The `GITHUB_TOKEN` is automatically provided by GitHub Actions and doesn't need to be configured manually
146
+
104
147
## Account Keys
105
148
106
149
The enforcement is also done by validating service account keys and their access permissions against the defined policies.
@@ -114,8 +157,11 @@ You can specify the action either through the configuration file (`config.yml`)
114
157
# Check compliance and report issues (default)
115
158
python account_keys.py --action check
116
159
117
-
# Create GitHub issue if compliance violations are found
118
-
python account_keys.py --action issue
160
+
# Create/update GitHub issue and send email if compliance violations are found
161
+
python account_keys.py --action announce
162
+
163
+
# Print announcement details for testing purposes (no actual issue created)
164
+
python account_keys.py --action print
119
165
120
166
# Generate new compliance file based on current service account keys policy
- **check**: Validates service account keys and their permissions against defined policies and reports any differences (default behavior)
127
-
- **issue**: Creates a GitHub issue when service account keys policies differ from the defined ones
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
+
- **print**: Prints announcement details for testing purposes without creating actual GitHub issues or sending emails
128
175
- **generate**: Updates the compliance file to match the current GCP service account keys and Secret Manager permissions
129
176
130
177
### Features
@@ -143,9 +190,21 @@ The `config.yml` file supports the following parameters for account keys:
143
190
144
191
- `project_id`: GCP project ID to check
145
192
- `service_account_keys_file`: Path to the YAML file containing expected service account keys policies (default: `../keys/keys.yaml`)
146
-
- `action`: Default action to perform (`check`, `issue`, or `generate`)
193
+
- `action`: Default action to perform (`check`, `announce`, `print`, or `generate`)
147
194
- `logging`: Logging configuration (level and format)
148
195
196
+
### Environment Variables (for announce action)
197
+
198
+
When using the `announce` action, the following environment variables are required:
199
+
200
+
- `GITHUB_TOKEN`: GitHub personal access token for creating issues
201
+
- `GITHUB_REPOSITORY`: Repository in format `owner/repo` (default: `apache/beam`)
202
+
- `SMTP_SERVER`: SMTP server for email notifications
203
+
- `SMTP_PORT`: SMTP port (default: 587)
204
+
- `EMAIL_ADDRESS`: Email address for sending notifications
205
+
- `EMAIL_PASSWORD`: Email password for authentication
206
+
- `EMAIL_RECIPIENT`: Email address to receive notifications
207
+
149
208
### Service Account Keys File Format
150
209
151
210
The service account keys file should follow this YAML structure:
0 commit comments