Search in sources :

Example 26 with HostnameResolver

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

the class SecureBootProviderTest method testConfirmInstanceWithSanIp.

@Test
public void testConfirmInstanceWithSanIp() {
    System.setProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS, "com.yahoo.athenz.instance.provider.impl.MockAttrValidatorFactory");
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    Mockito.when(hostnameResolver.getAllByName("athenz-examples1.abc.com")).thenReturn(new HashSet<>(Arrays.asList("10.1.1.2", "2001:db8:a0b:12f0:0:0:0:1")));
    SecureBootProvider provider = new SecureBootProvider();
    provider.initialize("sys.auth.sb-provider", "com.yahoo.athenz.instance.provider.impl.SecureBootProvider", null, null);
    provider.setHostnameResolver(hostnameResolver);
    InstanceConfirmation confirmation = new InstanceConfirmation();
    confirmation.setAttestationData("sample attestation data");
    confirmation.setDomain("sports");
    confirmation.setService("api");
    confirmation.setProvider("sys.auth.sb-provider");
    Map<String, String> attributes = new HashMap<>();
    String subjectDn = "CN=athenz-examples1.abc.com,OU=Testing Domain,O=Athenz,L=LA,ST=CA,C=US";
    attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_DNS, "api.sports.zts.athenz.cloud,inst1.instanceid.athenz.zts.athenz.cloud");
    attributes.put(InstanceProvider.ZTS_INSTANCE_HOSTNAME, "athenz-examples1.abc.com");
    attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.2");
    attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_ISSUER_DN, "CN=issuer1");
    attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_SUBJECT_DN, subjectDn);
    confirmation.setAttributes(attributes);
    assertNotNull(provider.confirmInstance(confirmation));
    provider.close();
    System.clearProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS);
}
Also used : InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) Test(org.testng.annotations.Test)

Example 27 with HostnameResolver

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

the class SecureBootProviderTest method testValidateSanIp.

@Test
public void testValidateSanIp() {
    assertTrue(new SecureBootProvider().validateSanIp("athenz-examples1.abc.com", null));
    assertTrue(new SecureBootProvider().validateSanIp("athenz-examples1.abc.com", new HashMap<>()));
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    Mockito.when(hostnameResolver.getAllByName("athenz-examples1.abc.com")).thenReturn(new HashSet<>(Arrays.asList("10.1.1.2", "2001:db8:a0b:12f0:0:0:0:1")));
    SecureBootProvider provider = new SecureBootProvider();
    provider.initialize("sys.auth.sb-provider", "com.yahoo.athenz.instance.provider.impl.SecureBootProvider", null, null);
    provider.setHostnameResolver(hostnameResolver);
    assertTrue(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.2,2001:db8:a0b:12f0:0:0:0:1")));
    assertTrue(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.2")));
    assertTrue(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "2001:db8:a0b:12f0:0:0:0:1")));
    assertTrue(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "2001:db8:a0b:12f0:0:0:0:1,10.1.1.2")));
    assertFalse(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.3")));
    assertFalse(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.3,2001:db8:a0b:12f0:0:0:0:1")));
    assertFalse(provider.validateSanIp("athenz-examples1.abc.com", Collections.singletonMap(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.2,2001:db8:a0b:12f0:0:0:0:2")));
}
Also used : HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) Test(org.testng.annotations.Test)

Example 28 with HostnameResolver

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

the class SecureBootProviderTest method testConfirmInstanceInvalidSanDns.

@Test
public void testConfirmInstanceInvalidSanDns() {
    System.setProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS, "com.yahoo.athenz.instance.provider.impl.MockAttrValidatorFactory");
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    Mockito.when(hostnameResolver.getAllByName("athenz-examples1.abc.com")).thenReturn(new HashSet<>(Arrays.asList("10.1.1.2", "2001:db8:a0b:12f0:0:0:0:1")));
    SecureBootProvider provider = new SecureBootProvider();
    provider.initialize("sys.auth.sb-provider", "com.yahoo.athenz.instance.provider.impl.SecureBootProvider", null, null);
    provider.setHostnameResolver(hostnameResolver);
    InstanceConfirmation confirmation = new InstanceConfirmation();
    confirmation.setAttestationData("sample attestation data");
    confirmation.setDomain("sports");
    confirmation.setService("api");
    confirmation.setProvider("sys.auth.sb-provider");
    Map<String, String> attributes = new HashMap<>();
    String subjectDn = "CN=athenz-examples1.abc.com,OU=Testing Domain,O=Athenz,L=LA,ST=CA,C=US";
    attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_DNS, "api.sports.unknown.cloud,inst1.instanceid.athenz.zts.athenz.cloud");
    attributes.put(InstanceProvider.ZTS_INSTANCE_HOSTNAME, "athenz-examples1.abc.com");
    attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.2");
    attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_ISSUER_DN, "CN=issuer1");
    attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_SUBJECT_DN, subjectDn);
    confirmation.setAttributes(attributes);
    try {
        provider.confirmInstance(confirmation);
        fail();
    } catch (ResourceException e) {
        assertTrue(e.getMessage().contains("Unable to validate certificate request DNS"));
    }
    provider.close();
    System.clearProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS);
}
Also used : InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) ResourceException(com.yahoo.athenz.instance.provider.ResourceException) Test(org.testng.annotations.Test)

Example 29 with HostnameResolver

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

the class SecureBootProviderTest method testConfirmInstance.

@Test
public void testConfirmInstance() {
    System.setProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS, "com.yahoo.athenz.instance.provider.impl.MockAttrValidatorFactory");
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    Mockito.when(hostnameResolver.getAllByName("athenz-examples1.abc.com")).thenReturn(new HashSet<>(Arrays.asList("10.1.1.2", "2001:db8:a0b:12f0:0:0:0:1")));
    SecureBootProvider provider = new SecureBootProvider();
    provider.initialize("sys.auth.sb-provider", "com.yahoo.athenz.instance.provider.impl.SecureBootProvider", null, null);
    provider.setHostnameResolver(hostnameResolver);
    InstanceConfirmation confirmation = new InstanceConfirmation();
    confirmation.setAttestationData("sample attestation data");
    confirmation.setDomain("sports");
    confirmation.setService("api");
    confirmation.setProvider("sys.auth.sb-provider");
    Map<String, String> attributes = new HashMap<>();
    String subjectDn = "CN=athenz-examples1.abc.com,OU=Testing Domain,O=Athenz,L=LA,ST=CA,C=US";
    attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_DNS, "api.sports.zts.athenz.cloud,inst1.instanceid.athenz.zts.athenz.cloud");
    attributes.put(InstanceProvider.ZTS_INSTANCE_HOSTNAME, "athenz-examples1.abc.com");
    attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_ISSUER_DN, "CN=issuer1");
    attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_SUBJECT_DN, subjectDn);
    confirmation.setAttributes(attributes);
    assertNotNull(provider.confirmInstance(confirmation));
    provider.close();
    System.clearProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS);
}
Also used : InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) Test(org.testng.annotations.Test)

Example 30 with HostnameResolver

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

the class SecureBootProviderTest method testConfirmInstanceInvalidSanIp.

@Test
public void testConfirmInstanceInvalidSanIp() {
    System.setProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS, "com.yahoo.athenz.instance.provider.impl.MockAttrValidatorFactory");
    HostnameResolver hostnameResolver = Mockito.mock(HostnameResolver.class);
    Mockito.when(hostnameResolver.getAllByName("athenz-examples1.abc.com")).thenReturn(new HashSet<>(Arrays.asList("10.1.1.2", "2001:db8:a0b:12f0:0:0:0:1")));
    SecureBootProvider provider = new SecureBootProvider();
    provider.initialize("sys.auth.sb-provider", "com.yahoo.athenz.instance.provider.impl.SecureBootProvider", null, null);
    provider.setHostnameResolver(hostnameResolver);
    InstanceConfirmation confirmation = new InstanceConfirmation();
    confirmation.setAttestationData("sample attestation data");
    confirmation.setDomain("sports");
    confirmation.setService("api");
    confirmation.setProvider("sys.auth.sb-provider");
    Map<String, String> attributes = new HashMap<>();
    String subjectDn = "CN=athenz-examples1.abc.com,OU=Testing Domain,O=Athenz,L=LA,ST=CA,C=US";
    attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_DNS, "api.sports.zts.athenz.cloud,inst1.instanceid.athenz.zts.athenz.cloud");
    attributes.put(InstanceProvider.ZTS_INSTANCE_HOSTNAME, "athenz-examples1.abc.com");
    attributes.put(InstanceProvider.ZTS_INSTANCE_SAN_IP, "10.1.1.3");
    attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_ISSUER_DN, "CN=issuer1");
    attributes.put(InstanceProvider.ZTS_INSTANCE_CERT_SUBJECT_DN, subjectDn);
    confirmation.setAttributes(attributes);
    try {
        provider.confirmInstance(confirmation);
        fail();
    } catch (ResourceException e) {
        assertTrue(e.getMessage().contains("Unable to validate request IP address"));
    }
    provider.close();
    System.clearProperty(SecureBootProvider.ZTS_PROP_SB_ATTR_VALIDATOR_FACTORY_CLASS);
}
Also used : InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) ResourceException(com.yahoo.athenz.instance.provider.ResourceException) 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