1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.xml;
import com.yahoo.component.ComponentId;
import com.yahoo.config.model.api.TenantSecretStore;
import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.deploy.TestProperties;
import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.RegionName;
import com.yahoo.config.provision.SystemName;
import com.yahoo.config.provision.Zone;
import com.yahoo.container.jdisc.secretstore.SecretStoreConfig;
import com.yahoo.vespa.model.container.ApplicationContainerCluster;
import com.yahoo.vespa.model.container.SecretStore;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Element;
import java.util.List;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author tokle
*/
public class SecretStoreTest extends ContainerModelBuilderTestBase {
@Test
void secret_store_can_be_set_up() {
Element clusterElem = DomBuilderTest.parse(
"<container version='1.0'>",
" <secret-store type='oath-ckms'>",
" <group name='group1' environment='env1'/>",
" </secret-store>",
"</container>");
createModel(root, clusterElem);
SecretStore secretStore = getContainerCluster("container").getSecretStore().get();
assertEquals("group1", secretStore.getGroups().get(0).name);
assertEquals("env1", secretStore.getGroups().get(0).environment);
}
@Test
void cloud_secret_store_requires_configured_secret_store() {
Element clusterElem = DomBuilderTest.parse(
"<container version='1.0'>",
" <secret-store type='cloud'>",
" <store id='store'>",
" <aws-parameter-store account='store1' region='eu-north-1'/>",
" </store>",
" </secret-store>",
"</container>");
try {
DeployState state = new DeployState.Builder()
.properties(new TestProperties().setHostedVespa(true))
.zone(new Zone(SystemName.Public, Environment.prod, RegionName.defaultName()))
.build();
createModel(root, state, null, clusterElem);
fail("secret store not defined");
} catch (RuntimeException e) {
assertEquals("No configured secret store named store1", e.getMessage());
}
}
@Test
void cloud_secret_store_can_be_set_up() {
Element clusterElem = DomBuilderTest.parse(
"<container version='1.0'>",
" <secret-store type='cloud'>",
" <store id='store'>",
" <aws-parameter-store account='store1' region='eu-north-1'/>",
" </store>",
" </secret-store>",
"</container>");
DeployState state = new DeployState.Builder()
.properties(
new TestProperties()
.setHostedVespa(true)
.setTenantSecretStores(List.of(new TenantSecretStore("store1", "1234", "role", Optional.of("externalid")))))
.zone(new Zone(SystemName.Public, Environment.prod, RegionName.defaultName()))
.build();
createModel(root, state, null, clusterElem);
ApplicationContainerCluster container = getContainerCluster("container");
assertComponentConfigured(container, "com.yahoo.jdisc.cloud.aws.AwsParameterStore");
CloudSecretStore secretStore = (CloudSecretStore) container.getComponentsMap().get(ComponentId.fromString("com.yahoo.jdisc.cloud.aws.AwsParameterStore"));
SecretStoreConfig.Builder configBuilder = new SecretStoreConfig.Builder();
secretStore.getConfig(configBuilder);
SecretStoreConfig secretStoreConfig = configBuilder.build();
assertEquals(1, secretStoreConfig.awsParameterStores().size());
assertEquals("store1", secretStoreConfig.awsParameterStores().get(0).name());
}
@Test
void cloud_secret_store_fails_to_set_up_in_non_public_zone() {
try {
Element clusterElem = DomBuilderTest.parse(
"<container version='1.0'>",
" <secret-store type='cloud'>",
" <store id='store'>",
" <aws-parameter-store account='store1' region='eu-north-1'/>",
" </store>",
" </secret-store>",
"</container>");
DeployState state = new DeployState.Builder()
.properties(
new TestProperties()
.setHostedVespa(true)
.setTenantSecretStores(List.of(new TenantSecretStore("store1", "1234", "role", Optional.of("externalid")))))
.zone(new Zone(SystemName.main, Environment.prod, RegionName.defaultName()))
.build();
createModel(root, state, null, clusterElem);
} catch (RuntimeException e) {
assertEquals("Cloud secret store is not supported in non-public system, see the documentation",
e.getMessage());
return;
}
fail();
}
}
|