Search in sources :

Example 11 with Secret

use of io.hops.hopsworks.persistence.entity.user.security.secrets.Secret in project hopsworks by logicalclocks.

the class SecretsController method add.

/**
 * Adds a new Secret. The secret is encrypted before persisted in the database.
 * It throws an exception if a Secret with the same name already exists for the
 * same user.
 *
 * @param user User to add the Secret
 * @param secretName Identifier of the secret
 * @param secret The secret itself
 * @param visibilityType Visibility of a Secret. It can be private or shared among members of a project
 * @throws UserException
 */
public Secret add(Users user, String secretName, String secret, VisibilityType visibilityType, Integer projectIdScope) throws UserException {
    SecretId secretId = new SecretId(user.getUid(), secretName);
    if (secretsFacade.findById(secretId) != null) {
        throw new UserException(RESTCodes.UserErrorCode.SECRET_EXISTS, Level.FINE, "Secret already exists", "Secret with name " + secretName + " already exists for user " + user.getUsername());
    }
    Secret storedSecret = validateAndCreateSecret(secretId, user, secret, visibilityType, projectIdScope);
    secretsFacade.persist(storedSecret);
    return storedSecret;
}
Also used : Secret(io.hops.hopsworks.persistence.entity.user.security.secrets.Secret) SecretId(io.hops.hopsworks.persistence.entity.user.security.secrets.SecretId) UserException(io.hops.hopsworks.exceptions.UserException)

Example 12 with Secret

use of io.hops.hopsworks.persistence.entity.user.security.secrets.Secret in project hopsworks by logicalclocks.

the class SecretsController method addOrUpdate.

/**
 * Adds a new Secret. The secret is encrypted before persisted in the database.
 * If a secret with the same name already exists for the user, it updates it.
 *
 * @param user
 * @param secretName
 * @param secretStr
 * @param visibilityType
 * @param projectIdScope
 * @return
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public Secret addOrUpdate(Users user, String secretName, String secretStr, VisibilityType visibilityType, Integer projectIdScope) throws UserException {
    SecretId secretId = new SecretId(user.getUid(), secretName);
    Secret secret = secretsFacade.findById(secretId);
    if (secret != null) {
        Secret generatedSecret = validateAndCreateSecret(secretId, user, secretStr, visibilityType, projectIdScope);
        secret.setSecret(generatedSecret.getSecret());
        secret.setAddedOn(generatedSecret.getAddedOn());
        secret.setVisibilityType(generatedSecret.getVisibilityType());
        secret.setProjectIdScope(generatedSecret.getProjectIdScope());
    } else {
        secret = validateAndCreateSecret(secretId, user, secretStr, visibilityType, projectIdScope);
    }
    secretsFacade.persist(secret);
    return secret;
}
Also used : Secret(io.hops.hopsworks.persistence.entity.user.security.secrets.Secret) SecretId(io.hops.hopsworks.persistence.entity.user.security.secrets.SecretId) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 13 with Secret

use of io.hops.hopsworks.persistence.entity.user.security.secrets.Secret in project hopsworks by logicalclocks.

the class FeaturestoreS3ConnectorController method updateSecret.

private Secret updateSecret(Users user, FeaturestoreS3ConnectorDTO featurestoreS3ConnectorDTO, Featurestore featurestore, FeaturestoreS3Connector featurestoreS3Connector) throws UserException, FeaturestoreException, ProjectException {
    Secret secret = featurestoreS3Connector.getSecret();
    if (secret != null) {
        secretsController.checkCanAccessSecret(secret, user);
    }
    if (secret == null && keysNotNullOrEmpty(featurestoreS3ConnectorDTO)) {
        verifyS3ConnectorAccessKey(featurestoreS3ConnectorDTO.getAccessKey());
        verifyS3ConnectorSecretKey(featurestoreS3ConnectorDTO.getSecretKey());
        setSecret(user, featurestoreS3ConnectorDTO, featurestoreS3Connector, featurestore);
    } else if (keysNotNullOrEmpty(featurestoreS3ConnectorDTO)) {
        try {
            verifyS3ConnectorAccessKey(featurestoreS3ConnectorDTO.getAccessKey());
            verifyS3ConnectorSecretKey(featurestoreS3ConnectorDTO.getSecretKey());
            String jsonSecretString = createS3AccessAndSecretKeysSecret(featurestoreS3ConnectorDTO.getAccessKey(), featurestoreS3ConnectorDTO.getSecretKey());
            secret.setSecret(secretsController.encryptSecret(jsonSecretString));
        } catch (IOException | GeneralSecurityException e) {
            throw new UserException(RESTCodes.UserErrorCode.SECRET_ENCRYPTION_ERROR, Level.SEVERE, "Error encrypting secret", "Could not encrypt Secret " + secret.getId().getName(), e);
        }
    } else {
        featurestoreS3Connector.setSecret(null);
    // Secret can't be removed here b/c of ON DELETE RESTRICT
    }
    return secret;
}
Also used : Secret(io.hops.hopsworks.persistence.entity.user.security.secrets.Secret) UserException(io.hops.hopsworks.exceptions.UserException)

Example 14 with Secret

use of io.hops.hopsworks.persistence.entity.user.security.secrets.Secret in project hopsworks by logicalclocks.

the class FeaturestoreSnowflakeConnectorController method updateSecret.

private Secret updateSecret(Users user, FeaturestoreSnowflakeConnectorDTO featurestoreSnowflakeConnectorDTO, FeaturestoreSnowflakeConnector snowflakeConnector) throws UserException, ProjectException {
    String secret;
    Secret existingSecret = getSecret(snowflakeConnector);
    secretsController.checkCanAccessSecret(existingSecret, user);
    if (!Strings.isNullOrEmpty(featurestoreSnowflakeConnectorDTO.getPassword())) {
        secret = featurestoreSnowflakeConnectorDTO.getPassword();
    } else {
        secret = featurestoreSnowflakeConnectorDTO.getToken();
    }
    try {
        existingSecret.setSecret(secretsController.encryptSecret(secret));
    } catch (IOException | GeneralSecurityException e) {
        throw new UserException(RESTCodes.UserErrorCode.SECRET_ENCRYPTION_ERROR, Level.SEVERE, "Error encrypting secret", "Could not encrypt Secret " + existingSecret.getId().getName(), e);
    }
    return existingSecret;
}
Also used : Secret(io.hops.hopsworks.persistence.entity.user.security.secrets.Secret) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) UserException(io.hops.hopsworks.exceptions.UserException)

Example 15 with Secret

use of io.hops.hopsworks.persistence.entity.user.security.secrets.Secret in project hopsworks by logicalclocks.

the class FeaturestoreSnowflakeConnectorController method createSecret.

private Secret createSecret(Users user, Featurestore featurestore, FeaturestoreSnowflakeConnectorDTO featurestoreSnowflakeConnectorDTO) throws ProjectException, UserException {
    String secretName = storageConnectorUtil.createSecretName(featurestore.getId(), featurestoreSnowflakeConnectorDTO.getName(), featurestoreSnowflakeConnectorDTO.getStorageConnectorType());
    Secret secret;
    if (!Strings.isNullOrEmpty(featurestoreSnowflakeConnectorDTO.getPassword())) {
        secret = secretsController.createSecretForProject(user, secretName, featurestoreSnowflakeConnectorDTO.getPassword(), featurestore.getProject().getId());
    } else {
        secret = secretsController.createSecretForProject(user, secretName, featurestoreSnowflakeConnectorDTO.getToken(), featurestore.getProject().getId());
    }
    return secret;
}
Also used : Secret(io.hops.hopsworks.persistence.entity.user.security.secrets.Secret)

Aggregations

Secret (io.hops.hopsworks.persistence.entity.user.security.secrets.Secret)17 UserException (io.hops.hopsworks.exceptions.UserException)6 SecretId (io.hops.hopsworks.persistence.entity.user.security.secrets.SecretId)6 IOException (java.io.IOException)4 GeneralSecurityException (java.security.GeneralSecurityException)4 TransactionAttribute (javax.ejb.TransactionAttribute)4 Transactional (javax.transaction.Transactional)3 HashMap (java.util.HashMap)2 MasterPasswordChangeResult (io.hops.hopsworks.common.security.MasterPasswordChangeResult)1 SymmetricEncryptionDescriptor (io.hops.hopsworks.common.security.SymmetricEncryptionDescriptor)1 EncryptionMasterPasswordException (io.hops.hopsworks.exceptions.EncryptionMasterPasswordException)1 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)1 ProjectException (io.hops.hopsworks.exceptions.ProjectException)1 ServiceException (io.hops.hopsworks.exceptions.ServiceException)1 FeaturestoreADLSConnector (io.hops.hopsworks.persistence.entity.featurestore.storageconnector.adls.FeaturestoreADLSConnector)1 FeaturestoreS3ConnectorAccessAndSecretKey (io.hops.hopsworks.persistence.entity.featurestore.storageconnector.s3.FeaturestoreS3ConnectorAccessAndSecretKey)1 FeaturestoreS3ConnectorEncryptionAlgorithm (io.hops.hopsworks.persistence.entity.featurestore.storageconnector.s3.FeaturestoreS3ConnectorEncryptionAlgorithm)1 FeaturestoreSnowflakeConnector (io.hops.hopsworks.persistence.entity.featurestore.storageconnector.snowflake.FeaturestoreSnowflakeConnector)1 Project (io.hops.hopsworks.persistence.entity.project.Project)1 ProjectTeam (io.hops.hopsworks.persistence.entity.project.team.ProjectTeam)1