Search in sources :

Example 1 with VaultConnectionDetails

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails in project halyard by spinnaker.

the class GoogleDistributedService method buildConnectionDetails.

default VaultConnectionDetails buildConnectionDetails(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, String secretName) {
    GoogleVaultServerService vaultService = getVaultServerService();
    VaultServerService.Vault vault = vaultService.connectToPrimaryService(details, runtimeSettings);
    ServiceSettings vaultSettings = runtimeSettings.getServiceSettings(vaultService);
    RunningServiceDetails vaultDetails = vaultService.getRunningServiceDetails(details, runtimeSettings);
    Integer latestVaultVersion = vaultDetails.getLatestEnabledVersion();
    if (latestVaultVersion == null) {
        throw new IllegalStateException("No vault services have been started yet. This is a bug.");
    }
    List<RunningServiceDetails.Instance> instances = vaultDetails.getInstances().get(latestVaultVersion);
    if (instances.isEmpty()) {
        throw new IllegalStateException("Current vault service has no running instances. This is a bug.");
    }
    String instanceId = instances.get(0).getId();
    String address = new URIBuilder().setScheme("http").setHost(instanceId).setPort(vaultSettings.getPort()).toString();
    String token = vaultService.getToken(details.getDeploymentName(), vault);
    return new VaultConnectionDetails().setAddress(address).setSecret(secretName).setToken(token);
}
Also used : VaultConnectionDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails) ManagedInstance(com.google.api.services.compute.model.ManagedInstance) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) VaultServerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.VaultServerService) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 2 with VaultConnectionDetails

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails in project halyard by spinnaker.

the class GoogleDistributedService method getMetadata.

default List<Metadata.Items> getMetadata(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, List<ConfigSource> configSources, Integer version) {
    List<Metadata.Items> metadataItems = new ArrayList<>();
    String deploymentName = details.getDeploymentName();
    Metadata.Items items = new Metadata.Items().setKey("startup-script").setValue(getStartupScript());
    metadataItems.add(items);
    items = new Metadata.Items().setKey("ssh-keys").setValue(GoogleProviderUtils.getSshPublicKey());
    metadataItems.add(items);
    if (!configSources.isEmpty()) {
        DaemonTaskHandler.message("Mounting config in vault server");
        GoogleVaultServerService vaultService = getVaultServerService();
        VaultServerService.Vault vault = vaultService.connectToPrimaryService(details, runtimeSettings);
        String secretName = secretName("config-mounts", version);
        VaultConfigMountSet mountSet = VaultConfigMountSet.fromConfigSources(configSources);
        secretName = vaultService.writeVaultConfigMountSet(deploymentName, vault, secretName, mountSet);
        VaultConnectionDetails connectionDetails = buildConnectionDetails(details, runtimeSettings, secretName);
        DaemonTaskHandler.message("Placing vault connection details into instance metadata");
        items = new Metadata.Items().setKey("vault_address").setValue(connectionDetails.getAddress());
        metadataItems.add(items);
        items = new Metadata.Items().setKey("vault_token").setValue(connectionDetails.getToken());
        metadataItems.add(items);
        items = new Metadata.Items().setKey("vault_secret").setValue(connectionDetails.getSecret());
        metadataItems.add(items);
    }
    GoogleConsulServerService consulServerService = getConsulServerService();
    RunningServiceDetails consulServerDetails = consulServerService.getRunningServiceDetails(details, runtimeSettings);
    Integer latestConsulVersion = consulServerDetails.getLatestEnabledVersion();
    if (latestConsulVersion != null) {
        List<RunningServiceDetails.Instance> instances = consulServerDetails.getInstances().get(latestConsulVersion);
        String instancesValue = String.join(" ", instances.stream().map(RunningServiceDetails.Instance::getId).collect(Collectors.toList()));
        items = new Metadata.Items().setKey(// TODO(lwander) change to consul_members for consistency w/ vault
        "consul-members").setValue(instancesValue);
        DaemonTaskHandler.message("Placing consul connection details into instance metadata");
        metadataItems.add(items);
    }
    return metadataItems;
}
Also used : ManagedInstance(com.google.api.services.compute.model.ManagedInstance) ArrayList(java.util.ArrayList) Metadata(com.google.api.services.compute.model.Metadata) VaultConfigMountSet(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMountSet) VaultConnectionDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) VaultServerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.VaultServerService)

Aggregations

ManagedInstance (com.google.api.services.compute.model.ManagedInstance)2 RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)2 VaultServerService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.VaultServerService)2 VaultConnectionDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails)2 Metadata (com.google.api.services.compute.model.Metadata)1 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)1 VaultConfigMountSet (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMountSet)1 ArrayList (java.util.ArrayList)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1