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
1 change: 1 addition & 0 deletions .github/workflows/on-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
examples: |
[
{ "example": "examples/secretstacks/minimal.yaml" },
{ "example": "examples/secretstacks/import-identity.yaml" },
{ "example": "examples/secretstacks/standard.yaml" },
{ "example": "examples/secretstacks/vault.yaml" },
{ "example": "examples/secretstacks/vault-external.yaml" },
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/on-push-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
examples: |
[
{ "example": "examples/secretstacks/minimal.yaml" },
{ "example": "examples/secretstacks/import-identity.yaml" },
{ "example": "examples/secretstacks/standard.yaml" },
{ "example": "examples/secretstacks/vault.yaml" },
{ "example": "examples/secretstacks/vault-external.yaml" },
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ generate-configuration:
# Format: example_path::observed_resources_path (observed_resources_path is optional)
EXAMPLES := \
examples/secretstacks/minimal.yaml:: \
examples/secretstacks/import-identity.yaml:: \
examples/secretstacks/standard.yaml:: \
examples/secretstacks/vault.yaml:: \
examples/secretstacks/vault-external.yaml:: \
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,9 @@ make test # run KCL unit tests
hops config install --path xrs/stacks/aws/secret
kubectl apply -f local/secretstack.yaml
```

## Import an existing pod identity

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.

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)
56 changes: 56 additions & 0 deletions apis/secretstacks/definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -121,6 +125,58 @@ spec:
description: AWS configuration. Required when backend=aws (region).
type: object
properties:
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
Expand Down
25 changes: 25 additions & 0 deletions examples/secretstacks/import-identity.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion functions/render/000-state-init.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"labels" $labels
"backend" $backend
"helm" (dict
"chartVersion" ($spec.chartVersion | default "")
"providerConfigRef" $helmProviderConfigRef
"releaseName" ($spec.name | default "external-secrets")
"namespace" $namespace
Expand All @@ -112,6 +113,7 @@
)
"kubernetesProviderConfigRef" $k8sProviderConfigRef
"aws" (dict
"podIdentity" ($aws.podIdentity | default dict)
"enabled" $awsEnabled
"region" $awsRegion
"providerConfigRef" $awsProviderConfigRef
Expand Down Expand Up @@ -146,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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
19 changes: 18 additions & 1 deletion functions/render/210-aws-pod-identity.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

{{- if $state.aws.enabled }}

{{- $identity := $state.aws.podIdentity }}
---
apiVersion: aws.hops.ops.com.ai/v1alpha1
kind: PodIdentity
Expand All @@ -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:
Expand All @@ -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: |
Expand Down Expand Up @@ -71,6 +87,7 @@ spec:
}
]
}
{{- end }}
tags: {{ $state.aws.tags | toJson }}

# Usage: Protect PodIdentity from deletion until Helm release is deleted
Expand Down
31 changes: 31 additions & 0 deletions tests/test-render/main.k
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,37 @@ _items = [
}
}

metav1alpha1.CompositionTest {
metadata.name = "import-existing-identity"
spec = {
compositionPath = "apis/secretstacks/composition.yaml"
xrdPath = "apis/secretstacks/definition.yaml"
xrPath = "examples/secretstacks/import-identity.yaml"
timeoutSeconds = 60
validate = False
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"
}
]
}
}
]

items = _items