Procházet zdrojové kódy

refresh ssh keys upon startup

tags/v0.1.6
Jonathan Cobb před 4 roky
rodič
revize
a8e2978a10
5 změnil soubory, kde provedl 26 přidání a 13 odebrání
  1. +1
    -1
      bubble-server/src/main/java/bubble/dao/account/AccountSshKeyDAO.java
  2. +2
    -5
      bubble-server/src/main/java/bubble/dao/device/DeviceDAO.java
  3. +17
    -0
      bubble-server/src/main/java/bubble/model/device/Device.java
  4. +4
    -0
      bubble-server/src/main/java/bubble/service/boot/StandardSelfNodeService.java
  5. +2
    -7
      bubble-server/src/main/java/bubble/service/dbfilter/FilteredEntityIterator.java

+ 1
- 1
bubble-server/src/main/java/bubble/dao/account/AccountSshKeyDAO.java Zobrazit soubor

@@ -72,6 +72,6 @@ public class AccountSshKeyDAO extends AccountOwnedEntityDAO<AccountSshKey> {

// refresh_bubble_ssh_keys_monitor.sh watches this file (in ansible bubble role)
private static final File REFRESH_SSH_KEYS_FILE = new File(HOME_DIR, ".refresh_ssh_keys");
private void refreshInstalledKeys() { touch(REFRESH_SSH_KEYS_FILE); }
public void refreshInstalledKeys() { touch(REFRESH_SSH_KEYS_FILE); }

}

+ 2
- 5
bubble-server/src/main/java/bubble/dao/device/DeviceDAO.java Zobrazit soubor

@@ -11,6 +11,7 @@ import java.util.List;

import static bubble.ApiConstants.HOME_DIR;
import static bubble.model.device.Device.UNINITIALIZED_DEVICE;
import static bubble.model.device.Device.newUninitializedDevice;
import static org.cobbzilla.util.io.FileUtil.abs;
import static org.cobbzilla.util.io.FileUtil.touch;

@@ -77,11 +78,7 @@ public class DeviceDAO extends AccountOwnedEntityDAO<Device> {
Device uninitialized = null;
if (devices.isEmpty()) {
log.info("ensureSpareDevice: no uninitialized devices for account " + account + ", creating one");
uninitialized = create(new Device()
.setName(UNINITIALIZED_DEVICE)
.setNetwork(network)
.setAccount(account)
.initTotpKey());
uninitialized = create(newUninitializedDevice(network, account));
}
if (refreshVpnUsers) refreshVpnUsers();
return uninitialized;


+ 17
- 0
bubble-server/src/main/java/bubble/model/device/Device.java Zobrazit soubor

@@ -16,6 +16,7 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.validation.constraints.Size;

import static java.util.UUID.randomUUID;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import static org.cobbzilla.util.reflect.ReflectionUtil.copy;
import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENCRYPTED_STRING;
@@ -39,6 +40,22 @@ public class Device extends IdentifiableBase implements HasAccount {

public Device (String uuid) { setUuid(uuid); }

public static Device newUninitializedDevice(String networkUuid, String accountUuid) {
return new Device()
.setName(UNINITIALIZED_DEVICE)
.setNetwork(networkUuid)
.setAccount(accountUuid)
.initTotpKey();
}

public static Device firstDeviceForNewNetwork(BubbleNetwork network) {
return new Device(randomUUID().toString())
.setName(UNINITIALIZED_DEVICE)
.setNetwork(network.getUuid())
.setAccount(network.getAccount())
.initTotpKey();
}

@Override public Identifiable update(Identifiable thing) {
copy(this, thing, UPDATE_FIELDS);
return this;


+ 4
- 0
bubble-server/src/main/java/bubble/service/boot/StandardSelfNodeService.java Zobrazit soubor

@@ -2,6 +2,7 @@ package bubble.service.boot;

import bubble.cloud.CloudServiceType;
import bubble.cloud.storage.local.LocalStorageDriver;
import bubble.dao.account.AccountSshKeyDAO;
import bubble.dao.cloud.BubbleNetworkDAO;
import bubble.dao.cloud.BubbleNodeDAO;
import bubble.dao.cloud.BubbleNodeKeyDAO;
@@ -70,6 +71,9 @@ public class StandardSelfNodeService implements SelfNodeService {
log.info("initThisNode: initializing with thisNode="+thisNode.id());
final BubbleConfiguration c = configuration;

// ensure ssh keys are configured
c.getBean(AccountSshKeyDAO.class).refreshInstalledKeys();

final BubbleNode dbThis = nodeDAO.findByUuid(thisNode.getUuid());
if (dbThis == null) return die("initThisNode: self_node not found in database: "+thisNode.getUuid());



+ 2
- 7
bubble-server/src/main/java/bubble/service/dbfilter/FilteredEntityIterator.java Zobrazit soubor

@@ -19,8 +19,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import static bubble.model.device.Device.UNINITIALIZED_DEVICE;
import static java.util.UUID.randomUUID;
import static bubble.model.device.Device.firstDeviceForNewNetwork;
import static org.cobbzilla.util.daemon.ZillaRuntime.die;

@Slf4j
@@ -94,11 +93,7 @@ public class FilteredEntityIterator extends EntityIterator {

// add an initial device so that algo starts properly the first time
// name and totp key will be overwritten when the device is initialized for use
add(new Device(randomUUID().toString())
.setName(UNINITIALIZED_DEVICE)
.setAccount(node.getAccount())
.setNetwork(node.getNetwork())
.initTotpKey());
add(firstDeviceForNewNetwork(network));

// in the new DB, the sage's node key must exist, but not its private key
final BubbleNodeKey sageKey = configuration.getBean(BubbleNodeKeyDAO.class).findFirstByNode(sageNode.getUuid());


Načítá se…
Zrušit
Uložit