Search in sources :

Example 46 with SSHCertRecord

use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.

the class DynamoDBSSHRecordStoreConnectionTest method testGetSSHCertRecord.

@Test
public void testGetSSHCertRecord() {
    Mockito.doReturn(item).when(table).getItem("primaryKey", "cn:1234");
    Mockito.doReturn("1234").when(item).getString("instanceId");
    Mockito.doReturn("cn").when(item).getString("service");
    Mockito.doReturn("host1,host2").when(item).getString("principals");
    Mockito.doReturn("10.10.10.11").when(item).getString("clientIP");
    Mockito.doReturn("10.10.10.12").when(item).getString("privateIP");
    DynamoDBSSHRecordStoreConnection dbConn = new DynamoDBSSHRecordStoreConnection(dynamoDB, tableName);
    dbConn.setOperationTimeout(10);
    SSHCertRecord certRecord = dbConn.getSSHCertRecord("1234", "cn");
    assertEquals(certRecord.getInstanceId(), "1234");
    assertEquals(certRecord.getService(), "cn");
    assertEquals(certRecord.getPrincipals(), "host1,host2");
    assertEquals(certRecord.getClientIP(), "10.10.10.11");
    assertEquals(certRecord.getPrivateIP(), "10.10.10.12");
    dbConn.close();
}
Also used : SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 47 with SSHCertRecord

use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.

the class DynamoDBSSHRecordStoreConnectionTest method testGetSSHCertRecordNotFoundNull.

@Test
public void testGetSSHCertRecordNotFoundNull() {
    Mockito.doReturn(null).when(table).getItem("primaryKey", "cn:1234");
    DynamoDBSSHRecordStoreConnection dbConn = new DynamoDBSSHRecordStoreConnection(dynamoDB, tableName);
    SSHCertRecord certRecord = dbConn.getSSHCertRecord("1234", "cn");
    assertNull(certRecord);
    dbConn.close();
}
Also used : SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 48 with SSHCertRecord

use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.

the class DynamoDBSSHRecordStoreConnectionTest method testUpdateSSHRecordException.

@Test
public void testUpdateSSHRecordException() {
    SSHCertRecord certRecord = new SSHCertRecord();
    Mockito.doThrow(new AmazonDynamoDBException("invalid operation")).when(table).updateItem(ArgumentMatchers.any(UpdateItemSpec.class));
    DynamoDBSSHRecordStoreConnection dbConn = new DynamoDBSSHRecordStoreConnection(dynamoDB, tableName);
    boolean requestSuccess = dbConn.updateSSHCertRecord(certRecord);
    assertFalse(requestSuccess);
    dbConn.close();
}
Also used : AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 49 with SSHCertRecord

use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.

the class ZTSImpl method generateSSHCertRecord.

SSHCertRecord generateSSHCertRecord(ResourceContext ctx, final String service, final String instanceId, final String privateIp) {
    // generate a ssh object for recording
    SSHCertRecord certRecord = new SSHCertRecord();
    certRecord.setService(service);
    certRecord.setInstanceId(instanceId);
    certRecord.setClientIP(ServletRequestUtil.getRemoteAddress(ctx.request()));
    if (StringUtil.isEmpty(privateIp)) {
        certRecord.setPrivateIP(certRecord.getClientIP());
    } else {
        certRecord.setPrivateIP(privateIp);
    }
    return certRecord;
}
Also used : SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord)

Example 50 with SSHCertRecord

use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.

the class FileSSHRecordStoreConnection method getCertRecord.

private synchronized SSHCertRecord getCertRecord(String instanceId, String service) {
    File file = new File(rootDir, getRecordFileName(instanceId, service));
    if (!file.exists()) {
        return null;
    }
    SSHCertRecord record = null;
    try {
        Path path = Paths.get(file.toURI());
        record = JSON.fromBytes(Files.readAllBytes(path), SSHCertRecord.class);
    } catch (IOException ex) {
        LOGGER.error("Unable to get ssh certificate record", ex);
    }
    return record;
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) File(java.io.File) SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord)

Aggregations

SSHCertRecord (com.yahoo.athenz.common.server.ssh.SSHCertRecord)57 Test (org.testng.annotations.Test)51 SSHSigner (com.yahoo.athenz.common.server.ssh.SSHSigner)14 HostnameResolver (com.yahoo.athenz.common.server.dns.HostnameResolver)12 Path (java.nio.file.Path)5 File (java.io.File)4 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 SSHRecordStore (com.yahoo.athenz.common.server.ssh.SSHRecordStore)3 SSHRecordStoreConnection (com.yahoo.athenz.common.server.ssh.SSHRecordStoreConnection)3 IOException (java.io.IOException)3 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)2 Principal (com.yahoo.athenz.auth.Principal)2 PrincipalToken (com.yahoo.athenz.auth.token.PrincipalToken)2 CryptoException (com.yahoo.athenz.auth.util.CryptoException)2 Priority (com.yahoo.athenz.common.server.cert.Priority)2 StatusCheckException (com.yahoo.athenz.common.server.status.StatusCheckException)2 InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)2 InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)2 ResourceException (com.yahoo.athenz.zts.ResourceException)2