Skip to content

Commit

Permalink
fix: k8s registry auth
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Sep 10, 2022
1 parent cb72bea commit ff49b53
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions GZCTF/Services/K8sService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ public K8sService(IOptions<RegistryConfig> _registry, ILogger<K8sService> logger
var padding = Codec.StrMD5($"{_registry.Value.UserName}@{_registry.Value.Password}@{_registry.Value.ServerAddress}");
SecretName = $"{_registry.Value.UserName}-{padding}";

var dockerjson = Codec.Base64.EncodeToBytes($"{{\"{_registry.Value.ServerAddress}\":{{\"username\":\"{_registry.Value.UserName}\",\"password\":\"{_registry.Value.Password}\"}}}}");
var auth = Codec.Base64.Encode($"{_registry.Value.UserName}:{_registry.Value.Password}");
var dockerjson = Codec.Base64.EncodeToBytes(
$"{{\"auths\":" +
$"{{\"{_registry.Value.ServerAddress}\":" +
$"{{\"auth\":\"{auth}\"," +
$"\"username\":\"{_registry.Value.UserName}\"," +
$"\"password\":\"{_registry.Value.Password}\"" +
$"}}}}}}");
var secret = new V1Secret()
{
Metadata = new V1ObjectMeta()
Expand All @@ -63,11 +70,11 @@ public K8sService(IOptions<RegistryConfig> _registry, ILogger<K8sService> logger

try
{
kubernetesClient.CoreV1.ReplaceNamespacedSecretAsync(secret, SecretName, Namespace);
kubernetesClient.CoreV1.ReplaceNamespacedSecret(secret, SecretName, Namespace);
}
catch (Exception)
catch(Exception)
{
kubernetesClient.CoreV1.CreateNamespacedSecretAsync(secret, Namespace);
kubernetesClient.CoreV1.CreateNamespacedSecret(secret, Namespace);
}
}

Expand Down

0 comments on commit ff49b53

Please sign in to comment.