Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions conf/openmetadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,9 @@ pipelineServiceClientConfiguration:
runAsGroup: ${K8S_RUN_AS_GROUP:-1000}
fsGroup: ${K8S_FS_GROUP:-1000}
runAsNonRoot: ${K8S_RUN_AS_NON_ROOT:-"true"}
# Set K8S_SECCOMP to '{"type":"RuntimeDefault"}' for restricted PodSecurity,
# or '{"type":"Localhost","localhostProfile":"profiles/ingestion.json"}' for a local profile.
seccomp: ${K8S_SECCOMP:-null}
extraEnvVars: ${K8S_EXTRA_ENV_VARS:-[]}
podAnnotations: ${K8S_POD_ANNOTATIONS:-""}
podLabels: ${K8S_POD_LABELS:-""}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,7 @@ private V1PodSecurityContext buildPodSecurityContext() {
if (k8sConfig.getFsGroup() != null) {
context.setFsGroup(k8sConfig.getFsGroup());
}
context.setSeccompProfile(k8sConfig.getSeccomp());
return context;
}

Expand All @@ -1689,6 +1690,7 @@ private V1SecurityContext buildContainerSecurityContext() {
.runAsNonRoot(k8sConfig.isRunAsNonRoot())
.runAsUser(k8sConfig.getRunAsUser())
.allowPrivilegeEscalation(false)
.seccompProfile(k8sConfig.getSeccomp())
.readOnlyRootFilesystem(false) // Ingestion may need to write temp files
.capabilities(new V1Capabilities().drop(List.of("ALL")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.kubernetes.client.custom.Quantity;
import io.kubernetes.client.openapi.models.V1LocalObjectReference;
import io.kubernetes.client.openapi.models.V1SeccompProfile;
import io.kubernetes.client.openapi.models.V1Toleration;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -29,6 +30,7 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.openmetadata.schema.utils.JsonUtils;
import org.openmetadata.sdk.exception.PipelineServiceClientException;

@Slf4j
Expand All @@ -52,6 +54,7 @@ public class K8sPipelineClientConfig {
private static final String RUN_AS_GROUP_KEY = "runAsGroup";
private static final String FS_GROUP_KEY = "fsGroup";
private static final String RUN_AS_NON_ROOT_KEY = "runAsNonRoot";
private static final String SECCOMP_KEY = "seccomp";
private static final String EXTRA_ENV_VARS_KEY = "extraEnvVars";
private static final String POD_ANNOTATIONS_KEY = "podAnnotations";
private static final String POD_LABELS_KEY = "podLabels";
Expand Down Expand Up @@ -84,6 +87,7 @@ public class K8sPipelineClientConfig {
private final Long runAsGroup;
private final Long fsGroup;
private final boolean runAsNonRoot;
private final V1SeccompProfile seccomp;

// Extra configuration
private final Map<String, String> extraEnvVars;
Expand Down Expand Up @@ -124,6 +128,7 @@ public K8sPipelineClientConfig(Map<String, Object> params) {
this.runAsGroup = getLongParam(params, RUN_AS_GROUP_KEY, 1000L);
this.fsGroup = getLongParam(params, FS_GROUP_KEY, 1000L);
this.runAsNonRoot = Boolean.parseBoolean(getStringParam(params, RUN_AS_NON_ROOT_KEY, "true"));
this.seccomp = JsonUtils.convertValue(params.get(SECCOMP_KEY), V1SeccompProfile.class);

// Extra configuration - parse as list like Argo does
List<String> rawExtraEnvs = parseListSafely(params.get(EXTRA_ENV_VARS_KEY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.dropwizard.configuration.SubstitutingSourceProvider;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.apis.BatchV1Api;
Expand All @@ -51,12 +53,18 @@
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.openapi.models.V1PodList;
import io.kubernetes.client.openapi.models.V1PodSpec;
import io.kubernetes.client.openapi.models.V1SeccompProfile;
import io.kubernetes.client.openapi.models.V1Secret;
import io.kubernetes.client.openapi.models.V1Status;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Map;
Expand All @@ -70,9 +78,12 @@
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringSubstitutor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockedStatic;
Expand Down Expand Up @@ -674,9 +685,11 @@ void testSecurityContextIsSetOnJob() throws Exception {
assertEquals(1000L, podSpec.getSecurityContext().getRunAsUser());
assertEquals(1000L, podSpec.getSecurityContext().getRunAsGroup());
assertEquals(1000L, podSpec.getSecurityContext().getFsGroup());
assertNull(podSpec.getSecurityContext().getSeccompProfile());

// Verify container security context
assertNotNull(podSpec.getContainers().get(0).getSecurityContext());
assertNull(podSpec.getContainers().get(0).getSecurityContext().getSeccompProfile());
assertTrue(podSpec.getContainers().get(0).getSecurityContext().getRunAsNonRoot());
assertFalse(podSpec.getContainers().get(0).getSecurityContext().getAllowPrivilegeEscalation());
assertNotNull(podSpec.getContainers().get(0).getSecurityContext().getCapabilities());
Expand All @@ -690,6 +703,69 @@ void testSecurityContextIsSetOnJob() throws Exception {
.contains("ALL"));
}

@ParameterizedTest
@CsvSource(
value = {
"||",
"''||",
"null||",
"{\"type\":\"RuntimeDefault\"}|RuntimeDefault|",
"{\"type\":\"Unconfined\"}|Unconfined|",
"{\"type\":\"Localhost\",\"localhostProfile\":\"profiles/ingestion.json\"}|Localhost|profiles/ingestion.json"
},
delimiter = '|')
void testSeccompConfigurationFromYamlIsSetOnJob(
String seccompEnv, String type, String localhostProfile) throws Exception {
String seccompConfiguration =
Files.readAllLines(Path.of("..", "conf", "openmetadata.yaml")).stream()
.map(String::strip)
.filter(line -> line.startsWith("seccomp:"))
.findFirst()
.orElseThrow();
String yaml =
"""
enabled: true
metadataApiEndpoint: http://localhost:8585/api
parameters:
namespace: openmetadata-pipelines
skipInit: true
%s
"""
.formatted(seccompConfiguration);
StringSubstitutor substitutor =
new StringSubstitutor(seccompEnv == null ? Map.of() : Map.of("K8S_SECCOMP", seccompEnv));
substitutor.setEnableSubstitutionInVariables(true);
SubstitutingSourceProvider sourceProvider =
new SubstitutingSourceProvider(
ignored -> new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)),
substitutor);
PipelineServiceClientConfiguration config;
try (InputStream input = sourceProvider.open("seccomp-config")) {
config =
new ObjectMapper(new YAMLFactory())
.readValue(input, PipelineServiceClientConfiguration.class);
}
client = new K8sPipelineClient(config);
client.setBatchApi(batchApi);
when(batchApi.createNamespacedJob(eq(NAMESPACE), any())).thenReturn(createJobRequest);
when(createJobRequest.execute()).thenReturn(new V1Job());

client.runPipeline(createTestPipeline("test-pipeline", null), testService);

ArgumentCaptor<V1Job> jobCaptor = ArgumentCaptor.forClass(V1Job.class);
verify(batchApi).createNamespacedJob(eq(NAMESPACE), jobCaptor.capture());
V1PodSpec podSpec = jobCaptor.getValue().getSpec().getTemplate().getSpec();
V1SeccompProfile expected =
type == null ? null : new V1SeccompProfile().type(type).localhostProfile(localhostProfile);
assertEquals(expected, podSpec.getSecurityContext().getSeccompProfile());
assertEquals(expected, podSpec.getContainers().get(0).getSecurityContext().getSeccompProfile());

CronOMJob cronOMJob = client.buildCronOMJob(createTestPipeline("test-pipeline", "0 * * * *"));
OMJob.OMJobSpec omJobSpec = cronOMJob.getSpec().getOmJobSpec();
assertEquals(expected, omJobSpec.getMainPodSpec().getSecurityContext().getSeccompProfile());
assertEquals(expected, omJobSpec.getExitHandlerSpec().getSecurityContext().getSeccompProfile());
}

@Test
void testRetryOnTransientFailure() throws Exception {
// Tests P0: Retry logic with exponential backoff for K8s API calls
Expand Down
Loading