Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

feat(iam): seed AWSXRayDaemonWriteAccess + 2 more managed policies (#956)

W. H. Wanged332acade8d
diff --git a/ministack/services/iam.py b/ministack/services/iam.py
index 294fde6f..d9f395a6 100644
--- a/ministack/services/iam.py
+++ b/ministack/services/iam.py
@@ -269,6 +269,20 @@ def _seed_aws_managed_policies() -> None:
('AmazonEKSServicePolicy',
'{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["ec2:CreateNetworkInterface","ec2:CreateNetworkInterfacePermission","ec2:DeleteNetworkInterface","ec2:DescribeInstances","ec2:DescribeNetworkInterfaces","ec2:DetachNetworkInterface","ec2:DescribeSecurityGroups","ec2:DescribeSubnets","ec2:DescribeVpcs","ec2:ModifyNetworkInterfaceAttribute","iam:ListAttachedRolePolicies","eks:UpdateClusterVersion","ec2:GetSecurityGroupsForVpc"],"Resource":"*"},{"Effect":"Allow","Action":["ec2:CreateTags","ec2:DeleteTags"],"Resource":["arn:aws:ec2:*:*:vpc/*","arn:aws:ec2:*:*:subnet/*"]},{"Effect":"Allow","Action":["ec2:CreateTags"],"Resource":["arn:aws:ec2:*:*:network-interface/*"],"Condition":{"StringLike":{"aws:RequestTag/Name":"eks-cluster-*"}}},{"Effect":"Allow","Action":"route53:AssociateVPCWithHostedZone","Resource":"*"},{"Effect":"Allow","Action":"logs:CreateLogGroup","Resource":"*"},{"Effect":"Allow","Action":["logs:CreateLogStream","logs:DescribeLogStreams"],"Resource":"arn:aws:logs:*:*:log-group:/aws/eks/*:*"},{"Effect":"Allow","Action":"logs:PutLogEvents","Resource":"arn:aws:logs:*:*:log-group:/aws/eks/*:*:*"},{"Effect":"Allow","Action":"iam:CreateServiceLinkedRole","Resource":"arn:aws:iam::*:role/aws-service-role/eks.amazonaws.com/AWSServiceRoleForAmazonEKS","Condition":{"StringLike":{"iam:AWSServiceName":"eks.amazonaws.com"}}}]}',
"This policy allows Amazon Elastic Container Service for Kubernetes to create and manage the necessary resources to operate EKS Clusters."),
+ # X-Ray daemon-side write + reader access. Heavily referenced by
+ # the upstream terraform-aws-modules/lambda module: every Lambda
+ # function module that sets `attach_tracing_policy = true` does
+ # `data "aws_iam_policy" "tracing" { arn = "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess" }`,
+ # so any Terraform stack that wires Lambdas with tracing on hits this.
+ ('AWSXRayDaemonWriteAccess',
+ '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["xray:PutTraceSegments","xray:PutTelemetryRecords","xray:GetSamplingRules","xray:GetSamplingTargets","xray:GetSamplingStatisticSummaries"],"Resource":["*"]}]}',
+ "AWS X-Ray Daemon write access — permissions required by the X-Ray daemon to upload telemetry segments to X-Ray and fetch sampling rules."),
+ ('AWSXrayReadOnlyAccess',
+ '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["xray:GetSamplingRules","xray:GetSamplingTargets","xray:GetSamplingStatisticSummaries","xray:BatchGetTraces","xray:GetServiceGraph","xray:GetTraceGraph","xray:GetTraceSummaries","xray:GetGroups","xray:GetGroup","xray:ListTagsForResource","xray:GetTimeSeriesServiceStatistics","xray:GetInsightSummaries","xray:GetInsight","xray:GetInsightEvents","xray:GetInsightImpactGraph"],"Resource":["*"]}]}',
+ "AWS X-Ray read-only access. Grants permission to retrieve trace data, service graphs, and sampling rules."),
+ ('AWSLambdaRole',
+ '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["lambda:InvokeFunction"],"Resource":["*"]}]}',
+ "Default policy for AWS Lambda service role — permits Lambda to invoke other Lambda functions."),
]
for name, document, description in seeds:
diff --git a/tests/test_iam.py b/tests/test_iam.py
index 90c0f87d..76810c30 100644
--- a/tests/test_iam.py
+++ b/tests/test_iam.py
@@ -632,6 +632,38 @@ def test_iam_seeded_amazon_eks_cni_policy(iam):
assert "ec2:ModifyNetworkInterfaceAttribute" in first_actions
+def test_iam_seeded_aws_xray_daemon_write_access(iam):
+ """AWSXRayDaemonWriteAccess is heavily referenced by
+ terraform-aws-modules/lambda's `attach_tracing_policy = true` path
+ via `data "aws_iam_policy" "tracing" { arn = ... }`."""
+ arn = "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess"
+ resp = iam.get_policy(PolicyArn=arn)
+ assert resp["Policy"]["PolicyName"] == "AWSXRayDaemonWriteAccess"
+ pv = iam.get_policy_version(PolicyArn=arn, VersionId="v1")["PolicyVersion"]
+ doc = pv["Document"] if isinstance(pv["Document"], dict) else json.loads(pv["Document"])
+ actions = doc["Statement"][0]["Action"]
+ assert "xray:PutTraceSegments" in actions
+ assert "xray:PutTelemetryRecords" in actions
+ assert "*" not in actions
+
+
+def test_iam_seeded_aws_xray_readonly(iam):
+ arn = "arn:aws:iam::aws:policy/AWSXrayReadOnlyAccess"
+ pv = iam.get_policy_version(PolicyArn=arn, VersionId="v1")["PolicyVersion"]
+ doc = pv["Document"] if isinstance(pv["Document"], dict) else json.loads(pv["Document"])
+ actions = doc["Statement"][0]["Action"]
+ assert "xray:BatchGetTraces" in actions
+ assert "xray:GetServiceGraph" in actions
+
+
+def test_iam_seeded_aws_lambda_role(iam):
+ arn = "arn:aws:iam::aws:policy/AWSLambdaRole"
+ pv = iam.get_policy_version(PolicyArn=arn, VersionId="v1")["PolicyVersion"]
+ doc = pv["Document"] if isinstance(pv["Document"], dict) else json.loads(pv["Document"])
+ actions = doc["Statement"][0]["Action"]
+ assert "lambda:InvokeFunction" in actions
+
+
def test_iam_list_policies_scope_all_includes_aws_managed(iam):
resp = iam.list_policies(Scope="All")
arns = [p["Arn"] for p in resp["Policies"]]