Search in sources :

Example 21 with SignedDomain

use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.

the class DataStore method processSignedDomains.

// Internal
boolean processSignedDomains(SignedDomains signedDomains) {
    if (signedDomains == null) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("No updates received from ZMS Server");
        }
        return true;
    }
    /* now process all of our domains */
    List<SignedDomain> domains = signedDomains.getDomains();
    if (domains == null || domains.isEmpty()) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("No updates received from ZMS Server");
        }
        return true;
    }
    // we're going to return success as long as one of the
    // domains was successfully processed, otherwise there is
    // no point of retrying all domains over and over again
    boolean result = false;
    for (SignedDomain domain : domains) {
        if (processDomain(domain, true)) {
            result = true;
        }
    }
    return result;
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain)

Example 22 with SignedDomain

use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.

the class S3ChangeLogStore method getSignedDomain.

SignedDomain getSignedDomain(AmazonS3 s3, String domainName) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("AWSS3ChangeLog: getting signed domain {}", domainName);
    }
    SignedDomain signedDomain = null;
    try {
        S3Object object = s3.getObject(s3BucketName, domainName);
        try (S3ObjectInputStream s3is = object.getObjectContent()) {
            byte[] data = ByteStreams.toByteArray(s3is);
            signedDomain = JSON.fromBytes(data, SignedDomain.class);
        }
    } catch (Exception ex) {
        LOGGER.error("AWSS3ChangeLog: getSignedDomain - unable to get domain {} error: {}", domainName, ex.getMessage());
    }
    return signedDomain;
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) S3Object(com.amazonaws.services.s3.model.S3Object)

Example 23 with SignedDomain

use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.

the class ZMSFileChangeLogStore method getUpdatedSignedDomains.

@Override
public SignedDomains getUpdatedSignedDomains(StringBuilder lastModTimeBuffer) {
    try (ZMSClient zmsClient = getZMSClient()) {
        // request all the changes from ZMS. In this call we're asking for
        // meta data only so we'll only get the list of domains
        Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>();
        SignedDomains domainList = zmsClient.getSignedDomains(null, VALUE_TRUE, lastModTime, responseHeaders);
        // retrieve the tag value for the request
        String newLastModTime = retrieveTagHeader(responseHeaders);
        if (newLastModTime == null) {
            return null;
        }
        // set the last modification time to be returned to the caller
        lastModTimeBuffer.setLength(0);
        lastModTimeBuffer.append(newLastModTime);
        if (domainList == null || domainList.getDomains() == null) {
            return null;
        }
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("getUpdatedSignedDomains: {} updated domains", domainList.getDomains().size());
        }
        List<SignedDomain> domains = getSignedDomainList(zmsClient, domainList);
        return new SignedDomains().setDomains(domains);
    } catch (ZMSClientException ex) {
        LOGGER.error("Error when refreshing data from ZMS: {}", ex.getMessage());
        return null;
    }
}
Also used : HashMap(java.util.HashMap) SignedDomain(com.yahoo.athenz.zms.SignedDomain) ArrayList(java.util.ArrayList) List(java.util.List) SignedDomains(com.yahoo.athenz.zms.SignedDomains) ZMSClient(com.yahoo.athenz.zms.ZMSClient) ZMSClientException(com.yahoo.athenz.zms.ZMSClientException)

Example 24 with SignedDomain

use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.

the class ZTSImplTest method testPostInstanceRefreshInformationCertDNSMismatch.

@Test
public void testPostInstanceRefreshInformationCertDNSMismatch() throws IOException {
    ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
    DataStore store = new DataStore(structStore, null);
    ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
    SignedDomain providerDomain = signedAuthorizedProviderDomain();
    store.processDomain(providerDomain, false);
    SignedDomain tenantDomain = signedBootstrapTenantDomain("athenz.provider", "athenz", "production");
    store.processDomain(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);
    InstanceConfirmation confirmation = new InstanceConfirmation().setDomain("athenz").setService("production").setProvider("athenz.provider");
    InstanceCertManager instanceManager = Mockito.spy(ztsImpl.instanceCertManager);
    X509CertRecord certRecord = new X509CertRecord();
    certRecord.setInstanceId("1001");
    certRecord.setProvider("athenz.provider");
    certRecord.setService("athenz.production");
    certRecord.setCurrentSerial("16503746516960996918");
    certRecord.setPrevSerial("16503746516960996918");
    Mockito.when(instanceManager.getX509CertRecord("athenz.provider", "1001")).thenReturn(certRecord);
    Mockito.when(instanceProviderManager.getProvider("athenz.provider")).thenReturn(providerClient);
    Mockito.when(providerClient.refreshInstance(Mockito.any())).thenReturn(confirmation);
    path = Paths.get("src/test/resources/valid_cn_x509.cert");
    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.anyInt());
    ztsImpl.instanceProviderManager = instanceProviderManager;
    ztsImpl.instanceCertManager = instanceManager;
    InstanceRefreshInformation info = new InstanceRefreshInformation().setCsr(certCsr);
    CertificateAuthority certAuthority = new CertificateAuthority();
    SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1;d=athenz;n=production;s=signature", 0, certAuthority);
    X509Certificate cert = Crypto.loadX509Certificate(pem);
    principal.setX509Certificate(cert);
    ResourceContext context = createResourceContext(principal);
    try {
        ztsImpl.postInstanceRefreshInformation(context, "athenz.provider", "athenz", "production", "1001", info);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
        assertTrue(ex.getMessage().contains("dnsName attribute mismatch in CSR"));
    }
}
Also used : Path(java.nio.file.Path) InstanceConfirmation(com.yahoo.athenz.instance.provider.InstanceConfirmation) InstanceCertManager(com.yahoo.athenz.zts.cert.InstanceCertManager) X509CertRecord(com.yahoo.athenz.zts.cert.X509CertRecord) X509Certificate(java.security.cert.X509Certificate) ChangeLogStore(com.yahoo.athenz.zts.store.ChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) DataStore(com.yahoo.athenz.zts.store.DataStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) CertificateAuthority(com.yahoo.athenz.auth.impl.CertificateAuthority) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) InstanceProvider(com.yahoo.athenz.instance.provider.InstanceProvider) Test(org.testng.annotations.Test)

Example 25 with SignedDomain

use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.

the class ZTSImplTest method testGetPublicKey.

@Test
public void testGetPublicKey() {
    SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
    store.processDomain(signedDomain, false);
    String pubKey = zts.getPublicKey("coretech", "storage", "0");
    assertEquals(pubKey, ZTS_PEM_CERT0);
    pubKey = zts.getPublicKey("coretech", "storage", "100");
    assertNull(pubKey);
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) Test(org.testng.annotations.Test)

Aggregations

SignedDomain (com.yahoo.athenz.zms.SignedDomain)78 Test (org.testng.annotations.Test)68 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)30 PrincipalAuthority (com.yahoo.athenz.auth.impl.PrincipalAuthority)16 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)16 InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)14 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)14 DomainData (com.yahoo.athenz.zms.DomainData)13 ArrayList (java.util.ArrayList)13 S3Object (com.amazonaws.services.s3.model.S3Object)10 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)10 Principal (com.yahoo.athenz.auth.Principal)10 SignedDomains (com.yahoo.athenz.zms.SignedDomains)10 ChangeLogStore (com.yahoo.athenz.zts.store.ChangeLogStore)9 DataStore (com.yahoo.athenz.zts.store.DataStore)9 HashSet (java.util.HashSet)7 AuditLogMsgBuilder (com.yahoo.athenz.common.server.log.AuditLogMsgBuilder)6 AuditLogger (com.yahoo.athenz.common.server.log.AuditLogger)6 DefaultAuditLogMsgBuilder (com.yahoo.athenz.common.server.log.impl.DefaultAuditLogMsgBuilder)6 DefaultAuditLogger (com.yahoo.athenz.common.server.log.impl.DefaultAuditLogger)6