lastlight-core 0.21.11 → 0.21.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deploy/k8s/README.md +111 -34
- package/deploy/k8s/architecture.md +199 -0
- package/deploy/k8s/configmap.yaml +14 -3
- package/deploy/k8s/harness-deployment.yaml +111 -0
- package/deploy/k8s/kustomization.yaml +10 -8
- package/deploy/k8s/sandbox-namespace.yaml +14 -0
- package/deploy/k8s/sandbox-quota.yaml +37 -0
- package/deploy/k8s/sandbox-rbac.yaml +60 -0
- package/dist/admin/routes.js +66 -10
- package/dist/admin/routes.js.map +1 -1
- package/dist/config/config.d.ts +36 -0
- package/dist/config/config.js +101 -3
- package/dist/config/config.js.map +1 -1
- package/dist/cron/review-discovery.d.ts +54 -0
- package/dist/cron/review-discovery.js +70 -0
- package/dist/cron/review-discovery.js.map +1 -0
- package/dist/engine/executors/orchestrator.js +124 -58
- package/dist/engine/executors/orchestrator.js.map +1 -1
- package/dist/engine/github/github.d.ts +8 -0
- package/dist/engine/github/github.js +14 -0
- package/dist/engine/github/github.js.map +1 -1
- package/dist/engine/github/profiles.d.ts +12 -1
- package/dist/engine/github/profiles.js +33 -1
- package/dist/engine/github/profiles.js.map +1 -1
- package/dist/index.js +55 -14
- package/dist/index.js.map +1 -1
- package/dist/sandbox/artifact-backend.d.ts +40 -0
- package/dist/sandbox/artifact-backend.js +67 -0
- package/dist/sandbox/artifact-backend.js.map +1 -0
- package/dist/sandbox/artifact-store.d.ts +55 -0
- package/dist/sandbox/artifact-store.js +203 -0
- package/dist/sandbox/artifact-store.js.map +1 -0
- package/dist/sandbox/docker.d.ts +2 -1
- package/dist/sandbox/docker.js +3 -3
- package/dist/sandbox/docker.js.map +1 -1
- package/dist/sandbox/k8s/agent-context-registry.d.ts +25 -0
- package/dist/sandbox/k8s/agent-context-registry.js +45 -0
- package/dist/sandbox/k8s/agent-context-registry.js.map +1 -0
- package/dist/sandbox/k8s/agent-context-route.d.ts +13 -0
- package/dist/sandbox/k8s/agent-context-route.js +21 -0
- package/dist/sandbox/k8s/agent-context-route.js.map +1 -0
- package/dist/sandbox/k8s/artifact-upload-route.d.ts +12 -0
- package/dist/sandbox/k8s/artifact-upload-route.js +40 -0
- package/dist/sandbox/k8s/artifact-upload-route.js.map +1 -0
- package/dist/sandbox/k8s/client.d.ts +22 -0
- package/dist/sandbox/k8s/client.js +35 -0
- package/dist/sandbox/k8s/client.js.map +1 -0
- package/dist/sandbox/k8s/egress-apply.d.ts +14 -0
- package/dist/sandbox/k8s/egress-apply.js +44 -0
- package/dist/sandbox/k8s/egress-apply.js.map +1 -0
- package/dist/sandbox/k8s/egress-ensurer.d.ts +37 -0
- package/dist/sandbox/k8s/egress-ensurer.js +54 -0
- package/dist/sandbox/k8s/egress-ensurer.js.map +1 -0
- package/dist/sandbox/k8s/egress-policy.d.ts +112 -0
- package/dist/sandbox/k8s/egress-policy.js +118 -0
- package/dist/sandbox/k8s/egress-policy.js.map +1 -0
- package/dist/sandbox/k8s/init-agent-context.d.ts +20 -0
- package/dist/sandbox/k8s/init-agent-context.js +35 -0
- package/dist/sandbox/k8s/init-agent-context.js.map +1 -0
- package/dist/sandbox/k8s/init-clone.d.ts +53 -0
- package/dist/sandbox/k8s/init-clone.js +114 -0
- package/dist/sandbox/k8s/init-clone.js.map +1 -0
- package/dist/sandbox/k8s/init-skills.d.ts +13 -0
- package/dist/sandbox/k8s/init-skills.js +28 -0
- package/dist/sandbox/k8s/init-skills.js.map +1 -0
- package/dist/sandbox/k8s/kubernetes-sandbox.d.ts +179 -0
- package/dist/sandbox/k8s/kubernetes-sandbox.js +418 -0
- package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -0
- package/dist/sandbox/k8s/log-stream.d.ts +4 -0
- package/dist/sandbox/k8s/log-stream.js +43 -0
- package/dist/sandbox/k8s/log-stream.js.map +1 -0
- package/dist/sandbox/k8s/naming.d.ts +19 -0
- package/dist/sandbox/k8s/naming.js +35 -0
- package/dist/sandbox/k8s/naming.js.map +1 -0
- package/dist/sandbox/k8s/pod-lifecycle.d.ts +40 -0
- package/dist/sandbox/k8s/pod-lifecycle.js +151 -0
- package/dist/sandbox/k8s/pod-lifecycle.js.map +1 -0
- package/dist/sandbox/k8s/pod-status.d.ts +46 -0
- package/dist/sandbox/k8s/pod-status.js +83 -0
- package/dist/sandbox/k8s/pod-status.js.map +1 -0
- package/dist/sandbox/k8s/pod.d.ts +79 -0
- package/dist/sandbox/k8s/pod.js +115 -0
- package/dist/sandbox/k8s/pod.js.map +1 -0
- package/dist/sandbox/k8s/pvc.d.ts +20 -0
- package/dist/sandbox/k8s/pvc.js +26 -0
- package/dist/sandbox/k8s/pvc.js.map +1 -0
- package/dist/sandbox/k8s/quota.d.ts +34 -0
- package/dist/sandbox/k8s/quota.js +52 -0
- package/dist/sandbox/k8s/quota.js.map +1 -0
- package/dist/sandbox/k8s/reclaim.d.ts +50 -0
- package/dist/sandbox/k8s/reclaim.js +141 -0
- package/dist/sandbox/k8s/reclaim.js.map +1 -0
- package/dist/sandbox/k8s/resource-name.d.ts +33 -0
- package/dist/sandbox/k8s/resource-name.js +49 -0
- package/dist/sandbox/k8s/resource-name.js.map +1 -0
- package/dist/sandbox/k8s/run-agent-script.d.ts +60 -0
- package/dist/sandbox/k8s/run-agent-script.js +48 -0
- package/dist/sandbox/k8s/run-agent-script.js.map +1 -0
- package/dist/sandbox/k8s/run-id.d.ts +23 -0
- package/dist/sandbox/k8s/run-id.js +32 -0
- package/dist/sandbox/k8s/run-id.js.map +1 -0
- package/dist/sandbox/k8s/run-secrets.d.ts +75 -0
- package/dist/sandbox/k8s/run-secrets.js +115 -0
- package/dist/sandbox/k8s/run-secrets.js.map +1 -0
- package/dist/sandbox/k8s/secret.d.ts +20 -0
- package/dist/sandbox/k8s/secret.js +38 -0
- package/dist/sandbox/k8s/secret.js.map +1 -0
- package/dist/sandbox/k8s/skill-bundle-route.d.ts +10 -0
- package/dist/sandbox/k8s/skill-bundle-route.js +18 -0
- package/dist/sandbox/k8s/skill-bundle-route.js.map +1 -0
- package/dist/sandbox/k8s/skill-bundle.d.ts +36 -0
- package/dist/sandbox/k8s/skill-bundle.js +85 -0
- package/dist/sandbox/k8s/skill-bundle.js.map +1 -0
- package/dist/sandbox/k8s/sweep.d.ts +47 -0
- package/dist/sandbox/k8s/sweep.js +29 -0
- package/dist/sandbox/k8s/sweep.js.map +1 -0
- package/dist/sandbox/k8s/workspace-provisioner.d.ts +51 -0
- package/dist/sandbox/k8s/workspace-provisioner.js +64 -0
- package/dist/sandbox/k8s/workspace-provisioner.js.map +1 -0
- package/dist/sandbox/sandbox.d.ts +20 -1
- package/dist/sandbox/sandbox.js +22 -1
- package/dist/sandbox/sandbox.js.map +1 -1
- package/dist/state/workflow-run-store.d.ts +11 -0
- package/dist/state/workflow-run-store.js +19 -0
- package/dist/state/workflow-run-store.js.map +1 -1
- package/dist/workflows/admission.d.ts +19 -0
- package/dist/workflows/admission.js +81 -13
- package/dist/workflows/admission.js.map +1 -1
- package/dist/workflows/handlers/post-review.d.ts +21 -0
- package/dist/workflows/handlers/post-review.js +56 -13
- package/dist/workflows/handlers/post-review.js.map +1 -1
- package/dist/workflows/resume.js +6 -0
- package/dist/workflows/resume.js.map +1 -1
- package/dist/workflows/runner.d.ts +11 -2
- package/dist/workflows/runner.js +73 -15
- package/dist/workflows/runner.js.map +1 -1
- package/dist/workflows/simple.d.ts +13 -1
- package/dist/workflows/simple.js +46 -4
- package/dist/workflows/simple.js.map +1 -1
- package/package.json +21 -20
- package/skills/issue-triage/SKILL.md +17 -0
- package/workflows/cron-review.yaml +14 -1
- package/workflows/dependabot-pr-merge.yaml +14 -9
- package/workflows/issue-triage.yaml +6 -0
- package/workflows/prompts/dependabot-pr-merge.md +53 -11
- package/deploy/k8s/deployment.yaml +0 -63
- package/deploy/k8s/generic-device-plugin.yaml +0 -63
- package/deploy/k8s/namespace.yaml +0 -10
- package/deploy/k8s/pvc.yaml +0 -13
- package/deploy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O,GAAG,CAAC,MAAM,MAAM,CAAC,yBAAyB,CAAC;YACtD,GAAG,MAAM;YACT,IAAI;SACL,CAAC,CAED,CAAC;QACF,MAAM,WAAW,GAAG;YAClB,GAAG,IAAI;YACP,QAAQ,EAAE,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE;SAClF,CAAC;QACF,MAAM,MAAM,CAAC,6BAA6B,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;IACrF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type CustomObjectsApi } from "@kubernetes/client-node";
|
|
2
|
+
import type { HarnessSelector } from "./egress-policy.js";
|
|
3
|
+
/**
|
|
4
|
+
* Applies the strict/open CiliumNetworkPolicy egress pair to a namespace,
|
|
5
|
+
* once per namespace for the lifetime of this instance.
|
|
6
|
+
*
|
|
7
|
+
* The ensure-once cache is an instance field (a `Map` keyed by namespace), not
|
|
8
|
+
* a process-global — production shares one instance (the module-level
|
|
9
|
+
* {@link egressEnsurer} singleton, injected via `K8sAdapterConfig.egressEnsurer`)
|
|
10
|
+
* across every `KubernetesSandbox`, so the policies still apply exactly once
|
|
11
|
+
* per namespace per process. Tests inject a fresh instance instead, so two
|
|
12
|
+
* tests sharing a namespace don't need one to dodge the other's cache.
|
|
13
|
+
*/
|
|
14
|
+
export declare class EgressEnsurer {
|
|
15
|
+
private readonly ensured;
|
|
16
|
+
/**
|
|
17
|
+
* Apply the egress policy pair to `namespace`, once. Best-effort: a 403 (the
|
|
18
|
+
* CiliumNetworkPolicy RBAC verb not yet granted — Plan 6) is logged as a
|
|
19
|
+
* single warning and the returned promise resolves, so the caller runs on
|
|
20
|
+
* Cilium's default-allow instead of failing. Any other error clears the
|
|
21
|
+
* cached entry — so a later call retries the apply — and rethrows.
|
|
22
|
+
*
|
|
23
|
+
* @param custom - Kubernetes `CustomObjectsApi` client used to apply the CRDs.
|
|
24
|
+
* @param namespace - Namespace the policy pair is scoped to; also the cache key.
|
|
25
|
+
* @param hosts - Allowlisted hosts for the strict policy's `toFQDNs` rule.
|
|
26
|
+
* @param harness - Harness Pod selector both policies carve an exception for.
|
|
27
|
+
* @returns A promise that resolves once the policies are applied (or the
|
|
28
|
+
* 403 is warned-and-swallowed); the same promise is returned to every
|
|
29
|
+
* caller for `namespace` until it settles or is cleared by a real error.
|
|
30
|
+
*/
|
|
31
|
+
ensure(custom: CustomObjectsApi, namespace: string, hosts: readonly string[], harness: HarnessSelector): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/** Process-wide singleton: production shares one instance across every
|
|
34
|
+
* `KubernetesSandbox`, so the egress policy pair is applied once per
|
|
35
|
+
* namespace per process (the same "ensure once" behaviour the previous
|
|
36
|
+
* module-global cache gave). */
|
|
37
|
+
export declare const egressEnsurer: EgressEnsurer;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ApiException } from "@kubernetes/client-node";
|
|
2
|
+
import { applyEgressPolicies } from "./egress-apply.js";
|
|
3
|
+
/**
|
|
4
|
+
* Applies the strict/open CiliumNetworkPolicy egress pair to a namespace,
|
|
5
|
+
* once per namespace for the lifetime of this instance.
|
|
6
|
+
*
|
|
7
|
+
* The ensure-once cache is an instance field (a `Map` keyed by namespace), not
|
|
8
|
+
* a process-global — production shares one instance (the module-level
|
|
9
|
+
* {@link egressEnsurer} singleton, injected via `K8sAdapterConfig.egressEnsurer`)
|
|
10
|
+
* across every `KubernetesSandbox`, so the policies still apply exactly once
|
|
11
|
+
* per namespace per process. Tests inject a fresh instance instead, so two
|
|
12
|
+
* tests sharing a namespace don't need one to dodge the other's cache.
|
|
13
|
+
*/
|
|
14
|
+
export class EgressEnsurer {
|
|
15
|
+
ensured = new Map();
|
|
16
|
+
/**
|
|
17
|
+
* Apply the egress policy pair to `namespace`, once. Best-effort: a 403 (the
|
|
18
|
+
* CiliumNetworkPolicy RBAC verb not yet granted — Plan 6) is logged as a
|
|
19
|
+
* single warning and the returned promise resolves, so the caller runs on
|
|
20
|
+
* Cilium's default-allow instead of failing. Any other error clears the
|
|
21
|
+
* cached entry — so a later call retries the apply — and rethrows.
|
|
22
|
+
*
|
|
23
|
+
* @param custom - Kubernetes `CustomObjectsApi` client used to apply the CRDs.
|
|
24
|
+
* @param namespace - Namespace the policy pair is scoped to; also the cache key.
|
|
25
|
+
* @param hosts - Allowlisted hosts for the strict policy's `toFQDNs` rule.
|
|
26
|
+
* @param harness - Harness Pod selector both policies carve an exception for.
|
|
27
|
+
* @returns A promise that resolves once the policies are applied (or the
|
|
28
|
+
* 403 is warned-and-swallowed); the same promise is returned to every
|
|
29
|
+
* caller for `namespace` until it settles or is cleared by a real error.
|
|
30
|
+
*/
|
|
31
|
+
ensure(custom, namespace, hosts, harness) {
|
|
32
|
+
const pending = this.ensured.get(namespace);
|
|
33
|
+
if (pending)
|
|
34
|
+
return pending;
|
|
35
|
+
const applied = applyEgressPolicies(custom, { namespace, hosts, harness }).catch((err) => {
|
|
36
|
+
if (err instanceof ApiException && err.code === 403) {
|
|
37
|
+
console.warn(`[k8s] egress policies not applied in ${namespace}: RBAC for ` +
|
|
38
|
+
`CiliumNetworkPolicy is not granted (Plan 6). Running WITHOUT egress ` +
|
|
39
|
+
`enforcement (Cilium default-allow).`);
|
|
40
|
+
return; // resolve — don't retry/re-log every run
|
|
41
|
+
}
|
|
42
|
+
this.ensured.delete(namespace); // real error: allow a later call to retry
|
|
43
|
+
throw err;
|
|
44
|
+
});
|
|
45
|
+
this.ensured.set(namespace, applied);
|
|
46
|
+
return applied;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Process-wide singleton: production shares one instance across every
|
|
50
|
+
* `KubernetesSandbox`, so the egress policy pair is applied once per
|
|
51
|
+
* namespace per process (the same "ensure once" behaviour the previous
|
|
52
|
+
* module-global cache gave). */
|
|
53
|
+
export const egressEnsurer = new EgressEnsurer();
|
|
54
|
+
//# sourceMappingURL=egress-ensurer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"egress-ensurer.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/egress-ensurer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGxD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,aAAa;IACP,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;IAE5D;;;;;;;;;;;;;;OAcG;IACH,MAAM,CACJ,MAAwB,EACxB,SAAiB,EACjB,KAAwB,EACxB,OAAwB;QAExB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,OAAO;YAAE,OAAO,OAAO,CAAC;QAC5B,MAAM,OAAO,GAAG,mBAAmB,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACvF,IAAI,GAAG,YAAY,YAAY,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE,CAAC;gBACpD,OAAO,CAAC,IAAI,CACV,wCAAwC,SAAS,aAAa;oBAC5D,sEAAsE;oBACtE,qCAAqC,CACxC,CAAC;gBACF,OAAO,CAAC,yCAAyC;YACnD,CAAC;YACD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,0CAA0C;YAC1E,MAAM,GAAG,CAAC;QACZ,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACrC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAED;;;iCAGiC;AACjC,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { EgressPolicy } from "../sandbox.js";
|
|
2
|
+
/** Pod/selector label choosing which egress policy applies. */
|
|
3
|
+
export declare const EGRESS_POLICY_LABEL = "egress-policy";
|
|
4
|
+
/** The two Cilium egress postures a sandbox pod can be labeled with — see
|
|
5
|
+
* {@link EGRESS_POLICY_LABEL}. Named once here so `pod.ts` and the adapter
|
|
6
|
+
* import it instead of retyping the bare union. */
|
|
7
|
+
export type EgressMode = "strict" | "open";
|
|
8
|
+
/** Single derivation point: the backend-agnostic intent-only {@link EgressPolicy}
|
|
9
|
+
* (`sandbox.ts`) → the k8s-specific {@link EgressMode} label value. */
|
|
10
|
+
export declare function egressModeFor(policy: EgressPolicy): EgressMode;
|
|
11
|
+
/** Name of the CiliumNetworkPolicy applied to strict-egress sandbox pods. */
|
|
12
|
+
export declare const STRICT_POLICY_NAME = "lastlight-sandbox-egress-strict";
|
|
13
|
+
/** Name of the CiliumNetworkPolicy applied to open-egress sandbox pods. */
|
|
14
|
+
export declare const OPEN_POLICY_NAME = "lastlight-sandbox-egress-open";
|
|
15
|
+
/** Cilium CiliumNetworkPolicy CRD coordinates (client-node CustomObjectsApi). */
|
|
16
|
+
export declare const CILIUM_GROUP = "cilium.io";
|
|
17
|
+
export declare const CILIUM_VERSION = "v2";
|
|
18
|
+
export declare const CILIUM_CNP_PLURAL = "ciliumnetworkpolicies";
|
|
19
|
+
/** One `toPorts` port entry — Cilium's wire format takes the port as a string. */
|
|
20
|
+
interface CiliumPort {
|
|
21
|
+
port: string;
|
|
22
|
+
protocol: "TCP" | "ANY";
|
|
23
|
+
}
|
|
24
|
+
/** DNS-proxy activation attached to a `toPorts` entry (see `dnsEgressRule`). */
|
|
25
|
+
interface CiliumDnsRules {
|
|
26
|
+
dns: Array<{
|
|
27
|
+
matchPattern: string;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
/** One `toPorts` entry: the allowed ports, plus optional DNS-proxy activation. */
|
|
31
|
+
interface CiliumToPorts {
|
|
32
|
+
ports: CiliumPort[];
|
|
33
|
+
rules?: CiliumDnsRules;
|
|
34
|
+
}
|
|
35
|
+
/** Cilium identity selector — labels an endpoint must carry (`toEndpoints`). */
|
|
36
|
+
interface CiliumEndpointSelector {
|
|
37
|
+
matchLabels: Record<string, string>;
|
|
38
|
+
}
|
|
39
|
+
/** One FQDN allow entry — either the exact apex or a `*.`-prefixed subdomain wildcard. */
|
|
40
|
+
export type CiliumFqdnMatch = {
|
|
41
|
+
matchName: string;
|
|
42
|
+
} | {
|
|
43
|
+
matchPattern: string;
|
|
44
|
+
};
|
|
45
|
+
/** One `toCIDRSet` entry — a CIDR block with its exception list. */
|
|
46
|
+
interface CiliumCidrRange {
|
|
47
|
+
cidr: string;
|
|
48
|
+
except: string[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Minimal shape of a Cilium egress rule — the closed set this file emits: an
|
|
52
|
+
* identity allow (`toEndpoints`), an FQDN allowlist (`toFQDNs`), or a CIDR
|
|
53
|
+
* allow-with-exceptions (`toCIDRSet`), each optionally paired with `toPorts`.
|
|
54
|
+
* Properties are optional so each rule literal sets only the ones it needs;
|
|
55
|
+
* this exists to reject a *misspelled* property at compile time (a `toFQDN`
|
|
56
|
+
* typo, say), not to enforce which combination of properties is valid.
|
|
57
|
+
*/
|
|
58
|
+
export interface CiliumEgressRule {
|
|
59
|
+
toEndpoints?: CiliumEndpointSelector[];
|
|
60
|
+
toFQDNs?: CiliumFqdnMatch[];
|
|
61
|
+
toCIDRSet?: CiliumCidrRange[];
|
|
62
|
+
toPorts?: CiliumToPorts[];
|
|
63
|
+
}
|
|
64
|
+
/** The harness Pod the sandbox may reach for the skill fetch (design §4/§7). */
|
|
65
|
+
export interface HarnessSelector {
|
|
66
|
+
namespace: string;
|
|
67
|
+
labels: Record<string, string>;
|
|
68
|
+
port: number;
|
|
69
|
+
}
|
|
70
|
+
/** Minimal shape of a Cilium `CiliumNetworkPolicy` custom resource. */
|
|
71
|
+
export interface CiliumNetworkPolicy {
|
|
72
|
+
apiVersion: string;
|
|
73
|
+
kind: string;
|
|
74
|
+
metadata: {
|
|
75
|
+
name: string;
|
|
76
|
+
namespace: string;
|
|
77
|
+
};
|
|
78
|
+
spec: {
|
|
79
|
+
endpointSelector: {
|
|
80
|
+
matchLabels: Record<string, string>;
|
|
81
|
+
};
|
|
82
|
+
egress: CiliumEgressRule[];
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Expand each bare allowlist host to the two Cilium FQDN forms it needs:
|
|
87
|
+
* `matchName` for the apex, `matchPattern: "*.host"` for every subdomain
|
|
88
|
+
* (the pattern alone excludes the apex). Mirrors nginx's `.host` and CoreDNS's
|
|
89
|
+
* `(^|\.)host\.$` — same apex+subdomain convention, one shared source list.
|
|
90
|
+
*/
|
|
91
|
+
export declare function fqdnRulesFor(hosts: readonly string[]): CiliumFqdnMatch[];
|
|
92
|
+
/** Strict = DNS + the allowlist FQDNs on 443/TCP; everything else default-denied. */
|
|
93
|
+
export declare function renderStrictEgressPolicy(opts: {
|
|
94
|
+
namespace: string;
|
|
95
|
+
hosts: readonly string[];
|
|
96
|
+
harness?: HarnessSelector;
|
|
97
|
+
}): CiliumNetworkPolicy;
|
|
98
|
+
/** Open = DNS + broad 80/443 egress minus the private-CIDR SSRF floor. */
|
|
99
|
+
export declare function renderOpenEgressPolicy(opts: {
|
|
100
|
+
namespace: string;
|
|
101
|
+
harness?: HarnessSelector;
|
|
102
|
+
}): CiliumNetworkPolicy;
|
|
103
|
+
/** Render the strict/open CiliumNetworkPolicy pair for one sandbox namespace. */
|
|
104
|
+
export declare function renderEgressPolicies(opts: {
|
|
105
|
+
namespace: string;
|
|
106
|
+
hosts: readonly string[];
|
|
107
|
+
harness?: HarnessSelector;
|
|
108
|
+
}): {
|
|
109
|
+
strict: CiliumNetworkPolicy;
|
|
110
|
+
open: CiliumNetworkPolicy;
|
|
111
|
+
};
|
|
112
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/** Pod/selector label choosing which egress policy applies. */
|
|
2
|
+
export const EGRESS_POLICY_LABEL = "egress-policy";
|
|
3
|
+
/** Single derivation point: the backend-agnostic intent-only {@link EgressPolicy}
|
|
4
|
+
* (`sandbox.ts`) → the k8s-specific {@link EgressMode} label value. */
|
|
5
|
+
export function egressModeFor(policy) {
|
|
6
|
+
return policy.unrestricted ? "open" : "strict";
|
|
7
|
+
}
|
|
8
|
+
/** Name of the CiliumNetworkPolicy applied to strict-egress sandbox pods. */
|
|
9
|
+
export const STRICT_POLICY_NAME = "lastlight-sandbox-egress-strict";
|
|
10
|
+
/** Name of the CiliumNetworkPolicy applied to open-egress sandbox pods. */
|
|
11
|
+
export const OPEN_POLICY_NAME = "lastlight-sandbox-egress-open";
|
|
12
|
+
/** Cilium CiliumNetworkPolicy CRD coordinates (client-node CustomObjectsApi). */
|
|
13
|
+
export const CILIUM_GROUP = "cilium.io";
|
|
14
|
+
export const CILIUM_VERSION = "v2";
|
|
15
|
+
export const CILIUM_CNP_PLURAL = "ciliumnetworkpolicies";
|
|
16
|
+
/**
|
|
17
|
+
* Private / link-local / loopback ranges the OPEN policy excepts from its
|
|
18
|
+
* broad `0.0.0.0/0` allow — the SSRF floor. RFC-1918 covers the cluster pod /
|
|
19
|
+
* service CIDRs on the target cluster (all within 10/8), and 169.254.0.0/16
|
|
20
|
+
* covers the cloud-metadata literal. Strict mode needs none of this: with only
|
|
21
|
+
* DNS + toFQDNs rules, a strict pod can reach *only* an allowlisted FQDN's
|
|
22
|
+
* resolved IP, so private space is unreachable by construction.
|
|
23
|
+
*/
|
|
24
|
+
const PRIVATE_CIDRS_V4 = [
|
|
25
|
+
"10.0.0.0/8",
|
|
26
|
+
"172.16.0.0/12",
|
|
27
|
+
"192.168.0.0/16",
|
|
28
|
+
"169.254.0.0/16",
|
|
29
|
+
"127.0.0.0/8",
|
|
30
|
+
];
|
|
31
|
+
const PRIVATE_CIDRS_V6 = ["::1/128", "fc00::/7", "fe80::/10"];
|
|
32
|
+
/** Selects the in-cluster DNS service so Cilium's DNS proxy sees the queries. */
|
|
33
|
+
const KUBE_DNS_SELECTOR = {
|
|
34
|
+
"k8s:io.kubernetes.pod.namespace": "kube-system",
|
|
35
|
+
"k8s-app": "kube-dns",
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* DNS egress rule shared by both policies: allow port 53 to kube-dns AND turn
|
|
39
|
+
* on the DNS proxy (`rules.dns: [{ matchPattern: "*" }]`). WITHOUT this rule
|
|
40
|
+
* `toFQDNs` never learns any IP and every connection is denied — Cilium only
|
|
41
|
+
* permits connecting to an IP it was allowed to resolve. This is the mechanism
|
|
42
|
+
* that closes the private-IP SSRF gap the docker SNI-peek admits it cannot.
|
|
43
|
+
*/
|
|
44
|
+
function dnsEgressRule() {
|
|
45
|
+
return {
|
|
46
|
+
toEndpoints: [{ matchLabels: KUBE_DNS_SELECTOR }],
|
|
47
|
+
toPorts: [
|
|
48
|
+
{ ports: [{ port: "53", protocol: "ANY" }], rules: { dns: [{ matchPattern: "*" }] } },
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Permit sandbox→harness only, by Cilium identity (namespace + labels), on the
|
|
53
|
+
* harness port — an identity rule, not a CIDR hole. Carries the Section 7 skill
|
|
54
|
+
* fetch under both strict and open. */
|
|
55
|
+
function harnessEgressRule(h) {
|
|
56
|
+
return {
|
|
57
|
+
toEndpoints: [
|
|
58
|
+
{ matchLabels: { "k8s:io.kubernetes.pod.namespace": h.namespace, ...h.labels } },
|
|
59
|
+
],
|
|
60
|
+
toPorts: [{ ports: [{ port: String(h.port), protocol: "TCP" }] }],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Expand each bare allowlist host to the two Cilium FQDN forms it needs:
|
|
65
|
+
* `matchName` for the apex, `matchPattern: "*.host"` for every subdomain
|
|
66
|
+
* (the pattern alone excludes the apex). Mirrors nginx's `.host` and CoreDNS's
|
|
67
|
+
* `(^|\.)host\.$` — same apex+subdomain convention, one shared source list.
|
|
68
|
+
*/
|
|
69
|
+
export function fqdnRulesFor(hosts) {
|
|
70
|
+
const rules = [];
|
|
71
|
+
for (const host of hosts) {
|
|
72
|
+
rules.push({ matchName: host });
|
|
73
|
+
rules.push({ matchPattern: `*.${host}` });
|
|
74
|
+
}
|
|
75
|
+
return rules;
|
|
76
|
+
}
|
|
77
|
+
function policy(name, namespace, value, egress) {
|
|
78
|
+
return {
|
|
79
|
+
apiVersion: `${CILIUM_GROUP}/${CILIUM_VERSION}`,
|
|
80
|
+
kind: "CiliumNetworkPolicy",
|
|
81
|
+
metadata: { name, namespace },
|
|
82
|
+
spec: { endpointSelector: { matchLabels: { [EGRESS_POLICY_LABEL]: value } }, egress },
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Strict = DNS + the allowlist FQDNs on 443/TCP; everything else default-denied. */
|
|
86
|
+
export function renderStrictEgressPolicy(opts) {
|
|
87
|
+
const egress = [
|
|
88
|
+
dnsEgressRule(),
|
|
89
|
+
{ toFQDNs: fqdnRulesFor(opts.hosts), toPorts: [{ ports: [{ port: "443", protocol: "TCP" }] }] },
|
|
90
|
+
];
|
|
91
|
+
if (opts.harness)
|
|
92
|
+
egress.push(harnessEgressRule(opts.harness));
|
|
93
|
+
return policy(STRICT_POLICY_NAME, opts.namespace, "strict", egress);
|
|
94
|
+
}
|
|
95
|
+
/** Open = DNS + broad 80/443 egress minus the private-CIDR SSRF floor. */
|
|
96
|
+
export function renderOpenEgressPolicy(opts) {
|
|
97
|
+
const egress = [
|
|
98
|
+
dnsEgressRule(),
|
|
99
|
+
{
|
|
100
|
+
toCIDRSet: [
|
|
101
|
+
{ cidr: "0.0.0.0/0", except: PRIVATE_CIDRS_V4 },
|
|
102
|
+
{ cidr: "::/0", except: PRIVATE_CIDRS_V6 },
|
|
103
|
+
],
|
|
104
|
+
toPorts: [{ ports: [{ port: "443", protocol: "TCP" }, { port: "80", protocol: "TCP" }] }],
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
if (opts.harness)
|
|
108
|
+
egress.push(harnessEgressRule(opts.harness));
|
|
109
|
+
return policy(OPEN_POLICY_NAME, opts.namespace, "open", egress);
|
|
110
|
+
}
|
|
111
|
+
/** Render the strict/open CiliumNetworkPolicy pair for one sandbox namespace. */
|
|
112
|
+
export function renderEgressPolicies(opts) {
|
|
113
|
+
return {
|
|
114
|
+
strict: renderStrictEgressPolicy(opts),
|
|
115
|
+
open: renderOpenEgressPolicy({ namespace: opts.namespace, harness: opts.harness }),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=egress-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"egress-policy.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/egress-policy.ts"],"names":[],"mappings":"AAEA,+DAA+D;AAC/D,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAOnD;wEACwE;AACxE,MAAM,UAAU,aAAa,CAAC,MAAoB;IAChD,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AACjD,CAAC;AAED,6EAA6E;AAC7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,iCAAiC,CAAC;AACpE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAAG,+BAA+B,CAAC;AAEhE,iFAAiF;AACjF,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;AACxC,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AACnC,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAG;IACvB,YAAY;IACZ,eAAe;IACf,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;CACd,CAAC;AACF,MAAM,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,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;SAC1F;KACF,CAAC;IACF,IAAI,IAAI,CAAC,OAAO;QAAE,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC/D,OAAO,MAAM,CAAC,gBAAgB,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAClE,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,oBAAoB,CAAC,IAIpC;IACC,OAAO;QACL,MAAM,EAAE,wBAAwB,CAAC,IAAI,CAAC;QACtC,IAAI,EAAE,sBAAsB,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;KACnF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { V1Container } from "@kubernetes/client-node";
|
|
2
|
+
/**
|
|
3
|
+
* The agent-context initContainer: fetch the per-run resolved agent-context
|
|
4
|
+
* (persona/hard-rules) from the harness (bearer token from the creds Secret
|
|
5
|
+
* env, endpoint as a positional arg so it is never interpolated into the script)
|
|
6
|
+
* and write it to `<WORKSPACE_DIR>/AGENTS.md` — the workspace ROOT, never a
|
|
7
|
+
* cwd-relative path, so a repo-write phase's `git add -A` can't commit the bot's
|
|
8
|
+
* AGENTS.md into the customer's checkout (cwd is `<WORKSPACE_DIR>/<repo>` after a
|
|
9
|
+
* pre-clone). agentic-pi reads `AGENTS.md` from cwd, and the agent container's
|
|
10
|
+
* `workingDir` is inside this same workspace volume, so the file is visible.
|
|
11
|
+
*
|
|
12
|
+
* `envFrom` (creds Secret) is attached by `buildPodManifest`. `-f` makes curl
|
|
13
|
+
* fail the init on a non-2xx so a bad fetch surfaces (checkInitContainerFailure
|
|
14
|
+
* appends its logs); with `-f`, curl also suppresses the error body so a failed
|
|
15
|
+
* fetch never leaves a partial/garbage `AGENTS.md` behind.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildAgentContextInitContainer(image: string, opts: {
|
|
18
|
+
endpoint: string;
|
|
19
|
+
runAsUser: number;
|
|
20
|
+
}): V1Container;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { WORKSPACE_DIR } from "./pod.js";
|
|
2
|
+
/**
|
|
3
|
+
* The agent-context initContainer: fetch the per-run resolved agent-context
|
|
4
|
+
* (persona/hard-rules) from the harness (bearer token from the creds Secret
|
|
5
|
+
* env, endpoint as a positional arg so it is never interpolated into the script)
|
|
6
|
+
* and write it to `<WORKSPACE_DIR>/AGENTS.md` — the workspace ROOT, never a
|
|
7
|
+
* cwd-relative path, so a repo-write phase's `git add -A` can't commit the bot's
|
|
8
|
+
* AGENTS.md into the customer's checkout (cwd is `<WORKSPACE_DIR>/<repo>` after a
|
|
9
|
+
* pre-clone). agentic-pi reads `AGENTS.md` from cwd, and the agent container's
|
|
10
|
+
* `workingDir` is inside this same workspace volume, so the file is visible.
|
|
11
|
+
*
|
|
12
|
+
* `envFrom` (creds Secret) is attached by `buildPodManifest`. `-f` makes curl
|
|
13
|
+
* fail the init on a non-2xx so a bad fetch surfaces (checkInitContainerFailure
|
|
14
|
+
* appends its logs); with `-f`, curl also suppresses the error body so a failed
|
|
15
|
+
* fetch never leaves a partial/garbage `AGENTS.md` behind.
|
|
16
|
+
*/
|
|
17
|
+
export function buildAgentContextInitContainer(image, opts) {
|
|
18
|
+
const script = 'curl -fsS -H "Authorization: Bearer $LASTLIGHT_AGENT_CONTEXT_TOKEN" ' +
|
|
19
|
+
`"$1/internal/agent-context" -o ${WORKSPACE_DIR}/AGENTS.md`;
|
|
20
|
+
return {
|
|
21
|
+
name: "agent-context",
|
|
22
|
+
image,
|
|
23
|
+
command: ["sh", "-c", script],
|
|
24
|
+
args: ["sh", opts.endpoint],
|
|
25
|
+
envFrom: [],
|
|
26
|
+
volumeMounts: [{ name: "workspace", mountPath: WORKSPACE_DIR }],
|
|
27
|
+
securityContext: {
|
|
28
|
+
allowPrivilegeEscalation: false,
|
|
29
|
+
runAsNonRoot: true,
|
|
30
|
+
runAsUser: opts.runAsUser,
|
|
31
|
+
capabilities: { drop: ["ALL"] },
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=init-agent-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-agent-context.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/init-agent-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,8BAA8B,CAC5C,KAAa,EACb,IAA6C;IAE7C,MAAM,MAAM,GACV,sEAAsE;QACtE,kCAAkC,aAAa,YAAY,CAAC;IAC9D,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,KAAK;QACL,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC;QAC7B,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC;QAC3B,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;QAC/D,eAAe,EAAE;YACf,wBAAwB,EAAE,KAAK;YAC/B,YAAY,EAAE,IAAI;YAClB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE;SAChC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { V1Container } from "@kubernetes/client-node";
|
|
2
|
+
export interface CloneSpec {
|
|
3
|
+
owner: string;
|
|
4
|
+
repo: string;
|
|
5
|
+
branch: string;
|
|
6
|
+
cwd: string;
|
|
7
|
+
runAsUser: number;
|
|
8
|
+
/**
|
|
9
|
+
* PR base branch. When set (and distinct from `branch`), the script fetches it
|
|
10
|
+
* and deepens both refs to a shared merge-base so `git diff origin/<base>...HEAD`
|
|
11
|
+
* works — for both the fresh clone and the reuse-refresh path. Skipped for a
|
|
12
|
+
* `recreateFromBase` run.
|
|
13
|
+
*/
|
|
14
|
+
baseBranch?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Owning workflow run id, stamped into a `<cwd>/.lastlight-run` marker so a
|
|
17
|
+
* reused PVC can tell "next phase of the same run" (preserve the checkout —
|
|
18
|
+
* the architect's plan.md survives) from "a fresh run reusing this PR's dir"
|
|
19
|
+
* (refresh to the new head). Undefined ⇒ always preserve (the safe direction).
|
|
20
|
+
*/
|
|
21
|
+
runId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Recreate the checkout from the default branch on a different-run reuse
|
|
24
|
+
* instead of refreshing the (possibly stale) feature branch: discard the
|
|
25
|
+
* leftover checkout and re-clone the default, cutting `branch` locally off it
|
|
26
|
+
* (issue #153, `build`). A same-run reuse still preserves.
|
|
27
|
+
*/
|
|
28
|
+
recreateFromBase?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Minimal clone init (locked decision #2): clone the branch shallow-ish; if the
|
|
32
|
+
* branch isn't on the remote yet (build-style first run), clone the default
|
|
33
|
+
* branch and cut the branch locally.
|
|
34
|
+
*
|
|
35
|
+
* Reuse (a per-(repo,PR) PVC already holds a checkout) is marker-gated, mirroring
|
|
36
|
+
* the host `prePopulateWorkspace`: the same run preserves the checkout (a later
|
|
37
|
+
* phase reads what an earlier one wrote), a different run refreshes the head
|
|
38
|
+
* (`git fetch` + `reset --hard` + `clean -fdx -e node_modules`) or, for a
|
|
39
|
+
* recreate-from-base run, re-clones the default branch. For PR-diff workflows the
|
|
40
|
+
* base branch is fetched + deepened to a shared merge-base on both the fresh and
|
|
41
|
+
* refresh paths so `git diff origin/<base>...HEAD` resolves.
|
|
42
|
+
*
|
|
43
|
+
* Auth is the github.com-scoped `http.extraheader` delivered as `GIT_CONFIG_*`
|
|
44
|
+
* env from the creds Secret (agentGitIdentityEnv) — no token in any URL.
|
|
45
|
+
*
|
|
46
|
+
* owner/repo/branch/cwd/base/runId are NOT validated upstream (branch is the PR
|
|
47
|
+
* head ref, attacker-named for external pr-review/pr-fix PRs) — so they're passed
|
|
48
|
+
* as positional args to a fixed script rather than interpolated into shell text.
|
|
49
|
+
* `sh -c CLONE_SCRIPT sh <owner> <repo> <branch> <cwd> <base> <runId> <recreate>`
|
|
50
|
+
* binds argv to `$1`..`$7` at exec time, immune to quote-breaking regardless of
|
|
51
|
+
* characters.
|
|
52
|
+
*/
|
|
53
|
+
export declare function buildCloneInitContainer(image: string, spec: CloneSpec): V1Container;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// A fixed script — untrusted values (owner/repo/branch/cwd/base/runId) arrive as
|
|
2
|
+
// positional args ($1..$7), NEVER interpolated into shell text, so a branch name
|
|
3
|
+
// containing shell metacharacters cannot break out. `--` before the URL/dir
|
|
4
|
+
// positionals blocks flag-smuggling on a value starting with `-`.
|
|
5
|
+
//
|
|
6
|
+
// Existing checkout (reused PVC): compare the `.lastlight-run` marker to decide.
|
|
7
|
+
// Same run (or no run id) → preserve, exactly as before. A different run → refresh
|
|
8
|
+
// the head (fetch + reset --hard + `clean -fdx -e node_modules`, keeping the deps
|
|
9
|
+
// tree warm) or, for a recreate-from-base run, discard and re-clone the default.
|
|
10
|
+
// The head refresh is best-effort: a failed fetch preserves the existing checkout
|
|
11
|
+
// rather than leaving a half-reset tree (mirrors the host `refreshExistingClone`).
|
|
12
|
+
// `ensure_base` fetches + deepens `origin/<base>` for the three-dot PR diff on
|
|
13
|
+
// both the fresh-clone and refresh paths (mirrors the host `ensureBaseAvailable`).
|
|
14
|
+
const CLONE_SCRIPT = [
|
|
15
|
+
"set -eu",
|
|
16
|
+
'owner="$1"; repo="$2"; branch="$3"; ws="$4"; base="$5"; run_id="$6"; recreate="$7"',
|
|
17
|
+
'repo_dir="$ws/$repo"',
|
|
18
|
+
'marker="$ws/.lastlight-run"',
|
|
19
|
+
'url="https://github.com/$owner/$repo.git"',
|
|
20
|
+
"ensure_base() {",
|
|
21
|
+
' [ -n "$base" ] && [ "$base" != "$branch" ] && [ -z "$recreate" ] || return 0',
|
|
22
|
+
' dest="+refs/heads/$base:refs/remotes/origin/$base"',
|
|
23
|
+
" for depth in 50 500; do",
|
|
24
|
+
' git -C "$repo_dir" fetch --depth "$depth" -- "$url" "$dest" || true',
|
|
25
|
+
' git -C "$repo_dir" fetch --depth "$depth" -- "$url" "$branch" || true',
|
|
26
|
+
' git -C "$repo_dir" merge-base "origin/$base" HEAD >/dev/null 2>&1 && return 0',
|
|
27
|
+
" done",
|
|
28
|
+
' git -C "$repo_dir" fetch --unshallow -- "$url" "$dest" || true',
|
|
29
|
+
' git -C "$repo_dir" fetch --unshallow -- "$url" "$branch" || true',
|
|
30
|
+
" return 0",
|
|
31
|
+
"}",
|
|
32
|
+
'stamp() { [ -n "$run_id" ] && printf %s "$run_id" > "$marker" 2>/dev/null || true; }',
|
|
33
|
+
'if [ -d "$repo_dir/.git" ]; then',
|
|
34
|
+
' last_run="$(cat "$marker" 2>/dev/null || true)"',
|
|
35
|
+
' if [ -z "$run_id" ] || [ "$last_run" = "$run_id" ]; then',
|
|
36
|
+
' echo "[clone] existing checkout (same run) — preserving"; exit 0',
|
|
37
|
+
" fi",
|
|
38
|
+
' if [ -z "$recreate" ]; then',
|
|
39
|
+
' if git -C "$repo_dir" fetch --depth 50 -- "$url" "$branch" \\',
|
|
40
|
+
' && git -C "$repo_dir" checkout -B "$branch" FETCH_HEAD \\',
|
|
41
|
+
' && git -C "$repo_dir" reset --hard FETCH_HEAD \\',
|
|
42
|
+
' && git -C "$repo_dir" clean -fdx -e node_modules; then',
|
|
43
|
+
' git -C "$repo_dir" remote set-url origin "$url" || true',
|
|
44
|
+
" ensure_base; stamp",
|
|
45
|
+
' echo "[clone] refreshed reused workspace -> $branch"',
|
|
46
|
+
" else",
|
|
47
|
+
' echo "[clone] refresh fetch failed — preserving existing checkout"',
|
|
48
|
+
" fi",
|
|
49
|
+
" exit 0",
|
|
50
|
+
" fi",
|
|
51
|
+
' echo "[clone] recreate-from-base — discarding stale checkout"',
|
|
52
|
+
' rm -rf "$repo_dir"',
|
|
53
|
+
"fi",
|
|
54
|
+
'if [ -n "$recreate" ]; then',
|
|
55
|
+
' git clone --depth 50 -- "$url" "$repo_dir"',
|
|
56
|
+
' git -C "$repo_dir" checkout -B "$branch"',
|
|
57
|
+
' git -C "$repo_dir" remote set-url origin "$url"',
|
|
58
|
+
'elif git clone --branch "$branch" --depth 50 -- "$url" "$repo_dir"; then',
|
|
59
|
+
' git -C "$repo_dir" remote set-url origin "$url"',
|
|
60
|
+
"else",
|
|
61
|
+
' echo "[clone] branch not on remote — cloning default and cutting $branch"',
|
|
62
|
+
' git clone --depth 50 -- "$url" "$repo_dir"',
|
|
63
|
+
' git -C "$repo_dir" checkout -B "$branch"',
|
|
64
|
+
' git -C "$repo_dir" remote set-url origin "$url"',
|
|
65
|
+
"fi",
|
|
66
|
+
"ensure_base",
|
|
67
|
+
"stamp",
|
|
68
|
+
].join("\n");
|
|
69
|
+
/**
|
|
70
|
+
* Minimal clone init (locked decision #2): clone the branch shallow-ish; if the
|
|
71
|
+
* branch isn't on the remote yet (build-style first run), clone the default
|
|
72
|
+
* branch and cut the branch locally.
|
|
73
|
+
*
|
|
74
|
+
* Reuse (a per-(repo,PR) PVC already holds a checkout) is marker-gated, mirroring
|
|
75
|
+
* the host `prePopulateWorkspace`: the same run preserves the checkout (a later
|
|
76
|
+
* phase reads what an earlier one wrote), a different run refreshes the head
|
|
77
|
+
* (`git fetch` + `reset --hard` + `clean -fdx -e node_modules`) or, for a
|
|
78
|
+
* recreate-from-base run, re-clones the default branch. For PR-diff workflows the
|
|
79
|
+
* base branch is fetched + deepened to a shared merge-base on both the fresh and
|
|
80
|
+
* refresh paths so `git diff origin/<base>...HEAD` resolves.
|
|
81
|
+
*
|
|
82
|
+
* Auth is the github.com-scoped `http.extraheader` delivered as `GIT_CONFIG_*`
|
|
83
|
+
* env from the creds Secret (agentGitIdentityEnv) — no token in any URL.
|
|
84
|
+
*
|
|
85
|
+
* owner/repo/branch/cwd/base/runId are NOT validated upstream (branch is the PR
|
|
86
|
+
* head ref, attacker-named for external pr-review/pr-fix PRs) — so they're passed
|
|
87
|
+
* as positional args to a fixed script rather than interpolated into shell text.
|
|
88
|
+
* `sh -c CLONE_SCRIPT sh <owner> <repo> <branch> <cwd> <base> <runId> <recreate>`
|
|
89
|
+
* binds argv to `$1`..`$7` at exec time, immune to quote-breaking regardless of
|
|
90
|
+
* characters.
|
|
91
|
+
*/
|
|
92
|
+
export function buildCloneInitContainer(image, spec) {
|
|
93
|
+
return {
|
|
94
|
+
name: "clone",
|
|
95
|
+
image,
|
|
96
|
+
command: ["sh", "-c", CLONE_SCRIPT],
|
|
97
|
+
args: [
|
|
98
|
+
"sh",
|
|
99
|
+
spec.owner,
|
|
100
|
+
spec.repo,
|
|
101
|
+
spec.branch,
|
|
102
|
+
spec.cwd,
|
|
103
|
+
spec.baseBranch ?? "",
|
|
104
|
+
spec.runId ?? "",
|
|
105
|
+
spec.recreateFromBase ? "1" : "",
|
|
106
|
+
],
|
|
107
|
+
workingDir: spec.cwd,
|
|
108
|
+
// Populated in the pod builder to share the creds Secret (GIT_CONFIG_* extraheader).
|
|
109
|
+
envFrom: [],
|
|
110
|
+
volumeMounts: [{ name: "workspace", mountPath: spec.cwd }],
|
|
111
|
+
securityContext: { allowPrivilegeEscalation: false, capabilities: { drop: ["ALL"] } },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=init-clone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-clone.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/init-clone.ts"],"names":[],"mappings":"AA+BA,iFAAiF;AACjF,iFAAiF;AACjF,4EAA4E;AAC5E,kEAAkE;AAClE,E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,CAAC,GAAG;YACR,IAAI,CAAC,UAAU,IAAI,EAAE;YACrB,IAAI,CAAC,KAAK,IAAI,EAAE;YAChB,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;SACjC;QACD,UAAU,EAAE,IAAI,CAAC,GAAG;QACpB,qFAAqF;QACrF,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC;QAC1D,eAAe,EAAE,EAAE,wBAAwB,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE;KACtF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { V1Container } from "@kubernetes/client-node";
|
|
2
|
+
/**
|
|
3
|
+
* The skills initContainer: fetch the per-phase bundle from the harness
|
|
4
|
+
* (bearer token from the creds Secret env, endpoint as a positional arg so it
|
|
5
|
+
* is never interpolated into the script) and unpack it into the shared
|
|
6
|
+
* `skills` emptyDir the agent container reads via `--skill`. `envFrom` (creds
|
|
7
|
+
* Secret) is attached by `buildPodManifest`. `-f` makes curl fail the init on a
|
|
8
|
+
* non-2xx so a bad fetch surfaces (checkInitContainerFailure appends its logs).
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildSkillsInitContainer(image: string, opts: {
|
|
11
|
+
endpoint: string;
|
|
12
|
+
runAsUser: number;
|
|
13
|
+
}): V1Container;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SKILLS_MOUNT_DIR } from "./skill-bundle.js";
|
|
2
|
+
/**
|
|
3
|
+
* The skills initContainer: fetch the per-phase bundle from the harness
|
|
4
|
+
* (bearer token from the creds Secret env, endpoint as a positional arg so it
|
|
5
|
+
* is never interpolated into the script) and unpack it into the shared
|
|
6
|
+
* `skills` emptyDir the agent container reads via `--skill`. `envFrom` (creds
|
|
7
|
+
* Secret) is attached by `buildPodManifest`. `-f` makes curl fail the init on a
|
|
8
|
+
* non-2xx so a bad fetch surfaces (checkInitContainerFailure appends its logs).
|
|
9
|
+
*/
|
|
10
|
+
export function buildSkillsInitContainer(image, opts) {
|
|
11
|
+
const script = 'curl -fsS -H "Authorization: Bearer $LASTLIGHT_SKILL_TOKEN" ' +
|
|
12
|
+
`"$1/internal/skill-bundle" | tar xzf - -C ${SKILLS_MOUNT_DIR}`;
|
|
13
|
+
return {
|
|
14
|
+
name: "skills",
|
|
15
|
+
image,
|
|
16
|
+
command: ["sh", "-c", script],
|
|
17
|
+
args: ["sh", opts.endpoint],
|
|
18
|
+
envFrom: [],
|
|
19
|
+
volumeMounts: [{ name: "skills", mountPath: SKILLS_MOUNT_DIR }],
|
|
20
|
+
securityContext: {
|
|
21
|
+
allowPrivilegeEscalation: false,
|
|
22
|
+
runAsNonRoot: true,
|
|
23
|
+
runAsUser: opts.runAsUser,
|
|
24
|
+
capabilities: { drop: ["ALL"] },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=init-skills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-skills.js","sourceRoot":"","sources":["../../../src/sandbox/k8s/init-skills.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CACtC,KAAa,EACb,IAA6C;IAE7C,MAAM,MAAM,GACV,8DAA8D;QAC9D,6CAA6C,gBAAgB,EAAE,CAAC;IAClE,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,KAAK;QACL,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC;QAC7B,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC;QAC3B,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;QAC/D,eAAe,EAAE;YACf,wBAAwB,EAAE,KAAK;YAC/B,YAAY,EAAE,IAAI;YAClB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE;SAChC;KACF,CAAC;AACJ,CAAC"}
|