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

feat(azure containerregistry): gather service infos and checks disabled admin user #5191

Conversation

johannes-engler-mw
Copy link
Contributor

Context

This PR adds support to checking Azure Container Registries for security relevant problems.

Description

This PR adds the following features:

  • Support for gathering informations about Azure Container Registries
  • Check if the admin user is disabled

Checklist

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the provider/azure Issues/PRs related with the Azure provider label Sep 25, 2024
@johannes-engler-mw johannes-engler-mw changed the title Feat/azure containerregistry service and disabled admin user Feat(azure containerregistry) gather service infos and checks disabled admin user Sep 25, 2024
@johannes-engler-mw johannes-engler-mw changed the title Feat(azure containerregistry) gather service infos and checks disabled admin user feat(azure containerregistry) gather service infos and checks disabled admin user Sep 25, 2024
@johannes-engler-mw johannes-engler-mw changed the title feat(azure containerregistry) gather service infos and checks disabled admin user feat(azure containerregistry): gather service infos and checks disabled admin user Sep 25, 2024
Copy link
Member

@puchy22 puchy22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thaks for the contribution, it is a great job 💯 , please review my comments

super().__init__(ContainerRegistryManagementClient, provider)
self.registries = self._get_container_registries(provider)

def _get_container_registries(self, provider):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _get_container_registries(self, provider):
def _get_container_registries(self):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is mandatory in the father constructor, in the methods that you define is not mandatory because you are not using in any line of the method. The above case was a fail, I only wanted to change this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok understood. Is fixed.

)


class Test_ContainerRegistry_Service:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class Test_ContainerRegistry_Service:
class TestContainerRegistryService:



class Test_ContainerRegistry_Service:
def test_container_registry(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_container_registry(self):
def test_get_container_registry(self):

)


class TestContainerRegistryAdminUserDisabled:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class TestContainerRegistryAdminUserDisabled:
class Test_containerregistry_admin_user_disabled:

"CLI": "az acr update --name <RegistryName> --resource-group <ResourceGroupName> --admin-user-enabled false",
"NativeIaC": "",
"Other": "",
"Terraform": "resource \"azurerm_container_registry\" \"example\" { admin_enabled = false }"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Terraform": "resource \"azurerm_container_registry\" \"example\" { admin_enabled = false }"
"Terraform": ""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why delete the example?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now we are not hardcoding Terraform in this field, it is commonly used to add a link with the Terraform code. I think it could be weird and in a future could be changed but now I think it is better to leave it empty.

"RelatedUrl": "https://docs.microsoft.com/en-us/azure/container-registry/administrative-user",
"Remediation": {
"Code": {
"CLI": "az acr update --name <RegistryName> --resource-group <ResourceGroupName> --admin-user-enabled false",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the parameter is --admin-user-enabled, see here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here indicates that the flag is --admin-enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, you are right. Fixed.

Copy link
Member

@puchy22 puchy22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thaks for the contribution, it is a great job 💯 , please review my comments

Copy link

codecov bot commented Sep 27, 2024

Codecov Report

Attention: Patch coverage is 85.07463% with 10 lines in your changes missing coverage. Please review.

Project coverage is 89.08%. Comparing base (da87c0d) to head (8d8242b).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ces/containerregistry/containerregistry_service.py 77.77% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5191      +/-   ##
==========================================
- Coverage   89.08%   89.08%   -0.01%     
==========================================
  Files         989      992       +3     
  Lines       30407    30474      +67     
==========================================
+ Hits        27089    27148      +59     
- Misses       3318     3326       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Co-authored-by: Rubén De la Torre Vico <[email protected]>
Co-authored-by: Rubén De la Torre Vico <[email protected]>
Co-authored-by: Rubén De la Torre Vico <[email protected]>
Co-authored-by: Rubén De la Torre Vico <[email protected]>
Copy link
Contributor Author

@johannes-engler-mw johannes-engler-mw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pleases check my comments.

"RelatedUrl": "https://docs.microsoft.com/en-us/azure/container-registry/administrative-user",
"Remediation": {
"Code": {
"CLI": "az acr update --name <RegistryName> --resource-group <ResourceGroupName> --admin-user-enabled false",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the parameter is --admin-user-enabled, see here.

"CLI": "az acr update --name <RegistryName> --resource-group <ResourceGroupName> --admin-user-enabled false",
"NativeIaC": "",
"Other": "",
"Terraform": "resource \"azurerm_container_registry\" \"example\" { admin_enabled = false }"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why delete the example?

registries = {}
for subscription, client in self.clients.items():
try:
registries.update({subscription: []})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean like this?

        for subscription, client in self.clients.items():
            try:
+              registries.update({subscription: {}})
                registries_list = client.registries.list()
                for registry in registries_list:
                    resource_group = self._get_resource_group(registry.id)
+                  registries[registry.id].append(
                        ContainerRegistryInfo(
                            id=getattr(registry, "id", ""),
                            name=getattr(registry, "name", ""),
                            location=getattr(registry, "location", ""),
                            resource_group=resource_group,
                            sku=getattr(registry.sku, "name", ""),
                            login_server=getattr(registry, "login_server", ""),
                            public_network_access=getattr(
                                registry, "public_network_access", ""
                            ),
                            admin_user_enabled=getattr(
                                registry, "admin_user_enabled", ""
                            ),
                            monitor_diagnostic_settings=self._get_registry_monitor_settings(
                                registry.name, resource_group, subscription
                            ),
                        )
                    )

puchy22

This comment was marked as duplicate.

puchy22
puchy22 previously approved these changes Sep 30, 2024
Copy link
Member

@puchy22 puchy22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for the contribution 🔝 🚀

@@ -9,18 +9,18 @@ def execute(self) -> list[Check_Report_Azure]:
findings = []

for subscription, registries in containerregistry_client.registries.items():
for registry_id, ContainerRegistryInfo in registries.items():
for registry_id, conatiner_registry_info in registries.items():
Copy link
Contributor Author

@johannes-engler-mw johannes-engler-mw Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misspelling of container, please adapt @puchy22

{
"Provider": "azure",
"CheckID": "containerregistry_admin_user_disabled",
"CheckTitle": "Admin User is disabled for Azure Container Registry",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"CheckTitle": "Admin User is disabled for Azure Container Registry",
"CheckTitle": "Ensure admin User is disabled for Azure Container Registry",

"ResourceIdTemplate": "",
"Severity": "high",
"ResourceType": "ContainerRegistry",
"Description": "Enabling the admin user for Azure Container Registry (ACR) can pose security risks as it grants unrestricted access to the registry. It is recommended to disable the admin user and utilize Role-Based Access Control (RBAC) instead.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Description": "Enabling the admin user for Azure Container Registry (ACR) can pose security risks as it grants unrestricted access to the registry. It is recommended to disable the admin user and utilize Role-Based Access Control (RBAC) instead.",
"Description": "Ensure that the admin user is disabled and Role-Based Access Control (RBAC) is used instead since it could grant unrestricted access to the registry",

findings = []

for subscription, registries in containerregistry_client.registries.items():
for registry_id, conatiner_registry_info in registries.items():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for registry_id, conatiner_registry_info in registries.items():
for registry_id, container_registry_info in registries.items():

@MrCloudSec MrCloudSec self-requested a review September 30, 2024 15:12
Copy link
Member

@MrCloudSec MrCloudSec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @johannes-engler-mw !

@MrCloudSec MrCloudSec merged commit 234f8c2 into prowler-cloud:master Sep 30, 2024
10 of 11 checks passed
@johannes-engler-mw johannes-engler-mw deleted the feat/azure-containerregistry-service-and-disabled-admin-user branch October 2, 2024 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
provider/azure Issues/PRs related with the Azure provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants