Review Board 1.7.22


ACCUMULO-1009 - add use of SSL for thrift comms

Review Request #14972 - Created Oct. 26, 2013 and discarded

John Vines
master
ACCUMULO-1009
Reviewers
accumulo
mberman
accumulo
Michael Berman's October 13 patch for ACCUMULO-1009

 

Diff revision 1 (Latest)

  1. core/src/main/java/org/apache/accumulo/core/conf/ClientConfiguration.java: Loading...
  2. core/src/main/java/org/apache/accumulo/core/conf/Property.java: Loading...
  3. core/src/main/java/org/apache/accumulo/core/security/Credentials.java: Loading...
  4. core/src/main/java/org/apache/accumulo/core/security/SecurityUtil.java: Loading...
  5. core/src/main/java/org/apache/accumulo/core/security/ssl/SslConnectionParams.java: Loading...
  6. core/src/main/java/org/apache/accumulo/core/util/ThriftUtil.java: Loading...
  7. core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java: Loading...
  8. core/src/main/java/org/apache/accumulo/core/util/shell/ShellOptionsJC.java: Loading...
  9. core/src/test/java/org/apache/accumulo/core/conf/ClientConfigurationTest.java: Loading...
  10. core/src/test/java/org/apache/accumulo/core/util/shell/ShellSetInstanceTest.java: Loading...
  11. minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java: Loading...
  12. minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java: Loading...
  13. minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloInstance.java: Loading...
  14. minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterTest.java: Loading...
  15. server/src/main/java/org/apache/accumulo/server/cli/ClientOnDefaultTable.java: Loading...
  16. server/src/main/java/org/apache/accumulo/server/cli/ClientOnRequiredTable.java: Loading...
  17. server/src/main/java/org/apache/accumulo/server/cli/ClientOpts.java: Loading...
  18. server/src/main/java/org/apache/accumulo/server/client/BulkImporter.java: Loading...
  19. server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java: Loading...
  20. server/src/main/java/org/apache/accumulo/server/util/TServerUtils.java: Loading...
This diff has been split across 3 pages: < 1 2 3 >
core/src/main/java/org/apache/accumulo/core/conf/ClientConfiguration.java
New File

    
   
1
/*

    
   
2
 * Licensed to the Apache Software Foundation (ASF) under one or more

    
   
3
 * contributor license agreements.  See the NOTICE file distributed with

    
   
4
 * this work for additional information regarding copyright ownership.

    
   
5
 * The ASF licenses this file to You under the Apache License, Version 2.0

    
   
6
 * (the "License"); you may not use this file except in compliance with

    
   
7
 * the License.  You may obtain a copy of the License at

    
   
8
 *

    
   
9
 *     http://www.apache.org/licenses/LICENSE-2.0

    
   
10
 *

    
   
11
 * Unless required by applicable law or agreed to in writing, software

    
   
12
 * distributed under the License is distributed on an "AS IS" BASIS,

    
   
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

    
   
14
 * See the License for the specific language governing permissions and

    
   
15
 * limitations under the License.

    
   
16
 */

    
   
17
package org.apache.accumulo.core.conf;

    
   
18

   

    
   
19
import java.io.File;

    
   
20
import java.io.FileNotFoundException;

    
   
21
import java.io.StringReader;

    
   
22
import java.io.StringWriter;

    
   
23
import java.util.Arrays;

    
   
24
import java.util.Collections;

    
   
25
import java.util.HashMap;

    
   
26
import java.util.Iterator;

    
   
27
import java.util.LinkedList;

    
   
28
import java.util.List;

    
   
29
import java.util.Map;

    
   
30
import java.util.Map.Entry;

    
   
31
import java.util.TreeMap;

    
   
32
import java.util.UUID;

    
   
33

   

    
   
34
import org.apache.accumulo.core.util.ArgumentChecker;

    
   
35
import org.apache.commons.configuration.CompositeConfiguration;

    
   
36
import org.apache.commons.configuration.Configuration;

    
   
37
import org.apache.commons.configuration.ConfigurationException;

    
   
38
import org.apache.commons.configuration.MapConfiguration;

    
   
39
import org.apache.commons.configuration.PropertiesConfiguration;

    
   
40

   

    
   
41
public class ClientConfiguration extends CompositeConfiguration {

    
   
42
  public static final String USER_ACCUMULO_DIR_NAME = ".accumulo";

    
   
43
  public static final String USER_CONF_FILENAME = "config";

    
   
44
  public static final String GLOBAL_CONF_FILENAME = "client.conf";

    
   
45

   

    
   
46
  public enum ClientProperty {

    
   
47
    RPC_SSL_TRUSTSTORE_PATH(Property.RPC_SSL_TRUSTSTORE_PATH),

    
   
48
    RPC_SSL_TRUSTSTORE_PASSWORD(Property.RPC_SSL_TRUSTSTORE_PASSWORD),

    
   
49
    RPC_SSL_TRUSTSTORE_TYPE(Property.RPC_SSL_TRUSTSTORE_TYPE),

    
   
50
    RPC_SSL_KEYSTORE_PATH(Property.RPC_SSL_KEYSTORE_PATH),

    
   
51
    RPC_SSL_KEYSTORE_PASSWORD(Property.RPC_SSL_KEYSTORE_PASSWORD),

    
   
52
    RPC_SSL_KEYSTORE_TYPE(Property.RPC_SSL_KEYSTORE_TYPE),

    
   
53
    RPC_USE_JSSE(Property.RPC_USE_JSSE),

    
   
54
    INSTANCE_RPC_SSL_CLIENT_AUTH(Property.INSTANCE_RPC_SSL_CLIENT_AUTH),

    
   
55
    INSTANCE_RPC_SSL_ENABLED(Property.INSTANCE_RPC_SSL_ENABLED),

    
   
56
    INSTANCE_ZK_HOST(Property.INSTANCE_ZK_HOST),

    
   
57
    INSTANCE_ZK_TIMEOUT(Property.INSTANCE_ZK_TIMEOUT),

    
   
58
    INSTANCE_NAME("client.instance.name", null, PropertyType.STRING, "Name of Accumulo instance to connect to"),

    
   
59
    INSTANCE_ID("client.instance.id", null, PropertyType.STRING, "UUID of Accumulo instance to connect to"),

    
   
60
    ;

    
   
61

   

    
   
62
    private String key;

    
   
63
    private String defaultValue;

    
   
64
    private PropertyType type;

    
   
65
    private String description;

    
   
66

   

    
   
67
    private Property accumuloProperty = null;

    
   
68

   

    
   
69
    private ClientProperty(Property prop) {

    
   
70
      this(prop.getKey(), prop.getDefaultValue(), prop.getType(), prop.getDescription());

    
   
71
      accumuloProperty = prop;

    
   
72
    }

    
   
73

   

    
   
74
    private ClientProperty(String key, String defaultValue, PropertyType type, String description) {

    
   
75
      this.key = key;

    
   
76
      this.defaultValue = defaultValue;

    
   
77
      this.type = type;

    
   
78
      this.description = description;

    
   
79
    }

    
   
80

   

    
   
81
    public String getKey() {

    
   
82
      return key;

    
   
83
    }

    
   
84

   

    
   
85
    public String getDefaultValue() {

    
   
86
      return defaultValue;

    
   
87
    }

    
   
88

   

    
   
89
    public PropertyType getType() {

    
   
90
      return type;

    
   
91
    }

    
   
92

   

    
   
93
    public String getDescription() {

    
   
94
      return description;

    
   
95
    }

    
   
96

   

    
   
97
    public Property getAccumuloProperty() {

    
   
98
      return accumuloProperty;

    
   
99
    }

    
   
100

   

    
   
101
    public static ClientProperty getPropertyByKey(String key) {

    
   
102
      for (ClientProperty prop : ClientProperty.values())

    
   
103
        if (prop.getKey().equals(key))

    
   
104
          return prop;

    
   
105
      return null;

    
   
106
    }

    
   
107
  };

    
   
108

   

    
   
109
  public ClientConfiguration(List<? extends Configuration> configs) {

    
   
110
    super(configs);

    
   
111
  }

    
   
112

   

    
   
113
  public ClientConfiguration(Configuration... configs) {

    
   
114
    this(Arrays.asList(configs));

    
   
115
  }

    
   
116

   

    
   
117
  public static ClientConfiguration loadFromFile(String propertiesFilename) throws FileNotFoundException {

    
   
118
    File propertiesFile = new File(propertiesFilename);

    
   
119
    if (!propertiesFile.canRead())

    
   
120
      throw new FileNotFoundException("Unable to load client config from " + propertiesFilename);

    
   
121
    return loadFromSearchPath(Collections.singletonList(propertiesFilename));

    
   
122
  }

    
   
123

   

    
   
124
  public static ClientConfiguration loadDefault() {

    
   
125
    return loadFromSearchPath(getDefaultSearchPath());

    
   
126
  }

    
   
127

   

    
   
128
  public static ClientConfiguration loadDefault(String overridePropertiesFilename) throws FileNotFoundException {

    
   
129
    if (overridePropertiesFilename == null)

    
   
130
      return loadDefault();

    
   
131
    else

    
   
132
      return loadFromFile(overridePropertiesFilename);

    
   
133
  }

    
   
134

   

    
   
135
  private static ClientConfiguration loadFromSearchPath(List<String> paths) {

    
   
136
    try {

    
   
137
      List<Configuration> configs = new LinkedList<Configuration>();

    
   
138
      for (String path : paths) {

    
   
139
        File conf = new File(path);

    
   
140
        if (conf.canRead()) {

    
   
141
          configs.add(new PropertiesConfiguration(conf));

    
   
142
       }

    
   
143
      }

    
   
144
      return new ClientConfiguration(configs);

    
   
145
    } catch (ConfigurationException e) {

    
   
146
      throw new IllegalStateException("Error loading client configuration", e);

    
   
147
    }

    
   
148
  }

    
   
149

   

    
   
150
  public static ClientConfiguration deserialize(String serializedConfig) {

    
   
151
    PropertiesConfiguration propConfig = new PropertiesConfiguration();

    
   
152
    try {

    
   
153
      propConfig.load(new StringReader(serializedConfig));

    
   
154
    } catch (ConfigurationException e) {

    
   
155
      throw new IllegalArgumentException("Error deserializing client configuration: " + serializedConfig, e);

    
   
156
    }

    
   
157
    return new ClientConfiguration(propConfig);

    
   
158
  }

    
   
159

   

    
   
160
  private static List<String> getDefaultSearchPath() {

    
   
161
    String clientConfSearchPath = System.getenv("ACCUMULO_CLIENT_CONF_PATH");

    
   
162
    List<String> clientConfPaths;

    
   
163
    if (clientConfSearchPath != null) {

    
   
164
      clientConfPaths = Arrays.asList(clientConfSearchPath.split(File.pathSeparator));

    
   
165
    } else {

    
   
166
      // if $ACCUMULO_CLIENT_CONF_PATH env isn't set, priority from top to bottom is:

    
   
167
      // ~/.accumulo/config

    
   
168
      // $ACCUMULO_CONF_DIR/client.conf -OR- $ACCUMULO_HOME/conf/client.conf (depending on whether $ACCUMULO_CONF_DIR is set)

    
   
169
      // /etc/accumulo/client.conf

    
   
170
      clientConfPaths = new LinkedList<String>();

    
   
171
      clientConfPaths.add(System.getProperty("user.home") + File.separator + USER_ACCUMULO_DIR_NAME + File.separator + USER_CONF_FILENAME);

    
   
172
      if (System.getenv("ACCUMULO_CONF_DIR") != null) {

    
   
173
        clientConfPaths.add(System.getenv("ACCUMULO_CONF_DIR") + File.separator + GLOBAL_CONF_FILENAME);

    
   
174
      } else if (System.getenv("ACCUMULO_HOME") != null) {

    
   
175
        clientConfPaths.add(System.getenv("ACCUMULO_HOME") + File.separator + "conf" + File.separator + GLOBAL_CONF_FILENAME);

    
   
176
      }

    
   
177
      clientConfPaths.add("/etc/accumulo/" + GLOBAL_CONF_FILENAME);

    
   
178
    }

    
   
179
    return clientConfPaths;

    
   
180
  }

    
   
181

   

    
   
182
  public String serialize() {

    
   
183
    PropertiesConfiguration propConfig = new PropertiesConfiguration();

    
   
184
    propConfig.copy(this);

    
   
185
    StringWriter writer = new StringWriter();

    
   
186
    try {

    
   
187
      propConfig.save(writer);

    
   
188
    } catch (ConfigurationException e) {

    
   
189
      // this should never happen

    
   
190
      throw new IllegalStateException(e);

    
   
191
    }

    
   
192
    return writer.toString();

    
   
193
  }

    
   
194

   

    
   
195
  public String get(ClientProperty prop) {

    
   
196
    if (this.containsKey(prop.getKey()))

    
   
197
      return this.getString(prop.getKey());

    
   
198
    else

    
   
199
      return prop.getDefaultValue();

    
   
200
  }

    
   
201

   

    
   
202
  public void setProperty(ClientProperty prop, String value) {

    
   
203
    this.setProperty(prop.getKey(), value);

    
   
204
  }

    
   
205

   

    
   
206
  public ClientConfiguration with(ClientProperty prop, String value) {

    
   
207
    this.setProperty(prop.getKey(), value);

    
   
208
    return this;

    
   
209
  }

    
   
210

   

    
   
211
  public ClientConfiguration withInstance(String instanceName) {

    
   
212
    ArgumentChecker.notNull(instanceName);

    
   
213
    return with(ClientProperty.INSTANCE_NAME, instanceName);

    
   
214
  }

    
   
215

   

    
   
216
  public ClientConfiguration withInstance(UUID instanceId) {

    
   
217
    ArgumentChecker.notNull(instanceId);

    
   
218
    return with(ClientProperty.INSTANCE_ID, instanceId.toString());

    
   
219
  }

    
   
220

   

    
   
221
  public ClientConfiguration withZkHosts(String zooKeepers) {

    
   
222
    ArgumentChecker.notNull(zooKeepers);

    
   
223
    return with(ClientProperty.INSTANCE_ZK_HOST, zooKeepers);

    
   
224
  }

    
   
225

   

    
   
226
  public ClientConfiguration withZkTimeout(int timeout) {

    
   
227
    return with(ClientProperty.INSTANCE_ZK_TIMEOUT, String.valueOf(timeout));

    
   
228
  }

    
   
229

   

    
   
230
  public ClientConfiguration withSsl(boolean sslEnabled) {

    
   
231
    return withSsl(sslEnabled, false);

    
   
232
  }

    
   
233

   

    
   
234
  public ClientConfiguration withSsl(boolean sslEnabled, boolean useJsseConfig) {

    
   
235
    return with(ClientProperty.INSTANCE_RPC_SSL_ENABLED, String.valueOf(sslEnabled))

    
   
236
        .with(ClientProperty.RPC_USE_JSSE, String.valueOf(useJsseConfig));

    
   
237
  }

    
   
238

   

    
   
239
  public ClientConfiguration withTruststore(String path) {

    
   
240
    return withTruststore(path, null, null);

    
   
241
  }

    
   
242

   

    
   
243
  public ClientConfiguration withTruststore(String path, String password, String type) {

    
   
244
    ArgumentChecker.notNull(path);

    
   
245
    setProperty(ClientProperty.RPC_SSL_TRUSTSTORE_PATH, path);

    
   
246
    if (password != null)

    
   
247
      setProperty(ClientProperty.RPC_SSL_TRUSTSTORE_PASSWORD, password);

    
   
248
    if (type != null)

    
   
249
      setProperty(ClientProperty.RPC_SSL_TRUSTSTORE_TYPE, type);

    
   
250
    return this;

    
   
251
  }

    
   
252

   

    
   
253
  public ClientConfiguration withKeystore(String path) {

    
   
254
    return withKeystore(path, null, null);

    
   
255
  }

    
   
256

   

    
   
257
  public ClientConfiguration withKeystore(String path, String password, String type) {

    
   
258
    ArgumentChecker.notNull(path);

    
   
259
    setProperty(ClientProperty.INSTANCE_RPC_SSL_CLIENT_AUTH, "true");

    
   
260
    setProperty(ClientProperty.RPC_SSL_KEYSTORE_PATH, path);

    
   
261
    if (password != null)

    
   
262
      setProperty(ClientProperty.RPC_SSL_KEYSTORE_PASSWORD, password);

    
   
263
    if (type != null)

    
   
264
      setProperty(ClientProperty.RPC_SSL_KEYSTORE_TYPE, type);

    
   
265
    return this;

    
   
266
  }

    
   
267

   

    
   
268
  public AccumuloConfiguration getAccumuloConfiguration() {

    
   
269
    final AccumuloConfiguration defaultConf = AccumuloConfiguration.getDefaultConfiguration();

    
   
270
    return new AccumuloConfiguration() {

    
   
271

   

    
   
272
      @Override

    
   
273
      public Iterator<Entry<String,String>> iterator() {

    
   
274
        TreeMap<String,String> entries = new TreeMap<String,String>();

    
   
275

   

    
   
276
        for (Entry<String,String> parentEntry : defaultConf)

    
   
277
          entries.put(parentEntry.getKey(), parentEntry.getValue());

    
   
278

   

    
   
279
        @SuppressWarnings("unchecked")

    
   
280
        Iterator<String> keyIter = getKeys();

    
   
281
        while (keyIter.hasNext()) {

    
   
282
          String key = keyIter.next();

    
   
283
          entries.put(key, getString(key));

    
   
284
        }

    
   
285

   

    
   
286
        return entries.entrySet().iterator();

    
   
287
      }

    
   
288

   

    
   
289
      @Override

    
   
290
      public String get(Property property) {

    
   
291
        if (containsKey(property.getKey()))

    
   
292
          return getString(property.getKey());

    
   
293
        else

    
   
294
          return defaultConf.get(property);

    
   
295
      }

    
   
296
    };

    
   
297
  }

    
   
298

   

    
   
299
  public static ClientConfiguration fromAccumuloConfiguration(AccumuloConfiguration accumuloConf) {

    
   
300
    Map<String,String> props = new HashMap<String,String>();

    
   
301
    for (ClientProperty prop : ClientProperty.values()) {

    
   
302
      if (prop.accumuloProperty == null)

    
   
303
        continue;

    
   
304
      props.put(prop.getKey(), accumuloConf.get(prop.accumuloProperty));

    
   
305
    }

    
   
306
    return new ClientConfiguration(new MapConfiguration(props));

    
   
307
  }

    
   
308
}
core/src/main/java/org/apache/accumulo/core/conf/Property.java
Revision b6fbdd2 New Change
 
core/src/main/java/org/apache/accumulo/core/security/Credentials.java
Revision 0552e7e New Change
 
core/src/main/java/org/apache/accumulo/core/security/SecurityUtil.java
Revision 8add1a7 New Change
 
core/src/main/java/org/apache/accumulo/core/security/ssl/SslConnectionParams.java
New File
 
core/src/main/java/org/apache/accumulo/core/util/ThriftUtil.java
Revision e8dd6a2 New Change
 
core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
Revision 4140c8c New Change
 
core/src/main/java/org/apache/accumulo/core/util/shell/ShellOptionsJC.java
Revision cb1f1c8 New Change
 
core/src/test/java/org/apache/accumulo/core/conf/ClientConfigurationTest.java
New File
 
core/src/test/java/org/apache/accumulo/core/util/shell/ShellSetInstanceTest.java
Revision 23ca13a New Change
 
minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
Revision 77776df New Change
 
minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
Revision 0b6c42c New Change
 
minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloInstance.java
Revision 540d7ae New Change
 
minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterTest.java
Revision 3e749ab New Change
 
server/src/main/java/org/apache/accumulo/server/cli/ClientOnDefaultTable.java
Revision 53f5ac2 New Change
 
server/src/main/java/org/apache/accumulo/server/cli/ClientOnRequiredTable.java
Revision e9e9bf1 New Change
 
server/src/main/java/org/apache/accumulo/server/cli/ClientOpts.java
Revision 6f3516a New Change
 
server/src/main/java/org/apache/accumulo/server/client/BulkImporter.java
Revision a04765f New Change
 
server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java
Revision 817aa74 New Change
 
server/src/main/java/org/apache/accumulo/server/util/TServerUtils.java
Revision 1df17fe New Change
 
  1. core/src/main/java/org/apache/accumulo/core/conf/ClientConfiguration.java: Loading...
  2. core/src/main/java/org/apache/accumulo/core/conf/Property.java: Loading...
  3. core/src/main/java/org/apache/accumulo/core/security/Credentials.java: Loading...
  4. core/src/main/java/org/apache/accumulo/core/security/SecurityUtil.java: Loading...
  5. core/src/main/java/org/apache/accumulo/core/security/ssl/SslConnectionParams.java: Loading...
  6. core/src/main/java/org/apache/accumulo/core/util/ThriftUtil.java: Loading...
  7. core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java: Loading...
  8. core/src/main/java/org/apache/accumulo/core/util/shell/ShellOptionsJC.java: Loading...
  9. core/src/test/java/org/apache/accumulo/core/conf/ClientConfigurationTest.java: Loading...
  10. core/src/test/java/org/apache/accumulo/core/util/shell/ShellSetInstanceTest.java: Loading...
  11. minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java: Loading...
  12. minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java: Loading...
  13. minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloInstance.java: Loading...
  14. minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterTest.java: Loading...
  15. server/src/main/java/org/apache/accumulo/server/cli/ClientOnDefaultTable.java: Loading...
  16. server/src/main/java/org/apache/accumulo/server/cli/ClientOnRequiredTable.java: Loading...
  17. server/src/main/java/org/apache/accumulo/server/cli/ClientOpts.java: Loading...
  18. server/src/main/java/org/apache/accumulo/server/client/BulkImporter.java: Loading...
  19. server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java: Loading...
  20. server/src/main/java/org/apache/accumulo/server/util/TServerUtils.java: Loading...
This diff has been split across 3 pages: < 1 2 3 >