blob: 2deaf81d338d6d24a7068934f9130051129b1847 (
plain) (
blame)
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
|
// Copyright Yahoo. 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.ComponentSpecification;
import com.yahoo.component.chain.dependencies.Dependencies;
import com.yahoo.component.chain.model.ChainedComponentModel;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.provision.DataplaneToken;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.jdisc.http.filter.security.cloud.config.CloudDataPlaneFilterConfig;
import com.yahoo.security.X509CertificateUtils;
import com.yahoo.vespa.model.container.ApplicationContainerCluster;
import com.yahoo.vespa.model.container.http.Client;
import com.yahoo.vespa.model.container.http.Filter;
import java.util.Collection;
import java.util.List;
class CloudDataPlaneFilter extends Filter implements CloudDataPlaneFilterConfig.Producer {
private static final String CLASS = "com.yahoo.jdisc.http.filter.security.cloud.CloudDataPlaneFilter";
private static final String BUNDLE = "jdisc-security-filters";
private final Collection<Client> clients;
private final boolean clientsLegacyMode;
private final String tokenContext;
CloudDataPlaneFilter(ApplicationContainerCluster cluster, DeployState state) {
super(model());
this.clients = List.copyOf(cluster.getClients());
this.clientsLegacyMode = cluster.clientsLegacyMode();
// Token domain must be identical to the domain used for generating the tokens
this.tokenContext = "Vespa Cloud tenant data plane:%s"
.formatted(state.getProperties().applicationId().tenant().value());
}
private static ChainedComponentModel model() {
return new ChainedComponentModel(
new BundleInstantiationSpecification(
new ComponentSpecification(CLASS), null, new ComponentSpecification(BUNDLE)),
Dependencies.emptyDependencies());
}
@Override
public void getConfig(CloudDataPlaneFilterConfig.Builder builder) {
if (clientsLegacyMode) {
builder.legacyMode(true);
} else {
var clientsCfg = clients.stream()
.map(x -> new CloudDataPlaneFilterConfig.Clients.Builder()
.id(x.id())
.certificates(x.certificates().stream().map(X509CertificateUtils::toPem).toList())
.tokens(tokensConfig(x.tokens()))
.permissions(x.permissions()))
.toList();
builder.clients(clientsCfg).legacyMode(false).tokenContext(tokenContext);
}
}
private static List<CloudDataPlaneFilterConfig.Clients.Tokens.Builder> tokensConfig(Collection<DataplaneToken> tokens) {
return tokens.stream()
.map(token -> new CloudDataPlaneFilterConfig.Clients.Tokens.Builder()
.id(token.tokenId())
.fingerprints(token.versions().stream().map(DataplaneToken.Version::fingerprint).toList())
.checkAccessHashes(token.versions().stream().map(DataplaneToken.Version::checkAccessHash).toList()))
.toList();
}
}
|