Search in sources :

Example 56 with SignedDomain

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

the class ZTSImplTest method testGetRoleTokenTrustDomainWildCardGivenRole.

@Test
public void testGetRoleTokenTrustDomainWildCardGivenRole() {
    SignedDomain signedDomain = createSignedDomainWildCard("weather", "netops");
    store.processDomain(signedDomain, false);
    signedDomain = createTenantSignedDomainWildCard("netops", "weather");
    store.processDomain(signedDomain, false);
    Principal principal = SimplePrincipal.create("user_domain", "siteops_user_1", "v=U1;d=user_domain;n=siteops_user_1;s=signature", 0, null);
    ResourceContext context = createResourceContext(principal);
    RoleToken roleToken = zts.getRoleToken(context, "weather", "netops_superusers", null, null, null);
    com.yahoo.athenz.auth.token.RoleToken token = new com.yahoo.athenz.auth.token.RoleToken(roleToken.getToken());
    assertEquals(token.getRoles().size(), 1);
    assertTrue(token.getRoles().contains("netops_superusers"));
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 57 with SignedDomain

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

the class ZTSImplTest method testGetPublicKeyEntry.

@Test
public void testGetPublicKeyEntry() {
    SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
    store.processDomain(signedDomain, false);
    SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("hockey", "kings", "v=S1,d=hockey;n=kings;s=sig", 0, new PrincipalAuthority());
    ResourceContext context = createResourceContext(principal);
    PublicKeyEntry entry = zts.getPublicKeyEntry(context, "coretech", "storage", "0");
    assertEquals(entry.getId(), "0");
    assertEquals(entry.getKey(), ZTS_Y64_CERT0);
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) PrincipalAuthority(com.yahoo.athenz.auth.impl.PrincipalAuthority) Test(org.testng.annotations.Test)

Example 58 with SignedDomain

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

the class ZTSImplTest method testGetAccess.

@Test
public void testGetAccess() {
    SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
    store.processDomain(signedDomain, false);
    Principal principal = SimplePrincipal.create("user_domain", "user", "v=U1;d=user_domain;n=user;s=signature", 0, null);
    ResourceContext context = createResourceContext(principal);
    // user_domain.user only has access to writers
    Access access = zts.getAccess(context, "coretech", "writers", "user_domain.user");
    assertTrue(access.getGranted());
    access = zts.getAccess(context, "coretech", "readers", "user_domain.user");
    assertFalse(access.getGranted());
    // user_domain.user1 had access to readers and writers
    access = zts.getAccess(context, "coretech", "writers", "user_domain.user1");
    assertTrue(access.getGranted());
    access = zts.getAccess(context, "coretech", "readers", "user_domain.user1");
    assertTrue(access.getGranted());
    access = zts.getAccess(context, "coretech", "editors", "user_domain.user1");
    assertFalse(access.getGranted());
    // user_domain.user4 only has access to readers
    access = zts.getAccess(context, "coretech", "readers", "user_domain.user4");
    assertTrue(access.getGranted());
    access = zts.getAccess(context, "coretech", "writers", "user_domain.user4");
    assertFalse(access.getGranted());
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 59 with SignedDomain

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

the class ZTSImplTest method testGetRoleTokenCertMismatchDomain.

@Test
public void testGetRoleTokenCertMismatchDomain() throws Exception {
    RoleCertificateRequest req = new RoleCertificateRequest().setCsr(ROLE_CERT_DB_REQUEST).setExpiryTime(Long.valueOf(3600));
    SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
    store.processDomain(signedDomain, false);
    Principal principal = SimplePrincipal.create("user_domain", "user1", "v=U1;d=user_domain;n=user;s=signature", 0, null);
    ResourceContext context = createResourceContext(principal);
    try {
        zts.postRoleCertificateRequest(context, "coretech", "readers", req);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
    }
}
Also used : SignedDomain(com.yahoo.athenz.zms.SignedDomain) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 60 with SignedDomain

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

the class ZTSImplTest method testPostInstanceRefreshInformationSSHMismatchSerial.

@Test
public void testPostInstanceRefreshInformationSSHMismatchSerial() 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);
    InstanceCertManager instanceManager = Mockito.spy(ztsImpl.instanceCertManager);
    X509CertRecord certRecord = new X509CertRecord();
    certRecord.setInstanceId("1001");
    certRecord.setProvider("athenz.provider");
    certRecord.setService("athenz.production");
    certRecord.setCurrentSerial("123413");
    certRecord.setPrevSerial("123413");
    Mockito.when(instanceManager.getX509CertRecord("athenz.provider", "1001")).thenReturn(certRecord);
    Mockito.when(instanceManager.updateX509CertRecord(Mockito.any())).thenReturn(true);
    ztsImpl.instanceCertManager = instanceManager;
    InstanceRefreshInformation info = new InstanceRefreshInformation().setSsh("ssh-csr");
    CertificateAuthority certAuthority = new CertificateAuthority();
    SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "production", "v=S1;d=athenz;n=production;s=signature", 0, certAuthority);
    Path path = Paths.get("src/test/resources/athenz.instanceid.pem");
    String pem = new String(Files.readAllBytes(path));
    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(), 403);
    }
}
Also used : Path(java.nio.file.Path) 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) 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