Skip to content

SS-1839 restrict image registry - #617

Open
YukiJanse wants to merge 3 commits into
developfrom
SS-1839-Restrict-image-registry
Open

YukiJanse wants to merge 3 commits into
developfrom
SS-1839-Restrict-image-registry

Conversation

@YukiJanse

Copy link
Copy Markdown
Collaborator

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

If you're unsure about any of the items below, don't hesitate to ask. We're here to help!
This is simply a reminder of what we are going to look for before merging your code.

  • This pull request is against develop branch (not applicable for hotfixes)
  • I have included a link to the issue on GitHub or JIRA (if any)
  • I have included migration files (if there are changes to the model classes)
  • I have added or updated unit and end2end tests or a manual test case to complement my changes
  • I have ran unit and end2end tests
  • I have considered accessibility for UI changes and reviewed pre-commit/Pa11y results or documented a manual check
  • I have updated the related documentation (if necessary)
  • I have added a reviewer for this pull request
  • I have added myself as an author for this pull request
  • In the case I have modified settings.py, then I have also updated the studio-settings-configmap.yaml file in serve-charts
  • In case your changes are large enough, did you deploy your changes to develop instance?

@YukiJanse YukiJanse self-assigned this Nov 20, 2026
@YukiJanse YukiJanse changed the title Ss 1839 restrict image registry SS-1839 restrict image registry Nov 20, 2026
@YukiJanse
YukiJanse marked this pull request as ready for review November 20, 2026 13:43
@YukiJanse
YukiJanse requested a review from a team as a code owner November 20, 2026 13:43

@hamzaimran08 hamzaimran08 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good work. Looks good in general, just a few comments to look into

Comment thread apps/forms/mixins.py

if "ghcr.io" in image:
# Validate the registry of image
if not self._validate_registry_allowed(image):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment thread studio/settings.py
ORCID_BASE_URL = "https://orcid.org"

# For image registry checking
ALLOWED_IMAGE_REGISTRIES = [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two things:

  1. This variable is missing from .env.template and serve-charts repo (https://github.com/ScilifelabDataCentre/serve-charts/blob/develop/serve/templates/studio-settings-configmap.yaml).
  2. 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?

Comment thread apps/forms/mixins.py
if registry not in allowed:
self.add_error(
"image",
f"Images from '{registry}' are not allowed. " f"Allowed registries: {', '.join(allowed)}",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could this be one string?

Suggested change
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()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Typo: iamge should be image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants