Search in sources :

Example 31 with HostnameResolver

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

the class SecureBootProviderTest method testRefreshInstance.

@Test
public void testRefreshInstance() {
    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.1", "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<>();
    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_HOSTNAME, "athenz-examples1.abc.com");
    confirmation.setAttributes(attributes);
    assertNotNull(provider.refreshInstance(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 32 with HostnameResolver

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

the class InstanceProviderManagerTest method testGetClassInstance.

@Test
public void testGetClassInstance() {
    HostnameResolver hostnameResolver = new HostnameResolver() {
    };
    InstanceProviderManager providerManager = new InstanceProviderManager(null, null, null, null, null);
    InstanceProvider provider = providerManager.getClassProvider("unknown.class", "provider", hostnameResolver);
    assertNull(provider);
    provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", "provider", hostnameResolver);
    assertNotNull(provider);
    provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSECSProvider", "provider", hostnameResolver);
    assertNotNull(provider);
    provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSLambdaProvider", "provider", hostnameResolver);
    assertNotNull(provider);
    // we should get this from the cache now
    provider = providerManager.getClassProvider("com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", "provider", hostnameResolver);
    assertNotNull(provider);
    // some invalid class name
    provider = providerManager.getClassProvider("com.yahoo.athenz.unknown.class", "provider", hostnameResolver);
    assertNull(provider);
    try {
        providerManager.getClassProvider("com.yahoo.athenz.zts.ZTSConsts", "provider", hostnameResolver);
        fail();
    } catch (Exception ignored) {
    }
}
Also used : HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InstanceProvider(com.yahoo.athenz.instance.provider.InstanceProvider) Test(org.testng.annotations.Test)

Example 33 with HostnameResolver

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

the class InstanceProviderManagerTest method testGetClassProviderForZTS.

@Test
public void testGetClassProviderForZTS() {
    SignedDomain signedDomain = createSignedDomainClassEndpoint("sys.auth", "zts", true, true);
    store.processSignedDomain(signedDomain, false);
    PrivateKey privateKey = Mockito.mock(PrivateKey.class);
    ServerPrivateKey serverPrivateKey = new ServerPrivateKey(privateKey, "0");
    InstanceProviderManager provider = new InstanceProviderManager(store, null, null, serverPrivateKey, null);
    InstanceProvider client = provider.getProvider("sys.auth.zts", new HostnameResolver() {
    });
    assertNotNull(client);
    client.close();
}
Also used : PrivateKey(java.security.PrivateKey) ServerPrivateKey(com.yahoo.athenz.auth.ServerPrivateKey) HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) SignedDomain(com.yahoo.athenz.zms.SignedDomain) ServerPrivateKey(com.yahoo.athenz.auth.ServerPrivateKey) InstanceProvider(com.yahoo.athenz.instance.provider.InstanceProvider) Test(org.testng.annotations.Test)

Example 34 with HostnameResolver

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

the class InstanceProviderManagerTest method testGetClassProviderException.

@Test
public void testGetClassProviderException() {
    SignedDomain signedDomain = createSignedDomainClassEndpoint("coretech", "weather", true, true);
    store.processSignedDomain(signedDomain, false);
    System.setProperty("athenz.instance.test.class.exception", "true");
    InstanceProviderManager provider = new InstanceProviderManager(store, null, null, null, null);
    InstanceProvider client = provider.getProvider("coretech.weather", new HostnameResolver() {
    });
    assertNull(client);
    System.clearProperty("athenz.instance.test.class.exception");
}
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 35 with HostnameResolver

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

the class ZTSImplTest method testPostInstanceRegisterInformationInvalidHostname.

@Test
public void testPostInstanceRegisterInformationInvalidHostname() throws IOException {
    ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
    DataStore store = new DataStore(structStore, null, ztsMetric);
    ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
    SignedDomain providerDomain = signedAuthorizedProviderDomain();
    store.processSignedDomain(providerDomain, false);
    SignedDomain tenantDomain = signedBootstrapTenantDomain("athenz.provider", "athenz", "production");
    store.processSignedDomain(tenantDomain, false);
    Path path = Paths.get("src/test/resources/athenz.instanceid.csr");
    String certCsr = new String(Files.readAllBytes(path));
    InstanceProviderManager instanceProviderManager = Mockito.mock(InstanceProviderManager.class);
    InstanceProvider providerClient = Mockito.mock(InstanceProvider.class);
    Mockito.when(providerClient.getProviderScheme()).thenReturn(InstanceProvider.Scheme.CLASS);
    Map<String, String> attrs = new HashMap<>();
    attrs.put("certSSH", "true");
    InstanceConfirmation confirmation = new InstanceConfirmation().setDomain("athenz").setService("production").setProvider("athenz.provider").setAttributes(attrs);
    HostnameResolver resolver = Mockito.mock(HostnameResolver.class);
    Mockito.when(resolver.isValidHostname("host1.athenz.cloud")).thenReturn(false);
    InstanceCertManager instanceManager = Mockito.spy(ztsImpl.instanceCertManager);
    Mockito.when(instanceProviderManager.getProvider("athenz.provider", resolver)).thenReturn(providerClient);
    Mockito.when(providerClient.confirmInstance(Mockito.any())).thenReturn(confirmation);
    Mockito.when(instanceManager.insertX509CertRecord(Mockito.any())).thenReturn(true);
    path = Paths.get("src/test/resources/athenz.instanceid.pem");
    String pem = new String(Files.readAllBytes(path));
    InstanceIdentity identity = new InstanceIdentity().setName("athenz.production").setX509Certificate(pem);
    Mockito.doReturn(identity).when(instanceManager).generateIdentity(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyInt(), Mockito.any());
    ztsImpl.instanceProviderManager = instanceProviderManager;
    ztsImpl.instanceCertManager = instanceManager;
    ztsImpl.hostnameResolver = resolver;
    InstanceRegisterInformation info = new InstanceRegisterInformation().setAttestationData("attestationData").setCsr(certCsr).setDomain("athenz").setService("production").setProvider("athenz.provider").setToken(true).setHostname("unknown.host.athenz.cloud");
    ResourceContext context = createResourceContext(null);
    try {
        ztsImpl.postInstanceRegisterInformation(context, info);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.BAD_REQUEST);
    }
}
Also used : Path(java.nio.file.Path) InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) InstanceCertManager(com.yahoo.athenz.zts.cert.InstanceCertManager) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore) HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) DataStore(com.yahoo.athenz.zts.store.DataStore) InstanceProvider(com.yahoo.athenz.instance.provider.InstanceProvider) 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