Skip to content

Commit 8b67c9a

Browse files
authored
Merge pull request #152 from haoranleo/categorize-explicit-deny-as-user-induced
Categorize explicit deny policy in IAM role as user induced
2 parents 49e4ddb + 54b5aa5 commit 8b67c9a

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

pkg/kmsplugin/kms.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ func ParseError(err error) (errorType KMSErrorType) {
9292

9393
// AWS SDK Go for KMS does not "yet" define specific error code for a case where a customer specifies the deleted key
9494
// "AccessDeniedException" error code may be returned when (1) CMK does not exist (not pending delete),
95-
// or (2) corresponding IAM role is not allowed to access the key.
96-
// Thus we only want to mark "AccessDeniedException" as user-induced for the case (1).
95+
// or (2) user explicitly denied access to the key via resource policy,
96+
// or (3) corresponding IAM role is not allowed to access the key.
97+
// Thus we only want to mark "AccessDeniedException" as user-induced for the case (1) and (2).
9798
// e.g., "AccessDeniedException: The ciphertext refers to a customer master key that does not exist, does not exist in this region, or you are not allowed to access."
9899
// or "AccessDeniedException: User xxx is not authorized to perform: xxx on this resource because the resource does not exist in this Region, no resource-based policies allow access, or a resource-based policy explicitly denies access"
100+
// or "AccessDeniedException: User xxx is not authorized to perform: xxx on this resource with an explicit deny in a resource control policy"
99101
// KMS service may change the error message, so we do the string match.
100102
case "AccessDeniedException":
101-
if strings.Contains(ae.ErrorMessage(), "does not exist") {
103+
if strings.Contains(ae.ErrorMessage(), "does not exist") || strings.Contains(ae.ErrorMessage(), "explicit deny in a resource control policy") {
102104
return KMSErrorTypeUserInduced
103105
}
104106
// Sometimes this error message is returned as part of KMSInvalidStateException or KMSInternalException

pkg/kmsplugin/kms_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ func TestParseError(t *testing.T) {
9898
err: &mockAPIError{code: "AccessDeniedException", message: "User dummy is not authorized to perform: kms:Decrypt on this resource because the resource does not exist in this Region, no resource-based policies allow access, or a resource-based policy explicitly denies access"},
9999
expected: KMSErrorTypeUserInduced,
100100
},
101+
{
102+
name: "AccessDeniedException caused by explicit deny in resource policy",
103+
err: &mockAPIError{code: "AccessDeniedException", message: "User dummy is not authorized to perform: kms:Decrypt on this resource with an explicit deny in a resource control policy"},
104+
expected: KMSErrorTypeUserInduced,
105+
},
101106
{
102107
name: "Other AccessDeniedException",
103108
err: &mockAPIError{code: "AccessDeniedException", message: "access denied for some other reason"},

pkg/plugin/plugin_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ func TestEncrypt(t *testing.T) {
111111
healthErr: true,
112112
checkErr: false,
113113
},
114+
{
115+
input: plainMessage,
116+
ctx: nil,
117+
output: "",
118+
err: &smithy.GenericAPIError{
119+
Code: "AccessDeniedException",
120+
Message: "User dummy is not authorized to perform: kms:Decrypt on this resource with an explicit deny in a resource control policy",
121+
Fault: 0,
122+
},
123+
errType: kmsplugin.KMSErrorTypeUserInduced,
124+
healthErr: true,
125+
checkErr: false,
126+
},
114127
{
115128
input: plainMessage,
116129
ctx: nil,

pkg/plugin/plugin_v2_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ func TestEncryptV2(t *testing.T) {
103103
healthErr: true,
104104
checkErr: false,
105105
},
106+
{
107+
input: plainMessage,
108+
ctx: nil,
109+
output: "",
110+
err: &smithy.GenericAPIError{
111+
Code: "AccessDeniedException",
112+
Message: "User dummy is not authorized to perform: kms:Decrypt on this resource with an explicit deny in a resource control policy",
113+
Fault: 0,
114+
},
115+
errType: kmsplugin.KMSErrorTypeUserInduced,
116+
healthErr: true,
117+
checkErr: false,
118+
},
106119
{
107120
input: plainMessage,
108121
ctx: nil,

0 commit comments

Comments
 (0)