@@ -3,6 +3,7 @@ namespace k8s
3
3
using System ;
4
4
using System . IO ;
5
5
using System . Linq ;
6
+ using System . Security . Cryptography . X509Certificates ;
6
7
using k8s . Exceptions ;
7
8
using k8s . KubeConfigModels ;
8
9
using YamlDotNet . Serialization ;
@@ -49,7 +50,7 @@ public KubernetesClientConfiguration(FileInfo kubeconfig = null, string currentC
49
50
/// <summary>
50
51
/// Gets SslCaCert
51
52
/// </summary>
52
- public string SslCaCert { get ; private set ; }
53
+ public X509Certificate2 SslCaCert { get ; private set ; }
53
54
54
55
/// <summary>
55
56
/// Gets ClientCertificateData
@@ -61,6 +62,16 @@ public KubernetesClientConfiguration(FileInfo kubeconfig = null, string currentC
61
62
/// </summary>
62
63
public string ClientCertificateKey { get ; private set ; }
63
64
65
+ /// <summary>
66
+ /// Gets ClientCertificate filename
67
+ /// </summary>
68
+ public string ClientCertificate { get ; private set ; }
69
+
70
+ /// <summary>
71
+ /// Gets ClientCertificate Key filename
72
+ /// </summary>
73
+ public string ClientKey { get ; private set ; }
74
+
64
75
/// <summary>
65
76
/// Gets a value indicating whether to skip ssl server cert validation
66
77
/// </summary>
@@ -145,13 +156,20 @@ private void Initialize(K8SConfiguration k8SConfig, string currentContext = null
145
156
}
146
157
147
158
if ( ! clusterDetails . ClusterEndpoint . SkipTlsVerify &&
148
- string . IsNullOrWhiteSpace ( clusterDetails . ClusterEndpoint . CertificateAuthorityData ) )
159
+ string . IsNullOrWhiteSpace ( clusterDetails . ClusterEndpoint . CertificateAuthorityData ) &&
160
+ string . IsNullOrWhiteSpace ( clusterDetails . ClusterEndpoint . CertificateAuthority ) )
149
161
{
150
- throw new KubeConfigException ( $ "certificate-authority-data not found for current-context :{ activeContext } in kubeconfig") ;
162
+ throw new KubeConfigException ( $ "neither certificate-authority-data nor certificate-authority not found for current-context :{ activeContext } in kubeconfig") ;
151
163
}
152
164
153
165
this . Host = clusterDetails . ClusterEndpoint . Server ;
154
- this . SslCaCert = clusterDetails . ClusterEndpoint . CertificateAuthorityData ;
166
+ if ( ! string . IsNullOrEmpty ( clusterDetails . ClusterEndpoint . CertificateAuthorityData ) ) {
167
+ string data = clusterDetails . ClusterEndpoint . CertificateAuthorityData ;
168
+ this . SslCaCert = new X509Certificate2 ( System . Text . Encoding . UTF8 . GetBytes ( Utils . Base64Decode ( data ) ) ) ;
169
+ }
170
+ else if ( ! string . IsNullOrEmpty ( clusterDetails . ClusterEndpoint . CertificateAuthority ) ) {
171
+ this . SslCaCert = new X509Certificate2 ( clusterDetails . ClusterEndpoint . CertificateAuthority , null ) ;
172
+ }
155
173
this . SkipTlsVerify = clusterDetails . ClusterEndpoint . SkipTlsVerify ;
156
174
}
157
175
else
@@ -202,6 +220,13 @@ private void SetUserDetails(User userDetails)
202
220
userCredentialsFound = true ;
203
221
}
204
222
223
+ if ( ! string . IsNullOrWhiteSpace ( userDetails . UserCredentials . ClientCertificate ) &&
224
+ ! string . IsNullOrWhiteSpace ( userDetails . UserCredentials . ClientKey ) ) {
225
+ this . ClientCertificate = userDetails . UserCredentials . ClientCertificate ;
226
+ this . ClientKey = userDetails . UserCredentials . ClientKey ;
227
+ userCredentialsFound = true ;
228
+ }
229
+
205
230
if ( ! userCredentialsFound )
206
231
{
207
232
throw new KubeConfigException ( $ "User: { userDetails . Name } does not have appropriate auth credentials in kube config") ;
0 commit comments