use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class AggregatingToolScanManager method fetchLayers.
private List<String> fetchLayers(Tool tool, String tag, DockerRegistry registry) throws ToolScanExternalServiceException {
DockerClient dockerClient = getDockerClient(tool.getImage(), registry);
ManifestV2 manifest = dockerClient.getManifest(registry, tool.getImage(), tag).orElseThrow(() -> new ToolScanExternalServiceException(tool, messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_COULD_NOT_GET_MANIFEST, tool.getImage())));
return manifest.getLayers().stream().map(c -> c.getDigest()).collect(Collectors.toList());
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class AggregatingToolScanManager method scanTool.
public ToolVersionScanResult scanTool(Tool tool, String tag, Boolean rescan) throws ToolScanExternalServiceException {
DockerRegistry registry = dockerRegistryManager.load(tool.getRegistryId());
Optional<ToolVersionScanResult> actualScan = rescan ? Optional.empty() : getActualScan(tool, tag, registry);
return actualScan.isPresent() ? actualScan.get() : doScan(tool, tag, registry);
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class ToolScanScheduler method scheduledToolScan.
/**
* A scheduled scan, that runs for all the registries, all tools and all tool versions, sends them to Tool Scanning
* System and stores scanning results to the database.
*/
public void scheduledToolScan() {
if (!preferenceManager.getPreference(SystemPreferences.DOCKER_SECURITY_TOOL_SCAN_ENABLED)) {
LOGGER.info(messageHelper.getMessage(MessageConstants.ERROR_TOOL_SCAN_DISABLED));
return;
} else {
LOGGER.info(messageHelper.getMessage(MessageConstants.INFO_TOOL_SCAN_SCHEDULED_STARTED));
}
boolean scanAllRegistries = preferenceManager.getPreference(SystemPreferences.DOCKER_SECURITY_TOOL_SCAN_ALL_REGISTRIES);
List<DockerRegistry> registries = scanAllRegistries ? dockerRegistryDao.loadAllDockerRegistry() : dockerRegistryDao.loadDockerRegistriesWithSecurityScanEnabled();
for (DockerRegistry registry : registries) {
LOGGER.info(messageHelper.getMessage(MessageConstants.INFO_TOOL_SCAN_REGISTRY_STARTED, registry.getPath()));
for (Tool tool : registry.getTools()) {
DockerClient dockerClient = getDockerClient(registry, tool);
try {
List<String> versions = toolManager.loadTags(tool.getId());
for (String version : versions) {
try {
ToolVersionScanResult result = toolScanManager.scanTool(tool, version, false);
toolManager.updateToolVulnerabilities(result.getVulnerabilities(), tool.getId(), version);
toolManager.updateToolDependencies(result.getDependencies(), tool.getId(), version);
toolManager.updateToolVersionScanStatus(tool.getId(), ToolScanStatus.COMPLETED, new Date(), version, result.getLastLayerRef(), result.getDigest());
updateToolVersion(tool, version, registry, dockerClient);
} catch (ToolScanExternalServiceException e) {
LOGGER.error(messageHelper.getMessage(MessageConstants.ERROR_TOOL_SCAN_FAILED, tool.getImage(), version), e);
toolManager.updateToolVersionScanStatus(tool.getId(), ToolScanStatus.FAILED, new Date(), version, null, null);
}
}
} catch (Exception e) {
LOGGER.error(messageHelper.getMessage(MessageConstants.ERROR_TOOL_SCAN_FAILED, tool.getImage()), e);
toolManager.updateToolVersionScanStatus(tool.getId(), ToolScanStatus.FAILED, new Date(), "latest", null, null);
}
}
}
LOGGER.info(messageHelper.getMessage(MessageConstants.INFO_TOOL_SCAN_SCHEDULED_DONE));
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManager method getCertificateContent.
/**
* @param id of a registry to look for certificate
* @return byte representation of docker registry if it is available, otherwise returns empty array.
*/
public byte[] getCertificateContent(Long id) {
DockerRegistry registry = load(id);
Assert.notNull(registry, messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_NOT_FOUND, id));
return StringUtils.isBlank(registry.getCaCert()) ? new byte[0] : registry.getCaCert().getBytes(Charset.defaultCharset());
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManager method updateToolVersionIfToolPresents.
private void updateToolVersionIfToolPresents(String registry, DockerRegistryEvent registryEvent, Tool tool) {
LOGGER.debug(messageHelper.getMessage(MessageConstants.DEBUG_DOCKER_REGISTRY_AUTO_ENABLE_SUCCESS, registryEvent.getTarget().getRepository()));
String version = registryEvent.getTarget().getTag();
LOGGER.debug("Detected version {} for image {}", version, tool.getImage());
DockerRegistry dockerRegistry = fetchDockerRegistry(registry, registryEvent);
toolVersionManager.updateOrCreateToolVersion(tool.getId(), version, tool.getImage(), dockerRegistry, getDockerClient(dockerRegistry, tool.getImage()));
LOGGER.debug("Tool version attributes for image {}:{} have been successfully updated", tool.getImage(), version);
}
Aggregations