-
Notifications
You must be signed in to change notification settings - Fork 318
feat: add CloudEvents webhook support for AWS ECR #1370
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
audacioustux
wants to merge
15
commits into
argoproj-labs:master
Choose a base branch
from
audacioustux:feat/cloudevents-webhook
base: master
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
15 commits
Select commit
Hold shift + click to select a range
aaa02b5
feat: add CloudEvents webhook support for AWS ECR
audacioustux 8d15807
fix(docs): correct typo in GHCR webhook secret flag name (gchr -> ghcr)
audacioustux 08d544e
docs: add inline field comments to WebhookConfig struct
audacioustux 0b0f8c2
docs: clarify that 0 disables rate limiting in WebhookConfig
audacioustux 2b4505b
Refactor CloudEvents logging to match server.go pattern
audacioustux 22ae8f0
Fix import grouping in cloudevents.go
audacioustux d90c5b7
Improve CloudEvents webhook security and robustness
audacioustux ea60a59
docs: reorganize CloudEvents documentation structure
audacioustux 865c4fd
Update config/examples/cloudevents/test-webhook.sh
audacioustux d3c7f2c
Update docs/configuration/webhook.md
audacioustux 9419148
Update config/examples/cloudevents/terraform/outputs.tf
audacioustux f9b6bc0
Update config/examples/cloudevents/test-webhook.sh
audacioustux fa25a7c
Update docs/configuration/webhook.md
audacioustux b3cd9db
Merge branch 'master' into feat/cloudevents-webhook
audacioustux e842d25
Add HTTPS validation for CloudEvents webhook URL
audacioustux 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
Some comments aren't visible on the classic Files Changed page.
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
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,38 @@ | ||
| # CloudEvents Webhook Example | ||
|
|
||
| Example Terraform configuration for setting up AWS EventBridge to send ECR push events to ArgoCD Image Updater via CloudEvents. | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ### 1. Configure EventBridge with Terraform | ||
|
|
||
| ```bash | ||
| cd terraform | ||
|
|
||
| # Set your variables | ||
| export TF_VAR_webhook_url="https://your-domain.com/webhook?type=cloudevents" | ||
| export TF_VAR_webhook_secret="your-webhook-secret" | ||
| export TF_VAR_aws_region="us-east-1" | ||
|
|
||
| # Apply the configuration | ||
| terraform init | ||
| terraform apply | ||
|
|
||
| # Return to parent directory | ||
| cd .. | ||
| ``` | ||
|
|
||
| ### 2. Test the Webhook | ||
|
|
||
| ```bash | ||
| ./test-webhook.sh https://your-webhook-url/webhook?type=cloudevents your-secret | ||
| ``` | ||
|
|
||
| ## Files | ||
|
|
||
| - `terraform/` - EventBridge configuration with input transformer for ECR events | ||
| - `test-webhook.sh` - Script to test the webhook endpoint | ||
|
|
||
| ## Documentation | ||
|
|
||
| For complete setup instructions, see the [webhook documentation](../../../docs/configuration/webhook.md#aws-ecr-via-eventbridge-cloudevents). |
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,145 @@ | ||
| terraform { | ||
| required_version = ">= 1.0" | ||
|
|
||
| required_providers { | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = "~> 5.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "aws" { | ||
| region = var.aws_region | ||
| } | ||
|
|
||
| # EventBridge Rule to capture ECR push events | ||
| resource "aws_cloudwatch_event_rule" "ecr_push" { | ||
| name = "argocd-image-updater-ecr-push" | ||
| description = "Capture ECR image push events for ArgoCD Image Updater" | ||
|
|
||
| event_pattern = jsonencode({ | ||
| source = ["aws.ecr"] | ||
| detail-type = ["ECR Image Action"] | ||
| detail = { | ||
| action-type = ["PUSH"] | ||
| result = ["SUCCESS"] | ||
| # Filter for events with image tags (excludes untagged/manifest-only pushes) | ||
| image-tag = [{ | ||
| exists = true | ||
| }] | ||
| # Optional: Filter by specific repositories | ||
| repository-name = length(var.ecr_repository_filter) > 0 ? var.ecr_repository_filter : null | ||
| } | ||
| }) | ||
|
|
||
| tags = var.tags | ||
| } | ||
|
|
||
| # EventBridge Connection for API authentication | ||
| resource "aws_cloudwatch_event_connection" "webhook" { | ||
| name = "argocd-image-updater-webhook" | ||
| description = "Connection to ArgoCD Image Updater webhook" | ||
| authorization_type = "API_KEY" | ||
|
|
||
| auth_parameters { | ||
| api_key { | ||
| key = "X-Webhook-Secret" | ||
| value = var.webhook_secret | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # API Destination pointing to ArgoCD Image Updater webhook | ||
| resource "aws_cloudwatch_event_api_destination" "webhook" { | ||
| name = "argocd-image-updater-webhook" | ||
| description = "ArgoCD Image Updater CloudEvents webhook endpoint" | ||
| invocation_endpoint = var.webhook_url | ||
| http_method = "POST" | ||
| invocation_rate_limit_per_second = 10 | ||
| connection_arn = aws_cloudwatch_event_connection.webhook.arn | ||
| } | ||
|
|
||
| # IAM Role for EventBridge to invoke API Destination | ||
| resource "aws_iam_role" "eventbridge" { | ||
| name = "argocd-image-updater-eventbridge-role" | ||
| assume_role_policy = data.aws_iam_policy_document.eventbridge_assume_role.json | ||
| tags = var.tags | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "eventbridge_assume_role" { | ||
| statement { | ||
| effect = "Allow" | ||
|
|
||
| principals { | ||
| type = "Service" | ||
| identifiers = ["events.amazonaws.com"] | ||
| } | ||
|
|
||
| actions = ["sts:AssumeRole"] | ||
| } | ||
| } | ||
|
|
||
| # IAM Policy for EventBridge to invoke API Destination | ||
| resource "aws_iam_role_policy" "eventbridge_invoke_api_destination" { | ||
| name = "invoke-api-destination" | ||
| role = aws_iam_role.eventbridge.id | ||
| policy = data.aws_iam_policy_document.eventbridge_invoke_api_destination.json | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "eventbridge_invoke_api_destination" { | ||
| statement { | ||
| effect = "Allow" | ||
|
|
||
| actions = [ | ||
| "events:InvokeApiDestination" | ||
| ] | ||
|
|
||
| resources = [ | ||
| aws_cloudwatch_event_api_destination.webhook.arn | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| # EventBridge Target with Input Transformer (ECR -> CloudEvents) | ||
| resource "aws_cloudwatch_event_target" "api_destination" { | ||
| rule = aws_cloudwatch_event_rule.ecr_push.name | ||
| target_id = "ArgocdImageUpdaterCloudEvent" | ||
| arn = aws_cloudwatch_event_api_destination.webhook.arn | ||
| role_arn = aws_iam_role.eventbridge.arn | ||
|
|
||
| input_transformer { | ||
| input_paths = { | ||
| id = "$.id" | ||
| time = "$.time" | ||
| account = "$.account" | ||
| region = "$.region" | ||
| repo = "$.detail.repository-name" | ||
| digest = "$.detail.image-digest" | ||
| tag = "$.detail.image-tag" | ||
| } | ||
|
|
||
| input_template = <<-EOF | ||
| { | ||
| "specversion": "1.0", | ||
| "id": "<id>", | ||
| "type": "com.amazon.ecr.image.push", | ||
| "source": "urn:aws:ecr:<region>:<account>:repository/<repo>", | ||
| "subject": "<repo>:<tag>", | ||
| "time": "<time>", | ||
| "datacontenttype": "application/json", | ||
| "data": { | ||
| "repositoryName": "<repo>", | ||
| "imageDigest": "<digest>", | ||
| "imageTag": "<tag>", | ||
| "registryId": "<account>" | ||
| } | ||
| } | ||
| EOF | ||
| } | ||
|
|
||
| retry_policy { | ||
| maximum_event_age_in_seconds = 3600 | ||
| maximum_retry_attempts = 3 | ||
| } | ||
| } | ||
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,20 @@ | ||
| output "eventbridge_rule_arn" { | ||
| description = "ARN of the EventBridge rule" | ||
| value = aws_cloudwatch_event_rule.ecr_push.arn | ||
| } | ||
|
|
||
| output "api_destination_arn" { | ||
| description = "ARN of the API destination" | ||
| value = aws_cloudwatch_event_api_destination.webhook.arn | ||
| } | ||
|
|
||
| output "eventbridge_role_arn" { | ||
| description = "ARN of the EventBridge IAM role" | ||
| value = aws_iam_role.eventbridge.arn | ||
| } | ||
|
|
||
| output "webhook_endpoint" { | ||
| description = "Configured webhook endpoint URL" | ||
| value = var.webhook_url | ||
audacioustux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sensitive = true | ||
| } | ||
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,37 @@ | ||
| variable "aws_region" { | ||
| description = "AWS region for ECR and EventBridge" | ||
| type = string | ||
| default = "us-east-1" | ||
| } | ||
|
|
||
| variable "webhook_url" { | ||
| description = "ArgoCD Image Updater webhook endpoint URL (must use HTTPS)" | ||
| type = string | ||
| # Example: "https://image-updater-webhook.example.com/webhook?type=cloudevents" | ||
|
|
||
| validation { | ||
| condition = can(regex("^https://", var.webhook_url)) | ||
| error_message = "webhook_url must use HTTPS protocol for secure credential transmission." | ||
| } | ||
| } | ||
|
|
||
| variable "webhook_secret" { | ||
| description = "Secret for webhook authentication" | ||
| type = string | ||
| sensitive = true | ||
| } | ||
|
|
||
| variable "ecr_repository_filter" { | ||
| description = "List of ECR repository names to monitor (empty list = all repositories)" | ||
| type = list(string) | ||
| default = [] | ||
| } | ||
|
|
||
| variable "tags" { | ||
| description = "Tags to apply to all resources" | ||
| type = map(string) | ||
| default = { | ||
| ManagedBy = "Terraform" | ||
| Purpose = "ArgoCD-Image-Updater" | ||
| } | ||
| } |
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.