Skip to content

Commit ff5e0e6

Browse files
Oracle TCPS Support
Signed-off-by: SajjadSadi074 <[email protected]>
1 parent 981dd5e commit ff5e0e6

File tree

166 files changed

+19630
-731
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+19630
-731
lines changed

go.mod

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ require (
3232
github.com/sijms/go-ora/v2 v2.8.24
3333
go.mongodb.org/mongo-driver v1.14.0
3434
go.virtual-secrets.dev/apimachinery v0.0.1
35-
k8s.io/api v0.32.3
36-
k8s.io/apimachinery v0.32.3
35+
k8s.io/api v0.32.8
36+
k8s.io/apimachinery v0.32.8
3737
k8s.io/klog/v2 v2.130.1
38-
kmodules.xyz/client-go v0.32.7
39-
kmodules.xyz/custom-resources v0.32.0
40-
kubedb.dev/apimachinery v0.58.0
38+
kmodules.xyz/client-go v0.32.9
39+
kmodules.xyz/custom-resources v0.32.2
40+
kubedb.dev/apimachinery v0.59.1-0.20251204132717-657fbb84a6dd
4141
sigs.k8s.io/controller-runtime v0.20.4
4242
xorm.io/xorm v1.3.9
4343
)
@@ -151,15 +151,15 @@ require (
151151
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
152152
gopkg.in/inf.v0 v0.9.1 // indirect
153153
gopkg.in/yaml.v3 v3.0.1 // indirect
154-
k8s.io/apiextensions-apiserver v0.32.3 // indirect
155-
k8s.io/client-go v0.32.3 // indirect
154+
k8s.io/apiextensions-apiserver v0.32.8 // indirect
155+
k8s.io/client-go v0.32.8 // indirect
156156
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
157157
k8s.io/utils v0.0.0-20241210054802-24370beab758 // indirect
158158
kmodules.xyz/apiversion v0.2.0 // indirect
159-
kmodules.xyz/monitoring-agent-api v0.32.1 // indirect
159+
kmodules.xyz/monitoring-agent-api v0.32.4 // indirect
160160
kmodules.xyz/offshoot-api v0.32.0 // indirect
161161
kubeops.dev/operator-shard-manager v0.0.3 // indirect
162-
kubeops.dev/petset v0.0.12 // indirect
162+
kubeops.dev/petset v0.0.14 // indirect
163163
kubeops.dev/sidekick v0.0.11 // indirect
164164
modernc.org/memory v1.5.0 // indirect
165165
modernc.org/token v1.1.0 // indirect

go.sum

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -526,14 +526,14 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
526526
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
527527
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
528528
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
529-
k8s.io/api v0.32.3 h1:Hw7KqxRusq+6QSplE3NYG4MBxZw1BZnq4aP4cJVINls=
530-
k8s.io/api v0.32.3/go.mod h1:2wEDTXADtm/HA7CCMD8D8bK4yuBUptzaRhYcYEEYA3k=
531-
k8s.io/apiextensions-apiserver v0.32.3 h1:4D8vy+9GWerlErCwVIbcQjsWunF9SUGNu7O7hiQTyPY=
532-
k8s.io/apiextensions-apiserver v0.32.3/go.mod h1:8YwcvVRMVzw0r1Stc7XfGAzB/SIVLunqApySV5V7Dss=
533-
k8s.io/apimachinery v0.32.3 h1:JmDuDarhDmA/Li7j3aPrwhpNBA94Nvk5zLeOge9HH1U=
534-
k8s.io/apimachinery v0.32.3/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
535-
k8s.io/client-go v0.32.3 h1:RKPVltzopkSgHS7aS98QdscAgtgah/+zmpAogooIqVU=
536-
k8s.io/client-go v0.32.3/go.mod h1:3v0+3k4IcT9bXTc4V2rt+d2ZPPG700Xy6Oi0Gdl2PaY=
529+
k8s.io/api v0.32.8 h1:PhuKPnqsaXYuwmLXRLAmdDJ9EZ2R2kEbOZTq4UE3lGc=
530+
k8s.io/api v0.32.8/go.mod h1:gdRZQ4zXGawr9YrJ5OjTl7aR3TD0mTowtFsqFtpCDXo=
531+
k8s.io/apiextensions-apiserver v0.32.8 h1:iYIIaZmn/BMTwzGYRZnYZysaKB4t2TL3O+0yhmbXE2U=
532+
k8s.io/apiextensions-apiserver v0.32.8/go.mod h1:GTGskWgcBo/7boX33zcS8JY6vaG4s728AdbQPxtheVk=
533+
k8s.io/apimachinery v0.32.8 h1:95I+2jX71Tev+C+UlhNbmKfv+A/TQII42HLskiHZpBg=
534+
k8s.io/apimachinery v0.32.8/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
535+
k8s.io/client-go v0.32.8 h1:BkSFWUtRz/BbE3DJF98KPg7ix6lwMnIQ9DnHw3iWiSw=
536+
k8s.io/client-go v0.32.8/go.mod h1:vGkCzRxZ7BuRX2zdW7+kOwCdcgOkq9omDWb26wk/sE0=
537537
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
538538
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
539539
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff h1:/usPimJzUKKu+m+TE36gUyGcf03XZEP0ZIKgKj35LS4=
@@ -542,20 +542,20 @@ k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJ
542542
k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
543543
kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk=
544544
kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80=
545-
kmodules.xyz/client-go v0.32.7 h1:vBAbp8vs4coYRhY4wqm1Hw/eBEDiVU238AyMLSoRJ1c=
546-
kmodules.xyz/client-go v0.32.7/go.mod h1:ZwLnc7UqEXUNSe43n/SnER6+7YAQCu38L2te6YefoHU=
547-
kmodules.xyz/custom-resources v0.32.0 h1:wzmJTtswO+OmvtqYc70pVoopZyt5UJHKTom4Jh6bfhM=
548-
kmodules.xyz/custom-resources v0.32.0/go.mod h1:aLFrfbUKS+AkKtxFYWpPGzuLNarRtGlkHwC07APHba8=
549-
kmodules.xyz/monitoring-agent-api v0.32.1 h1:F0cm5NJWfgiANw3eiKkXXSXoClMBpAolMXE/N7Xts74=
550-
kmodules.xyz/monitoring-agent-api v0.32.1/go.mod h1:zgRKiJcuK7FOHy0Y1TsONRbJfgnPCs8t4Zh/6Afr+yU=
545+
kmodules.xyz/client-go v0.32.9 h1:iZVhmTuMybHR7THGqnkbQdAJEOJCtZ9Ry9cY8TBvTJI=
546+
kmodules.xyz/client-go v0.32.9/go.mod h1:ZwLnc7UqEXUNSe43n/SnER6+7YAQCu38L2te6YefoHU=
547+
kmodules.xyz/custom-resources v0.32.2 h1:NkRqL/4AWHiXdT5WKFcJlBcvRuoNdeYIrBGvQIRJRn4=
548+
kmodules.xyz/custom-resources v0.32.2/go.mod h1:YKFNcsFQU7Z3AcPvYVCdFtgAdWiG1Wd1HQMOxCrAoWc=
549+
kmodules.xyz/monitoring-agent-api v0.32.4 h1:JGm2bvHfAXHAf7EKjFrNDG3f7+QFpYV2Mvgj3RDVRhw=
550+
kmodules.xyz/monitoring-agent-api v0.32.4/go.mod h1:NkCiNP05EWrsjTTU2Npova/Sm27+I8vwUXqXVCmBbQ4=
551551
kmodules.xyz/offshoot-api v0.32.0 h1:gogc5scSZe2JoXtZof72UGRl3Tit0kFaFRMkLLT1D8o=
552552
kmodules.xyz/offshoot-api v0.32.0/go.mod h1:tled7OxYZ3SkUJcrVFVVYyd+zXjsRSEm1R6Q3k4gcx0=
553-
kubedb.dev/apimachinery v0.58.0 h1:bsDqWcYsfjbZ6Ca4PyXbKr7jj3dhzzlPBS5NfQ9CD+I=
554-
kubedb.dev/apimachinery v0.58.0/go.mod h1:t6BwVURkvyLKpx7teRZ20hBkjAgF8JB1CCLSjBbbPqo=
553+
kubedb.dev/apimachinery v0.59.1-0.20251204132717-657fbb84a6dd h1:AUYMIXpbpV3VqxKa63Wy4czifZy7VDWcUoQArZ3a11A=
554+
kubedb.dev/apimachinery v0.59.1-0.20251204132717-657fbb84a6dd/go.mod h1:8zu7zUBEd2PQsI0JZJFmxzglf63zxbwlAJIJlY77UqM=
555555
kubeops.dev/operator-shard-manager v0.0.3 h1:Z2YOAfyQIjvHMwT4O56lR0l9z25s2tCVDO22u/XuYnw=
556556
kubeops.dev/operator-shard-manager v0.0.3/go.mod h1:2oRq5vnCaUxzE+qIiRuzB34PlqahiynE+sYqWu6AMIY=
557-
kubeops.dev/petset v0.0.12 h1:NSFEeuckBVm44f3cAL4HhcQWvnfOE4qgbfug7+FEyaY=
558-
kubeops.dev/petset v0.0.12/go.mod h1:akG9QH1JaOZQcuQKEKWvkVWI8P3im/5O554aTRvB6Y0=
557+
kubeops.dev/petset v0.0.14 h1:Lk3prjtm5AgR44qr2SX8elx6sF9PK1G0GYlv8AZd9OY=
558+
kubeops.dev/petset v0.0.14/go.mod h1:X10jcvIjjP9HIa8ezh9PjtaXvFfk2zT+JmmO/S+7uhA=
559559
kubeops.dev/sidekick v0.0.11 h1:OydXdIH6cYSiWxKIWvrywk95WhhHSERkc7RNPOmTekc=
560560
kubeops.dev/sidekick v0.0.11/go.mod h1:90KMNmJOPoMKHbrdC1cpEsMx+1KjTea/lHDAbGRDzHc=
561561
lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=

oracle/kubedb_client_builder.go

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ package postgres
22

33
import (
44
"context"
5+
"crypto/tls"
56
"database/sql"
67
"fmt"
8+
"net/url"
9+
"os"
10+
"path/filepath"
711

812
olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
913
apiutils "kubedb.dev/apimachinery/pkg/utils"
1014

1115
"github.com/pkg/errors"
12-
_ "github.com/sijms/go-ora/v2" // Oracle driver
16+
go_ora "github.com/sijms/go-ora/v2"
1317
core "k8s.io/api/core/v1"
1418
"sigs.k8s.io/controller-runtime/pkg/client"
1519
)
@@ -21,6 +25,7 @@ type OracleClientBuilder struct {
2125
port int32
2226
service string
2327
ctx context.Context
28+
wallet string
2429
}
2530

2631
func NewOracleClientBuilder(kc client.Client, db *olddbapi.Oracle) *OracleClientBuilder {
@@ -50,6 +55,11 @@ func (o *OracleClientBuilder) WithContext(ctx context.Context) *OracleClientBuil
5055
return o
5156
}
5257

58+
func (o *OracleClientBuilder) WithWallet(wallet string) *OracleClientBuilder {
59+
o.wallet = wallet
60+
return o
61+
}
62+
5363
func (o *OracleClientBuilder) GetOracleClient() (*sql.DB, error) {
5464
if o.ctx == nil {
5565
o.ctx = context.Background()
@@ -60,6 +70,7 @@ func (o *OracleClientBuilder) GetOracleClient() (*sql.DB, error) {
6070
return nil, err
6171
}
6272

73+
// Fallback to standard connection (with wallet if configured)
6374
db, err := sql.Open("oracle", connStr)
6475
if err != nil {
6576
return nil, fmt.Errorf("failed to open Oracle connection: %v", err)
@@ -83,16 +94,69 @@ func (o *OracleClientBuilder) getConnectionString() (string, error) {
8394
return "", fmt.Errorf("failed to get auth credentials for Oracle %s/%s: %v", o.db.Namespace, o.db.Name, err)
8495
}
8596

86-
url := o.url
87-
if url == "" {
88-
url = PrimaryServiceDNS(o.db)
97+
serverURL := o.url
98+
if serverURL == "" {
99+
serverURL = PrimaryServiceDNS(o.db)
89100
}
90101
// Use the provided URL (e.g., service DNS)
91-
host := fmt.Sprintf("%v:%v/%v", url, o.port, o.service)
102+
host := fmt.Sprintf("%v:%v/%v", serverURL, o.port, o.service)
92103

93104
// Construct basic connection string
94-
connStr := fmt.Sprintf("oracle://%s:%s@%s", user, pass, host)
105+
connStr := ""
106+
107+
if o.db.Spec.TCPSConfig != nil && o.db.Spec.TCPSConfig.TLS != nil {
108+
// Constract connection string with wallet
109+
dbname := o.db.Name
110+
dstDir := o.wallet
111+
if dstDir == "" {
112+
dstDir = fmt.Sprintf("/tmp/%s/.tls-wallet", dbname)
113+
114+
if err := os.MkdirAll(dstDir, 0o755); err != nil {
115+
fmt.Printf("[ERROR] Failed to create wallet directory: %v\n", err)
116+
}
117+
118+
// Read the TLS secret from Kubernetes
119+
var tlsSecret core.Secret
120+
secretName := o.db.Name + "-tls-wallet"
121+
if err := o.kc.Get(o.ctx, client.ObjectKey{Namespace: o.db.Namespace, Name: secretName}, &tlsSecret); err != nil {
122+
return "", fmt.Errorf("failed to get TLS secret %s: %v", secretName, err)
123+
}
124+
125+
// Extract and save all files in the secret data
126+
for filename, data := range tlsSecret.Data {
127+
filePath := filepath.Join(dstDir, filename)
128+
if err := os.WriteFile(filePath, data, 0o600); err != nil {
129+
return "", fmt.Errorf("failed to write wallet file %s: %v", filename, err)
130+
}
131+
}
132+
133+
}
134+
135+
// Get service name from database spec
136+
service := "ORCL"
137+
if o.db.Spec.Listener != nil && o.db.Spec.Listener.Service != nil {
138+
service = *o.db.Spec.Listener.Service
139+
}
140+
141+
// Build connection string with SSL enabled
142+
baseURL := go_ora.BuildUrl(serverURL, int(o.port), service, user, pass, nil)
95143

144+
// Add SSL parameters with proper URL encoding
145+
params := url.Values{}
146+
params.Add("SSL", "true")
147+
params.Add("SSL VERIFY", "false")
148+
params.Add("WALLET", dstDir)
149+
params.Add("WALLET PASSWORD", pass)
150+
151+
// Build final connection string with parameters
152+
connStr = baseURL + "?" + params.Encode()
153+
for _, fname := range []string{"cwallet.sso", "ewallet.p12", "server.p12"} {
154+
filepath.Join(dstDir, fname)
155+
}
156+
} else {
157+
// Construct basic connection string without wallet
158+
connStr = fmt.Sprintf("oracle://%s:%s@%s", user, pass, host)
159+
}
96160
return connStr, nil
97161
}
98162

@@ -115,6 +179,23 @@ func (o *OracleClientBuilder) getOracleAuthCredentials() (string, string, error)
115179
return username, password, nil
116180
}
117181

182+
// getTLSConfig creates a TLS configuration without client certificates
183+
// Since SSL_CLIENT_AUTHENTICATION = FALSE on the server, we don't need client certs
184+
func (o *OracleClientBuilder) getTLSConfig() (*tls.Config, error) {
185+
// Create a basic TLS config that accepts any server certificate
186+
// Match Oracle server's configuration:
187+
// - SSL_VERSION = 1.2
188+
// - SSL_CLIENT_AUTHENTICATION = FALSE
189+
tlsConfig := &tls.Config{
190+
InsecureSkipVerify: true, // Accept server's self-signed certificate
191+
MinVersion: tls.VersionTLS12,
192+
MaxVersion: tls.VersionTLS12,
193+
// Let Go negotiate cipher suites - it will use compatible RSA+AES ciphers
194+
}
195+
196+
return tlsConfig, nil
197+
}
198+
118199
// PrimaryServiceDNS make primary host dns with require template
119200
func PrimaryServiceDNS(db *olddbapi.Oracle) string {
120201
return fmt.Sprintf("%v.%v.svc.%s", db.ServiceName(), db.Namespace, apiutils.FindDomain())

vendor/kmodules.xyz/client-go/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
5858
BASEIMAGE_PROD ?= gcr.io/distroless/static-debian12
5959
BASEIMAGE_DBG ?= debian:12
6060

61-
GO_VERSION ?= 1.24
61+
GO_VERSION ?= 1.25
6262
BUILD_IMAGE ?= ghcr.io/appscode/golang-dev:$(GO_VERSION)
6363

6464
OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)

vendor/kmodules.xyz/client-go/api/v1/cluster_enum.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/kmodules.xyz/client-go/api/v1/object_enum.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1/appbinding_types.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type AppBindingSpec struct {
6868

6969
// Secret is the name of the secret to create in the AppBinding's
7070
// namespace that will hold the credentials associated with the AppBinding.
71-
Secret *core.LocalObjectReference `json:"secret,omitempty"`
71+
Secret *TypedLocalObjectReference `json:"secret,omitempty"`
7272

7373
// List of transformations that should be applied to the credentials
7474
// associated with the ServiceBinding before they are inserted into the Secret.
@@ -90,7 +90,7 @@ type AppBindingSpec struct {
9090

9191
// TLSSecret is the name of the secret that will hold
9292
// the client certificate and private key associated with the AppBinding.
93-
TLSSecret *core.LocalObjectReference `json:"tlsSecret,omitempty"`
93+
TLSSecret *TypedLocalObjectReference `json:"tlsSecret,omitempty"`
9494
}
9595

9696
type AppType string
@@ -175,6 +175,21 @@ type ServiceReference struct {
175175
Query string `json:"query,omitempty"`
176176
}
177177

178+
// +structType=atomic
179+
type TypedLocalObjectReference struct {
180+
// APIGroup is the group for the resource being referenced.
181+
// If APIGroup is not specified, the specified Kind must be in the core API group.
182+
// For any other third-party types, APIGroup is required.
183+
// +optional
184+
// +kubebuilder:default=""
185+
APIGroup string `json:"apiGroup"`
186+
// Kind is the type of resource being referenced
187+
// +kubebuilder:default="Secret"
188+
Kind string `json:"kind"`
189+
// Name is the name of resource being referenced
190+
Name string `json:"name"`
191+
}
192+
178193
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
179194

180195
// AppBindingList is a list of Apps

0 commit comments

Comments
 (0)