Skip to content

Commit

Permalink
generate a metric when domain validation fails (AthenZ#1437)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Avetisyan <[email protected]>

Co-authored-by: Henry Avetisyan <[email protected]>
  • Loading branch information
havetisyan and Henry Avetisyan authored Apr 9, 2021
1 parent b7440c2 commit 11da4bc
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public ZTSImpl(CloudStore implCloudStore, DataStore implDataStore) {
// create our data store. we must have our cloud store and private
// key details already retrieved at this point

dataStore = new DataStore(clogStore, cloudStore);
dataStore = new DataStore(clogStore, cloudStore, metric);

// Initialize our storage subsystem which would load all data into
// memory and if necessary retrieve the data from ZMS. It will also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.yahoo.athenz.auth.util.StringUtils;
import com.yahoo.athenz.common.metrics.Metric;
import com.yahoo.athenz.common.server.db.RolesProvider;
import com.yahoo.athenz.common.server.store.ChangeLogStore;
import com.yahoo.athenz.common.server.util.ConfigProperties;
Expand Down Expand Up @@ -67,6 +68,7 @@ public class DataStore implements DataCacheProvider, RolesProvider {

ChangeLogStore changeLogStore;
private CloudStore cloudStore;
private final Metric metric;
private final Cache<String, DataCache> cacheStore;
final Cache<String, PublicKey> zmsPublicKeyCache;
final Cache<String, List<GroupMember>> groupMemberCache;
Expand Down Expand Up @@ -98,12 +100,13 @@ public class DataStore implements DataCacheProvider, RolesProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(DataStore.class);

public DataStore(ChangeLogStore clogStore, CloudStore cloudStore) {
public DataStore(ChangeLogStore clogStore, CloudStore cloudStore, Metric metric) {

/* save our store objects */

this.changeLogStore = clogStore;
this.setCloudStore(cloudStore);
this.metric = metric;

/* generate our cache stores */

Expand Down Expand Up @@ -519,6 +522,7 @@ boolean validateSignedDomain(SignedDomain signedDomain) {
boolean result = Crypto.verify(SignUtils.asCanonicalString(domainData), zmsKey, signature);

if (!result) {
metric.increment("domain_validation_failure", domainData.getName());
LOGGER.error("validateSignedDomain: Domain={} signature validation failed", domainData.getName());
LOGGER.error("validateSignedDomain: Signed Domain Data: {}", SignUtils.asCanonicalString(domainData));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static org.testng.Assert.assertFalse;

import com.yahoo.athenz.auth.ServerPrivateKey;
import com.yahoo.athenz.common.metrics.Metric;
import com.yahoo.athenz.common.server.dns.HostnameResolver;
import com.yahoo.athenz.common.server.store.ChangeLogStore;
import com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore;
Expand All @@ -60,6 +61,7 @@
public class InstanceProviderManagerTest {

private PrivateKey privateKey = null;
private Metric ztsMetric = null;
private DataStore store = null;

private static final String ZTS_DATA_STORE_PATH = "/tmp/zts_server_unit_tests/zts_root";
Expand All @@ -69,6 +71,10 @@ public class InstanceProviderManagerTest {
public void setUpClass() {
System.setProperty(PROP_ATHENZ_CONF, "src/test/resources/athenz.conf");
System.setProperty(ZTS_PROP_FILE_NAME, "src/test/resources/zts.properties");

// setup our metric class

ztsMetric = new com.yahoo.athenz.common.metrics.impl.NoOpMetric();
}

@BeforeMethod
Expand All @@ -88,7 +94,7 @@ public void setup() {

System.setProperty(ZTSConsts.ZTS_PROP_PROVIDER_ENDPOINTS, ".athenz2.com,.athenz.com");

store = new DataStore(structStore, null);
store = new DataStore(structStore, null, ztsMetric);
}

@AfterMethod
Expand Down
Loading

0 comments on commit 11da4bc

Please sign in to comment.