This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multicluster: Adding GetMulticlusterGatewaySubjectCommonName() (#3857)
Signed-off-by: Delyan Raychev <[email protected]>
- Loading branch information
Showing
5 changed files
with
68 additions
and
3 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
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,17 @@ | ||
package multicluster | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
|
||
"github.com/openservicemesh/osm/pkg/certificate" | ||
"github.com/openservicemesh/osm/pkg/envoy" | ||
) | ||
|
||
// GetMulticlusterGatewaySubjectCommonName creates a unique certificate.CommonName | ||
// specifically for a Multicluster Gateway. Each gateway will have its own unique | ||
// cert. The kind of Envoy (gateway) is encoded in the cert CN by convention. | ||
func GetMulticlusterGatewaySubjectCommonName(serviceAccount, namespace string) certificate.CommonName { | ||
gatewayUID := uuid.New() | ||
envoyType := envoy.KindGateway | ||
return envoy.NewXDSCertCommonName(gatewayUID, envoyType, serviceAccount, namespace) | ||
} |
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,27 @@ | ||
package multicluster | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/openservicemesh/osm/pkg/envoy" | ||
|
||
tassert "github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMulticlusterHelpers(t *testing.T) { | ||
assert := tassert.New(t) | ||
serviceAccount := "-svc-account-" | ||
namespace := "-namespace-" | ||
|
||
actualCN := GetMulticlusterGatewaySubjectCommonName(serviceAccount, namespace) | ||
expectedSuffix := ".gateway.-svc-account-.-namespace-.cluster.local" | ||
assert.True(strings.HasSuffix(actualCN.String(), expectedSuffix), fmt.Sprintf("Expected the Proxy Cert's Common Name to end with %s", expectedSuffix)) | ||
|
||
// Is the kind of proxy properly encoded in this certificate? | ||
actualProxyKind, err := envoy.GetKindFromProxyCertificate(actualCN) | ||
assert.Nil(err, fmt.Sprintf("Expected error to be nil; It was %+v", err)) | ||
expectedProxyKind := envoy.KindGateway | ||
assert.Equal(expectedProxyKind, actualProxyKind, fmt.Sprintf("Expected proxy kind to be %s; it was actually %s", expectedProxyKind, actualProxyKind)) | ||
} |