@@ -971,6 +971,12 @@ func (r *OCIRepositoryReconciler) transport(ctx context.Context, obj *sourcev1.O
971971 return nil , err
972972 }
973973 if tlsConfig != nil {
974+ // Set ServerName for proper virtual hosting support
975+ serverName , err := extractServerNameFromURL (obj .Spec .URL )
976+ if err != nil {
977+ return nil , fmt .Errorf ("failed to extract server name for TLS: %w" , err )
978+ }
979+ tlsConfig .ServerName = serverName
974980 transport .TLSClientConfig = tlsConfig
975981 }
976982
@@ -981,6 +987,29 @@ func (r *OCIRepositoryReconciler) transport(ctx context.Context, obj *sourcev1.O
981987 return transport , nil
982988}
983989
990+ // extractServerNameFromURL extracts the server name from an OCI repository URL
991+ // for use in TLS configuration. It returns the hostname without port
992+ // that should be used as the ServerName in TLS handshakes.
993+ func extractServerNameFromURL (ociURL string ) (string , error ) {
994+ if ! strings .HasPrefix (ociURL , sourcev1 .OCIRepositoryPrefix ) {
995+ return "" , fmt .Errorf ("URL must be in format 'oci://<domain>/<org>/<repo>'" )
996+ }
997+
998+ // Convert OCI URL to a parseable format by replacing oci:// with https://
999+ // This allows us to use the standard url package
1000+ u , err := url .Parse (strings .Replace (ociURL , sourcev1 .OCIRepositoryPrefix , "https://" , 1 ))
1001+ if err != nil {
1002+ return "" , fmt .Errorf ("failed to parse OCI URL: %w" , err )
1003+ }
1004+
1005+ hostname := u .Hostname ()
1006+ if hostname == "" {
1007+ return "" , fmt .Errorf ("failed to extract hostname from OCI URL" )
1008+ }
1009+
1010+ return hostname , nil
1011+ }
1012+
9841013// getTLSConfig gets the TLS configuration for the transport based on the
9851014// specified secret reference in the OCIRepository object, or the insecure flag.
9861015func (r * OCIRepositoryReconciler ) getTLSConfig (ctx context.Context , obj * sourcev1.OCIRepository ) (* cryptotls.Config , error ) {
0 commit comments