Skip to content

Commit

Permalink
Validate image (#1157)
Browse files Browse the repository at this point in the history
* Validate image

* Fix
  • Loading branch information
ArtoLord authored Dec 12, 2023
1 parent 9897fee commit 78d6705
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void install(LogStream outStream, LogStream errStream) throws Environment
String sourceImage = config.image();
try {
prepareImage(sourceImage, outStream);
validateImage(sourceImage);
} catch (InterruptedException e) {
LOG.error("Image pulling was interrupted");
errStream.log("Image pulling was interrupted");
Expand Down Expand Up @@ -291,4 +292,17 @@ private void prepareImage(String image, LogStream out) throws Exception {
LOG.info(msg);
out.log(msg);
}

private void validateImage(String image) throws Exception {
var inspectResp = client.inspectImageCmd(image).exec();
var config = inspectResp.getConfig();

if (config != null) {
var user = config.getUser();
if (user != null && !user.isEmpty() && !user.equals("root")) {
LOG.error("Got custom user {} in image {}", user, image);
throw new Exception("Cannot use docker image " + image + "with custom user " + user);
}
}
}
}

0 comments on commit 78d6705

Please sign in to comment.