Search in sources :

Example 6 with HostnameResolver

use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.

the class InstanceProviderManagerTest method testGetClassProvider.

@Test
public void testGetClassProvider() {
    SignedDomain signedDomain = createSignedDomainClassEndpoint("coretech", "weather", true, true);
    store.processSignedDomain(signedDomain, false);
    InstanceProviderManager provider = new InstanceProviderManager(store, null, null, null, null);
    InstanceProvider client = provider.getProvider("coretech.weather", new HostnameResolver() {
    });
    assertNotNull(client);
    client.close();
}
Also used : HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) SignedDomain(com.yahoo.athenz.zms.SignedDomain) InstanceProvider(com.yahoo.athenz.instance.provider.InstanceProvider) Test(org.testng.annotations.Test)

Example 7 with HostnameResolver

use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.

the class InstanceCertManagerTest method testValidPrincipalsHostnameAlone.

@Test
public void testValidPrincipalsHostnameAlone() {
    String hostname = "host1.athenz.cloud";
    SshHostCsr sshHostCsr = new SshHostCsr();
    sshHostCsr.setXPrincipals(new String[] { hostname });
    sshHostCsr.setPrincipals(new String[] { "service.domain.athenz.cloud", hostname });
    SSHCertRecord sshCertRecord = new SSHCertRecord();
    sshCertRecord.setService("athenz.examples.httpd");
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    when(hostnameResolver.isValidHostname(hostname)).thenReturn(true);
    InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
    boolean result = instanceManager.validPrincipals(hostname, sshCertRecord, sshHostCsr);
    assertTrue(result);
    instanceManager.shutdown();
}
Also used : HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 8 with HostnameResolver

use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.

the class InstanceCertManagerTest method testGenerateSshIdentityValidPrincipals.

@Test
public void testGenerateSshIdentityValidPrincipals() throws IOException {
    Path path = Paths.get("src/test/resources/sshhost_valid_sample.csr");
    String sshCsr = new String(Files.readAllBytes(path));
    SSHSigner sshSigner = Mockito.mock(com.yahoo.athenz.common.server.ssh.SSHSigner.class);
    SSHCertRequest sshRequest = new SSHCertRequest();
    sshRequest.setCsr(sshCsr);
    SSHCertificates certs = new SSHCertificates();
    SSHCertificate cert = new SSHCertificate();
    cert.setCertificate("ssh-cert");
    SSHCertRecord sshCertRecord = new SSHCertRecord();
    sshCertRecord.setPrincipals("127.0.0.1");
    sshCertRecord.setService("athenz.service");
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.service");
    final SSHCertificates sshCertificates = certs.setCertificates(Collections.singletonList(cert));
    when(sshSigner.generateCertificate(null, sshRequest, sshCertRecord, "host")).thenReturn(sshCertificates);
    when(sshSigner.getSignerCertificate(ZTSConsts.ZTS_SSH_HOST)).thenReturn("ssh-host");
    // setup the hostname resolver for our request
    String hostname = "host1.athenz.cloud";
    List<String> cnames = new ArrayList<>();
    cnames.add("cname.athenz.info");
    cnames.add("vip.athenz.info");
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    when(hostnameResolver.isValidHostCnameList(sshCertRecord.getService(), hostname, cnames, CertType.SSH_HOST)).thenReturn(true);
    when(hostnameResolver.isValidHostname(hostname)).thenReturn(true);
    InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
    instanceManager.setSSHSigner(sshSigner);
    boolean result = instanceManager.generateSSHIdentity(null, identity, hostname, sshCsr, null, sshCertRecord, "host");
    assertTrue(result);
    assertEquals(identity.getSshCertificate(), "ssh-cert");
    assertEquals(identity.getSshCertificateSigner(), "ssh-host");
    instanceManager.shutdown();
}
Also used : Path(java.nio.file.Path) HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) SSHSigner(com.yahoo.athenz.common.server.ssh.SSHSigner) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 9 with HostnameResolver

use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.

the class InstanceCertManagerTest method testGenerateSshIdentityInalidPrincipals.

@Test
public void testGenerateSshIdentityInalidPrincipals() throws IOException {
    Path path = Paths.get("src/test/resources/sshhost_valid_sample.csr");
    String sshCsr = new String(Files.readAllBytes(path));
    SSHSigner sshSigner = Mockito.mock(com.yahoo.athenz.common.server.ssh.SSHSigner.class);
    SSHCertRequest sshRequest = new SSHCertRequest();
    sshRequest.setCsr(sshCsr);
    SSHCertificates certs = new SSHCertificates();
    SSHCertificate cert = new SSHCertificate();
    cert.setCertificate("ssh-cert");
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.service");
    final SSHCertificates sshCertificates = certs.setCertificates(Collections.singletonList(cert));
    when(sshSigner.generateCertificate(null, sshRequest, null, "host")).thenReturn(sshCertificates);
    when(sshSigner.getSignerCertificate(ZTSConsts.ZTS_SSH_HOST)).thenReturn("ssh-host");
    // setup the hostname resolver for our request
    String hostname = "host1.athenz.cloud";
    List<String> cnames = new ArrayList<>();
    cnames.add("cname.athenz.info");
    cnames.add("vip.athenz.info");
    SSHCertRecord sshCertRecord = new SSHCertRecord();
    sshCertRecord.setService("athenz.examples.httpd");
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    when(hostnameResolver.isValidHostCnameList(sshCertRecord.getService(), hostname, cnames, CertType.SSH_HOST)).thenReturn(false);
    when(hostnameResolver.isValidHostname(hostname)).thenReturn(true);
    InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
    instanceManager.setSSHSigner(sshSigner);
    boolean result = instanceManager.generateSSHIdentity(null, identity, hostname, sshCsr, null, new SSHCertRecord(), "host");
    assertFalse(result);
    instanceManager.shutdown();
}
Also used : Path(java.nio.file.Path) HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) SSHSigner(com.yahoo.athenz.common.server.ssh.SSHSigner) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 10 with HostnameResolver

use of com.yahoo.athenz.common.server.dns.HostnameResolver in project athenz by yahoo.

the class InstanceCertManagerTest method testValidPrincipalsSSHRequestNulls.

@Test
public void testValidPrincipalsSSHRequestNulls() {
    final String hostname = "host1.athenz.cloud";
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    InstanceCertManager instanceManager = new InstanceCertManager(null, null, hostnameResolver, true, null);
    SSHCertRecord sshCertRecord = new SSHCertRecord();
    sshCertRecord.setService("athenz.examples.httpd");
    SSHCertRequest sshCertRequest = new SSHCertRequest();
    assertFalse(instanceManager.validPrincipals(hostname, sshCertRecord, sshCertRequest));
    sshCertRequest.setCertRequestData(new SSHCertRequestData());
    sshCertRequest.setCertRequestMeta(null);
    assertFalse(instanceManager.validPrincipals(hostname, sshCertRecord, sshCertRequest));
    sshCertRequest.setCertRequestData(null);
    sshCertRequest.setCertRequestMeta(new SSHCertRequestMeta());
    assertFalse(instanceManager.validPrincipals(hostname, sshCertRecord, sshCertRequest));
    // null principals returns true
    sshCertRequest.setCertRequestData(new SSHCertRequestData());
    sshCertRequest.setCertRequestMeta(new SSHCertRequestMeta());
    assertTrue(instanceManager.validPrincipals(hostname, sshCertRecord, sshCertRequest));
    instanceManager.shutdown();
}
Also used : HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Aggregations

HostnameResolver (com.yahoo.athenz.common.server.dns.HostnameResolver)37 Test (org.testng.annotations.Test)36 InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)14 SSHCertRecord (com.yahoo.athenz.common.server.ssh.SSHCertRecord)12 Path (java.nio.file.Path)12 InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)9 InstanceCertManager (com.yahoo.athenz.zts.cert.InstanceCertManager)7 DataStore (com.yahoo.athenz.zts.store.DataStore)7 SSHSigner (com.yahoo.athenz.common.server.ssh.SSHSigner)6 ChangeLogStore (com.yahoo.athenz.common.server.store.ChangeLogStore)5 ZMSFileChangeLogStore (com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore)5 InstanceZTSProvider (com.yahoo.athenz.instance.provider.impl.InstanceZTSProvider)5 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore)5 KeyStore (com.yahoo.athenz.auth.KeyStore)4 PrincipalToken (com.yahoo.athenz.auth.token.PrincipalToken)4 ResourceException (com.yahoo.athenz.instance.provider.ResourceException)4 X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)3 SignedDomain (com.yahoo.athenz.zms.SignedDomain)3 DataCache (com.yahoo.athenz.zts.cache.DataCache)3 TestHostnameResolver (com.yahoo.athenz.zts.cert.impl.TestHostnameResolver)3