mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
Check for container updates rather than using image-id.txt
This commit is contained in:
parent
53fbbc6cdf
commit
6359e488e3
1 changed files with 25 additions and 32 deletions
|
@ -5,7 +5,7 @@ import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
from .. import container_utils, errors
|
from .. import container_utils, errors, updater
|
||||||
from ..container_utils import Runtime
|
from ..container_utils import Runtime
|
||||||
from ..document import Document
|
from ..document import Document
|
||||||
from ..util import get_resource_path, get_subprocess_startupinfo
|
from ..util import get_resource_path, get_subprocess_startupinfo
|
||||||
|
@ -95,23 +95,18 @@ class Container(IsolationProvider):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def install() -> bool:
|
def install() -> bool:
|
||||||
"""Install the container image tarball, or verify that it's already installed.
|
"""Check if an update is available and install it if necessary."""
|
||||||
|
# XXX Do this only if users have optted in to auto-updates
|
||||||
|
|
||||||
Perform the following actions:
|
# # Load the image tarball into the container runtime.
|
||||||
1. Get the tags of any locally available images that match Dangerzone's image
|
update_available, image_digest = updater.is_update_available(
|
||||||
name.
|
container_utils.CONTAINER_NAME
|
||||||
2. Get the expected image tag from the image-id.txt file.
|
)
|
||||||
- If this tag is present in the local images, then we can return.
|
if update_available and image_digest:
|
||||||
- Else, prune the older container images and continue.
|
updater.upgrade_container_image(
|
||||||
3. Load the image tarball and make sure it matches the expected tag.
|
container_utils.CONTAINER_NAME,
|
||||||
"""
|
image_digest,
|
||||||
old_tags = container_utils.list_image_tags()
|
updater.DEFAULT_PUBKEY_LOCATION,
|
||||||
expected_tag = container_utils.get_expected_tag()
|
|
||||||
|
|
||||||
if expected_tag not in old_tags:
|
|
||||||
# Prune older container images.
|
|
||||||
log.info(
|
|
||||||
f"Could not find a Dangerzone container image with tag '{expected_tag}'"
|
|
||||||
)
|
)
|
||||||
for tag in old_tags:
|
for tag in old_tags:
|
||||||
tag = container_utils.CONTAINER_NAME + ":" + tag
|
tag = container_utils.CONTAINER_NAME + ":" + tag
|
||||||
|
@ -119,18 +114,9 @@ class Container(IsolationProvider):
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Load the image tarball into the container runtime.
|
updater.verify_local_image(
|
||||||
container_utils.load_image_tarball()
|
container_utils.CONTAINER_NAME, updater.DEFAULT_PUBKEY_LOCATION
|
||||||
|
)
|
||||||
# Check that the container image has the expected image tag.
|
|
||||||
# See https://github.com/freedomofpress/dangerzone/issues/988 for an example
|
|
||||||
# where this was not the case.
|
|
||||||
new_tags = container_utils.list_image_tags()
|
|
||||||
if expected_tag not in new_tags:
|
|
||||||
raise errors.ImageNotPresentException(
|
|
||||||
f"Could not find expected tag '{expected_tag}' after loading the"
|
|
||||||
" container image tarball"
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -214,6 +200,15 @@ class Container(IsolationProvider):
|
||||||
name: str,
|
name: str,
|
||||||
) -> subprocess.Popen:
|
) -> subprocess.Popen:
|
||||||
runtime = Runtime()
|
runtime = Runtime()
|
||||||
|
|
||||||
|
image_digest = container_utils.get_local_image_digest(
|
||||||
|
container_utils.CONTAINER_NAME
|
||||||
|
)
|
||||||
|
updater.verify_local_image(
|
||||||
|
container_utils.CONTAINER_NAME,
|
||||||
|
updater.DEFAULT_PUBKEY_LOCATION,
|
||||||
|
image_digest,
|
||||||
|
)
|
||||||
security_args = self.get_runtime_security_args()
|
security_args = self.get_runtime_security_args()
|
||||||
debug_args = []
|
debug_args = []
|
||||||
if self.debug:
|
if self.debug:
|
||||||
|
@ -222,9 +217,7 @@ class Container(IsolationProvider):
|
||||||
enable_stdin = ["-i"]
|
enable_stdin = ["-i"]
|
||||||
set_name = ["--name", name]
|
set_name = ["--name", name]
|
||||||
prevent_leakage_args = ["--rm"]
|
prevent_leakage_args = ["--rm"]
|
||||||
image_name = [
|
image_name = [container_utils.CONTAINER_NAME + "@sha256:" + image_digest]
|
||||||
container_utils.CONTAINER_NAME + ":" + container_utils.get_expected_tag()
|
|
||||||
]
|
|
||||||
args = (
|
args = (
|
||||||
["run"]
|
["run"]
|
||||||
+ security_args
|
+ security_args
|
||||||
|
|
Loading…
Reference in a new issue