This module is used to check that the infrastructure rules are being used and provides automated notifications for compliance violations.
The enforcement tools support multiple notification methods:
The enforcement is done by validating the IAM policies against the defined policies. The tool monitors and enforces compliance for user permissions, service account roles, and group memberships across your GCP project.
You can specify the action either through the configuration file (config.yml) or via command-line arguments:
# Check compliance and report issues (default) python iam.py --action check # Create/update GitHub issue and send email if compliance violations are found python iam.py --action announce # Print announcement details for testing purposes (no actual issue created) python iam.py --action print # Generate new compliance file based on current IAM policy python iam.py --action generate
The IAM Policy enforcement tool provides the following capabilities:
The config.yml file supports the following parameters for IAM policies:
project_id: GCP project ID to check (default: apache-beam-testing)users_file: Path to the YAML file containing expected IAM policies (default: ../iam/users.yml)action: Default action to perform (check, announce, print, or generate)logging: Logging configuration (level and format)When using the announce action, the following environment variables are required:
GITHUB_TOKEN: GitHub personal access token for creating issuesGITHUB_REPOSITORY: Repository in format owner/repo (default: apache/beam)SMTP_SERVER: SMTP server for email notificationsSMTP_PORT: SMTP port (default: 587)EMAIL_ADDRESS: Email address for sending notificationsEMAIL_PASSWORD: Email password for authenticationEMAIL_RECIPIENT: Email address to receive notificationsThe IAM policy file should follow this YAML structure:
- username: john.doe email: john.doe@example.com permissions: - role: roles/viewer - role: roles/storage.objectViewer - username: service-account-name email: service-account-name@project-id.iam.gserviceaccount.com permissions: - role: roles/compute.instanceAdmin - role: roles/iam.serviceAccountUser
Each user entry includes:
username: The derived username (typically the part before @ in email addresses)email: The full email address of the user or service accountpermissions: List of IAM roles assigned to this memberrole: The full GCP IAM role name (e.g., roles/viewer, roles/editor)The print action can be used for testing notification content without actually creating GitHub issues or sending emails.
Command-line arguments take precedence over configuration file settings.
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.
The GitHub Actions workflow (.github/workflows/beam_Infrastructure_PolicyEnforcer.yml) runs:
workflow_dispatchannounce actionNote:
dev@beam.apache.org for Apache Beam project notificationsGITHUB_TOKEN is automatically provided by GitHub Actions and doesn't need to be configured manuallyThe enforcement is also done by validating service account keys and their access permissions against the defined policies. The tool supports three different actions when discrepancies are found:
You can specify the action either through the configuration file (config.yml) or via command-line arguments:
# Check compliance and report issues (default) python account_keys.py --action check # Create/update GitHub issue and send email if compliance violations are found python account_keys.py --action announce # Print announcement details for testing purposes (no actual issue created) python account_keys.py --action print # Generate new compliance file based on current service account keys policy python account_keys.py --action generate
The Account Keys enforcement tool provides the following capabilities:
The config.yml file supports the following parameters for account keys:
project_id: GCP project ID to checkservice_account_keys_file: Path to the YAML file containing expected service account keys policies (default: ../keys/keys.yaml)action: Default action to perform (check, announce, print, or generate)logging: Logging configuration (level and format)When using the announce action, the following environment variables are required:
GITHUB_TOKEN: GitHub personal access token for creating issuesGITHUB_REPOSITORY: Repository in format owner/repo (default: apache/beam)SMTP_SERVER: SMTP server for email notificationsSMTP_PORT: SMTP port (default: 587)EMAIL_ADDRESS: Email address for sending notificationsEMAIL_PASSWORD: Email password for authenticationEMAIL_RECIPIENT: Email address to receive notificationsThe service account keys file should follow this YAML structure:
service_accounts: - account_id: example-service-account display_name: example-service-account@project-id.iam.gserviceaccount.com authorized_users: - email: user1@example.com - email: user2@example.com
Each service account entry includes:
account_id: The unique identifier for the service account (without the full email domain)display_name: The full service account email address or any custom display nameauthorized_users: List of users who should have access to the service account's secrets