Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ Use the build/bin/set-cli-image-digest.sh script to update this value across all
{{- $_cli_image_digest := "sha256:1c5701a24c9796e02b33036f56babbe74032831e1db733ce9228a46dce4a870b" }}

{{ $ns := printf "mas-%s-core" .Values.instance_id }}
{{ $syncres_ns := printf "mas-%s-syncres" .Values.instance_id }}
{{ $prefix := printf "post-jdbc-usr-%s" .Values.mas_config_name }}
{{ $secret := printf "%s-creds" $prefix }}
{{ $sa := printf "%s-sa" $prefix }}
{{ $role := printf "%s-role" $prefix }}
{{ $rb := printf "%s-rb" $prefix }}
{{ $syncres_role := printf "%s-syncres-role" $prefix }}
{{ $syncres_rb := printf "%s-syncres-rb" $prefix }}
{{ $np := printf "%s-np" $prefix }}
{{ $job := printf "%s-job" $prefix }}

Expand All @@ -23,7 +25,7 @@ metadata:
name: {{ $sa }}
namespace: {{ $ns }}
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook: PostDelete
argocd.argoproj.io/hook-delete-policy: HookSucceeded,BeforeHookCreation
{{- if .Values.custom_labels }}
labels:
Expand All @@ -32,6 +34,53 @@ metadata:




---
# Role in syncres namespace — grants the postdelete SA read access to the aws credentials secret.
# This avoids embedding AVP placeholder tokens (sm_aws_access_key_id / sm_aws_secret_access_key)
# as literal env var values in the Job, which would cause AVP to try to resolve them at manifest
# generation time and fail if the upstream AWS SM secret has since been deleted.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ $syncres_role }}
namespace: {{ $syncres_ns }}
annotations:
argocd.argoproj.io/hook: PostDelete
argocd.argoproj.io/hook-delete-policy: HookSucceeded,BeforeHookCreation
{{- if .Values.custom_labels }}
labels:
{{ .Values.custom_labels | toYaml | indent 4 }}
{{- end }}
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]
resourceNames: ["aws"]

---
# RoleBinding in syncres namespace to bind the postdelete SA from mas-core namespace
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ $syncres_rb }}
namespace: {{ $syncres_ns }}
annotations:
argocd.argoproj.io/hook: PostDelete
argocd.argoproj.io/hook-delete-policy: HookSucceeded,BeforeHookCreation
{{- if .Values.custom_labels }}
labels:
{{ .Values.custom_labels | toYaml | indent 4 }}
{{- end }}
subjects:
- kind: ServiceAccount
name: {{ $sa }}
namespace: {{ $ns }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ $syncres_role }}

---
# Role in DB2 namespace for accessing DB2 resources
# This allows the service account from mas-core namespace to access resources in db2 namespace
Expand All @@ -41,7 +90,7 @@ metadata:
name: {{ $role }}
namespace: {{ .Values.db2_namespace }}
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook: PostDelete
argocd.argoproj.io/hook-delete-policy: HookSucceeded,BeforeHookCreation
{{- if .Values.custom_labels }}
labels:
Expand Down Expand Up @@ -70,6 +119,7 @@ rules:
- get
- list


---
# RoleBinding in DB2 namespace to bind the service account from mas-core namespace
kind: RoleBinding
Expand All @@ -78,7 +128,7 @@ metadata:
name: {{ $rb }}
namespace: {{ .Values.db2_namespace }}
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook: PostDelete
argocd.argoproj.io/hook-delete-policy: HookSucceeded,BeforeHookCreation
{{- if .Values.custom_labels }}
labels:
Expand All @@ -93,6 +143,30 @@ roleRef:
kind: Role
name: {{ $role }}

---
# Permit outbound communication by the Job pods
# (Needed to communicate with the K8S HTTP API and AWS SM)
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: {{ $np }}
namespace: {{ $ns }}
annotations:
argocd.argoproj.io/hook: PostDelete
argocd.argoproj.io/hook-delete-policy: HookSucceeded,BeforeHookCreation
{{- if .Values.custom_labels }}
labels:
{{ .Values.custom_labels | toYaml | indent 4 }}
{{- end }}
spec:
podSelector:
matchLabels:
app: {{ $job }}
egress:
- {}
policyTypes:
- Egress

---
apiVersion: batch/v1
kind: Job
Expand Down Expand Up @@ -144,24 +218,16 @@ spec:
- name: MAS_INSTANCE_ID
value: "{{ .Values.instance_id }}"

# Hard-coded for now:
# AWS SM credentials are read at runtime from the aws Secret in the syncres namespace
# (via the syncres Role/RoleBinding above) to avoid embedding AVP placeholder tokens
# as literal values — which would cause manifest generation failures during deprovisioning
# if the upstream AWS SM secret has since been deleted.
- name: AVP_TYPE
value: "aws"
- name: SM_AWS_REGION
valueFrom:
secretKeyRef:
name: aws
key: aws_default_region
- name: SM_AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: aws
key: aws_access_key_id
- name: SM_AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: aws
key: aws_secret_access_key
value: "{{ .Values.region_id }}"
- name: SYNCRES_NS
value: "{{ $syncres_ns }}"

command:
- /bin/sh
Expand All @@ -178,11 +244,15 @@ spec:
SECRETS_KEY_SEPERATOR="/"
SECRET_NAME_JDBC_CONFIG=${ACCOUNT_ID}${SECRETS_KEY_SEPERATOR}${CLUSTER_ID}${SECRETS_KEY_SEPERATOR}${MAS_INSTANCE_ID}${SECRETS_KEY_SEPERATOR}jdbc${SECRETS_KEY_SEPERATOR}${DB2_INSTANCE_NAME}${SECRETS_KEY_SEPERATOR}config

export SM_AWS_ACCESS_KEY_ID=$(oc get secret aws -n ${SYNCRES_NS} -o jsonpath='{.data.aws_access_key_id}' | base64 -d)
export SM_AWS_SECRET_ACCESS_KEY=$(oc get secret aws -n ${SYNCRES_NS} -o jsonpath='{.data.aws_secret_access_key}' | base64 -d)

echo "Params:"
echo " - ACCOUNT_ID ................... ${ACCOUNT_ID}"
echo " - CLUSTER_ID ................... ${CLUSTER_ID}"
echo " - MAS_INSTANCE_ID ................... ${MAS_INSTANCE_ID}"
echo " - SECRET_NAME_JDBC_CONFIG ................... ${SECRET_NAME_JDBC_CONFIG}"
echo " - SYNCRES_NS ................... ${SYNCRES_NS}"
echo " - SM_AWS_REGION ................... ${SM_AWS_REGION}"
echo " - SM_AWS_ACCESS_KEY_ID ................... ${SM_AWS_ACCESS_KEY_ID:0:2}<snip>"
echo " - SM_AWS_SECRET_ACCESS_KEY ................... ${SM_AWS_SECRET_ACCESS_KEY:0:2}<snip>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ metadata:
{{- end }}
finalizers:
- resources-finalizer.argocd.argoproj.io
- post-delete-finalizer.argocd.argoproj.io
- post-delete-finalizer.argocd.argoproj.io
- post-delete-finalizer.argocd.argoproj.io/cleanup
labels:
environment: '{{ $.Values.account.id }}'
Expand Down
Loading