Skip to content

test: Add an integration test for LDAP with TLS #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions tests/templates/kuttl/ldap/00-patch-ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# see https://github.com/stackabletech/issues/issues/566
---
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
kubectl patch namespace $NAMESPACE --patch='
{
"metadata": {
"labels": {
"pod-security.kubernetes.io/enforce": "privileged"
}
}
}'
timeout: 120
31 changes: 31 additions & 0 deletions tests/templates/kuttl/ldap/01-rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: test-service-account
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: test-role
rules:
- apiGroups:
- security.openshift.io
resources:
- securitycontextconstraints
resourceNames:
- privileged
verbs:
- use
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: test-role-binding
subjects:
- kind: ServiceAccount
name: test-service-account
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: test-role
12 changes: 12 additions & 0 deletions tests/templates/kuttl/ldap/10-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 300
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: openldap
status:
readyReplicas: 1
replicas: 1
81 changes: 81 additions & 0 deletions tests/templates/kuttl/ldap/10-install-openldap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: openldap
labels:
app.kubernetes.io/name: openldap
spec:
selector:
matchLabels:
app.kubernetes.io/name: openldap
serviceName: openldap
replicas: 1
template:
metadata:
labels:
app.kubernetes.io/name: openldap
spec:
serviceAccountName: test-service-account
containers:
- name: openldap
image: docker.io/bitnami/openldap:2.5
env:
- name: LDAP_ADMIN_USERNAME
value: admin
- name: LDAP_ADMIN_PASSWORD
value: admin
- name: LDAP_ENABLE_TLS
value: "yes"
- name: LDAP_TLS_CERT_FILE
value: /tls/tls.crt
- name: LDAP_TLS_KEY_FILE
value: /tls/tls.key
- name: LDAP_TLS_CA_FILE
value: /tls/ca.crt
ports:
- name: ldap
containerPort: 1389
- name: tls-ldap
containerPort: 1636
volumeMounts:
- name: tls
mountPath: /tls
startupProbe:
tcpSocket:
port: 1389
readinessProbe:
tcpSocket:
port: 1389
# See https://github.com/bitnami/containers/issues/40841#issuecomment-1649977191
securityContext:
capabilities:
drop:
- ALL
add:
- NET_BIND_SERVICE
volumes:
- name: tls
csi:
driver: secrets.stackable.tech
volumeAttributes:
secrets.stackable.tech/class: tls
secrets.stackable.tech/scope: pod
---
apiVersion: v1
kind: Service
metadata:
name: openldap
labels:
app.kubernetes.io/name: openldap
spec:
type: ClusterIP
ports:
- name: ldap
port: 1389
targetPort: ldap
- name: tls-ldap
port: 1636
targetPort: tls-ldap
selector:
app.kubernetes.io/name: openldap
6 changes: 6 additions & 0 deletions tests/templates/kuttl/ldap/11-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
commands:
- script: kubectl exec -n $NAMESPACE openldap-0 -- ldapsearch -H ldap://localhost:1389 -D cn=integrationtest,ou=users,dc=example,dc=org -w integrationtest -b ou=users,dc=example,dc=org > /dev/null
- script: kubectl exec -n $NAMESPACE openldap-0 -- bash -c LDAPTLS_CACERT=/tls/ca.crt ldapsearch -Z -H ldaps://localhost:1636 -D cn=integrationtest,ou=users,dc=example,dc=org -w integrationtest -b ou=users,dc=example,dc=org > /dev/null
8 changes: 8 additions & 0 deletions tests/templates/kuttl/ldap/11-create-ldap-user.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestStep
metadata:
name: create-ldap-user
commands:
- script: kubectl cp -n $NAMESPACE ./create_ldap_user.sh openldap-0:/tmp
- script: kubectl exec -n $NAMESPACE openldap-0 -- sh /tmp/create_ldap_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: >
envsubst '$NAMESPACE' < 20_opensearch-security-config.yaml |
kubectl apply -n $NAMESPACE -f -
106 changes: 106 additions & 0 deletions tests/templates/kuttl/ldap/20_opensearch-security-config.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
apiVersion: v1
kind: Secret
metadata:
name: opensearch-security-config
stringData:
action_groups.yml: |
---
_meta:
type: actiongroups
config_version: 2
allowlist.yml: |
---
_meta:
type: allowlist
config_version: 2

config:
enabled: false
audit.yml: |
---
_meta:
type: audit
config_version: 2

config:
enabled: false
config.yml: |
---
_meta:
type: config
config_version: 2

config:
dynamic:
authc:
ldap:
http_enabled: true
transport_enabled: true
order: 1
http_authenticator:
type: basic
challenge: false
authentication_backend:
type: ldap
config:
enable_ssl: true
hosts:
- openldap.$NAMESPACE.svc.cluster.local:1636
pemtrustedcas_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/ca.crt
userbase: ou=users,dc=example,dc=org
username_attribute: uid
usersearch: (cn={0})
verify_hostnames: true
authz: {}
internal_users.yml: |
---
# The hash value is a bcrypt hash and can be generated with plugin/tools/hash.sh

_meta:
type: internalusers
config_version: 2

admin:
hash: $2y$10$xRtHZFJ9QhG9GcYhRpAGpufCZYsk//nxsuel5URh0GWEBgmiI4Q/e
reserved: true
backend_roles:
- admin
description: OpenSearch admin user

kibanaserver:
hash: $2y$10$vPgQ/6ilKDM5utawBqxoR.7euhVQ0qeGl8mPTeKhmFT475WUDrfQS
reserved: true
description: OpenSearch Dashboards user
nodes_dn.yml: |
---
_meta:
type: nodesdn
config_version: 2
roles.yml: |
---
_meta:
type: roles
config_version: 2
roles_mapping.yml: |
---
_meta:
type: rolesmapping
config_version: 2

all_access:
reserved: false
backend_roles:
- admin
users:
- integrationtest

kibana_server:
reserved: true
users:
- kibanaserver
tenants.yml: |
---
_meta:
type: tenants
config_version: 2
12 changes: 12 additions & 0 deletions tests/templates/kuttl/ldap/21-assert.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 600
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: opensearch-nodes-default
status:
readyReplicas: 3
replicas: 3
66 changes: 66 additions & 0 deletions tests/templates/kuttl/ldap/21-install-opensearch.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
apiVersion: opensearch.stackable.tech/v1alpha1
kind: OpenSearchCluster
metadata:
name: opensearch
spec:
image:
{% if test_scenario['values']['opensearch'].find(",") > 0 %}
custom: "{{ test_scenario['values']['opensearch'].split(',')[1] }}"
productVersion: "{{ test_scenario['values']['opensearch'].split(',')[0] }}"
{% else %}
productVersion: "{{ test_scenario['values']['opensearch'] }}"
{% endif %}
pullPolicy: IfNotPresent
nodes:
roleGroups:
default:
replicas: 3
envOverrides:
DISABLE_INSTALL_DEMO_CONFIG: "true"
OPENSEARCH_HOME: {{ test_scenario['values']['opensearch_home'] }}
configOverrides:
opensearch.yml:
# Disable memory mapping in this test; If memory mapping were activated, the kernel setting
# vm.max_map_count would have to be increased to 262144 on the node.
node.store.allow_mmap: "false"
plugins.security.allow_default_init_securityindex: "true"
plugins.security.ssl.transport.enabled: "true"
plugins.security.ssl.transport.pemcert_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/tls.crt
plugins.security.ssl.transport.pemkey_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/tls.key
plugins.security.ssl.transport.pemtrustedcas_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/ca.crt
plugins.security.ssl.http.enabled: "true"
plugins.security.ssl.http.pemcert_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/tls.crt
plugins.security.ssl.http.pemkey_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/tls.key
plugins.security.ssl.http.pemtrustedcas_filepath: {{ test_scenario['values']['opensearch_home'] }}/config/tls/ca.crt
podOverrides:
spec:
containers:
- name: opensearch
volumeMounts:
- name: security-config
mountPath: {{ test_scenario['values']['opensearch_home'] }}/config/opensearch-security
readOnly: true
- name: tls
mountPath: {{ test_scenario['values']['opensearch_home'] }}/config/tls
readOnly: true
securityContext:
fsGroup: 1000
volumes:
- name: security-config
secret:
secretName: opensearch-security-config
- name: tls
ephemeral:
volumeClaimTemplate:
metadata:
annotations:
secrets.stackable.tech/class: tls
secrets.stackable.tech/scope: node,pod,service=opensearch,service=opensearch-nodes-default-headless
spec:
storageClassName: secrets.stackable.tech
accessModes:
- ReadWriteOnce
resources:
requests:
storage: "1"
11 changes: 11 additions & 0 deletions tests/templates/kuttl/ldap/30-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
timeout: 600
---
apiVersion: batch/v1
kind: Job
metadata:
name: test-opensearch
status:
succeeded: 1
Loading
Loading