Skip to content

Commit a6e46e7

Browse files
linoyaslantsorya
authored andcommitted
feat: add secrets validation
- Validate SSH key and pull secrets exist with required keys Generated with Claude Code
1 parent 06180d8 commit a6e46e7

14 files changed

Lines changed: 1154 additions & 21 deletions

File tree

api/v1alpha1/dpfhcpbridge_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type DPFHCPBridgeSpec struct {
6666
OCPReleaseImage string `json:"ocpReleaseImage"`
6767

6868
// SSHKeySecretRef is a reference to a Secret containing the SSH public key for cluster node access
69-
// Secret must be in the same namespace as the DPFHCPBridge CR and contain key 'ssh-publickey'
69+
// Secret must be in the same namespace as the DPFHCPBridge CR and contain key 'id_rsa.pub'
7070
// This field is immutable.
7171
// +kubebuilder:validation:Required
7272
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="sshKeySecretRef is immutable"
@@ -75,7 +75,7 @@ type DPFHCPBridgeSpec struct {
7575
SSHKeySecretRef corev1.LocalObjectReference `json:"sshKeySecretRef"`
7676

7777
// PullSecretRef is a reference to a Secret containing the container registry pull secret
78-
// Secret must be in the same namespace as the DPFHCPBridge CR and contain key 'pullsecret'
78+
// Secret must be in the same namespace as the DPFHCPBridge CR and contain key '.dockerconfigjson'
7979
// This field is immutable.
8080
// +kubebuilder:validation:Required
8181
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="pullSecretRef is immutable"

cmd/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"github.com/rh-ecosystem-edge/dpf-hcp-bridge-operator/internal/controller"
4343
"github.com/rh-ecosystem-edge/dpf-hcp-bridge-operator/internal/controller/bluefield"
4444
"github.com/rh-ecosystem-edge/dpf-hcp-bridge-operator/internal/controller/dpucluster"
45+
"github.com/rh-ecosystem-edge/dpf-hcp-bridge-operator/internal/controller/secrets"
4546
// +kubebuilder:scaffold:imports
4647
)
4748

@@ -212,12 +213,16 @@ func main() {
212213
// Initialize DPUCluster Validator
213214
dpuClusterValidator := dpucluster.NewValidator(mgr.GetClient(), mgr.GetEventRecorderFor("dpfhcpbridge-controller"))
214215

216+
// Initialize Secrets Validator
217+
secretsValidator := secrets.NewValidator(mgr.GetClient(), mgr.GetEventRecorderFor("dpfhcpbridge-controller"))
218+
215219
if err := (&controller.DPFHCPBridgeReconciler{
216220
Client: mgr.GetClient(),
217221
Scheme: mgr.GetScheme(),
218222
Recorder: mgr.GetEventRecorderFor("dpfhcpbridge-controller"),
219223
ImageResolver: imageResolver,
220224
DPUClusterValidator: dpuClusterValidator,
225+
SecretsValidator: secretsValidator,
221226
}).SetupWithManager(mgr); err != nil {
222227
setupLog.Error(err, "unable to create controller", "controller", "DPFHCPBridge")
223228
os.Exit(1)

config/crd/bases/provisioning.dpu.hcp.io_dpfhcpbridges.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ spec:
131131
pullSecretRef:
132132
description: |-
133133
PullSecretRef is a reference to a Secret containing the container registry pull secret
134-
Secret must be in the same namespace as the DPFHCPBridge CR and contain key 'pullsecret'
134+
Secret must be in the same namespace as the DPFHCPBridge CR and contain key '.dockerconfigjson'
135135
This field is immutable.
136136
properties:
137137
name:
@@ -151,7 +151,7 @@ spec:
151151
sshKeySecretRef:
152152
description: |-
153153
SSHKeySecretRef is a reference to a Secret containing the SSH public key for cluster node access
154-
Secret must be in the same namespace as the DPFHCPBridge CR and contain key 'ssh-publickey'
154+
Secret must be in the same namespace as the DPFHCPBridge CR and contain key 'id_rsa.pub'
155155
This field is immutable.
156156
properties:
157157
name:

config/rbac/role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ rules:
88
- ""
99
resources:
1010
- configmaps
11+
- secrets
1112
verbs:
1213
- get
1314
- list

helm/dpf-hcp-bridge-operator/INSTALL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ oc create namespace my-dpu-clusters
114114

115115
# Create pull secret
116116
oc create secret generic my-pull-secret \
117-
--from-file=pullsecret=$HOME/.docker/config.json \
117+
--from-file=.dockerconfigjson=$HOME/.docker/config.json \
118118
-n my-dpu-clusters
119119

120120
# Create SSH public key secret
121121
oc create secret generic my-ssh-key \
122-
--from-file=ssh-publickey=$HOME/.ssh/id_rsa.pub \
122+
--from-file=id_rsa.pub=$HOME/.ssh/id_rsa.pub \
123123
-n my-dpu-clusters
124124
```
125125

helm/dpf-hcp-bridge-operator/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ Before creating a DPFHCPBridge CR, create the required secrets:
251251
```bash
252252
# Create pull secret
253253
kubectl create secret generic my-pull-secret \
254-
--from-file=pullsecret=/path/to/pull-secret.json \
254+
--from-file=.dockerconfigjson=/path/to/pull-secret.json \
255255
-n default
256256

257257
# Create SSH key secret
258258
kubectl create secret generic my-ssh-key \
259-
--from-file=ssh-publickey=/path/to/id_rsa.pub \
259+
--from-file=id_rsa.pub=/path/to/id_rsa.pub \
260260
-n default
261261
```
262262

helm/dpf-hcp-bridge-operator/crds/provisioning.dpu.hcp.io_dpfhcpbridges.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ spec:
117117
pullSecretRef:
118118
description: |-
119119
PullSecretRef is a reference to a Secret containing the container registry pull secret
120-
Secret must be in the same namespace as the DPFHCPBridge CR and contain key 'pullsecret'
120+
Secret must be in the same namespace as the DPFHCPBridge CR and contain key '.dockerconfigjson'
121121
This field is immutable.
122122
properties:
123123
name:
@@ -137,7 +137,7 @@ spec:
137137
sshKeySecretRef:
138138
description: |-
139139
SSHKeySecretRef is a reference to a Secret containing the SSH public key for cluster node access
140-
Secret must be in the same namespace as the DPFHCPBridge CR and contain key 'ssh-publickey'
140+
Secret must be in the same namespace as the DPFHCPBridge CR and contain key 'id_rsa.pub'
141141
This field is immutable.
142142
properties:
143143
name:

helm/dpf-hcp-bridge-operator/examples/dpfhcpbridge-basic.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ spec:
2626
ocpReleaseImage: quay.io/openshift-release-dev/ocp-release:4.19.0-ec.5-x86_64
2727

2828
# Pull secret reference (must exist in same namespace as this CR)
29-
# Secret must contain key 'pullsecret' with container registry credentials
29+
# Secret must contain key '.dockerconfigjson' with container registry credentials
3030
pullSecretRef:
3131
name: my-pull-secret
3232

3333
# SSH public key reference (must exist in same namespace as this CR)
34-
# Secret must contain key 'ssh-publickey' with SSH public key
34+
# Secret must contain key 'id_rsa.pub' with SSH public key
3535
sshKeySecretRef:
3636
name: my-ssh-key
3737

helm/dpf-hcp-bridge-operator/examples/secrets-example.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ metadata:
1212
namespace: default
1313
type: Opaque
1414
stringData:
15-
pullsecret: |
15+
.dockerconfigjson: |
1616
{
1717
"auths": {
1818
"quay.io": {
@@ -37,29 +37,29 @@ metadata:
3737
namespace: default
3838
type: Opaque
3939
stringData:
40-
ssh-publickey: |
40+
id_rsa.pub: |
4141
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC... user@example.com
4242
4343
---
4444
# Example: Creating secrets from files using kubectl
4545
#
4646
# Pull secret from Docker config:
4747
# kubectl create secret generic my-pull-secret \
48-
# --from-file=pullsecret=$HOME/.docker/config.json \
48+
# --from-file=.dockerconfigjson=$HOME/.docker/config.json \
4949
# -n default
5050
#
5151
# Pull secret from OpenShift pull secret file:
5252
# kubectl create secret generic my-pull-secret \
53-
# --from-file=pullsecret=/path/to/pull-secret.json \
53+
# --from-file=.dockerconfigjson=/path/to/pull-secret.json \
5454
# -n default
5555
#
5656
# SSH public key:
5757
# kubectl create secret generic my-ssh-key \
58-
# --from-file=ssh-publickey=$HOME/.ssh/id_rsa.pub \
58+
# --from-file=id_rsa.pub=$HOME/.ssh/id_rsa.pub \
5959
# -n default
6060
#
6161
# Generate new SSH key pair:
6262
# ssh-keygen -t rsa -b 4096 -f /tmp/cluster-key -N ""
6363
# kubectl create secret generic my-ssh-key \
64-
# --from-file=ssh-publickey=/tmp/cluster-key.pub \
64+
# --from-file=id_rsa.pub=/tmp/cluster-key.pub \
6565
# -n default

helm/dpf-hcp-bridge-operator/templates/NOTES.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ TROUBLESHOOTING:
9393
- Common issues:
9494
* Missing BlueField image mapping: Add to ocp-bluefield-images ConfigMap
9595
* DPUCluster not found: Ensure DPUCluster CR exists and is referenced correctly
96-
* Pull secret missing: Create secret with 'pullsecret' key in CR namespace
97-
* SSH key missing: Create secret with 'ssh-publickey' key in CR namespace
96+
* Pull secret missing: Create secret with '.dockerconfigjson' key in CR namespace
97+
* SSH key missing: Create secret with 'id_rsa.pub' key in CR namespace
9898

9999
For more information:
100100
- Documentation: https://github.com/rh-ecosystem-edge/dpf-hcp-bridge-operator

0 commit comments

Comments
 (0)