@@ -1848,3 +1848,66 @@ def test_skip_service_account_key(run_slack_alerter, number_of_http_calls, caplo
1848
1848
logging .INFO ,
1849
1849
"Skipping service account key alert" ,
1850
1850
) in caplog .record_tuples
1851
+
1852
+
1853
+ def test_skip_permission_denied_by_iam (run_slack_alerter , number_of_http_calls , caplog ):
1854
+ # arrange
1855
+ example_log_entry = {
1856
+ "protoPayload" : {
1857
+ "@type" : "type.googleapis.com/google.cloud.audit.AuditLog" ,
1858
+ "status" : {"code" : 2 , "message" : "permission denied by IAM" },
1859
+ "authenticationInfo" : {},
1860
+ "requestMetadata" : {
1861
+ "callerIp" : "5.161.230.161" ,
1862
+ "callerSuppliedUserAgent" : "Fuzz Faster U Fool v2.1.0,gzip(gfe)" ,
1863
+ },
1864
+ "serviceName" : "artifactregistry.googleapis.com" ,
1865
+ "methodName" : "Docker-GetTags" ,
1866
+ "authorizationInfo" : [
1867
+ {
1868
+ "resource" : "projects/ons-blaise-v2-prod/locations/europe/repositories/eu.gcr.io" ,
1869
+ "permission" : "artifactregistry.repositories.downloadArtifacts" ,
1870
+ "granted" : False ,
1871
+ "resourceAttributes" : {},
1872
+ "permissionType" : "DATA_READ" ,
1873
+ }
1874
+ ],
1875
+ "resourceName" : "projects/ons-blaise-v2-prod/locations/europe/repositories/eu.gcr.io" ,
1876
+ "request" : {
1877
+ "requestMethod" : "GET" ,
1878
+ "requestUrl" : "/v2/ons-blaise-v2-prod/eu.gcr.io/tags/list" ,
1879
+ "@type" : "type.googleapis.com/google.logging.type.HttpRequest" ,
1880
+ },
1881
+ "resourceLocation" : {
1882
+ "currentLocations" : ["europe" ],
1883
+ "originalLocations" : ["europe" ],
1884
+ },
1885
+ },
1886
+ "insertId" : "1q7acrxd7195" ,
1887
+ "resource" : {
1888
+ "type" : "audited_resource" ,
1889
+ "labels" : {
1890
+ "method" : "Docker-GetTags" ,
1891
+ "service" : "artifactregistry.googleapis.com" ,
1892
+ "project_id" : "ons-blaise-v2-prod" ,
1893
+ },
1894
+ },
1895
+ "timestamp" : "2025-03-03T05:07:51.689323290Z" ,
1896
+ "severity" : "ERROR" ,
1897
+ "logName" : "projects/ons-blaise-v2-prod/logs/cloudaudit.googleapis.com%2Fdata_access" ,
1898
+ "receiveTimestamp" : "2025-03-03T05:07:51.704386101Z" ,
1899
+ }
1900
+ event = create_event (example_log_entry )
1901
+
1902
+ # act
1903
+ with caplog .at_level (logging .INFO ):
1904
+ response = run_slack_alerter (event )
1905
+
1906
+ # assert
1907
+ assert response == "Alert skipped"
1908
+ assert number_of_http_calls () == 0
1909
+ assert (
1910
+ "root" ,
1911
+ logging .INFO ,
1912
+ "Skipping permission denied by IAM alert" ,
1913
+ ) in caplog .record_tuples
0 commit comments