@@ -72,6 +72,6 @@ public class AccountSshKeyDAO extends AccountOwnedEntityDAO<AccountSshKey> { | |||||
// refresh_bubble_ssh_keys_monitor.sh watches this file (in ansible bubble role) | // 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 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); } | |||||
} | } |
@@ -11,6 +11,7 @@ import java.util.List; | |||||
import static bubble.ApiConstants.HOME_DIR; | import static bubble.ApiConstants.HOME_DIR; | ||||
import static bubble.model.device.Device.UNINITIALIZED_DEVICE; | 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.abs; | ||||
import static org.cobbzilla.util.io.FileUtil.touch; | import static org.cobbzilla.util.io.FileUtil.touch; | ||||
@@ -77,11 +78,7 @@ public class DeviceDAO extends AccountOwnedEntityDAO<Device> { | |||||
Device uninitialized = null; | Device uninitialized = null; | ||||
if (devices.isEmpty()) { | if (devices.isEmpty()) { | ||||
log.info("ensureSpareDevice: no uninitialized devices for account " + account + ", creating one"); | 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(); | if (refreshVpnUsers) refreshVpnUsers(); | ||||
return uninitialized; | return uninitialized; | ||||
@@ -16,6 +16,7 @@ import javax.persistence.Column; | |||||
import javax.persistence.Entity; | import javax.persistence.Entity; | ||||
import javax.validation.constraints.Size; | import javax.validation.constraints.Size; | ||||
import static java.util.UUID.randomUUID; | |||||
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; | import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; | ||||
import static org.cobbzilla.util.reflect.ReflectionUtil.copy; | import static org.cobbzilla.util.reflect.ReflectionUtil.copy; | ||||
import static org.cobbzilla.wizard.model.crypto.EncryptedTypes.ENCRYPTED_STRING; | 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 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) { | @Override public Identifiable update(Identifiable thing) { | ||||
copy(this, thing, UPDATE_FIELDS); | copy(this, thing, UPDATE_FIELDS); | ||||
return this; | return this; | ||||
@@ -2,6 +2,7 @@ package bubble.service.boot; | |||||
import bubble.cloud.CloudServiceType; | import bubble.cloud.CloudServiceType; | ||||
import bubble.cloud.storage.local.LocalStorageDriver; | import bubble.cloud.storage.local.LocalStorageDriver; | ||||
import bubble.dao.account.AccountSshKeyDAO; | |||||
import bubble.dao.cloud.BubbleNetworkDAO; | import bubble.dao.cloud.BubbleNetworkDAO; | ||||
import bubble.dao.cloud.BubbleNodeDAO; | import bubble.dao.cloud.BubbleNodeDAO; | ||||
import bubble.dao.cloud.BubbleNodeKeyDAO; | import bubble.dao.cloud.BubbleNodeKeyDAO; | ||||
@@ -70,6 +71,9 @@ public class StandardSelfNodeService implements SelfNodeService { | |||||
log.info("initThisNode: initializing with thisNode="+thisNode.id()); | log.info("initThisNode: initializing with thisNode="+thisNode.id()); | ||||
final BubbleConfiguration c = configuration; | final BubbleConfiguration c = configuration; | ||||
// ensure ssh keys are configured | |||||
c.getBean(AccountSshKeyDAO.class).refreshInstalledKeys(); | |||||
final BubbleNode dbThis = nodeDAO.findByUuid(thisNode.getUuid()); | final BubbleNode dbThis = nodeDAO.findByUuid(thisNode.getUuid()); | ||||
if (dbThis == null) return die("initThisNode: self_node not found in database: "+thisNode.getUuid()); | if (dbThis == null) return die("initThisNode: self_node not found in database: "+thisNode.getUuid()); | ||||
@@ -19,8 +19,7 @@ import java.util.ArrayList; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.concurrent.atomic.AtomicReference; | 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; | import static org.cobbzilla.util.daemon.ZillaRuntime.die; | ||||
@Slf4j | @Slf4j | ||||
@@ -94,11 +93,7 @@ public class FilteredEntityIterator extends EntityIterator { | |||||
// add an initial device so that algo starts properly the first time | // 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 | // 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 | // 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()); | final BubbleNodeKey sageKey = configuration.getBean(BubbleNodeKeyDAO.class).findFirstByNode(sageNode.getUuid()); | ||||