fix(gcp): use KMS key id in checks (#4610)

This commit is contained in:
Sergio Garcia
2024-08-05 02:16:56 -04:00
committed by GitHub
parent a0e3cb87a4
commit b0709d08cd
5 changed files with 16 additions and 8 deletions
@@ -8,7 +8,7 @@ class kms_key_not_publicly_accessible(Check):
for key in kms_client.crypto_keys:
report = Check_Report_GCP(self.metadata())
report.project_id = key.project_id
report.resource_id = key.name
report.resource_id = key.id
report.resource_name = key.name
report.location = key.location
report.status = "PASS"
@@ -8,7 +8,7 @@ class kms_key_rotation_enabled(Check):
for key in kms_client.crypto_keys:
report = Check_Report_GCP(self.metadata())
report.project_id = key.project_id
report.resource_id = key.name
report.resource_id = key.id
report.resource_name = key.name
report.location = key.location
report.status = "FAIL"
@@ -88,6 +88,7 @@ class KMS(GCPService):
for key in response.get("cryptoKeys", []):
self.crypto_keys.append(
CriptoKey(
id=key["name"],
name=key["name"].split("/")[-1],
location=key["name"].split("/")[3],
rotation_period=key.get("rotationPeriod"),
@@ -139,6 +140,7 @@ class KeyRing(BaseModel):
class CriptoKey(BaseModel):
id: str
name: str
location: str
rotation_period: Optional[str]
@@ -65,6 +65,7 @@ class Test_kms_key_not_publicly_accessible_gcp:
kms_client.crypto_keys = [
CriptoKey(
name="key1",
id="projects/123/locations/us-central1/keyRings/keyring1/cryptoKeys/key1",
project_id=GCP_PROJECT_ID,
rotation_period="7776000s",
key_ring=keyring.name,
@@ -81,7 +82,7 @@ class Test_kms_key_not_publicly_accessible_gcp:
result[0].status_extended
== f"Key {kms_client.crypto_keys[0].name} may be publicly accessible."
)
assert result[0].resource_id == kms_client.crypto_keys[0].name
assert result[0].resource_id == kms_client.crypto_keys[0].id
assert result[0].resource_name == kms_client.crypto_keys[0].name
assert result[0].location == kms_client.crypto_keys[0].location
assert result[0].project_id == kms_client.crypto_keys[0].project_id
@@ -121,6 +122,7 @@ class Test_kms_key_not_publicly_accessible_gcp:
kms_client.crypto_keys = [
CriptoKey(
name="key1",
id="projects/123/locations/us-central1/keyRings/keyring1/cryptoKeys/key1",
project_id=GCP_PROJECT_ID,
rotation_period="7776000s",
key_ring=keyring.name,
@@ -137,7 +139,7 @@ class Test_kms_key_not_publicly_accessible_gcp:
result[0].status_extended
== f"Key {kms_client.crypto_keys[0].name} is not exposed to Public."
)
assert result[0].resource_id == kms_client.crypto_keys[0].name
assert result[0].resource_id == kms_client.crypto_keys[0].id
assert result[0].resource_name == kms_client.crypto_keys[0].name
assert result[0].location == kms_client.crypto_keys[0].location
assert result[0].project_id == kms_client.crypto_keys[0].project_id
@@ -177,6 +179,7 @@ class Test_kms_key_not_publicly_accessible_gcp:
kms_client.crypto_keys = [
CriptoKey(
name="key1",
id="projects/123/locations/us-central1/keyRings/keyring1/cryptoKeys/key1",
project_id=GCP_PROJECT_ID,
rotation_period="7776000s",
key_ring=keyring.name,
@@ -193,7 +196,7 @@ class Test_kms_key_not_publicly_accessible_gcp:
result[0].status_extended
== f"Key {kms_client.crypto_keys[0].name} is not exposed to Public."
)
assert result[0].resource_id == kms_client.crypto_keys[0].name
assert result[0].resource_id == kms_client.crypto_keys[0].id
assert result[0].resource_name == kms_client.crypto_keys[0].name
assert result[0].location == kms_client.crypto_keys[0].location
assert result[0].project_id == kms_client.crypto_keys[0].project_id
@@ -65,6 +65,7 @@ class Test_kms_key_rotation_enabled:
kms_client.crypto_keys = [
CriptoKey(
name="key1",
id="projects/123/locations/us-central1/keyRings/keyring1/cryptoKeys/key1",
project_id=GCP_PROJECT_ID,
key_ring=keyring.name,
location=keylocation.name,
@@ -80,7 +81,7 @@ class Test_kms_key_rotation_enabled:
result[0].status_extended
== f"Key {kms_client.crypto_keys[0].name} is not rotated every 90 days or less."
)
assert result[0].resource_id == kms_client.crypto_keys[0].name
assert result[0].resource_id == kms_client.crypto_keys[0].id
assert result[0].resource_name == kms_client.crypto_keys[0].name
assert result[0].location == kms_client.crypto_keys[0].location
assert result[0].project_id == kms_client.crypto_keys[0].project_id
@@ -120,6 +121,7 @@ class Test_kms_key_rotation_enabled:
kms_client.crypto_keys = [
CriptoKey(
name="key1",
id="projects/123/locations/us-central1/keyRings/keyring1/cryptoKeys/key1",
project_id=GCP_PROJECT_ID,
rotation_period="8776000s",
key_ring=keyring.name,
@@ -136,7 +138,7 @@ class Test_kms_key_rotation_enabled:
result[0].status_extended
== f"Key {kms_client.crypto_keys[0].name} is not rotated every 90 days or less."
)
assert result[0].resource_id == kms_client.crypto_keys[0].name
assert result[0].resource_id == kms_client.crypto_keys[0].id
assert result[0].resource_name == kms_client.crypto_keys[0].name
assert result[0].location == kms_client.crypto_keys[0].location
assert result[0].project_id == kms_client.crypto_keys[0].project_id
@@ -176,6 +178,7 @@ class Test_kms_key_rotation_enabled:
kms_client.crypto_keys = [
CriptoKey(
name="key1",
id="projects/123/locations/us-central1/keyRings/keyring1/cryptoKeys/key1",
project_id=GCP_PROJECT_ID,
rotation_period="7776000s",
key_ring=keyring.name,
@@ -192,7 +195,7 @@ class Test_kms_key_rotation_enabled:
result[0].status_extended
== f"Key {kms_client.crypto_keys[0].name} is rotated every 90 days or less."
)
assert result[0].resource_id == kms_client.crypto_keys[0].name
assert result[0].resource_id == kms_client.crypto_keys[0].id
assert result[0].resource_name == kms_client.crypto_keys[0].name
assert result[0].location == kms_client.crypto_keys[0].location
assert result[0].project_id == kms_client.crypto_keys[0].project_id