SyncSecret Overview
SyncSecret is a wrapper around Kubernetes Secret objects that enables secure, controlled synchronization between tenant clusters and the KubeLB management cluster.SyncSecret provides the same functionality as Kubernetes Secrets but with controlled propagation across cluster boundaries.
Key Features
- Controlled Propagation: Secrets are only synced when explicitly wrapped in a SyncSecret
- Namespace Isolation: Secrets are confined to tenant-specific namespaces
- Automatic Cleanup: Finalizers ensure secrets are properly deleted when no longer needed
- UID-Based Naming: Secrets are stored with randomized names to prevent collisions
Architecture
Synchronization Flow
Component Responsibilities
CCM (Cloud Controller Manager)
Location: Runs in tenant clusters Responsibilities:- Watch for SyncSecret resources in the tenant cluster
- Propagate SyncSecret to the management cluster’s tenant namespace
- Add origin labels (
kubelb.k8c.io/origin-name,kubelb.k8c.io/origin-namespace) - Use UID-based naming to prevent conflicts
- Handle cleanup when the original SyncSecret is deleted
internal/controllers/ccm/sync_secret_controller.go:111
Manager
Location: Runs in the management cluster Responsibilities:- Watch for SyncSecret resources in tenant namespaces
- Create corresponding Kubernetes Secret with the same data
- Maintain owner references for automatic cleanup
- Update secrets when SyncSecret changes
- Delete secrets when SyncSecret is removed
internal/controllers/kubelb/sync_secret_controller.go:108
SyncSecret CRD
Resource Definition
Fields
The SyncSecret CRD mirrors the Kubernetes Secret structure:| Field | Type | Description |
|---|---|---|
data | map[string][]byte | Secret data as base64-encoded strings |
stringData | map[string]string | Secret data as plain strings (encoded on creation) |
type | corev1.SecretType | Type of secret (Opaque, kubernetes.io/tls, etc.) |
immutable | *bool | If true, the secret data cannot be updated |
api/ce/kubelb.k8c.io/v1alpha1/sync_secret_types.go:28
Supported Secret Types
SyncSecret supports all Kubernetes secret types:Opaque- Default secret typekubernetes.io/tls- TLS certificateskubernetes.io/dockerconfigjson- Docker registry credentialskubernetes.io/basic-auth- Basic authentication credentialskubernetes.io/ssh-auth- SSH authentication credentialskubernetes.io/service-account-token- Service account tokens
Usage Examples
TLS Certificate for Ingress
Create a SyncSecret for TLS certificates used by Ingress resources:Docker Registry Credentials
Create a SyncSecret for private Docker registry access:Opaque Secret
Create a generic secret for application configuration:Security Considerations
UID-Based Naming
Secrets are stored in the management cluster using the SyncSecret’s UID as the name:- Collision Prevention: No risk of name conflicts between tenants
- Security Through Obscurity: Secret names are not predictable
- Automatic Uniqueness: UIDs are guaranteed unique by Kubernetes
internal/controllers/ccm/sync_secret_controller.go:120
Origin Tracking
The CCM adds labels to track the original secret location:- Audit trails for secret propagation
- Troubleshooting secret sources
- Preventing unauthorized modifications
internal/controllers/ccm/sync_secret_controller.go:115
Owner References
Secrets include owner references to their parent SyncSecret:- Automatic Cleanup: Secrets are deleted when the SyncSecret is removed
- Garbage Collection: Kubernetes automatically handles orphaned secrets
- Clear Ownership: Easy to trace which SyncSecret owns each secret
internal/controllers/kubelb/sync_secret_controller.go:121
Finalizers
Both CCM and Manager controllers use finalizers (kubelb.k8c.io/lb-finalizer) to ensure proper cleanup:
CCM Cleanup:
- Delete the SyncSecret from the management cluster
- Wait for deletion to complete
- Remove finalizer from the tenant cluster SyncSecret
- Delete the Kubernetes Secret from the management cluster
- Wait for deletion to complete
- Remove finalizer from the SyncSecret
RBAC Permissions
Manager Permissions
The KubeLB manager requires permissions for both SyncSecrets and Secrets:config/rbac/role.yaml:250
CCM Permissions
The CCM requires permissions to manage SyncSecrets:CCM does not need direct access to Kubernetes Secrets in the management cluster. All synchronization happens through the SyncSecret CRD.
Reconciliation Logic
CCM Reconciliation
The CCM controller:- Watches SyncSecrets in the tenant cluster
- Adds origin labels for tracking
- Updates the namespace to the tenant’s management namespace
- Resets the UID to generate a new one in the management cluster
- Creates or updates the SyncSecret in the management cluster
- Handles conflicts with retry logic
internal/controllers/ccm/sync_secret_controller.go:111
Manager Reconciliation
The Manager controller:- Watches SyncSecrets in tenant namespaces
- Creates a Kubernetes Secret with the same data
- Uses the SyncSecret UID as the Secret name
- Sets owner references for automatic cleanup
- Updates the Secret when the SyncSecret changes
- Performs semantic equality checks to avoid unnecessary updates
internal/controllers/kubelb/sync_secret_controller.go:108
Update Detection
Both controllers use semantic equality checks to avoid unnecessary updates:internal/controllers/kubelb/sync_secret_controller.go:149
Monitoring and Metrics
Prometheus Metrics
SyncSecret controllers expose Prometheus metrics: CCM Metrics:kubelb_ccm_sync_secret_reconcile_total{namespace, result}- Total reconciliationskubelb_ccm_sync_secret_reconcile_duration_seconds{namespace}- Reconciliation duration
kubelb_manager_sync_secret_reconcile_total{namespace, result}- Total reconciliationskubelb_manager_sync_secret_reconcile_duration_seconds{namespace}- Reconciliation duration
Logging
Both controllers log key events:- SyncSecret creation
- SyncSecret updates
- Secret synchronization
- Cleanup operations
- Reconciliation errors
Troubleshooting
Secret Not Appearing in Management Cluster
Check:- Verify the SyncSecret exists in the tenant cluster
- Check CCM logs for propagation errors
- Verify CCM has permissions to create SyncSecrets in the management cluster
- Check for network connectivity between clusters
Secret Not Created from SyncSecret
Check:- Verify the SyncSecret exists in the management cluster tenant namespace
- Check Manager logs for reconciliation errors
- Verify Manager has permissions to create Secrets
- Check for finalizer issues
Secret Not Updating
Check:- Verify the SyncSecret data has actually changed
- Check for reconciliation errors in controller logs
- Verify the Secret is not marked as immutable
- Check ResourceVersion conflicts
Orphaned Secrets
Check:- Verify SyncSecret has proper finalizers
- Check for controller errors during cleanup
- Manually delete orphaned secrets if necessary
Best Practices
Secret Hygiene
- Use Immutable Secrets: For secrets that should never change (like TLS certificates), set
immutable: true - Rotate Regularly: Update SyncSecrets periodically to rotate credentials
- Limit Scope: Only sync secrets that are actually needed in the management cluster
- Use Descriptive Names: Name SyncSecrets clearly to indicate their purpose
Access Control
- Restrict Creation: Limit who can create SyncSecrets in tenant clusters
- Monitor Usage: Track SyncSecret creation and updates
- Audit Access: Review who has access to secrets in the management cluster
- Use RBAC: Apply proper RBAC policies to control secret access
Operational
- Document Secret Purpose: Add annotations describing what each secret is for
- Monitor Metrics: Track reconciliation failures and durations
- Test Cleanup: Verify secrets are properly deleted when SyncSecrets are removed
- Backup Important Secrets: Keep secure backups of critical secrets outside the cluster
Example: TLS Certificate Workflow
Complete workflow for syncing TLS certificates:1. Create SyncSecret in Tenant Cluster
2. Verify Propagation
3. Use in Ingress
4. Monitor
Next Steps
Tenant Isolation
Understand namespace separation and RBAC policies
Security Overview
Review the complete security model
