From 7f02b2e806fe0b80bcf75326027ec24358919900 Mon Sep 17 00:00:00 2001 From: Patrick Lee Scott Date: Wed, 2 Dec 2026 16:39:35 -0600 Subject: [PATCH 1/3] feat(eso): support externally managed pod identity [[tasks/harmony-4042]] --- .github/workflows/on-pr.yaml | 1 + .github/workflows/on-push-main.yaml | 1 + Makefile | 1 + README.md | 14 ++++++++ apis/secretstacks/definition.yaml | 8 +++++ examples/secretstacks/external-identity.yaml | 14 ++++++++ functions/render/000-state-init.yaml.gotmpl | 2 ++ ...-helm-release-external-secrets.yaml.gotmpl | 4 +++ .../render/210-aws-pod-identity.yaml.gotmpl | 2 +- tests/test-render/main.k | 32 +++++++++++++++++++ 10 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 examples/secretstacks/external-identity.yaml diff --git a/.github/workflows/on-pr.yaml b/.github/workflows/on-pr.yaml index cc2852e..45bbb43 100644 --- a/.github/workflows/on-pr.yaml +++ b/.github/workflows/on-pr.yaml @@ -33,6 +33,7 @@ jobs: examples: | [ { "example": "examples/secretstacks/minimal.yaml" }, + { "example": "examples/secretstacks/external-identity.yaml" }, { "example": "examples/secretstacks/standard.yaml" }, { "example": "examples/secretstacks/vault.yaml" }, { "example": "examples/secretstacks/vault-external.yaml" }, diff --git a/.github/workflows/on-push-main.yaml b/.github/workflows/on-push-main.yaml index 268402d..2e81809 100644 --- a/.github/workflows/on-push-main.yaml +++ b/.github/workflows/on-push-main.yaml @@ -28,6 +28,7 @@ jobs: examples: | [ { "example": "examples/secretstacks/minimal.yaml" }, + { "example": "examples/secretstacks/external-identity.yaml" }, { "example": "examples/secretstacks/standard.yaml" }, { "example": "examples/secretstacks/vault.yaml" }, { "example": "examples/secretstacks/vault-external.yaml" }, diff --git a/Makefile b/Makefile index 3e4ba70..3592228 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ generate-configuration: # Format: example_path::observed_resources_path (observed_resources_path is optional) EXAMPLES := \ examples/secretstacks/minimal.yaml:: \ + examples/secretstacks/external-identity.yaml:: \ examples/secretstacks/standard.yaml:: \ examples/secretstacks/vault.yaml:: \ examples/secretstacks/vault-external.yaml:: \ diff --git a/README.md b/README.md index 00e724e..d0d55ba 100644 --- a/README.md +++ b/README.md @@ -117,3 +117,17 @@ make test # run KCL unit tests hops config install --path xrs/stacks/aws/secret kubectl apply -f local/secretstack.yaml ``` + +## Externally managed pod identity + +To use an existing EKS association, keep the role and association under their current owner and configure the stack when creating the claim. + +```yaml +spec: + aws: + managePodIdentity: false +``` + +The default is true. Before changing an existing claim to false, transfer ownership of any composed identity you intend to retain. Crossplane removes resources omitted from the desired composition, and their management policies govern external deletion. + +Use `spec.chartVersion` to pin the installed ESO chart during adoption, then test a chart upgrade independently. diff --git a/apis/secretstacks/definition.yaml b/apis/secretstacks/definition.yaml index d198392..66cc143 100644 --- a/apis/secretstacks/definition.yaml +++ b/apis/secretstacks/definition.yaml @@ -97,6 +97,10 @@ spec: description: external-secrets Helm values merged with defaults. type: object x-kubernetes-preserve-unknown-fields: true + chartVersion: + description: Pin the External Secrets Operator Helm chart version during import or a staged upgrade. Defaults to the version bundled with this stack. + type: string + minLength: 1 overrideAllValues: description: external-secrets Helm values that replace all defaults. type: object @@ -121,6 +125,10 @@ spec: description: AWS configuration. Required when backend=aws (region). type: object properties: + managePodIdentity: + description: Manage the IAM role and EKS association for the service account. Set false when identity is managed separately. + type: boolean + default: true region: description: AWS region for the EKS cluster and Secrets Manager. type: string diff --git a/examples/secretstacks/external-identity.yaml b/examples/secretstacks/external-identity.yaml new file mode 100644 index 0000000..066e48e --- /dev/null +++ b/examples/secretstacks/external-identity.yaml @@ -0,0 +1,14 @@ +apiVersion: hops.ops.com.ai/v1alpha1 +kind: SecretStack +metadata: + name: existing + namespace: default +spec: + clusterName: example + aws: + region: us-east-2 + managePodIdentity: false + backend: aws + secretStore: + enabled: false + chartVersion: 2.2.0 diff --git a/functions/render/000-state-init.yaml.gotmpl b/functions/render/000-state-init.yaml.gotmpl index 7afb800..03ae506 100644 --- a/functions/render/000-state-init.yaml.gotmpl +++ b/functions/render/000-state-init.yaml.gotmpl @@ -104,6 +104,7 @@ "labels" $labels "backend" $backend "helm" (dict + "chartVersion" ($spec.chartVersion | default "") "providerConfigRef" $helmProviderConfigRef "releaseName" ($spec.name | default "external-secrets") "namespace" $namespace @@ -112,6 +113,7 @@ ) "kubernetesProviderConfigRef" $k8sProviderConfigRef "aws" (dict + "managePodIdentity" (dig "managePodIdentity" true $aws) "enabled" $awsEnabled "region" $awsRegion "providerConfigRef" $awsProviderConfigRef diff --git a/functions/render/200-helm-release-external-secrets.yaml.gotmpl b/functions/render/200-helm-release-external-secrets.yaml.gotmpl index e6943eb..2e2245d 100644 --- a/functions/render/200-helm-release-external-secrets.yaml.gotmpl +++ b/functions/render/200-helm-release-external-secrets.yaml.gotmpl @@ -34,8 +34,12 @@ spec: chart: name: external-secrets repository: https://charts.external-secrets.io + {{- if $state.helm.chartVersion }} + version: {{ $state.helm.chartVersion | quote }} + {{- else }} # renovate: datasource=helm depName=external-secrets registryUrl=https://charts.external-secrets.io version: "2.15.0" + {{- end }} namespace: {{ $state.helm.namespace }} values: {{- if $state.helm.overrideAllValues }} diff --git a/functions/render/210-aws-pod-identity.yaml.gotmpl b/functions/render/210-aws-pod-identity.yaml.gotmpl index 74f9a1c..849ead5 100644 --- a/functions/render/210-aws-pod-identity.yaml.gotmpl +++ b/functions/render/210-aws-pod-identity.yaml.gotmpl @@ -4,7 +4,7 @@ # Only rendered when backend=aws. # -{{- if $state.aws.enabled }} +{{- if and $state.aws.enabled $state.aws.managePodIdentity }} --- apiVersion: aws.hops.ops.com.ai/v1alpha1 diff --git a/tests/test-render/main.k b/tests/test-render/main.k index 5e9bf9d..2f17f92 100644 --- a/tests/test-render/main.k +++ b/tests/test-render/main.k @@ -357,6 +357,38 @@ _items = [ } } + metav1alpha1.CompositionTest { + metadata.name = "externally-managed-identity" + spec = { + compositionPath = "apis/secretstacks/composition.yaml" + xrdPath = "apis/secretstacks/definition.yaml" + xrPath = "examples/secretstacks/external-identity.yaml" + timeoutSeconds = 60 + validate = False + observedResources = [{ + apiVersion = "helm.m.crossplane.io/v1beta1" + kind = "Release" + metadata.name = "external-secrets" + metadata.namespace = "default" + metadata.annotations = {"crossplane.io/composition-resource-name" = "helm-external-secrets"} + status.conditions = [{type = "Ready", status = "True"}] + }] + assertResources = [ + { + apiVersion = "helm.m.crossplane.io/v1beta1" + kind = "Release" + metadata.name = "external-secrets" + spec.forProvider.chart.version = "2.2.0" + } + { + apiVersion = "hops.ops.com.ai/v1alpha1" + kind = "SecretStack" + metadata.name = "existing" + status.conditions = [{type = "Ready", status = "True"}] + } + ] + } + } ] items = _items From f77f2cd455c55ce7897bcc9791695153fec4dcef Mon Sep 17 00:00:00 2001 From: Patrick Lee Scott Date: Wed, 2 Dec 2026 16:41:39 -0600 Subject: [PATCH 2/3] test(eso): assert the exact composed resource list --- tests/test-render/main.k | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test-render/main.k b/tests/test-render/main.k index 2f17f92..422060b 100644 --- a/tests/test-render/main.k +++ b/tests/test-render/main.k @@ -384,7 +384,11 @@ _items = [ apiVersion = "hops.ops.com.ai/v1alpha1" kind = "SecretStack" metadata.name = "existing" - status.conditions = [{type = "Ready", status = "True"}] + spec.crossplane.resourceRefs = [{ + apiVersion = "helm.m.crossplane.io/v1beta1" + kind = "Release" + name = "external-secrets" + }] } ] } From 686b24e3980053ceff4f6cf7522d5b6d384a748a Mon Sep 17 00:00:00 2001 From: Patrick Lee Scott Date: Wed, 2 Dec 2026 16:45:51 -0600 Subject: [PATCH 3/3] feat(eso): adopt existing managed pod identities [[tasks/harmony-4042]] --- .github/workflows/on-pr.yaml | 2 +- .github/workflows/on-push-main.yaml | 2 +- Makefile | 2 +- README.md | 14 +---- apis/secretstacks/definition.yaml | 56 +++++++++++++++++-- examples/secretstacks/external-identity.yaml | 14 ----- examples/secretstacks/import-identity.yaml | 25 +++++++++ functions/render/000-state-init.yaml.gotmpl | 4 +- .../render/210-aws-pod-identity.yaml.gotmpl | 21 ++++++- tests/test-render/main.k | 35 +++++------- 10 files changed, 119 insertions(+), 56 deletions(-) delete mode 100644 examples/secretstacks/external-identity.yaml create mode 100644 examples/secretstacks/import-identity.yaml diff --git a/.github/workflows/on-pr.yaml b/.github/workflows/on-pr.yaml index 45bbb43..bf5922f 100644 --- a/.github/workflows/on-pr.yaml +++ b/.github/workflows/on-pr.yaml @@ -33,7 +33,7 @@ jobs: examples: | [ { "example": "examples/secretstacks/minimal.yaml" }, - { "example": "examples/secretstacks/external-identity.yaml" }, + { "example": "examples/secretstacks/import-identity.yaml" }, { "example": "examples/secretstacks/standard.yaml" }, { "example": "examples/secretstacks/vault.yaml" }, { "example": "examples/secretstacks/vault-external.yaml" }, diff --git a/.github/workflows/on-push-main.yaml b/.github/workflows/on-push-main.yaml index 2e81809..abe2722 100644 --- a/.github/workflows/on-push-main.yaml +++ b/.github/workflows/on-push-main.yaml @@ -28,7 +28,7 @@ jobs: examples: | [ { "example": "examples/secretstacks/minimal.yaml" }, - { "example": "examples/secretstacks/external-identity.yaml" }, + { "example": "examples/secretstacks/import-identity.yaml" }, { "example": "examples/secretstacks/standard.yaml" }, { "example": "examples/secretstacks/vault.yaml" }, { "example": "examples/secretstacks/vault-external.yaml" }, diff --git a/Makefile b/Makefile index 3592228..2dae5ed 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ generate-configuration: # Format: example_path::observed_resources_path (observed_resources_path is optional) EXAMPLES := \ examples/secretstacks/minimal.yaml:: \ - examples/secretstacks/external-identity.yaml:: \ + examples/secretstacks/import-identity.yaml:: \ examples/secretstacks/standard.yaml:: \ examples/secretstacks/vault.yaml:: \ examples/secretstacks/vault-external.yaml:: \ diff --git a/README.md b/README.md index d0d55ba..8ccef4a 100644 --- a/README.md +++ b/README.md @@ -118,16 +118,8 @@ hops config install --path xrs/stacks/aws/secret kubectl apply -f local/secretstack.yaml ``` -## Externally managed pod identity +## Import an existing pod identity -To use an existing EKS association, keep the role and association under their current owner and configure the stack when creating the claim. +Use `spec.aws.podIdentity` to set the existing PodIdentity composite name, IAM role name and EKS association ID. Start with identity management policies set to Observe. Supply the complete inline policies and managed policy ARNs that the role should have when you enable Update. An explicit empty list replaces that policy set. Omitting either list retains the stack's defaults. Pin the current controller chart with `spec.chartVersion` to test the chart upgrade separately. -```yaml -spec: - aws: - managePodIdentity: false -``` - -The default is true. Before changing an existing claim to false, transfer ownership of any composed identity you intend to retain. Crossplane removes resources omitted from the desired composition, and their management policies govern external deletion. - -Use `spec.chartVersion` to pin the installed ESO chart during adoption, then test a chart upgrade independently. +Match the cluster, namespace and service account to the existing association. Transfer the existing writer before enabling updates and verify the same role and association IDs after reconciliation. The stack keeps managing its PodIdentity and its deletion dependency. [Import example](examples/secretstacks/import-identity.yaml) diff --git a/apis/secretstacks/definition.yaml b/apis/secretstacks/definition.yaml index 66cc143..ddefbd9 100644 --- a/apis/secretstacks/definition.yaml +++ b/apis/secretstacks/definition.yaml @@ -125,10 +125,58 @@ spec: description: AWS configuration. Required when backend=aws (region). type: object properties: - managePodIdentity: - description: Manage the IAM role and EKS association for the service account. Set false when identity is managed separately. - type: boolean - default: true + podIdentity: + type: object + description: Import and policy settings for the composed PodIdentity. Omitted policies retain the stack defaults. + properties: + name: + type: string + minLength: 1 + maxLength: 253 + pattern: '^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$' + description: Name of the PodIdentity composite in the stack namespace. + role: + type: object + required: [externalName] + properties: + externalName: + type: string + minLength: 1 + description: Existing IAM role name, as recorded on the Role managed resource. + association: + type: object + required: [externalName] + properties: + externalName: + type: string + minLength: 1 + description: Existing EKS Pod Identity association ID for this cluster and service account. + managementPolicies: + type: array + minItems: 1 + description: Management actions for the identity leaves. Defaults to the stack management policies. + items: + type: string + enum: ["*", Observe, Create, Update, Delete, LateInitialize] + inlinePolicy: + type: array + description: Complete replacement for the default IAM inline policies, including an explicit empty list. + items: + type: object + required: [name, policy] + properties: + name: + type: string + minLength: 1 + policy: + type: string + minLength: 1 + managedPolicyArns: + type: array + description: Complete replacement for the default IAM managed policy ARNs, including an explicit empty list. + items: + type: string + minLength: 1 region: description: AWS region for the EKS cluster and Secrets Manager. type: string diff --git a/examples/secretstacks/external-identity.yaml b/examples/secretstacks/external-identity.yaml deleted file mode 100644 index 066e48e..0000000 --- a/examples/secretstacks/external-identity.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: hops.ops.com.ai/v1alpha1 -kind: SecretStack -metadata: - name: existing - namespace: default -spec: - clusterName: example - aws: - region: us-east-2 - managePodIdentity: false - backend: aws - secretStore: - enabled: false - chartVersion: 2.2.0 diff --git a/examples/secretstacks/import-identity.yaml b/examples/secretstacks/import-identity.yaml new file mode 100644 index 0000000..2f80235 --- /dev/null +++ b/examples/secretstacks/import-identity.yaml @@ -0,0 +1,25 @@ +apiVersion: hops.ops.com.ai/v1alpha1 +kind: SecretStack +metadata: + name: existing + namespace: default +spec: + clusterName: example + aws: + region: us-east-2 + podIdentity: + name: existing-controller + role: + externalName: example-controller + association: + externalName: a-0123456789abcdef0 + managementPolicies: + - Observe + inlinePolicy: [] + managedPolicyArns: [] + backend: aws + secretStore: + enabled: false + chartVersion: 2.2.0 + managementPolicies: + - Observe diff --git a/functions/render/000-state-init.yaml.gotmpl b/functions/render/000-state-init.yaml.gotmpl index 03ae506..c99a073 100644 --- a/functions/render/000-state-init.yaml.gotmpl +++ b/functions/render/000-state-init.yaml.gotmpl @@ -113,7 +113,7 @@ ) "kubernetesProviderConfigRef" $k8sProviderConfigRef "aws" (dict - "managePodIdentity" (dig "managePodIdentity" true $aws) + "podIdentity" ($aws.podIdentity | default dict) "enabled" $awsEnabled "region" $awsRegion "providerConfigRef" $awsProviderConfigRef @@ -148,7 +148,7 @@ "name" ($secretStoreSpec.name | default "default") ) "podIdentity" (dict - "name" (printf "%s-external-secrets" $name) + "name" (dig "podIdentity" "name" (printf "%s-external-secrets" $name) $aws) ) "serviceAccount" (dict "name" "external-secrets" diff --git a/functions/render/210-aws-pod-identity.yaml.gotmpl b/functions/render/210-aws-pod-identity.yaml.gotmpl index 849ead5..73abb2a 100644 --- a/functions/render/210-aws-pod-identity.yaml.gotmpl +++ b/functions/render/210-aws-pod-identity.yaml.gotmpl @@ -4,8 +4,9 @@ # Only rendered when backend=aws. # -{{- if and $state.aws.enabled $state.aws.managePodIdentity }} +{{- if $state.aws.enabled }} +{{- $identity := $state.aws.podIdentity }} --- apiVersion: aws.hops.ops.com.ai/v1alpha1 kind: PodIdentity @@ -15,7 +16,7 @@ metadata: {{ setResourceNameAnnotation "pod-identity" }} labels: {{ $state.labels | toJson }} spec: - managementPolicies: {{ $state.managementPolicies | toJson }} + managementPolicies: {{ dig "managementPolicies" $state.managementPolicies $identity | toJson }} clusterName: {{ $state.clusterName }} region: {{ $state.aws.region }} providerConfigRef: @@ -27,9 +28,24 @@ spec: {{- if $state.aws.permissionsBoundaryArn }} permissionsBoundaryArn: {{ $state.aws.permissionsBoundaryArn }} {{- end }} + {{- with $identity.role }} + role: + externalName: {{ .externalName | quote }} + roleNameOverride: {{ .externalName | quote }} + {{- end }} + {{- with $identity.association }} + association: + externalName: {{ .externalName | quote }} + {{- end }} serviceAccount: name: {{ $state.serviceAccount.name }} namespace: {{ $state.serviceAccount.namespace }} + {{- if hasKey $identity "managedPolicyArns" }} + managedPolicyArns: {{ $identity.managedPolicyArns | toJson }} + {{- end }} + {{- if hasKey $identity "inlinePolicy" }} + inlinePolicy: {{ $identity.inlinePolicy | toJson }} + {{- else }} inlinePolicy: - name: external-secrets policy: | @@ -71,6 +87,7 @@ spec: } ] } + {{- end }} tags: {{ $state.aws.tags | toJson }} # Usage: Protect PodIdentity from deletion until Helm release is deleted diff --git a/tests/test-render/main.k b/tests/test-render/main.k index 422060b..f3aef02 100644 --- a/tests/test-render/main.k +++ b/tests/test-render/main.k @@ -358,38 +358,33 @@ _items = [ } metav1alpha1.CompositionTest { - metadata.name = "externally-managed-identity" + metadata.name = "import-existing-identity" spec = { compositionPath = "apis/secretstacks/composition.yaml" xrdPath = "apis/secretstacks/definition.yaml" - xrPath = "examples/secretstacks/external-identity.yaml" + xrPath = "examples/secretstacks/import-identity.yaml" timeoutSeconds = 60 validate = False - observedResources = [{ - apiVersion = "helm.m.crossplane.io/v1beta1" - kind = "Release" - metadata.name = "external-secrets" - metadata.namespace = "default" - metadata.annotations = {"crossplane.io/composition-resource-name" = "helm-external-secrets"} - status.conditions = [{type = "Ready", status = "True"}] - }] assertResources = [ + { + apiVersion = "aws.hops.ops.com.ai/v1alpha1" + kind = "PodIdentity" + metadata.name = "existing-controller" + spec = { + managementPolicies = ["Observe"] + roleNameOverride = "example-controller" + role.externalName = "example-controller" + association.externalName = "a-0123456789abcdef0" + inlinePolicy = [] + managedPolicyArns = [] + } + } { apiVersion = "helm.m.crossplane.io/v1beta1" kind = "Release" metadata.name = "external-secrets" spec.forProvider.chart.version = "2.2.0" } - { - apiVersion = "hops.ops.com.ai/v1alpha1" - kind = "SecretStack" - metadata.name = "existing" - spec.crossplane.resourceRefs = [{ - apiVersion = "helm.m.crossplane.io/v1beta1" - kind = "Release" - name = "external-secrets" - }] - } ] } }