Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
test for permissive mode
Browse files Browse the repository at this point in the history
Signed-off-by: Shashank Ram <shashank08@gmail.com>
  • Loading branch information
shashankram committed Nov 5, 2020
1 parent c3deb52 commit 0a73c30
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/envoy/sds/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ func (s *sdsImpl) getRootCert(cert certificate.Certificater, sdscert envoy.SDSCe
log.Trace().Msgf("Proxy for service %s will only allow %s SANs exactly matching: %v", proxyService, directionMap[sdscert.CertType], matchingCerts)

// Ensure the Subject Alternate Names (SAN) added by CertificateManager.IssueCertificate()
// matches what is allowed to connect to the downstream service as defined in TrafficPolicy.
// matches what is allowed to connect to or accept connections from, as defined in the SMI
// TrafficTarget policy.
secret.GetValidationContext().MatchSubjectAltNames = matchSANs
default:
log.Debug().Msgf("SAN matching not needed for cert type %s", sdscert.CertType.String())
Expand Down
27 changes: 27 additions & 0 deletions pkg/envoy/sds/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,33 @@ func TestGetRootCert(t *testing.T) {
expectError: false,
},
// Test case 2 end -------------------------------

// Test case 3: tests SDS secret for permissive mode -------------------------------
{
s: &sdsImpl{
proxyServices: []service.MeshService{
{Name: "service-1", Namespace: "ns-1"},
},
svcAccount: service.K8sServiceAccount{Name: "sa-1", Namespace: "ns-1"},
proxy: envoy.NewProxy(certificate.CommonName(fmt.Sprintf("%s.%s.%s", uuid.New().String(), "sa-1", "ns-1")), nil),
meshCatalog: mockCatalog,
certManager: mockCertManager,
cfg: mockConfigurator,
},
certCN: certificate.CommonName("sa-1.ns-1.cluster.local"),
sdsCert: envoy.SDSCert{
MeshService: service.MeshService{Name: "service-1", Namespace: "ns-1"},
CertType: envoy.RootCertTypeForMTLSOutbound,
},
proxyService: service.MeshService{Name: "service-1", Namespace: "ns-1"},
allowedDirectionalSvcAccounts: []service.K8sServiceAccount{},
permissiveMode: true,

// expectations
expectedSANs: []string{}, // no SAN matching in permissive mode
expectError: false,
},
// Test case 2 end -------------------------------
}

for i, tc := range testCases {
Expand Down

0 comments on commit 0a73c30

Please sign in to comment.