use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManager method issueTokenForDockerRegistry.
/**
* Checks permissions for a requested docker registry and issues a valid JWT token,
* if action is allowed. Otherwise 401 code will be returned to registry. See documentation
* for details https://docs.docker.com/registry/spec/auth/token/#requesting-a-token
* @param userName requesting permission
* @param token provided by docker client, should be a valid Cloud Pipeline token
* @param dockerRegistryHost id of docker registry
* @param scope requested action in format
* 'scope=repository:samalba/my-app:push,repository:samalba/my-test:push'
* @return
*/
public JwtRawToken issueTokenForDockerRegistry(String userName, String token, String dockerRegistryHost, String scope) {
LOGGER.debug("Processing authorization request from registry {} for user {} and scope {}", dockerRegistryHost, userName, scope);
UserContext user = dockerAuthService.verifyTokenForDocker(userName, token, dockerRegistryHost);
DockerRegistry dockerRegistry = loadByNameOrId(dockerRegistryHost);
if (dockerRegistry == null) {
throw new DockerAuthorizationException(dockerRegistryHost, messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_NOT_FOUND, dockerRegistryHost));
}
try {
List<DockerRegistryClaim> claims = parseAndValidateScope(userName, dockerRegistry, scope);
JwtRawToken jwtRawToken = dockerAuthService.issueDockerToken(user, dockerRegistryHost, claims);
LOGGER.debug("Successfully issued JWT token for registry {} user {} and scope {}", dockerRegistry, userName, scope);
return jwtRawToken;
} catch (IllegalArgumentException e) {
throw new DockerAuthorizationException(dockerRegistryHost, e.getMessage());
}
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManager method updateDockerRegistryCredentials.
@Transactional(propagation = Propagation.REQUIRED)
public DockerRegistry updateDockerRegistryCredentials(DockerRegistryVO dockerRegistryVO) {
DockerRegistry dockerRegistry = dockerRegistryVO.convertToDockerRegistry();
DockerRegistry loadedDockerRegistry = loadByIdOrName(dockerRegistry);
Assert.notNull(loadedDockerRegistry, messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_NOT_FOUND, dockerRegistry.getPath()));
loadedDockerRegistry.setExternalUrl(dockerRegistry.getExternalUrl());
loadedDockerRegistry.setPipelineAuth(dockerRegistry.isPipelineAuth());
loadedDockerRegistry.setUserName(dockerRegistry.getUserName());
loadedDockerRegistry.setPassword(dockerRegistry.getPassword());
loadedDockerRegistry.setCaCert(dockerRegistry.getCaCert());
normalizeCert(loadedDockerRegistry);
validateAuthentication(loadedDockerRegistry);
kubernetesManager.deleteSecret(loadedDockerRegistry.getSecretName());
if (StringUtils.isNotBlank(loadedDockerRegistry.getUserName())) {
loadedDockerRegistry.setSecretName(kubernetesManager.createDockerRegistrySecret(DockerRegistrySecret.builder().registryUrl(loadedDockerRegistry.getPath()).userName(loadedDockerRegistry.getUserName()).password(loadedDockerRegistry.getPassword()).build()));
}
dockerRegistryDao.updateDockerRegistry(loadedDockerRegistry);
return loadedDockerRegistry;
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class ToolGroupManagerTest method setUp.
@Before
public void setUp() throws Exception {
registry = new DockerRegistry();
registry.setPath(TEST_REPO);
registry.setOwner(TEST_USER);
registryDao.createDockerRegistry(registry);
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class PipelineConfigurationManagerTest method setUp.
@Before
public void setUp() throws Exception {
registry = new DockerRegistry();
registry.setPath(TEST_REPO);
registry.setOwner(TEST_USER);
dockerRegistryDao.createDockerRegistry(registry);
library = new ToolGroup();
library.setName(TOOL_GROUP_NAME);
library.setRegistryId(registry.getId());
library.setOwner(TEST_USER);
toolGroupDao.createToolGroup(library);
tool = new Tool();
tool.setImage(TEST_IMAGE);
tool.setRam(TEST_RAM);
tool.setCpu(TEST_CPU);
tool.setOwner(TEST_USER);
tool.setRegistryId(registry.getId());
tool.setToolGroupId(library.getId());
toolDao.createTool(tool);
// Data storages of user 1
NFSDataStorage dataStorage = new NFSDataStorage(dataStorageDao.createDataStorageId(), "testNFS", "test/path1");
dataStorage.setMountOptions("testMountOptions1");
dataStorage.setMountPoint("/some/other/path");
dataStorage.setOwner(TEST_OWNER1);
dataStorageDao.createDataStorage(dataStorage);
dataStorages.add(dataStorage);
S3bucketDataStorage bucketDataStorage = new S3bucketDataStorage(dataStorageDao.createDataStorageId(), "testBucket", "test/path2");
bucketDataStorage.setOwner(TEST_OWNER1);
dataStorageDao.createDataStorage(bucketDataStorage);
dataStorages.add(bucketDataStorage);
// Data storages of user 2
dataStorage = new NFSDataStorage(dataStorageDao.createDataStorageId(), "testNFS2", "test/path3");
dataStorage.setMountOptions("testMountOptions2");
dataStorage.setOwner(TEST_OWNER2);
dataStorageDao.createDataStorage(dataStorage);
dataStorages.add(dataStorage);
bucketDataStorage = new S3bucketDataStorage(dataStorageDao.createDataStorageId(), "testBucket2", "test/path4");
bucketDataStorage.setOwner(TEST_OWNER2);
dataStorageDao.createDataStorage(bucketDataStorage);
dataStorages.add(bucketDataStorage);
dataStorages.forEach(ds -> aclTestDao.createAclForObject(ds));
aclTestDao.grantPermissions(dataStorage, TEST_OWNER1, Collections.singletonList((AclPermission) AclPermission.READ));
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryMapper method map.
@Override
public XContentBuilder map(final EntityContainer<DockerRegistry> container) {
DockerRegistry dockerRegistry = container.getEntity();
try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
jsonBuilder.startObject().field(DOC_TYPE_FIELD, SearchDocumentType.DOCKER_REGISTRY.name()).field("id", dockerRegistry.getId()).field("name", dockerRegistry.getName()).field("path", dockerRegistry.getPath()).field("createdDate", parseDataToString(dockerRegistry.getCreatedDate())).field("description", dockerRegistry.getDescription()).field("userName", dockerRegistry.getUserName());
buildUserContent(container.getOwner(), jsonBuilder);
buildMetadata(container.getMetadata(), jsonBuilder);
buildPermissions(container.getPermissions(), jsonBuilder);
jsonBuilder.endObject();
return jsonBuilder;
} catch (IOException e) {
throw new IllegalArgumentException("Failed to create elasticsearch document for docker registry: ", e);
}
}
Aggregations