use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.
the class ZTSImplTest method testGetRoleTokenCert.
@Test
public void testGetRoleTokenCert() throws Exception {
// this csr is for sports:role.readers role
RoleCertificateRequest req = new RoleCertificateRequest().setCsr(ROLE_CERT_CORETECH_REQUEST).setExpiryTime(Long.valueOf(3600));
SignedDomain signedDomain = createSignedDomain("coretech", "weather", "storage", true);
store.processDomain(signedDomain, false);
File caCert = new File("src/test/resources/valid_cn_x509.cert");
X509Certificate caCertificate = Crypto.loadX509Certificate(caCert);
File caKey = new File("src/test/resources/private_encrypted.key");
PrivateKey caPrivateKey = Crypto.loadPrivateKey(caKey, "athenz");
CertSigner certSigner = new SelfCertSigner(caPrivateKey, caCertificate);
CloudStore cloudStore = new MockCloudStore(certSigner);
store.setCloudStore(cloudStore);
zts.cloudStore = cloudStore;
Principal principal = SimplePrincipal.create("user_domain", "user1", "v=U1;d=user_domain;n=user;s=signature", 0, null);
ResourceContext context = createResourceContext(principal);
RoleToken roleToken = zts.postRoleCertificateRequest(context, "coretech", "readers", req);
assertNotNull(roleToken);
assertEquals(roleToken.getExpiryTime(), TimeUnit.SECONDS.convert(30, TimeUnit.DAYS));
}
use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.
the class ZTSImplTest method testGetTenantDomainsSingleDomainWithUserDomain.
@Test
public void testGetTenantDomainsSingleDomainWithUserDomain() {
SignedDomain signedDomain = createSignedDomain("athenz.product", "weather.frontpage", "storage", true);
store.processDomain(signedDomain, false);
signedDomain = createTenantSignedDomain("weather.frontpage", "athenz.product", "storage");
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);
TenantDomains tenantDomains = zts.getTenantDomains(context, "athenz.product", "user_domain.user100", null, null);
assertNotNull(tenantDomains);
assertEquals(tenantDomains.getTenantDomainNames().size(), 1);
assertEquals(tenantDomains.getTenantDomainNames().get(0), "weather.frontpage");
}
use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.
the class ZTSImplTest method createMultipleSignedDomains.
private SignedDomain createMultipleSignedDomains(String domainName, String tenantDomain1, String tenantDomain2, String serviceName, boolean includeServices) {
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.adminuser"));
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(generateRoleName(domainName, serviceName + ".tenant." + tenantDomain1 + ".admin"));
role.setTrust(tenantDomain1);
roles.add(role);
role = new Role();
role.setName(generateRoleName(domainName, serviceName + ".tenant." + tenantDomain2 + ".admin"));
role.setTrust(tenantDomain2);
roles.add(role);
List<ServiceIdentity> services = new ArrayList<>();
if (includeServices) {
ServiceIdentity service = new ServiceIdentity();
service.setName(generateServiceIdentityName(domainName, serviceName));
setServicePublicKey(service, "0", ZTS_Y64_CERT0);
List<String> hosts = new ArrayList<>();
hosts.add("host1");
hosts.add("host2");
service.setHosts(hosts);
services.add(service);
}
List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>();
// tenant admin domain
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 + ":service." + serviceName + ".tenant." + tenantDomain1 + ".*");
assertion.setAction("read");
assertion.setRole(generateRoleName(domainName, serviceName + ".tenant." + tenantDomain1 + ".admin"));
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(generatePolicyName(domainName, serviceName + ".tenant." + tenantDomain1 + ".admin"));
policies.add(policy);
policy = new com.yahoo.athenz.zms.Policy();
assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource(domainName + ":service." + serviceName + ".tenant." + tenantDomain2 + ".*");
assertion.setAction("read");
assertion.setRole(generateRoleName(domainName, serviceName + ".tenant." + tenantDomain2 + ".admin"));
assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(generatePolicyName(domainName, serviceName + ".tenant." + tenantDomain2 + ".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);
domain.setModified(Timestamp.fromCurrentTime());
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), privateKey));
signedDomain.setKeyId("0");
return signedDomain;
}
use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.
the class ZTSImplTest method testGetTenantDomainsInvalidDomain.
@Test
public void testGetTenantDomainsInvalidDomain() {
SignedDomain signedDomain = createSignedDomain("athenz.product", "weather.frontpage", "storage", true);
store.processDomain(signedDomain, false);
signedDomain = createTenantSignedDomain("weather.frontpage", "athenz.product", "storage");
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);
try {
zts.getTenantDomains(context, "athenz.non_product", "user100", null, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 404);
}
}
use of com.yahoo.athenz.zms.SignedDomain in project athenz by yahoo.
the class ZTSImplTest method createSignedDomainWildCard.
private SignedDomain createSignedDomainWildCard(String domainName, String tenantDomain) {
SignedDomain signedDomain = new SignedDomain();
List<Role> roles = new ArrayList<>();
Role role = new Role();
role.setName(generateRoleName(domainName, "superusers"));
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.admin_user"));
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(generateRoleName(domainName, "users"));
roles.add(role);
role = new Role();
role.setName(generateRoleName(domainName, "netops_superusers"));
role.setTrust(tenantDomain);
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 + ":node.*");
assertion.setAction("node_user");
assertion.setRole(generateRoleName(domainName, "users"));
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(generatePolicyName(domainName, "users"));
policies.add(policy);
policy = new com.yahoo.athenz.zms.Policy();
assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource(domainName + ":node.*");
assertion.setAction("node_sudo");
assertion.setRole(generateRoleName(domainName, "netops_superusers"));
assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(generatePolicyName(domainName, "netops_superusers"));
policies.add(policy);
policy = new com.yahoo.athenz.zms.Policy();
assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource(domainName + ":node.*");
assertion.setAction("node_user");
assertion.setRole(generateRoleName(domainName, "superusers"));
assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(generatePolicyName(domainName, "superusers"));
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.setPolicies(signedPolicies);
domain.setModified(Timestamp.fromCurrentTime());
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), privateKey));
signedDomain.setKeyId("0");
return signedDomain;
}
Aggregations