Commit 06717653 authored by Kostis Trantzas's avatar Kostis Trantzas
Browse files

Merge branch 'osl-secrets' into 'develop'

Implement automatic unsealing with a secrets controller

See merge request !33
parents ac11de9e e74e4078
Loading
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -150,14 +150,23 @@ public abstract class LcmBaseExecutor {
				if (c.getName().equals(charName)) {
					if (c.getValue() != null) {
						if (c.getValue().getValue() != null) {
							// Unseal secrets as needed
							if (c.getValueType().equals(EValueType.SECRET.getValue())) {
								final var secretsClient = this.vars.getServiceOrderManager().getSecretsClient();
								if (secretsClient.isPresent()) {
									c.getValue().setValue(
											secretsClient.get().unseal(c.getValue().getValue(), c.getName()));
								}
							}

							return Optional.of(c);
						}
					}
				}
			}
		}
		Characteristic z = null;
		return Optional.ofNullable(z);

		return Optional.empty();
	}

	public void setCharValFromStringType(String charName, String newValue) {
+63 −0
Original line number Diff line number Diff line
package org.etsi.osl.osom.lcm;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.camel.ProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


@Service
@ConditionalOnExpression("${SECRETS_CONTROLLER_ENABLE:false}")
public class SecretsClient {

	private static final transient Log logger = LogFactory.getLog( SecretsClient.class.getName() );

	private final ProducerTemplate producerTemplate;

	private final String unsealSecretQueue;

	private final ObjectMapper mapper = new ObjectMapper();

	@Autowired
	public SecretsClient(
		ProducerTemplate producerTemplate,
		@Value("${SECRETS_CHARACTERISTIC_UNSEAL}") String unsealSecretQueue
	) {
		this.producerTemplate = producerTemplate;
		this.unsealSecretQueue = unsealSecretQueue;
	}

	public String unseal(String uri, String characteristic) {
		try {
			final var cmd = new UnsealCharacteristicCommand(uri, characteristic);
			final var payload = this.mapper.writeValueAsString(cmd);
			final var responseRaw = this.producerTemplate.requestBody(this.unsealSecretQueue, payload, String.class);
			
			if (responseRaw == null || responseRaw.isEmpty()) {
				return uri;
			}
			
			final var response = this.mapper.readValue(responseRaw, String.class);

			if (response == null || response.isEmpty()) {
				return uri;
			}

			return response;
		} catch (JsonProcessingException e) {
			throw new RuntimeException(e);
		} catch (Exception e) {
			// controller is enabled by the request failed (no route, timeout, broker down)
			logger.warn("Secrets controller did not respond for " + uri, e);
			return uri;
		}
	}

	private record UnsealCharacteristicCommand(String secretURI, String characteristic) {
	}
}
+9 −11
Original line number Diff line number Diff line
@@ -20,11 +20,7 @@
package org.etsi.osl.osom.management;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -35,6 +31,7 @@ import org.etsi.osl.model.nfv.DeploymentDescriptor;
import org.etsi.osl.model.nfv.NetworkServiceDescriptor;
import org.etsi.osl.model.nfv.ScaleDescriptor;
import org.etsi.osl.osom.lcm.ChatClient;
import org.etsi.osl.osom.lcm.SecretsClient;
import org.etsi.osl.osom.serviceactions.NSActionRequestPayload;
import org.etsi.osl.tmf.pm628.model.MeasurementCollectionJob;
import org.etsi.osl.tmf.pm628.model.MeasurementCollectionJobFVO;
@@ -208,6 +205,8 @@ public class ServiceOrderManager {
    @Autowired
	private ChatClient chatClient;

	@Autowired
	private Optional<SecretsClient> secretsClient;

	@Transactional
	public void processOrder(ServiceOrder serviceOrder) {
@@ -1213,8 +1212,7 @@ public class ServiceOrderManager {
    return chatClient;
  }

  



  public Optional<SecretsClient> getSecretsClient() {
      return this.secretsClient;
  }
}
+5 −1
Original line number Diff line number Diff line
@@ -129,3 +129,7 @@ CRD_PATCH_CR_REQ: "jms:queue:CRD.PATCH.CR_REQ"
#TMF628 ACTIONS
PM_MEASUREMENT_COLLECTION_JOB_ADD:         "jms:queue:PM.MEASUREMENTCOLLECTIONJOB.ADD"
PM_MEASUREMENT_COLLECTION_JOB_UPDATE:      "jms:queue:PM.MEASUREMENTCOLLECTIONJOB.UPDATE"

# Secrets controller ACTIONS
SECRETS_CONTROLLER_ENABLE: false
SECRETS_CHARACTERISTIC_UNSEAL: "jms:queue:SECRETS.CHARACTERISTIC.UNSEAL?exchangePattern=InOut"