alopresto commented on a change in pull request #3672: NIFI-6363 Additional Sensitive Property Providers URL: https://github.com/apache/nifi/pull/3672#discussion_r318211409
########## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/java/org/apache/nifi/properties/sensitive/gcp/kms/GCPKMSSensitivePropertyProviderIT.java ########## @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.properties.sensitive.gcp.kms; + +import com.google.cloud.kms.v1.CryptoKey; +import com.google.cloud.kms.v1.CryptoKeyName; +import com.google.cloud.kms.v1.CryptoKeyVersion; +import com.google.cloud.kms.v1.CryptoKeyVersionName; +import com.google.cloud.kms.v1.CryptoKeyVersionTemplate; +import com.google.cloud.kms.v1.KeyManagementServiceClient; +import com.google.cloud.kms.v1.KeyRing; +import com.google.cloud.kms.v1.KeyRingName; +import com.google.cloud.kms.v1.LocationName; +import org.apache.nifi.properties.sensitive.AbstractSensitivePropertyProviderTest; +import org.apache.nifi.properties.sensitive.SensitivePropertyConfigurationException; +import org.apache.nifi.properties.sensitive.SensitivePropertyProvider; +import org.apache.nifi.security.util.CipherUtils; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.regex.Pattern; + + +/* + +Configure your test environment like: + + $ export GOOGLE_APPLICATION_CREDENTIALS=/home/troy/var/nifi-gcp-it.json + $ export GOOGLE_PROJECT=nifi-gcp-unit-tests-project + +*/ +public class GCPKMSSensitivePropertyProviderIT extends AbstractSensitivePropertyProviderTest { + private static final Logger logger = LoggerFactory.getLogger(GCPKMSSensitivePropertyProviderIT.class); + private static String keyId; + + private static final String locationId = "us-west2"; + private static final String keyRingId = "key-ring-" + CipherUtils.getRandomHex(6); + private static final String cryptoKeyId = "key-name-" + CipherUtils.getRandomHex(6); + + private static KeyRing keyRing; + private static CryptoKey createdKey; + private static String projectId; + + @BeforeClass + public static void createKeyRingAndKey() { + Assume.assumeTrue(System.getenv("GOOGLE_APPLICATION_CREDENTIALS") != null); + Assume.assumeTrue(System.getenv("GOOGLE_PROJECT") != null); + + projectId = System.getenv("GOOGLE_PROJECT"); + try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) { + String parent = LocationName.format(projectId, locationId); + keyRing = client.createKeyRing(parent, keyRingId, KeyRing.newBuilder().build()); + CryptoKey cryptoKey = CryptoKey.newBuilder().setPurpose(CryptoKey.CryptoKeyPurpose.ENCRYPT_DECRYPT).build(); + createdKey = client.createCryptoKey(KeyRingName.format(projectId, locationId, keyRingId), cryptoKeyId, cryptoKey); + keyId = "gcp/kms/" + createdKey.getName(); + logger.info("Created GCP key: {}", createdKey.getName()); + + } catch (IOException e) { + logger.warn("Error during create key ring and key: " + e); + } + } + + @AfterClass + public static void deleteKeyRingAndKey() { Review comment: I don't think it can happen here but we should be confident that none of the integration tests could accidentally delete a user's _real_ keys in the cloud provider's (or Vault's) secrets store. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
