Skip to content

Commit da40e8b

Browse files
committed
Fix missing IAM permissions for Fluent Bit
The service account for Fluent Bit currently does not have permission to create the log streams with the new log stream template name. This means that non-system logs won't be sent to Cloudwatch. This updates the IAM policy to allow creating these log groups, set retention policies, and put log events within the Flightdeck namespace.
1 parent 98bd2d2 commit da40e8b

File tree

4 files changed

+40
-25
lines changed

4 files changed

+40
-25
lines changed

.github/workflows/tests.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
run: |
4444
CLUSTER=$(echo 'flightdeck-${{ github.ref_name }}' | cut -c1-20)
4545
CLUSTER="$CLUSTER-sandbox-v1"
46+
echo "CLUSTER=$CLUSTER" >> "$GITHUB_ENV"
4647
aws \
4748
--region us-east-1 \
4849
eks \
@@ -64,4 +65,6 @@ jobs:
6465

6566
- name: Run tests
6667
run: |
67-
make tests ADDRESS=https://${{ github.ref_name }}.flightdeck-test.thoughtbot.com
68+
make tests \
69+
ADDRESS=https://${{ github.ref_name }}.flightdeck-test.thoughtbot.com \
70+
CLUSTER="$CLUSTER"

aws/platform/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ locals {
370370
[OUTPUT]
371371
Name cloudwatch_logs
372372
Match *
373+
auto_create_group true
373374
region ${data.aws_region.current.name}
374375
log_group_name ${module.cloudwatch_logs.log_group_name}
375376
log_group_template ${var.logs_prefix}/$kubernetes['namespace_name']

aws/platform/modules/cloudwatch-logs/main.tf

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,17 @@ resource "aws_iam_role_policy_attachment" "this" {
2727

2828
data "aws_iam_policy_document" "this" {
2929
statement {
30-
sid = "AllowCreateLogEvents"
30+
sid = "AllowWriteLogs"
3131
actions = [
32-
"logs:DescribeLogStreams",
33-
"logs:PutLogEvents"
34-
]
35-
resources = [
36-
"${aws_cloudwatch_log_group.this.arn}:log-stream:*"
37-
]
38-
}
39-
40-
statement {
41-
sid = "AllowCreateLogGroup"
42-
actions = [
43-
"logs:CreateLogGroup"
32+
"logs:CreateLogGroup",
33+
"logs:CreateLogStream",
34+
"logs:PutLogEvents",
35+
"logs:PutRetentionPolicy",
4436
]
4537
resources = [
4638
"${local.arn_prefix}:log-group:${var.log_group_prefix}/*"
4739
]
4840
}
49-
50-
statement {
51-
sid = "AllowCreateLogStream"
52-
actions = [
53-
"logs:CreateLogStream"
54-
]
55-
resources = [
56-
aws_cloudwatch_log_group.this.arn,
57-
"${aws_cloudwatch_log_group.this.arn}:log-stream:*"
58-
]
59-
}
6041
}
6142

6243
data "aws_caller_identity" "current" {}

tests/fluentbit.bats

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,33 @@
2929
false
3030
fi
3131
}
32+
33+
@test "creates log streams within groups for Kubernetes namespaces" {
34+
expected="$RANDOM"
35+
curl -v "$ADDRESS/echo?log=$expected"
36+
pod=$(kubectl \
37+
get pod \
38+
--field-selector=status.phase=Running \
39+
--selector=app=echoserver \
40+
-n acceptance \
41+
--output=name \
42+
| cut -d'/' -f2)
43+
logs=$(aws \
44+
--region us-east-1 \
45+
logs \
46+
get-log-events \
47+
--log-group-name "/flightdeck/acceptance" \
48+
--log-stream-name "$pod.echoserver" \
49+
--query 'events[*].[message]' \
50+
--output text)
51+
52+
if ! echo "$logs" | grep -q "log=$expected"; then
53+
echo "Failed to find log for test request." >&2
54+
echo >&2
55+
echo "Test request was: GET /echo?log=$expected" >&2
56+
echo >&2
57+
echo "Found log entries" >&2
58+
echo "$logs" >&2
59+
false
60+
fi
61+
}

0 commit comments

Comments
 (0)