Repository navigation
feat: run python transformation tests on ephemeral per-request pyt deployments - #7177
Conversation
🔒 Scanned for secrets using gitleaks 8.28.0
…forwards 🔒 Scanned for secrets using gitleaks 8.28.0
…forwards 🔒 Scanned for secrets using gitleaks 8.28.0
…ring 🔒 Scanned for secrets using gitleaks 8.28.0
…ved error handling 🔒 Scanned for secrets using gitleaks 8.28.0
…ordingly 🔒 Scanned for secrets using gitleaks 8.28.0
…e resources 🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #7177 +/- ##
==========================================
+ Coverage 79.62% 79.70% +0.07%
==========================================
Files 595 595
Lines 66154 66353 +199
==========================================
+ Hits 52677 52886 +209
+ Misses 10359 10335 -24
- Partials 3118 3132 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| // each retry re-resolves DNS, and the pod's replacement (the forward path | ||
| // scales the deployment up before dialing) answers a later attempt. | ||
| var opErr *net.OpError | ||
| if errors.As(err, &opErr) && opErr.Op == "dial" && opErr.Timeout() { |
There was a problem hiding this comment.
Syntax update in Go 1.26: replace 'errors.As' with the type-safe 'errors.AsType'
| return err | ||
| } | ||
| if isColdStartError(nil, resp) { | ||
| httputil.CloseResponse(resp) |
There was a problem hiding this comment.
Why not just move the defer before if isColdStartError(nil, resp)?
| return backoff.Permanent(err) | ||
| // Connection broke mid-response — as transient as a failed | ||
| // request; retry. | ||
| return err |
There was a problem hiding this comment.
I'm a bit confused here. This used to be a permanent error (i.e. not retryable). Now we're saying it's "as transient as a failed request" and retry indefinitely but we don't have visibility on this, right? No metrics, no logs. We can only wait until max tries is reached and it then propagates.
Are we sure this isn't a regression? Is it really as the comment says "Connection broke mid-response"? Can it be something else as well?
There was a problem hiding this comment.
Yeah, there can be multiple network errors, so just like processor transform flow, I am retrying for every error. will add some observability here.
| func loadConfig(conf *config.Config) deployerConfig { | ||
| return deployerConfig{ | ||
| namespace: conf.GetStringVar("test-pytransformer", "Processor.pytDeployer.pytTestNamespace"), | ||
| image: conf.GetStringVar("", "Processor.pytDeployer.pytTestImage"), |
There was a problem hiding this comment.
What happens if this one stays empty? Is there any validation done?
There was a problem hiding this comment.
there is no validation will add
| return deployerConfig{ | ||
| namespace: conf.GetStringVar("test-pytransformer", "Processor.pytDeployer.pytTestNamespace"), | ||
| image: conf.GetStringVar("", "Processor.pytDeployer.pytTestImage"), | ||
| imagePullSecret: conf.GetStringVar("regcred", "Processor.pytDeployer.pytTestImagePullSecret"), |
There was a problem hiding this comment.
Shouldn't we remove this default as it could be considered a leak and we panic if empty (or error)?
| InitialDelaySeconds: 5, PeriodSeconds: 10, TimeoutSeconds: 5, FailureThreshold: 3, | ||
| }, | ||
| Resources: corev1.ResourceRequirements{ | ||
| Requests: corev1.ResourceList{ |
There was a problem hiding this comment.
Given that it's untrusted code plus it's also testing code (not production grade) I think it would make sense to add a limit as well.
…oyer 🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
fracasula
left a comment
There was a problem hiding this comment.
LGTM, I left a bunch of comments for you to review.
In addition to them I was thinking that we have no "rate limit" whatsoever, so a burst of test requests can provision unbounded Kata microVM pods. It's good that we'll have a reaper handling cleanups, but what about admissions? cc @ktgowtham
We could have a simple semaphore in the deployer and optionally a ResourceQuota so that a bug/misconfiguration can't exhaust the Kata nodepool.
| // workspaceID has already passed validWorkspaceID in Forward, so it is safe | ||
| // to interpolate into the key. | ||
| func (s *Service) isProdRouted(workspaceID string) bool { | ||
| return s.conf.GetReloadableBoolVar(false, |
There was a problem hiding this comment.
Given that this is called every time and that nothing would clean up the registered variables (and we could register any number given that we're interpolating the workspaceID), why not register it only once by using GetReloadableStringMapVar? I know it's an edge case, and that it's very unlikely that we would register that many, but it seems like an easy change to avoid a potential leak.
| maxElapsedTime: conf.GetDurationVar(30, time.Second, "Processor.UserTransformer.pytScaler.retry.maxElapsedTime"), | ||
| multiplier: conf.GetFloat64Var(1.5, "Processor.UserTransformer.pytScaler.retry.multiplier"), | ||
| randomizationFactor: conf.GetFloat64Var(0.5, "Processor.UserTransformer.pytScaler.retry.randomizationFactor"), | ||
| initialInterval: conf.GetDurationVar(200, time.Millisecond, "Processor.pytDeployer.retry.initialInterval"), |
There was a problem hiding this comment.
I was looking at this file again due to these changes, and I was thinking if perhaps we should extend isTransient a bit further and add k8s.io/apimachinery/pkg/util/net's IsConnectionReset, IsConnectionRefused, IsProbableEOF (and optionally a net.Error.Timeout() check). It shouldn't cause issues and it could improve the detection a bit more. Wdyt?
| podLabels := maps.Clone(labels) | ||
| svcSelector := maps.Clone(labels) | ||
| if d.config.zone != "" { | ||
| podSpec.NodeSelector["topology.kubernetes.io/zone"] = d.config.zone | ||
| podLabels["zone"] = d.config.zone | ||
| svcSelector["zone"] = d.config.zone | ||
| } |
There was a problem hiding this comment.
Shouldn't we add the zone label first and the clone to avoid potential collisions?
if d.config.zone != "" {
podSpec.NodeSelector["topology.kubernetes.io/zone"] = d.config.zone
labels["zone"] = d.config.zone
}
podLabels := maps.Clone(labels)
svcSelector := maps.Clone(labels)If an operator's pytTestLabels includes a key literally named "zone" while AVAILABILITY_ZONE is also set, then we might have a problem.
A test on this would be nice too.
| @@ -28,36 +32,64 @@ type endpointForward func(ctx context.Context, workspaceID string, payload []byt | |||
| var validWorkspaceID = regexp.MustCompile(`^[a-zA-Z0-9-]{1,59}$`) | |||
There was a problem hiding this comment.
This regex allows leading/trailing hyphens as well (like -abc or abc-) while k8s label values must begin and end as alphanumeric or we could get a non-transient Create failure. Given that we're already validating it, we might as well make sure this is more precise.
| Containers: []corev1.Container{{ | ||
| Name: "pytransformer", | ||
| Image: d.config.image, | ||
| SecurityContext: &corev1.SecurityContext{ |
There was a problem hiding this comment.
I got a comment from a security agent here but haven't verified. Can you please look into it?
#### 5. Untrusted-code container lacks `Capabilities.Drop: ["ALL"]` and a `SeccompProfile` (security)
**Why:** The `SecurityContext` sets `RunAsNonRoot`, `RunAsUser/Group`, `ReadOnlyRootFilesystem`, `AllowPrivilegeEscalation: false` — but still omits a capability drop and seccomp profile, so it doesn't meet the PSS "restricted" baseline standard for untrusted workloads (this update added resource Limits but not these). Kata (`kata-fc`) is the primary boundary, so it's defense-in-depth, but a cheap, direct fit for the stated goal.
**Fix:** Add `Capabilities: {Drop: ["ALL"]}` and `SeccompProfile: {Type: RuntimeDefault}`.There was a problem hiding this comment.
If I understood correctly these makes sense:
Capabilities Drop: ["ALL"] — Even non-root containers get a default set of Linux privileges (raw network access, changing file ownership, switching users, etc.). Dropping all of them means the customer's
Python code has zero privileged operations available — and pytransformer needs none of them anyway (unprivileged port, fixed user, own temp dir).
Seccomp RuntimeDefault — Filters which kernel syscalls the container can make, blocking the ~40-50 obscure ones that most kernel exploits enter through. Kubernetes leaves this off by default, so setting
it explicitly guarantees the filter regardless of cluster config.
Why together — Kata's microVM is the primary sandbox; these two are defense-in-depth inside it, and they complete the PSS "restricted" profile (the strictest k8s standard) at zero cost to the app.
| corev1.ResourceMemory: d.config.memoryRequest, | ||
| }, | ||
| Limits: corev1.ResourceList{ | ||
| corev1.ResourceCPU: d.config.cpuLimit, |
There was a problem hiding this comment.
We could add an easy check and make sure that limits >= requests
|
|
||
| ticker := time.NewTicker(readinessPollInterval) | ||
| defer ticker.Stop() | ||
| var lastErr error |
There was a problem hiding this comment.
I see we never reset lastErr. Can this be a problem after a successful-but-not-ready Get? 🤔
This is a good point; I will pick this as a follow-up task, as this is not a blocker for the release. |
…aces 🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
… selectors 🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
…its at startup 🔒 Scanned for secrets using gitleaks 8.28.0
🤖 I have created a release *beep* *boop* --- ## [1.81.0-rc.1](v1.80.0...v1.81.0-rc.1) (2026-07-20) ### Features * run python transformation tests on ephemeral per-request pyt deployments ([#7177](#7177)) ([1008ae7](1008ae7)) * support partition migration job fanout per jobsdb ([#7141](#7141)) ([be42e48](be42e48)) ### Bug Fixes * abort snowpipe events on channel bad request ([#7118](#7118)) ([6c08584](6c08584)) * avoid redundant transformer statTags unmarshalling ([#7182](#7182)) ([c3c283c](c3c283c)) * classify reverse-ETL sources from config for MAR metering ([#7159](#7159)) ([fa7870f](fa7870f)) * detect server-side snowpipe channel failures via per-channel status at stuck threshold ([#7166](#7166)) ([581410c](581410c)) * kafkamanager compilation error ([#7189](#7189)) ([1fb7f6e](1fb7f6e)) * **kafka:** support insecure TLS skip verify config ([#7022](#7022)) ([d01574f](d01574f)) * preserve order when overflowing snowpipe insert batches ([#7178](#7178)) ([9c01fa0](9c01fa0)) * quote postgres warehouse ddl identifiers ([#7127](#7127)) ([5aeb481](5aeb481)) * **router:** emit invalid payload metric ([#7168](#7168)) ([6e2009a](6e2009a)) * update null to #N/A for salesforce bulk upload ([#7151](#7151)) ([1dffd93](1dffd93)) * **warehouse:** use pod identity for rudder-storage flow; keep S3-copy user fallback for user S3 destinations ([#7167](#7167)) ([3f9aa32](3f9aa32)) ### Miscellaneous * add contract tests for test endpoints in pytransformer ([#7147](#7147)) ([3b210ec](3b210ec)) * bump compose-test to v0.1.5 to remediate pgx CVE-2026-33815 ([#7162](#7162)) ([7672f96](7672f96)) * **deps:** bump actions/checkout from 6.0.3 to 7.0.0 ([#7132](#7132)) ([d453c93](d453c93)) * **deps:** bump actions/setup-go from 6.4.0 to 6.5.0 ([#7150](#7150)) ([75d9648](75d9648)) * **deps:** bump aws-actions/amazon-ecr-login from 2.1.5 to 2.1.6 ([#7109](#7109)) ([7b2a859](7b2a859)) * **deps:** bump aws-actions/configure-aws-credentials from 6.2.0 to 6.2.2 ([#7152](#7152)) ([c984268](c984268)) * **deps:** bump golangci/golangci-lint-action from 9.2.1 to 9.3.0 ([#7170](#7170)) ([4565d25](4565d25)) * **deps:** bump the frequent group across 1 directory with 4 updates ([#6891](#6891)) ([88a0ddf](88a0ddf)) * support compression in bqstream destinations ([#7142](#7142)) ([0694f12](0694f12)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
We should introduce rate limit on control plane side. cc: @mihir20 |
🤖 I have created a release *beep* *boop* --- ## [1.81.0](v1.80.0...v1.81.0) (2026-07-20) ### Features * run python transformation tests on ephemeral per-request pyt deployments ([#7177](#7177)) ([1008ae7](1008ae7)) * support partition migration job fanout per jobsdb ([#7141](#7141)) ([be42e48](be42e48)) ### Bug Fixes * abort snowpipe events on channel bad request ([#7118](#7118)) ([6c08584](6c08584)) * avoid redundant transformer statTags unmarshalling ([#7182](#7182)) ([c3c283c](c3c283c)) * classify reverse-ETL sources from config for MAR metering ([#7159](#7159)) ([fa7870f](fa7870f)) * detect server-side snowpipe channel failures via per-channel status at stuck threshold ([#7166](#7166)) ([581410c](581410c)) * kafkamanager compilation error ([#7189](#7189)) ([1fb7f6e](1fb7f6e)) * **kafka:** support insecure TLS skip verify config ([#7022](#7022)) ([d01574f](d01574f)) * preserve order when overflowing snowpipe insert batches ([#7178](#7178)) ([9c01fa0](9c01fa0)) * quote postgres warehouse ddl identifiers ([#7127](#7127)) ([5aeb481](5aeb481)) * **router:** emit invalid payload metric ([#7168](#7168)) ([6e2009a](6e2009a)) * update null to #N/A for salesforce bulk upload ([#7151](#7151)) ([1dffd93](1dffd93)) * **warehouse:** use pod identity for rudder-storage flow; keep S3-copy user fallback for user S3 destinations ([#7167](#7167)) ([3f9aa32](3f9aa32)) ### Miscellaneous * add contract tests for test endpoints in pytransformer ([#7147](#7147)) ([3b210ec](3b210ec)) * bump compose-test to v0.1.5 to remediate pgx CVE-2026-33815 ([#7162](#7162)) ([7672f96](7672f96)) * **deps:** bump actions/checkout from 6.0.3 to 7.0.0 ([#7132](#7132)) ([d453c93](d453c93)) * **deps:** bump actions/setup-go from 6.4.0 to 6.5.0 ([#7150](#7150)) ([75d9648](75d9648)) * **deps:** bump aws-actions/amazon-ecr-login from 2.1.5 to 2.1.6 ([#7109](#7109)) ([7b2a859](7b2a859)) * **deps:** bump aws-actions/configure-aws-credentials from 6.2.0 to 6.2.2 ([#7152](#7152)) ([c984268](c984268)) * **deps:** bump golangci/golangci-lint-action from 9.2.1 to 9.3.0 ([#7170](#7170)) ([4565d25](4565d25)) * **deps:** bump the frequent group across 1 directory with 4 updates ([#6891](#6891)) ([88a0ddf](88a0ddf)) * support compression in bqstream destinations ([#7142](#7142)) ([0694f12](0694f12)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
Description
Python transformation tests (execution ops) run arbitrary, untrusted customer code. Previously, the processor's
cpservicescaled up the workspace's shared production pyt deployment (pytscaler) andforwarded the test to it — meaning test code ran on the same pods that serve production traffic.
This PR replaces that model with ephemeral, per-request pyt deployments: every execution test request gets its own fresh Deployment + Service, created just for that request and torn down after it —
one test per pod.
Changes
New
processor/internal/pytdeployerpackage (replacespytscaler)Deployer.RunOnEphemeral(ctx, workspaceID, forward)owns the full lifecycle: create Deployment + Service → wait for readiness → forward the request → delete both (best-effort).kata-fc), kata nodepool selector + tolerations, resource requests, image pull secret — all configurablevia
Processor.pytDeployer.*config keys (env, labels, pod annotations, and readiness timeout are hot-reloadable).AVAILABILITY_ZONE(node selector + pod label) and the Service selector is scoped to that zone, so cross-zone traffic is avoided.app.kubernetes.io/managed-by=rudderstack-processor,rudderstack.com/purpose=pyt-test,rudderstack.com/workspace-id) that the reaper CronJob key off.pytscaler): if a real k8s-backed deployer can't be built, execution ops fail withFailedPrecondition— there is no safe fallback target for untrusted code.AST ops are unaffected.
pytscaler).cpservicerouting changestest,testRun) → fresh ephemeral deployment viadeployer.RunOnEphemeral.testLibrary,extractLibs) never execute user code → forwarded straight to a shared static AST deployment (Processor.pytTestStaticASTURL), no k8s API involvement.Processor.pytTestOverrides.<workspaceID>.routeToProduction(hot-reloadable, with a global fallback key) forward to their production pytdeployment instead — for workspaces whose tests need prod-only config (custom DNS, pinned egress IPs, ...) that the generic ephemeral spec can't reproduce. No readiness wait there; the forwarder's
cold-start retries ride out the scale-from-zero window.
Forwardnow logs the end-to-end forward duration per op for performance monitoring.user_transformerforwarder refactorTest,TestRun,TestLibrary,ExtractLibs) now take an explicitbaseURLresolved by the caller instead of deriving the URL from the workspace ID, so the same clientserves ephemeral, prod-routed, and static-AST targets.
ErrPerWorkspacePyTNotEnabledreplaced byErrEmptyForwardBaseURL(mapped toFailedPrecondition, since misconfiguration must not be retried away).PerWorkspacePyTBaseURLextracted as the single place the{workspaceID}template substitution lives.Linear Ticket
PIPE-3172
Security