Search in sources :

Example 61 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 62 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 63 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 64 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 65 with SignedDomain

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

the class ZTSImplTest method testGetAWSTemporaryCredentialsForbidden.

@Test
public void testGetAWSTemporaryCredentialsForbidden() {
    Principal principal = SimplePrincipal.create("user_domain", "user102", "v=U1;d=user_domain;n=user102;s=signature", 0, null);
    CloudStore cloudStore = Mockito.mock(CloudStore.class);
    Mockito.when(cloudStore.isAwsEnabled()).thenReturn(true);
    store.setCloudStore(cloudStore);
    zts.cloudStore = cloudStore;
    SignedDomain signedDomain = createAwsSignedDomain("athenz.product", "1234");
    store.processDomain(signedDomain, false);
    try {
        zts.getAWSTemporaryCredentials(createResourceContext(principal), "athenz.product", "aws_role_name");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 403);
    }
}
Also used : MockCloudStore(com.yahoo.athenz.zts.store.MockCloudStore) CloudStore(com.yahoo.athenz.zts.store.CloudStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Aggregations

SignedDomain (com.yahoo.athenz.zms.SignedDomain)157 Test (org.testng.annotations.Test)137 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)72 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)71 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)70 ArrayList (java.util.ArrayList)44 ChangeLogStore (com.yahoo.athenz.zts.store.ChangeLogStore)38 DataStore (com.yahoo.athenz.zts.store.DataStore)38 Principal (com.yahoo.athenz.auth.Principal)33 InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)31 Path (java.nio.file.Path)30 RoleMember (com.yahoo.athenz.zms.RoleMember)26 DomainData (com.yahoo.athenz.zms.DomainData)25 InstanceCertManager (com.yahoo.athenz.zts.cert.InstanceCertManager)25 Role (com.yahoo.athenz.zms.Role)22 CertificateAuthority (com.yahoo.athenz.auth.impl.CertificateAuthority)20 HashSet (java.util.HashSet)20 X509Certificate (java.security.cert.X509Certificate)19 InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)18 X509CertRecord (com.yahoo.athenz.zts.cert.X509CertRecord)18