Repository navigation
Conversation
hamzaimran08
left a comment
There was a problem hiding this comment.
Good work. Looks good in general, just a few comments to look into
|
|
||
| if "ghcr.io" in image: | ||
| # Validate the registry of image | ||
| if not self._validate_registry_allowed(image): |
There was a problem hiding this comment.
clean_image runs on every save, not only when the image changes. A regular user whose app already uses an image outside the allowlist can’t save any edit, even to the description. This happens with apps created before this change, and with apps where an admin set a custom-registry image. In the second case the user is locked out of their own app, which defeats the admin exception.
Could we skip the registry check when the image hasn’t changed? Something like:
image_unchanged = (
self.instance
and self.instance.pk
and self.instance.image
and image == self._normalize_image_registry(self.instance.image)
)
if not image_unchanged and not self._validate_registry_allowed(image):
return image
| ORCID_BASE_URL = "https://orcid.org" | ||
|
|
||
| # For image registry checking | ||
| ALLOWED_IMAGE_REGISTRIES = [ |
There was a problem hiding this comment.
Two things:
- This variable is missing from
.env.templateand serve-charts repo (https://github.com/ScilifelabDataCentre/serve-charts/blob/develop/serve/templates/studio-settings-configmap.yaml). - If the variable is set but empty (ALLOWED_IMAGE_REGISTRIES=), we get an empty list and every regular user is blocked. Should an empty value fall back to the defaults?
| if registry not in allowed: | ||
| self.add_error( | ||
| "image", | ||
| f"Images from '{registry}' are not allowed. " f"Allowed registries: {', '.join(allowed)}", |
There was a problem hiding this comment.
Could this be one string?
| f"Images from '{registry}' are not allowed. " f"Allowed registries: {', '.join(allowed)}", | |
| f"Images from '{registry}' are not allowed. Allowed registries: {', '.join(allowed)}", |
| def setUp(self): | ||
| # Image registry checks hit the network; not what this test verifies. | ||
| patcher = patch("apps.forms.mixins.validate_docker_image") | ||
| self.mock_validate_docker_iamge = patcher.start() |
There was a problem hiding this comment.
Typo: iamge should be image.
Description
This PR is related to SS-1839.
Add validation to restrict the image registries users can submit. By default, the following registries allowed: docker.io, ghcr.io, quay.io. To add more allowed registries, configure ALLOWED_IMAGE_REGISTRIES in env. SuperUser and Staff can use any registry without this setting.
Due to this change, some unit tests need to mock the image access validation in mixins. Since the tests should avoid making HTTP requests, I chose to mock this function rather than the one introduced in this PR.
Additionally, fix two ambiguous conditions in clean_image that could potentially allow Serve access malicious URLs.
Checklist