use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class ZTSImplTest method createSignedDomainExpiration.
private SignedDomain createSignedDomainExpiration(String domainName, String serviceName, Boolean enabled) {
SignedDomain signedDomain = new SignedDomain();
List<Role> roles = new ArrayList<>();
String memberName = "user_domain.user1";
Role role = new Role();
role.setName(generateRoleName(domainName, "admin"));
List<RoleMember> members = new ArrayList<RoleMember>();
RoleMember roleMember = new RoleMember();
roleMember.setMemberName("user_domain.adminuser");
members.add(roleMember);
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(generateRoleName(domainName, "role1"));
members = new ArrayList<RoleMember>();
roleMember = new RoleMember();
roleMember.setMemberName(memberName);
roleMember.setExpiration(Timestamp.fromMillis(System.currentTimeMillis() - 100));
members.add(roleMember);
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(generateRoleName(domainName, "role2"));
members = new ArrayList<RoleMember>();
roleMember = new RoleMember();
roleMember.setMemberName(memberName);
roleMember.setExpiration(Timestamp.fromMillis(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1)));
members.add(roleMember);
role.setRoleMembers(members);
roles.add(role);
List<ServiceIdentity> services = new ArrayList<>();
ServiceIdentity service = new ServiceIdentity();
service.setName(generateServiceIdentityName(domainName, serviceName));
setServicePublicKey(service, "0", ZTS_Y64_CERT0);
services.add(service);
DomainData domain = new DomainData();
domain.setName(domainName);
domain.setRoles(roles);
domain.setServices(services);
domain.setModified(Timestamp.fromCurrentTime());
domain.setEnabled(enabled);
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), privateKey));
signedDomain.setKeyId("0");
return signedDomain;
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class ZTSImpl method getServiceIdentity.
// ----------------- the ServiceIdentity interface
public ServiceIdentity getServiceIdentity(ResourceContext ctx, String domainName, String serviceName) {
final String caller = "getserviceidentity";
final String callerTiming = "getserviceidentity_timing";
metric.increment(HTTP_GET);
logPrincipal(ctx);
validateRequest(ctx.request(), caller);
validate(domainName, TYPE_DOMAIN_NAME, caller);
validate(serviceName, TYPE_SIMPLE_NAME, caller);
// for consistent handling of all requests, we're going to convert
// all incoming object values into lower case since ZMS Server
// saves all of its object names in lower case
domainName = domainName.toLowerCase();
serviceName = serviceName.toLowerCase();
Object timerMetric = metric.startTiming(callerTiming, domainName);
DomainData domainData = dataStore.getDomainData(domainName);
if (domainData == null) {
metric.increment(HTTP_REQUEST, ZTSConsts.ZTS_UNKNOWN_DOMAIN);
metric.increment(caller, ZTSConsts.ZTS_UNKNOWN_DOMAIN);
throw notFoundError("Domain not found: '" + domainName + "'", caller, ZTSConsts.ZTS_UNKNOWN_DOMAIN);
}
// update our metric with dimension. we're moving the metric here
// after the domain name has been confirmed as valid since with
// dimensions we get stuck with persistent indexes so we only want
// to create them for valid domain names
metric.increment(HTTP_REQUEST, domainName);
metric.increment(caller, domainName);
String cnService = generateServiceIdentityName(domainName, serviceName);
ServiceIdentity ztsService = lookupServiceIdentity(domainData, cnService);
if (ztsService == null) {
throw notFoundError("Service not found: '" + cnService + "'", caller, domainName);
}
metric.stopTiming(timerMetric);
return ztsService;
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStore method processDomain.
public boolean processDomain(SignedDomain signedDomain, boolean saveInStore) {
DomainData domainData = signedDomain.getDomain();
String domainName = domainData.getName();
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Processing domain: {}", domainName);
}
if (domainData.getEnabled() == Boolean.FALSE) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Skipping disabled domain domain: {}", domainName);
}
return true;
}
if (!validateSignedDomain(signedDomain)) {
return false;
}
/* generate our cache object */
DataCache domainCache = new DataCache();
/* process the roles for this domain */
processDomainRoles(domainData, domainCache);
/* process the policies for this domain */
processDomainPolicies(domainData, domainCache);
/* finally process the service identities */
processDomainServiceIdentities(domainData, domainCache);
/* save the full domain object with the cache entry itself
* since we need to that information to handle
* getServiceIdentity and getServiceIdentityList requests */
domainCache.setDomainData(domainData);
/* add the entry to the cache and struct store */
addDomainToCache(domainName, domainCache);
if (saveInStore) {
changeLogStore.saveLocalDomain(domainName, signedDomain);
}
return true;
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStore method validateSignedDomain.
boolean validateSignedDomain(SignedDomain signedDomain) {
DomainData domainData = signedDomain.getDomain();
String keyId = signedDomain.getKeyId();
String signature = signedDomain.getSignature();
PublicKey zmsKey = zmsPublicKeyCache.getIfPresent(keyId == null ? "0" : keyId);
if (zmsKey == null) {
LOGGER.error("validateSignedDomain: ZMS Public Key id={} not available", keyId);
return false;
}
boolean result = Crypto.verify(SignUtils.asCanonicalString(domainData), zmsKey, signature);
if (!result) {
LOGGER.error("validateSignedDomain: Domain={} signature validation failed", domainData.getName());
LOGGER.error("validateSignedDomain: Signed Domain Data: {}", SignUtils.asCanonicalString(domainData));
}
return result;
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheRemovedPublicKeysVersions.
@Test
public void testAddDomainToCacheRemovedPublicKeysVersions() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DataCache dataCache = new DataCache();
ServiceIdentity service = new ServiceIdentity();
service.setName("coretech.storage");
setServicePublicKey(service, "0", ZTS_Y64_CERT0);
List<com.yahoo.athenz.zms.PublicKeyEntry> publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
com.yahoo.athenz.zms.PublicKeyEntry publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT1);
publicKey.setId("1");
publicKeys.add(publicKey);
publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT2);
publicKey.setId("2");
publicKeys.add(publicKey);
service.setPublicKeys(publicKeys);
List<ServiceIdentity> services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(service);
DomainData domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
/* update multiple version public keys */
dataCache = new DataCache();
service = new ServiceIdentity();
service.setName("coretech.storage");
publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT0);
publicKey.setId("0");
publicKeys.add(publicKey);
publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT2);
publicKey.setId("2");
publicKeys.add(publicKey);
service.setPublicKeys(publicKeys);
services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(service);
domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
assertEquals(store.getPublicKey("coretech", "storage", "0"), ZTS_PEM_CERT0);
assertNull(store.getPublicKey("coretech", "storage", "1"));
assertEquals(store.getPublicKey("coretech", "storage", "2"), ZTS_PEM_CERT2);
assertNull(store.getPublicKey("coretech", "storage", "3"));
}
Aggregations