Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLA-26855 - Updated azure remediation jobs to wait for the poller result #99

Merged
merged 2 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Network ACL should restrict administration ports (3389 and 22) from public acces

### Prerequisites

The provided AWS credential must have access to `ec2:DeleteNetworkAcl`, `ec2:DescribeNetworkAcls` and `ec2:ReplaceNetworkAclEntry`.
The provided AWS credential must have access to `ec2:CreateNetworkAclEntry`, `ec2:DeleteNetworkAclEntry`, `DescribeNetworkAcls` and `ec2:ReplaceNetworkAclEntry`.

You may find the latest example policy file [here](minimum_policy.json)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"Sid": "RemoveAdministrationPortsIngress",
"Effect": "Allow",
"Action": [
"ec2:CreateNetworkAclEntry",
"ec2:DescribeNetworkAcls",
"ec2:DeleteNetworkAcl"
"ec2:DeleteNetworkAclEntry",
"ec2:ReplaceNetworkAclEntry"
],
"Resource": "*"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def remediate(self, client, resource_group_name, mysql_server_name):
resource_group_name=resource_group_name,
server_name=mysql_server_name,
parameters=ServerUpdateParameters(ssl_enforcement="Enabled"),
)
).result()
except Exception as e:
logging.error(f"{str(e)}")
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def remediate(self, client, resource_group_name, postgre_server_name):
resource_group_name=resource_group_name,
server_name=postgre_server_name,
firewall_rule_name="AllowAllWindowsAzureIps",
)
).result()
except Exception as e:
logging.error(f"{str(e)}")
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def remediate(self, client, resource_group_name, postgre_server_name):
resource_group_name=resource_group_name,
server_name=postgre_server_name,
parameters=ServerUpdateParameters(ssl_enforcement="Enabled"),
)
).result()
except Exception as e:
logging.error(f"{str(e)}")
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def create_server_blob_auditing_policy(
state=BlobAuditingPolicyState.enabled,
storage_endpoint=f"https://{stg_account_name}.blob.core.windows.net/",
),
)
).result()

def ensure_identity_assigned(
self, client, resource_group_name, sql_server_name, region
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The provided Azure service principal must have the following permissions:
`Microsoft.KeyVault/vaults/accessPolicies/write`,
`Microsoft.Sql/servers/read`,
`Microsoft.Sql/servers/write`,
`Microsoft.Sql/servers/encryptionProtector/read`,
`Microsoft.Sql/servers/encryptionProtector/write`,
`Microsoft.Sql/servers/keys/write`
`Microsoft.Sql/servers/keys/read`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def remediate(
parameters=EncryptionProtector(
server_key_name=server_key_name, server_key_type="AzureKeyVault"
),
)
).result()
except Exception as e:
logging.error(f"{str(e)}")
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"Microsoft.KeyVault/vaults/accessPolicies/write",
"Microsoft.Sql/servers/read",
"Microsoft.Sql/servers/write",
"Microsoft.Sql/servers/encryptionProtector/read",
"Microsoft.Sql/servers/encryptionProtector/write",
"Microsoft.Sql/servers/keys/write",
"Microsoft.Sql/servers/keys/read"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def remediate(self, client, resource_group_name, sql_server_name):
parameters=ServerSecurityAlertPolicy(
state=SecurityAlertPolicyState.enabled
),
)
).result()
except Exception as e:
logging.error(f"{str(e)}")
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def remediate(self, client, resource_group_name, sql_server_name):
parameters=ServerSecurityAlertPolicy(
state=SecurityAlertPolicyState.enabled, disabled_alerts=[]
),
)
).result()
except Exception as e:
logging.error(f"{str(e)}")
raise
Expand Down
5 changes: 4 additions & 1 deletion test/unit/test_azure_sql_auditing_on_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def test_remediate_without_stg_without_keyvault(self):
action.ensure_identity_assigned = Mock()
action.create_role_assignment = Mock()
action.create_server_blob_auditing_policy = Mock()
action.check_role_assignment = Mock()

identity = Identity(
principal_id="139bcf82-e14e-4773-bcf4-1da136674792",
Expand Down Expand Up @@ -106,6 +107,7 @@ def test_remediate_without_stg_without_keyvault(self):
location="eastus",
identity=identity,
)
action.check_role_assignment.return_value = True
action.check_stg_account.return_value = None
action.check_key_vault.return_value = None
assert (
Expand Down Expand Up @@ -134,7 +136,6 @@ def test_remediate_without_stg_without_keyvault(self):
assert action.create_storage_account.call_count == 1
assert action.create_key_vault.call_count == 1
assert action.create_diagnostic_setting.call_count == 1
assert action.create_role_assignment.call_count == 1
assert action.create_server_blob_auditing_policy.call_count == 1

def test_remediate_without_stg_with_keyvault(self):
Expand All @@ -159,6 +160,7 @@ def test_remediate_without_stg_with_keyvault(self):
action.ensure_identity_assigned = Mock()
action.create_role_assignment = Mock()
action.create_server_blob_auditing_policy = Mock()
action.check_role_assignment = Mock()

identity = Identity(
principal_id="139bcf82-e14e-4773-bcf4-1da136674792",
Expand Down Expand Up @@ -189,6 +191,7 @@ def test_remediate_without_stg_with_keyvault(self):
vault_uri="https://stg-keyvault-rem.vault.azure.net",
),
)
action.check_role_assignment.return_value = False
assert (
action.remediate(
client_id,
Expand Down