Search in sources :

Example 41 with Assertion

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

the class ZTSImplTest method createTenantSignedDomain.

private SignedDomain createTenantSignedDomain(String domainName, String providerDomain, String providerService) {
    SignedDomain signedDomain = new SignedDomain();
    List<Role> roles = new ArrayList<>();
    Role role = new Role();
    role.setName(generateRoleName(domainName, "admin"));
    List<RoleMember> members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user"));
    role.setRoleMembers(members);
    roles.add(role);
    role = new Role();
    role.setName(generateRoleName(domainName, "tenancy." + providerDomain + "." + providerService + ".admin"));
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user100"));
    members.add(new RoleMember().setMemberName("user_domain.user101"));
    role.setRoleMembers(members);
    roles.add(role);
    role = new Role();
    role.setName(generateRoleName(domainName, "readers"));
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user100"));
    members.add(new RoleMember().setMemberName("user_domain.user101"));
    role.setRoleMembers(members);
    roles.add(role);
    ServiceIdentity service = new ServiceIdentity();
    service.setName(domainName + ".storage");
    setServicePublicKey(service, "0", ZTS_Y64_CERT0);
    List<String> hosts = new ArrayList<>();
    hosts.add("host1");
    hosts.add("host2");
    service.setHosts(hosts);
    List<ServiceIdentity> services = new ArrayList<>();
    services.add(service);
    List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>();
    com.yahoo.athenz.zms.Policy policy = new com.yahoo.athenz.zms.Policy();
    com.yahoo.athenz.zms.Assertion assertion = new com.yahoo.athenz.zms.Assertion();
    assertion.setResource(generateRoleName(providerDomain, "tenant.readers"));
    assertion.setAction("assume_role");
    assertion.setRole(generateRoleName(domainName, "readers"));
    List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
    assertions.add(assertion);
    policy.setAssertions(assertions);
    policy.setName(generatePolicyName(domainName, "tenancy.readers"));
    policies.add(policy);
    policy = new com.yahoo.athenz.zms.Policy();
    assertion = new com.yahoo.athenz.zms.Assertion();
    assertion.setResource(generateRoleName(providerDomain, providerService + ".tenant." + domainName + ".admin"));
    assertion.setAction("assume_role");
    assertion.setRole(generateRoleName(domainName, "tenancy." + providerDomain + "." + providerService + ".admin"));
    assertions = new ArrayList<>();
    assertions.add(assertion);
    policy.setAssertions(assertions);
    policy.setName(generatePolicyName(domainName, "tenancy." + providerDomain + "." + providerService + ".admin"));
    policies.add(policy);
    com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies();
    domainPolicies.setDomain(domainName);
    domainPolicies.setPolicies(policies);
    com.yahoo.athenz.zms.SignedPolicies signedPolicies = new com.yahoo.athenz.zms.SignedPolicies();
    signedPolicies.setContents(domainPolicies);
    signedPolicies.setSignature(Crypto.sign(SignUtils.asCanonicalString(domainPolicies), privateKey));
    signedPolicies.setKeyId("0");
    DomainData domain = new DomainData();
    domain.setName(domainName);
    domain.setRoles(roles);
    domain.setServices(services);
    domain.setPolicies(signedPolicies);
    signedDomain.setDomain(domain);
    signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), privateKey));
    signedDomain.setKeyId("0");
    return signedDomain;
}
Also used : Policy(com.yahoo.athenz.zms.Policy) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) Assertion(com.yahoo.athenz.zms.Assertion) SignedDomain(com.yahoo.athenz.zms.SignedDomain) Policy(com.yahoo.athenz.zms.Policy) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) Assertion(com.yahoo.athenz.zms.Assertion) Role(com.yahoo.athenz.zms.Role) RoleMember(com.yahoo.athenz.zms.RoleMember)

Example 42 with Assertion

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

the class ZTSImplTest method createAwsSignedDomain.

private SignedDomain createAwsSignedDomain(String domainName, String account) {
    SignedDomain signedDomain = new SignedDomain();
    List<Role> roles = new ArrayList<>();
    Role role = new Role();
    role.setName(generateRoleName(domainName, "admin"));
    List<RoleMember> members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user"));
    role.setRoleMembers(members);
    roles.add(role);
    role = new Role();
    role.setName(generateRoleName(domainName, "aws_role"));
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user100"));
    members.add(new RoleMember().setMemberName("user_domain.user101"));
    role.setRoleMembers(members);
    roles.add(role);
    List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>();
    com.yahoo.athenz.zms.Policy policy = new com.yahoo.athenz.zms.Policy();
    com.yahoo.athenz.zms.Assertion assertion = new com.yahoo.athenz.zms.Assertion();
    assertion.setResource(domainName + ":aws_role_name");
    assertion.setAction("assume_aws_role");
    assertion.setRole(generateRoleName(domainName, "aws_role"));
    List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
    assertions.add(assertion);
    policy.setAssertions(assertions);
    policy.setName(generatePolicyName(domainName, "aws_policy"));
    policies.add(policy);
    com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies();
    domainPolicies.setDomain(domainName);
    domainPolicies.setPolicies(policies);
    com.yahoo.athenz.zms.SignedPolicies signedPolicies = new com.yahoo.athenz.zms.SignedPolicies();
    signedPolicies.setContents(domainPolicies);
    signedPolicies.setSignature(Crypto.sign(SignUtils.asCanonicalString(domainPolicies), privateKey));
    signedPolicies.setKeyId("0");
    DomainData domain = new DomainData();
    domain.setName(domainName);
    domain.setAccount(account);
    domain.setRoles(roles);
    domain.setPolicies(signedPolicies);
    signedDomain.setDomain(domain);
    signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), privateKey));
    signedDomain.setKeyId("0");
    return signedDomain;
}
Also used : Policy(com.yahoo.athenz.zms.Policy) Policy(com.yahoo.athenz.zms.Policy) ArrayList(java.util.ArrayList) Assertion(com.yahoo.athenz.zms.Assertion) DomainData(com.yahoo.athenz.zms.DomainData) Assertion(com.yahoo.athenz.zms.Assertion) Role(com.yahoo.athenz.zms.Role) SignedDomain(com.yahoo.athenz.zms.SignedDomain) RoleMember(com.yahoo.athenz.zms.RoleMember)

Example 43 with Assertion

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

the class ZTSImplTest method testGetPolicyList.

@Test
public void testGetPolicyList() {
    List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>();
    List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
    com.yahoo.athenz.zms.Policy policy = new com.yahoo.athenz.zms.Policy();
    com.yahoo.athenz.zms.Assertion assertion = new com.yahoo.athenz.zms.Assertion();
    assertion.setResource("coretech:tenant.weather.*");
    assertion.setAction("read");
    assertion.setRole("coretech:role.readers");
    assertions.add(assertion);
    policy.setAssertions(assertions);
    policy.setName("coretech:policy.reader");
    policies.add(policy);
    policy = new com.yahoo.athenz.zms.Policy();
    assertion = new com.yahoo.athenz.zms.Assertion();
    assertion.setResource("coretech:tenant.weather.*");
    assertion.setAction("write");
    assertion.setRole("coretech:role.writers");
    assertions.add(assertion);
    policy.setAssertions(assertions);
    policy.setName("coretech:policy.writer");
    policies.add(policy);
    com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies();
    domainPolicies.setDomain("coretech");
    domainPolicies.setPolicies(policies);
    com.yahoo.athenz.zms.SignedPolicies signedPolicies = new com.yahoo.athenz.zms.SignedPolicies();
    signedPolicies.setContents(domainPolicies);
    signedPolicies.setSignature(Crypto.sign(SignUtils.asCanonicalString(domainPolicies), privateKey));
    signedPolicies.setKeyId("0");
    DomainData domain = new DomainData();
    domain.setName("coretech");
    domain.setPolicies(signedPolicies);
    domain.setModified(Timestamp.fromCurrentTime());
    List<com.yahoo.athenz.zts.Policy> policyList = zts.getPolicyList(domain);
    assertEquals(policyList.size(), 2);
    assertEquals(policyList.get(0).getName(), "coretech:policy.reader");
    assertEquals(policyList.get(1).getName(), "coretech:policy.writer");
}
Also used : Policy(com.yahoo.athenz.zms.Policy) Policy(com.yahoo.athenz.zms.Policy) ArrayList(java.util.ArrayList) Assertion(com.yahoo.athenz.zms.Assertion) DomainData(com.yahoo.athenz.zms.DomainData) Assertion(com.yahoo.athenz.zms.Assertion) Test(org.testng.annotations.Test)

Example 44 with Assertion

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

the class ZTSImplTest method testMatchDelegatedTrustAssertionNoRoleMatchWithOutPattern.

@Test
public void testMatchDelegatedTrustAssertionNoRoleMatchWithOutPattern() {
    Assertion assertion = new Assertion();
    assertion.setAction("ASSUME_ROLE");
    assertion.setEffect(AssertionEffect.ALLOW);
    assertion.setResource("*:role.Role");
    assertion.setRole("weather:role.Role");
    Role role = null;
    List<Role> roles = new ArrayList<>();
    role = createRoleObject("coretech", "Role1", null);
    roles.add(role);
    role = createRoleObject("coretech", "Role2", null);
    roles.add(role);
    assertFalse(authorizer.matchDelegatedTrustAssertion(assertion, "weather:role.Role1", null, roles));
    assertFalse(authorizer.matchDelegatedTrustAssertion(assertion, "coretech:role.Role", null, roles));
}
Also used : Role(com.yahoo.athenz.zms.Role) Assertion(com.yahoo.athenz.zms.Assertion) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 45 with Assertion

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

the class ZTSImplTest method createPolicyObject.

private Policy createPolicyObject(String domainName, String policyName, String roleName, boolean generateRoleName, String action, String resource, AssertionEffect effect) {
    Policy policy = new Policy();
    policy.setName(domainName + ":policy." + policyName);
    Assertion assertion = new Assertion();
    assertion.setAction(action);
    assertion.setEffect(effect);
    assertion.setResource(resource);
    if (generateRoleName) {
        assertion.setRole(domainName + ":role." + roleName);
    } else {
        assertion.setRole(roleName);
    }
    List<Assertion> assertList = new ArrayList<Assertion>();
    assertList.add(assertion);
    policy.setAssertions(assertList);
    return policy;
}
Also used : Policy(com.yahoo.athenz.zms.Policy) Assertion(com.yahoo.athenz.zms.Assertion) ArrayList(java.util.ArrayList)

Aggregations

Assertion (com.yahoo.athenz.zms.Assertion)61 Test (org.testng.annotations.Test)38 ArrayList (java.util.ArrayList)29 Policy (com.yahoo.athenz.zms.Policy)23 Role (com.yahoo.athenz.zms.Role)19 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)16 RoleMember (com.yahoo.athenz.zms.RoleMember)11 DomainData (com.yahoo.athenz.zms.DomainData)10 HashMap (java.util.HashMap)9 SQLException (java.sql.SQLException)8 SignedDomain (com.yahoo.athenz.zms.SignedDomain)7 DataCache (com.yahoo.athenz.zts.cache.DataCache)7 Domain (com.yahoo.athenz.zms.Domain)5 ResourceAccessList (com.yahoo.athenz.zms.ResourceAccessList)5 ResourceAccess (com.yahoo.athenz.zms.ResourceAccess)4 ResourceException (com.yahoo.athenz.zms.ResourceException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 DomainModifiedList (com.yahoo.athenz.zms.DomainModifiedList)3 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)3