use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class ZKPermHandler method initUser.
@Override
public void initUser(String user) throws AccumuloSecurityException {
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
try {
zoo.putPersistentData(ZKUserPath + "/" + user, new byte[0], NodeExistsPolicy.SKIP);
zoo.putPersistentData(ZKUserPath + "/" + user + ZKUserTablePerms, new byte[0], NodeExistsPolicy.SKIP);
zoo.putPersistentData(ZKUserPath + "/" + user + ZKUserNamespacePerms, new byte[0], NodeExistsPolicy.SKIP);
} catch (KeeperException e) {
log.error("{}", e.getMessage(), e);
throw new AccumuloSecurityException(user, SecurityErrorCode.CONNECTION_ERROR, e);
} catch (InterruptedException e) {
log.error("{}", e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class ChangeSecret method rewriteZooKeeperInstance.
private static void rewriteZooKeeperInstance(final Instance inst, final String newInstanceId, String oldPass, String newPass) throws Exception {
final ZooReaderWriter orig = new ZooReaderWriter(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), oldPass);
final IZooReaderWriter new_ = new ZooReaderWriter(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), newPass);
String root = ZooUtil.getRoot(inst);
recurse(orig, root, new Visitor() {
@Override
public void visit(ZooReader zoo, String path) throws Exception {
String newPath = path.replace(inst.getInstanceID(), newInstanceId);
byte[] data = zoo.getData(path, null);
List<ACL> acls = orig.getZooKeeper().getACL(path, new Stat());
if (acls.containsAll(Ids.READ_ACL_UNSAFE)) {
new_.putPersistentData(newPath, data, NodeExistsPolicy.FAIL);
} else {
// upgrade
if (acls.containsAll(Ids.OPEN_ACL_UNSAFE)) {
// make user nodes private, they contain the user's password
String[] parts = path.split("/");
if (parts[parts.length - 2].equals("users")) {
new_.putPrivatePersistentData(newPath, data, NodeExistsPolicy.FAIL);
} else {
// everything else can have the readable acl
new_.putPersistentData(newPath, data, NodeExistsPolicy.FAIL);
}
} else {
new_.putPrivatePersistentData(newPath, data, NodeExistsPolicy.FAIL);
}
}
}
});
String path = "/accumulo/instances/" + inst.getInstanceName();
orig.recursiveDelete(path, NodeMissingPolicy.SKIP);
new_.putPersistentData(path, newInstanceId.getBytes(UTF_8), NodeExistsPolicy.OVERWRITE);
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class ChangeSecret method deleteInstance.
private static void deleteInstance(Instance origInstance, String oldPass) throws Exception {
IZooReaderWriter orig = new ZooReaderWriter(origInstance.getZooKeepers(), origInstance.getZooKeepersSessionTimeOut(), oldPass);
orig.recursiveDelete("/accumulo/" + origInstance.getInstanceID(), NodeMissingPolicy.SKIP);
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class KerberosAuthenticator method initializeSecurity.
@Override
public void initializeSecurity(TCredentials credentials, String principal, byte[] token) throws AccumuloSecurityException, ThriftSecurityException {
try {
// remove old settings from zookeeper first, if any
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
synchronized (zooCache) {
zooCache.clear();
if (zoo.exists(zkUserPath)) {
zoo.recursiveDelete(zkUserPath, NodeMissingPolicy.SKIP);
log.info("Removed {}/ from zookeeper", zkUserPath);
}
// prep parent node of users with root username
// ACCUMULO-4140 The root user needs to be stored un-base64 encoded in the znode's value
byte[] principalData = principal.getBytes(UTF_8);
zoo.putPersistentData(zkUserPath, principalData, NodeExistsPolicy.FAIL);
// Create the root user in ZK using base64 encoded name (since the name is included in the znode)
createUserNodeInZk(Base64.getEncoder().encodeToString(principalData));
}
} catch (KeeperException | InterruptedException e) {
log.error("Failed to initialize security", e);
throw new RuntimeException(e);
}
}
use of org.apache.accumulo.fate.zookeeper.IZooReaderWriter in project accumulo by apache.
the class TabletServerLocks method main.
public static void main(String[] args) throws Exception {
Instance instance = HdfsZooInstance.getInstance();
String tserverPath = ZooUtil.getRoot(instance) + Constants.ZTSERVERS;
Opts opts = new Opts();
opts.parseArgs(TabletServerLocks.class.getName(), args);
ZooCache cache = new ZooCache(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
if (opts.list) {
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
List<String> tabletServers = zoo.getChildren(tserverPath);
for (String tabletServer : tabletServers) {
byte[] lockData = ZooLock.getLockData(cache, tserverPath + "/" + tabletServer, null);
String holder = null;
if (lockData != null) {
holder = new String(lockData, UTF_8);
}
System.out.printf("%32s %16s%n", tabletServer, holder);
}
} else if (opts.delete != null) {
ZooLock.deleteLock(tserverPath + "/" + args[1]);
} else {
System.out.println("Usage : " + TabletServerLocks.class.getName() + " -list|-delete <tserver lock>");
}
}
Aggregations