forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure unique VPN tlsauth secrets for different tlsauth keys
- Loading branch information
1 parent
539913d
commit a205370
Showing
8 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 2 | ||
|
||
secret: | ||
ignored_matches: | ||
- match: vpn-seed-server-tlsauth-a1d0aa00-2a3206b8 | ||
name: it's a secret name only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package vpntlsauth | ||
|
||
import ( | ||
"context" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
|
||
secretsutils "github.com/gardener/gardener/pkg/utils/secrets" | ||
secretsmanager "github.com/gardener/gardener/pkg/utils/secrets/manager" | ||
) | ||
|
||
const ( | ||
// SecretNameTLSAuth is the name of seed server tlsauth Secret. | ||
SecretNameTLSAuth = "vpn-seed-server-tlsauth" // #nosec G101 -- No credential. | ||
) | ||
|
||
// VPNTLSAuthConfigFromSecret is a configuration for a VPN TLS auth secret with the tlsauth key itself as part | ||
// of the configuration. | ||
type VPNTLSAuthConfigFromSecret struct { | ||
Name string | ||
Data map[string][]byte | ||
} | ||
|
||
var _ secretsutils.ConfigInterface = &VPNTLSAuthConfigFromSecret{} | ||
var _ secretsutils.DataInterface = &VPNTLSAuthConfigFromSecret{} | ||
|
||
// GetName returns the name of the secret. | ||
func (s *VPNTLSAuthConfigFromSecret) GetName() string { | ||
return s.Name | ||
} | ||
|
||
// Generate implements ConfigInterface. | ||
func (s *VPNTLSAuthConfigFromSecret) Generate() (secretsutils.DataInterface, error) { | ||
return s, nil | ||
} | ||
|
||
// SecretData computes the data map which can be used in a Kubernetes secret. | ||
func (s *VPNTLSAuthConfigFromSecret) SecretData() map[string][]byte { | ||
return s.Data | ||
} | ||
|
||
// GenerateSecret generates a VPN TLS auth secret using the provided secrets manager. | ||
// It is used for two-staged generation of tlsauth secret to include the tlsauth key in the secret name hash. | ||
func GenerateSecret(ctx context.Context, secretsManager secretsmanager.Interface) (*corev1.Secret, error) { | ||
// generate a secret with the tlsauth key | ||
secretTLSAuthIntermediate, err := secretsManager.Generate(ctx, &secretsutils.VPNTLSAuthConfig{ | ||
Name: SecretNameTLSAuth, | ||
}, secretsmanager.Rotate(secretsmanager.InPlace)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// use the secret to get a secret with same data but including the tlsauth key itself in name hash | ||
secretTLSAuth, err := secretsManager.Generate(ctx, &VPNTLSAuthConfigFromSecret{ | ||
Name: secretTLSAuthIntermediate.Name, | ||
Data: secretTLSAuthIntermediate.Data, | ||
}, secretsmanager.Rotate(secretsmanager.InPlace)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return secretTLSAuth, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters