Security Guide
Security hardening for Lynq: credential management with SecretRef, RBAC least-privilege roles, audit logging, and namespace isolation practices.
Security Checklist
Before going to production:
- Database password stored in a Kubernetes Secret, referenced via
passwordRef - Operator ClusterRole scoped to only the API groups your nodes need
-
secretsverb limited to the namespaces where node Secrets are created - Kubernetes audit policy captures changes to
operator.lynq.shresources - Container images scanned for vulnerabilities
- Node isolation strategy chosen (namespace-per-node recommended)
- NetworkPolicies applied if nodes should not communicate with each other
Credentials Management
Always use Kubernetes Secrets for sensitive data. Never hardcode credentials in CRDs or templates.
apiVersion: v1
kind: Secret
metadata:
name: mysql-credentials
namespace: lynq-system
type: Opaque
stringData:
password: your-secure-passwordReference in LynqHub:
spec:
source:
mysql:
passwordRef:
name: mysql-credentials
key: passwordRotating credentials: Update the Secret — the operator detects the change and reconnects automatically. No pod restart required.
Sensitive data in templates: Store only references in database columns, not actual secrets.
-- Store a reference, not the value
api_key_ref = "secret-acme-api-key"# Resolve the reference in templates
env:
- name: API_KEY
valueFrom:
secretKeyRef:
name: "{{ .uid }}-secrets"
key: api-keyRBAC
Operator Permissions
The operator service account (lynq-controller-manager) requires:
| Resource | Verbs | Scope |
|---|---|---|
lynqhubs, lynqforms, lynqnodes | * | Cluster |
lynqhubs/status, lynqforms/status, lynqnodes/status | get, update, patch | Cluster |
namespaces | get, list, watch, create | Cluster |
| Managed resources (Deployments, Services, etc.) | * | Target namespaces |
events | create, patch | All namespaces |
leases | get, create, update | lynq-system |
secrets | * | Namespaces with node credentials |
Minimal Single-Namespace Role
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: lynq-role
namespace: production
rules:
- apiGroups: [""]
resources: ["services", "configmaps", "secrets", "serviceaccounts", "persistentvolumeclaims"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: ["apps"]
resources: ["deployments", "statefulsets", "daemonsets"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: ["networking.k8s.io"]
resources: ["ingresses", "networkpolicies"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: ["batch"]
resources: ["jobs", "cronjobs"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: lynq-binding
namespace: production
subjects:
- kind: ServiceAccount
name: lynq-controller-manager
namespace: lynq-system
roleRef:
kind: Role
name: lynq-role
apiGroup: rbac.authorization.k8s.ioRead-Only Viewer Role
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: lynq-viewer
rules:
- apiGroups: ["operator.lynq.sh"]
resources: ["lynqhubs", "lynqforms", "lynqnodes"]
verbs: ["get", "list", "watch"]Verify Permissions
# Check a specific permission
kubectl auth can-i create deployments -n production \
--as=system:serviceaccount:lynq-system:lynq-controller-manager
# List all permissions
kubectl auth can-i --list \
--as=system:serviceaccount:lynq-system:lynq-controller-manager
# Debug "forbidden" errors in logs
kubectl logs -n lynq-system deployment/lynq-controller-manager | grep forbiddenAudit Logging
Configure Kubernetes audit policy to capture all changes to Lynq CRDs:
# audit-policy.yaml
apiVersion: audit.k8s.io/v1
kind: Policy
rules:
- level: RequestResponse
resources:
- group: "operator.lynq.sh"
resources: ["lynqhubs", "lynqforms", "lynqnodes"]Monitor events for lifecycle changes:
kubectl get events --all-namespaces --field-selector involvedObject.kind=LynqNodeMulti-Tenant Isolation
To isolate node resources using namespace-per-node, NetworkPolicy, and ResourceQuota, see Multi-Tenant Isolation.
Key compliance patterns using Lynq policies:
# Retain PVC data after node deletion (compliance/audit)
persistentVolumeClaims:
- id: data
deletionPolicy: Retain
# Immutable audit log ConfigMap
configMaps:
- id: audit-log
creationPolicy: OnceVulnerability Management
# Scan operator image
trivy image ghcr.io/k8s-lynq/lynq:latest
# Check Go dependency vulnerabilities
go list -json -m all | nancy sleuthSee Also
- Multi-Tenant Isolation — namespace isolation, NetworkPolicy, ResourceQuota.
- Configuration — controller flags and resource limits.
- Installation — initial RBAC setup via Helm or Kustomize.
Multi-Tenant Isolation
Each node gets its own namespace, network boundary, and resource quota — enforced by Lynq automatically from database rows. Add a customer; isolation follows.
Time to working
~10 minutes to apply the complete isolation template. New nodes are isolated automatically from the first sync.
How It Works
- Namespace-per-node —
targetNamespace: "{{ .uid }}"creates a dedicated namespace for every node. - NetworkPolicy — default-deny plus allow-internal rules confine traffic to the node's own namespace.
- ResourceQuota — CPU/memory/pod limits prevent any single node from exhausting cluster resources.
Prerequisites
- A CNI that enforces NetworkPolicy (Calico, Cilium, Weave Net, or similar). Flannel does not enforce policies by default.
- Operator RBAC must include
namespacescreate/delete andnetworkpoliciesall verbs.
Isolation Models
Namespace-per-Node (Recommended)
Each node gets its own namespace for complete isolation:
apiVersion: operator.lynq.sh/v1
kind: LynqForm
metadata:
name: isolated-node
spec:
hubId: customer-hub
namespaces:
- id: node-ns
nameTemplate: "{{ .uid }}"
spec:
labels:
lynq.sh/node: "{{ .uid }}"
environment: production
deployments:
- id: app
targetNamespace: "{{ .uid }}"
nameTemplate: "{{ .uid }}-app"
dependIds: ["node-ns"]
spec:
# ... deployment specShared Namespace with Labels
Multiple nodes share namespaces, isolated by label selectors. Simpler but provides weaker security boundaries:
deployments:
- id: app
nameTemplate: "{{ .uid }}-app"
labelsTemplate:
lynq.sh/node: "{{ .uid }}"
tenant: "{{ .uid }}"
spec:
template:
metadata:
labels:
lynq.sh/node: "{{ .uid }}"Network Isolation with NetworkPolicy
Default Deny All
Apply as the first policy in every node namespace:
networkPolicies:
- id: default-deny
nameTemplate: "default-deny"
targetNamespace: "{{ .uid }}"
dependIds: ["node-ns"]
spec:
podSelector: {}
policyTypes:
- Ingress
- EgressAllow Internal Communication
Pods within the same node namespace can communicate:
networkPolicies:
- id: allow-internal
nameTemplate: "allow-internal"
targetNamespace: "{{ .uid }}"
dependIds: ["default-deny"]
spec:
podSelector:
matchLabels:
lynq.sh/node: "{{ .uid }}"
policyTypes: [Ingress, Egress]
ingress:
- from:
- podSelector:
matchLabels:
lynq.sh/node: "{{ .uid }}"
egress:
- to:
- podSelector:
matchLabels:
lynq.sh/node: "{{ .uid }}"Allow DNS Resolution
Required for any pod that resolves service names:
networkPolicies:
- id: allow-dns
nameTemplate: "allow-dns"
targetNamespace: "{{ .uid }}"
dependIds: ["default-deny"]
spec:
podSelector: {}
policyTypes: [Egress]
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53Allow External Ingress
Permit traffic from your ingress controller:
networkPolicies:
- id: allow-ingress
nameTemplate: "allow-ingress"
targetNamespace: "{{ .uid }}"
dependIds: ["default-deny"]
spec:
podSelector:
matchLabels:
lynq.sh/node: "{{ .uid }}"
policyTypes: [Ingress]
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
podSelector:
matchLabels:
app.kubernetes.io/name: ingress-nginx
ports:
- protocol: TCP
port: 8080Resource Quotas per Node
Prevent resource exhaustion by scoping CPU, memory, and object counts per namespace:
manifests:
- id: quota
nameTemplate: "resource-quota"
targetNamespace: "{{ .uid }}"
dependIds: ["node-ns"]
spec:
apiVersion: v1
kind: ResourceQuota
metadata:
name: node-quota
spec:
hard:
requests.cpu: "2"
requests.memory: "4Gi"
limits.cpu: "4"
limits.memory: "8Gi"
pods: "20"
services: "10"
persistentvolumeclaims: "5"Complete Isolation Template
Combine namespace, network policies, and quota into a single LynqForm:
apiVersion: operator.lynq.sh/v1
kind: LynqForm
metadata:
name: secure-node
spec:
hubId: customer-hub
namespaces:
- id: node-ns
nameTemplate: "{{ .uid }}"
spec:
labels:
lynq.sh/node: "{{ .uid }}"
networkPolicies:
- id: default-deny
nameTemplate: "default-deny"
targetNamespace: "{{ .uid }}"
dependIds: ["node-ns"]
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
- id: allow-dns
nameTemplate: "allow-dns"
targetNamespace: "{{ .uid }}"
dependIds: ["default-deny"]
spec:
podSelector: {}
policyTypes: [Egress]
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- protocol: UDP
port: 53
- id: allow-internal
nameTemplate: "allow-internal"
targetNamespace: "{{ .uid }}"
dependIds: ["default-deny"]
spec:
podSelector:
matchLabels:
lynq.sh/node: "{{ .uid }}"
policyTypes: [Ingress, Egress]
ingress:
- from:
- podSelector:
matchLabels:
lynq.sh/node: "{{ .uid }}"
egress:
- to:
- podSelector:
matchLabels:
lynq.sh/node: "{{ .uid }}"
manifests:
- id: quota
nameTemplate: "resource-quota"
targetNamespace: "{{ .uid }}"
dependIds: ["node-ns"]
spec:
apiVersion: v1
kind: ResourceQuota
metadata:
name: node-quota
spec:
hard:
requests.cpu: "2"
requests.memory: "4Gi"
limits.cpu: "4"
limits.memory: "8Gi"
pods: "20"
deployments:
- id: app
nameTemplate: "app"
targetNamespace: "{{ .uid }}"
dependIds: ["allow-internal", "allow-dns", "quota"]
spec:
# ... deployment specVerify It Works
# List namespaces created by Lynq
kubectl get namespaces -l lynq.sh/node
# List NetworkPolicies for a specific node
kubectl get networkpolicies -n acme-corp
# Test cross-node traffic is blocked
kubectl run test --rm -it -n acme-corp --image=busybox -- \
wget -T 5 http://app.other-node.svc.cluster.local
# Expected: wget: download timed out
# Test internal traffic succeeds
kubectl run test --rm -it -n acme-corp --image=busybox -- \
wget -T 5 http://app.acme-corp.svc.cluster.local
# Expected: connected
# Verify resource quota
kubectl describe resourcequota node-quota -n acme-corpCaveats
- CNI requirement: NetworkPolicy enforcement requires a compatible CNI plugin. Flannel does not enforce policies without an additional plugin.
- Namespace deletion lag: When a node is deactivated, Lynq deletes the namespace. Kubernetes namespace deletion is asynchronous — the namespace enters
Terminatingstate while child resources are cleaned up. This can take 30–60 seconds for namespaces with many resources. - ResourceQuota is not a hard wall: CPU limits only apply when pods specify
resources.limits. Pods without limits can still exhaust node CPU. - NetworkPolicy scope: Policies only apply within the cluster. They do not control traffic to/from external services unless you add explicit egress rules for those CIDRs.
See Also
- Security Guide — RBAC, credentials, and audit logging.
- Dependencies — Order namespace creation before deploying workloads into it.
- Policies — DeletionPolicy Retain for keeping namespaces after node deactivation.
- Templates — Dynamic namespace naming and targetNamespace.
Troubleshooting
Diagnose Lynq issues by symptom: TLS errors, hub sync failures, nodes not provisioning, resource lifecycle problems, and performance.
Performance Tuning Guide
Tuning guide for Lynq at scale. Covers concurrency flags, requeue intervals, watch predicates, and large node count recommendations.