Search in sources :

Example 1 with ConfigParamPreprocessor

use of com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor in project gocd by gocd.

the class BasicCruiseConfigTest method shouldEncryptSecurePluggableArtifactConfigPropertiesOfAllPipelinesInConfig.

@Test
public void shouldEncryptSecurePluggableArtifactConfigPropertiesOfAllPipelinesInConfig(ResetCipher resetCipher) throws IOException, CryptoException {
    // ancestor => parent => child [fetch pluggable artifact(ancestor), fetch pluggable artifact(parent)]
    resetCipher.setupAESCipherFile();
    BasicCruiseConfig config = setupPipelines();
    BasicCruiseConfig preprocessed = GoConfigMother.deepClone(config);
    new ConfigParamPreprocessor().process(preprocessed);
    config.encryptSecureProperties(preprocessed);
    PipelineConfig ancestor = config.pipelineConfigByName(new CaseInsensitiveString("ancestor"));
    PipelineConfig child = config.pipelineConfigByName(new CaseInsensitiveString("child"));
    Configuration ancestorPublishArtifactConfig = ancestor.getStage("stage1").jobConfigByConfigName("job1").artifactTypeConfigs().getPluggableArtifactConfigs().get(0).getConfiguration();
    GoCipher goCipher = new GoCipher();
    assertThat(ancestorPublishArtifactConfig.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("pub_v1")));
    assertThat(ancestorPublishArtifactConfig.getProperty("k1").getConfigValue(), is(nullValue()));
    assertThat(ancestorPublishArtifactConfig.getProperty("k1").getValue(), is("pub_v1"));
    assertThat(ancestorPublishArtifactConfig.getProperty("k2").getEncryptedValue(), is(nullValue()));
    assertThat(ancestorPublishArtifactConfig.getProperty("k2").getConfigValue(), is("pub_v2"));
    assertThat(ancestorPublishArtifactConfig.getProperty("k2").getValue(), is("pub_v2"));
    assertThat(ancestorPublishArtifactConfig.getProperty("k3").getEncryptedValue(), is(goCipher.encrypt("pub_v3")));
    assertThat(ancestorPublishArtifactConfig.getProperty("k3").getConfigValue(), is(nullValue()));
    assertThat(ancestorPublishArtifactConfig.getProperty("k3").getValue(), is("pub_v3"));
    Configuration childFetchFromAncestorConfig = ((FetchPluggableArtifactTask) child.getStage("stage1").jobConfigByConfigName("job1").tasks().get(0)).getConfiguration();
    assertThat(childFetchFromAncestorConfig.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("fetch_v1")));
    assertThat(childFetchFromAncestorConfig.getProperty("k1").getConfigValue(), is(nullValue()));
    assertThat(childFetchFromAncestorConfig.getProperty("k1").getValue(), is("fetch_v1"));
    assertThat(childFetchFromAncestorConfig.getProperty("k2").getEncryptedValue(), is(nullValue()));
    assertThat(childFetchFromAncestorConfig.getProperty("k2").getConfigValue(), is("fetch_v2"));
    assertThat(childFetchFromAncestorConfig.getProperty("k2").getValue(), is("fetch_v2"));
    assertThat(childFetchFromAncestorConfig.getProperty("k3").getEncryptedValue(), is(goCipher.encrypt("fetch_v3")));
    assertThat(childFetchFromAncestorConfig.getProperty("k3").getConfigValue(), is(nullValue()));
    assertThat(childFetchFromAncestorConfig.getProperty("k3").getValue(), is("fetch_v3"));
    Configuration childFetchFromParentConfig = ((FetchPluggableArtifactTask) child.getStage("stage1").jobConfigByConfigName("job1").tasks().get(1)).getConfiguration();
    assertThat(childFetchFromParentConfig.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("fetch_v1")));
    assertThat(childFetchFromParentConfig.getProperty("k1").getConfigValue(), is(nullValue()));
    assertThat(childFetchFromParentConfig.getProperty("k1").getValue(), is("fetch_v1"));
    assertThat(childFetchFromParentConfig.getProperty("k2").getEncryptedValue(), is(nullValue()));
    assertThat(childFetchFromParentConfig.getProperty("k2").getConfigValue(), is("fetch_v2"));
    assertThat(childFetchFromParentConfig.getProperty("k2").getValue(), is("fetch_v2"));
    assertThat(childFetchFromParentConfig.getProperty("k3").getEncryptedValue(), is(goCipher.encrypt("fetch_v3")));
    assertThat(childFetchFromParentConfig.getProperty("k3").getConfigValue(), is(nullValue()));
    assertThat(childFetchFromParentConfig.getProperty("k3").getValue(), is("fetch_v3"));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigParamPreprocessor(com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor) Test(org.junit.jupiter.api.Test)

Example 2 with ConfigParamPreprocessor

use of com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor in project gocd by gocd.

the class BasicCruiseConfigTest method shouldEncryptElasticAgentProfileConfigProperties.

@Test
public void shouldEncryptElasticAgentProfileConfigProperties(ResetCipher resetCipher) throws IOException, CryptoException {
    setEAPluginInfo();
    resetCipher.setupAESCipherFile();
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.getElasticConfig().getClusterProfiles().add(new ClusterProfile("prod-cluster", "ecs"));
    ElasticProfile elasticProfile = new ElasticProfile("profile1", "prod-cluster");
    elasticProfile.addConfigurations(asList(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("pub_v1")), new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("pub_v2")), new ConfigurationProperty(new ConfigurationKey("k3"), new ConfigurationValue("pub_v3"))));
    cruiseConfig.getElasticConfig().getProfiles().add(elasticProfile);
    BasicCruiseConfig preprocessed = GoConfigMother.deepClone(cruiseConfig);
    new ConfigParamPreprocessor().process(preprocessed);
    cruiseConfig.encryptSecureProperties(preprocessed);
    Configuration properties = cruiseConfig.getElasticConfig().getProfiles().get(0);
    GoCipher goCipher = new GoCipher();
    assertThat(properties.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("pub_v1")));
    assertThat(properties.getProperty("k1").getConfigValue(), is(nullValue()));
    assertThat(properties.getProperty("k1").getValue(), is("pub_v1"));
    assertThat(properties.getProperty("k2").getEncryptedValue(), is(nullValue()));
    assertThat(properties.getProperty("k2").getConfigValue(), is("pub_v2"));
    assertThat(properties.getProperty("k2").getValue(), is("pub_v2"));
    assertThat(properties.getProperty("k3").getEncryptedValue(), is(goCipher.encrypt("pub_v3")));
    assertThat(properties.getProperty("k3").getConfigValue(), is(nullValue()));
    assertThat(properties.getProperty("k3").getValue(), is("pub_v3"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) GoCipher(com.thoughtworks.go.security.GoCipher) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) ConfigParamPreprocessor(com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigParamPreprocessor

use of com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor in project gocd by gocd.

the class AbstractMaterialTestController method performParamExpansion.

private void performParamExpansion(ScmMaterialConfig scmMaterialConfig, String pipelineName) {
    PipelineConfig pipelineConfig;
    // If the pipeline name is provided, find the pipeline and add the params to the new pipeline config object
    if (isNotBlank(pipelineName)) {
        PipelineConfig existingPipeline = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
        pipelineConfig = new PipelineConfig(existingPipeline.name(), new MaterialConfigs());
        GoConfigCloner goConfigCloner = new GoConfigCloner();
        pipelineConfig.setParams(goConfigCloner.deepClone(existingPipeline.getParams()));
    } else {
        // If the pipeline name is not provided, this means that the pipeline is still in creation nd hence no params exist
        pipelineConfig = new PipelineConfig(new CaseInsensitiveString(""), new MaterialConfigs());
    }
    pipelineConfig.addMaterialConfig(scmMaterialConfig);
    ConfigParamPreprocessor configParamPreprocessor = new ConfigParamPreprocessor();
    configParamPreprocessor.process(pipelineConfig);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GoConfigCloner(com.thoughtworks.go.config.GoConfigCloner) ConfigParamPreprocessor(com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 4 with ConfigParamPreprocessor

use of com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor in project gocd by gocd.

the class BasicCruiseConfigTest method shouldEncryptSecurePluggableArtifactConfigPropertiesOfAllTemplatesInConfig.

@Test
public void shouldEncryptSecurePluggableArtifactConfigPropertiesOfAllTemplatesInConfig(ResetCipher resetCipher) throws IOException, CryptoException {
    setArtifactPluginInfo();
    resetCipher.setupAESCipherFile();
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.getArtifactStores().add(new ArtifactStore("store1", "cd.go.s3"));
    PipelineConfig pipelineConfig = new GoConfigMother().addPipelineWithTemplate(cruiseConfig, "p1", "t1", "s1", "j1");
    cruiseConfig.addPipeline("first", pipelineConfig);
    PipelineTemplateConfig templateConfig = cruiseConfig.getTemplates().first();
    JobConfig jobConfig = templateConfig.getStages().get(0).getJobs().get(0);
    PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("foo", "store1");
    artifactConfig.addConfigurations(asList(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("pub_v1")), new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("pub_v2")), new ConfigurationProperty(new ConfigurationKey("k3"), new ConfigurationValue("pub_v3"))));
    jobConfig.artifactTypeConfigs().add(artifactConfig);
    BasicCruiseConfig preprocessed = GoConfigMother.deepClone(cruiseConfig);
    new ConfigParamPreprocessor().process(preprocessed);
    cruiseConfig.encryptSecureProperties(preprocessed);
    Configuration properties = ((PluggableArtifactConfig) cruiseConfig.getTemplates().get(0).getStages().get(0).getJobs().get(0).artifactTypeConfigs().get(0)).getConfiguration();
    GoCipher goCipher = new GoCipher();
    assertThat(properties.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("pub_v1")));
    assertThat(properties.getProperty("k1").getConfigValue(), is(nullValue()));
    assertThat(properties.getProperty("k1").getValue(), is("pub_v1"));
    assertThat(properties.getProperty("k2").getEncryptedValue(), is(nullValue()));
    assertThat(properties.getProperty("k2").getConfigValue(), is("pub_v2"));
    assertThat(properties.getProperty("k2").getValue(), is("pub_v2"));
    assertThat(properties.getProperty("k3").getEncryptedValue(), is(goCipher.encrypt("pub_v3")));
    assertThat(properties.getProperty("k3").getConfigValue(), is(nullValue()));
    assertThat(properties.getProperty("k3").getValue(), is("pub_v3"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigParamPreprocessor(com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigParamPreprocessor

use of com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor in project gocd by gocd.

the class BasicCruiseConfigTest method shouldEncryptSecureRoleConfigProperties.

@Test
public void shouldEncryptSecureRoleConfigProperties(ResetCipher resetCipher) throws IOException, CryptoException {
    setAuthorizationPluginInfo();
    resetCipher.setupAESCipherFile();
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.server().security().securityAuthConfigs().add(new SecurityAuthConfig("auth1", "cd.go.github"));
    PluginRoleConfig pluginRole = new PluginRoleConfig("role1", "auth1");
    pluginRole.addConfigurations(asList(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("pub_v1")), new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("pub_v2")), new ConfigurationProperty(new ConfigurationKey("k3"), new ConfigurationValue("pub_v3"))));
    cruiseConfig.server().security().getRoles().add(pluginRole);
    BasicCruiseConfig preprocessed = GoConfigMother.deepClone(cruiseConfig);
    new ConfigParamPreprocessor().process(preprocessed);
    cruiseConfig.encryptSecureProperties(preprocessed);
    Configuration properties = cruiseConfig.server().security().getRoles().getPluginRoleConfigs().get(0);
    GoCipher goCipher = new GoCipher();
    assertThat(properties.getProperty("k1").getEncryptedValue(), is(goCipher.encrypt("pub_v1")));
    assertThat(properties.getProperty("k1").getConfigValue(), is(nullValue()));
    assertThat(properties.getProperty("k1").getValue(), is("pub_v1"));
    assertThat(properties.getProperty("k2").getEncryptedValue(), is(nullValue()));
    assertThat(properties.getProperty("k2").getConfigValue(), is("pub_v2"));
    assertThat(properties.getProperty("k2").getValue(), is("pub_v2"));
    assertThat(properties.getProperty("k3").getEncryptedValue(), is(goCipher.encrypt("pub_v3")));
    assertThat(properties.getProperty("k3").getConfigValue(), is(nullValue()));
    assertThat(properties.getProperty("k3").getValue(), is("pub_v3"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigParamPreprocessor(com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigParamPreprocessor (com.thoughtworks.go.config.preprocessor.ConfigParamPreprocessor)5 Configuration (com.thoughtworks.go.domain.config.Configuration)4 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)4 GoCipher (com.thoughtworks.go.security.GoCipher)4 Test (org.junit.jupiter.api.Test)4 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)3 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)3 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 GoConfigCloner (com.thoughtworks.go.config.GoConfigCloner)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)1 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)1