Search in sources :

Example 11 with ClusterUser

use of org.apache.accumulo.cluster.ClusterUser in project accumulo by apache.

the class ScanIteratorIT method tearDown.

@After
public void tearDown() throws Exception {
    if (null != user) {
        if (saslEnabled) {
            ClusterUser rootUser = getAdminUser();
            UserGroupInformation.loginUserFromKeytab(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
        }
        connector.securityOperations().dropLocalUser(user);
    }
}
Also used : ClusterUser(org.apache.accumulo.cluster.ClusterUser) After(org.junit.After)

Example 12 with ClusterUser

use of org.apache.accumulo.cluster.ClusterUser in project accumulo by apache.

the class ConditionalWriterIT method testFields.

@Test
public void testFields() throws Exception {
    Connector conn = getConnector();
    String tableName = getUniqueNames(1)[0];
    String user = null;
    ClientConfiguration clientConf = cluster.getClientConfig();
    final boolean saslEnabled = clientConf.hasSasl();
    ClusterUser user1 = getUser(0);
    user = user1.getPrincipal();
    if (saslEnabled) {
        // The token is pointless for kerberos
        conn.securityOperations().createLocalUser(user, null);
    } else {
        conn.securityOperations().createLocalUser(user, new PasswordToken(user1.getPassword()));
    }
    Authorizations auths = new Authorizations("A", "B");
    conn.securityOperations().changeUserAuthorizations(user, auths);
    conn.securityOperations().grantSystemPermission(user, SystemPermission.CREATE_TABLE);
    conn = conn.getInstance().getConnector(user, user1.getToken());
    conn.tableOperations().create(tableName);
    try (ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig().setAuthorizations(auths));
        Scanner scanner = conn.createScanner(tableName, auths)) {
        ColumnVisibility cva = new ColumnVisibility("A");
        ColumnVisibility cvb = new ColumnVisibility("B");
        ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva));
        cm0.put("name", "last", cva, "doe");
        cm0.put("name", "first", cva, "john");
        cm0.put("tx", "seq", cva, "1");
        Assert.assertEquals(Status.ACCEPTED, cw.write(cm0).getStatus());
        scanner.setRange(new Range("99006"));
        // TODO verify all columns
        scanner.fetchColumn(new Text("tx"), new Text("seq"));
        Entry<Key, Value> entry = Iterables.getOnlyElement(scanner);
        Assert.assertEquals("1", entry.getValue().toString());
        long ts = entry.getKey().getTimestamp();
        // test wrong colf
        ConditionalMutation cm1 = new ConditionalMutation("99006", new Condition("txA", "seq").setVisibility(cva).setValue("1"));
        cm1.put("name", "last", cva, "Doe");
        cm1.put("name", "first", cva, "John");
        cm1.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm1).getStatus());
        // test wrong colq
        ConditionalMutation cm2 = new ConditionalMutation("99006", new Condition("tx", "seqA").setVisibility(cva).setValue("1"));
        cm2.put("name", "last", cva, "Doe");
        cm2.put("name", "first", cva, "John");
        cm2.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm2).getStatus());
        // test wrong colv
        ConditionalMutation cm3 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvb).setValue("1"));
        cm3.put("name", "last", cva, "Doe");
        cm3.put("name", "first", cva, "John");
        cm3.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm3).getStatus());
        // test wrong timestamp
        ConditionalMutation cm4 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts + 1).setValue("1"));
        cm4.put("name", "last", cva, "Doe");
        cm4.put("name", "first", cva, "John");
        cm4.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm4).getStatus());
        // test wrong timestamp
        ConditionalMutation cm5 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts - 1).setValue("1"));
        cm5.put("name", "last", cva, "Doe");
        cm5.put("name", "first", cva, "John");
        cm5.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm5).getStatus());
        // ensure no updates were made
        entry = Iterables.getOnlyElement(scanner);
        Assert.assertEquals("1", entry.getValue().toString());
        // set all columns correctly
        ConditionalMutation cm6 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts).setValue("1"));
        cm6.put("name", "last", cva, "Doe");
        cm6.put("name", "first", cva, "John");
        cm6.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.ACCEPTED, cw.write(cm6).getStatus());
        entry = Iterables.getOnlyElement(scanner);
        Assert.assertEquals("2", entry.getValue().toString());
    }
}
Also used : Condition(org.apache.accumulo.core.data.Condition) Connector(org.apache.accumulo.core.client.Connector) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) ConditionalWriter(org.apache.accumulo.core.client.ConditionalWriter) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) Value(org.apache.accumulo.core.data.Value) ClusterUser(org.apache.accumulo.cluster.ClusterUser) ConditionalWriterConfig(org.apache.accumulo.core.client.ConditionalWriterConfig) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 13 with ClusterUser

use of org.apache.accumulo.cluster.ClusterUser in project accumulo by apache.

the class TestingKdc method start.

/**
 * Starts the KDC and creates the principals and their keytabs
 */
public synchronized void start() throws Exception {
    checkArgument(!started, "KDC was already started");
    kdc.start();
    Thread.sleep(1000);
    // Create the identity for accumulo servers
    File accumuloKeytab = new File(keytabDir, "accumulo.keytab");
    String accumuloPrincipal = String.format("accumulo/%s", hostname);
    log.info("Creating Kerberos principal {} with keytab {}", accumuloPrincipal, accumuloKeytab);
    kdc.createPrincipal(accumuloKeytab, accumuloPrincipal);
    accumuloServerUser = new ClusterUser(qualifyUser(accumuloPrincipal), accumuloKeytab);
    // Create the identity for the "root" user
    String rootPrincipal = "root";
    File rootKeytab = new File(keytabDir, rootPrincipal + ".keytab");
    log.info("Creating Kerberos principal {} with keytab {}", rootPrincipal, rootKeytab);
    kdc.createPrincipal(rootKeytab, rootPrincipal);
    accumuloAdmin = new ClusterUser(qualifyUser(rootPrincipal), rootKeytab);
    clientPrincipals = new ArrayList<>(NUM_USERS);
    // Create a number of unprivileged users for tests to use
    for (int i = 1; i <= NUM_USERS; i++) {
        String clientPrincipal = "client" + i;
        File clientKeytab = new File(keytabDir, clientPrincipal + ".keytab");
        log.info("Creating Kerberos principal {} with keytab {}", clientPrincipal, clientKeytab);
        kdc.createPrincipal(clientKeytab, clientPrincipal);
        clientPrincipals.add(new ClusterUser(qualifyUser(clientPrincipal), clientKeytab));
    }
    started = true;
}
Also used : ClusterUser(org.apache.accumulo.cluster.ClusterUser) File(java.io.File)

Example 14 with ClusterUser

use of org.apache.accumulo.cluster.ClusterUser in project accumulo by apache.

the class AccumuloMiniClusterConfiguration method getAdminToken.

@Override
public AuthenticationToken getAdminToken() {
    if (saslEnabled) {
        // Turn on Kerberos authentication so UGI acts properly
        final Configuration conf = new Configuration(false);
        conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
        UserGroupInformation.setConfiguration(conf);
        ClusterUser rootUser = AccumuloClusterHarness.getKdc().getRootUser();
        try {
            UserGroupInformation.loginUserFromKeytab(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
            return new KerberosToken();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        String password = conf.get(ACCUMULO_MINI_PASSWORD_KEY);
        if (null == password) {
            password = ACCUMULO_MINI_PASSWORD_DEFAULT;
        }
        return new PasswordToken(password);
    }
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Configuration(org.apache.hadoop.conf.Configuration) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) ClusterUser(org.apache.accumulo.cluster.ClusterUser) IOException(java.io.IOException)

Example 15 with ClusterUser

use of org.apache.accumulo.cluster.ClusterUser in project accumulo by apache.

the class ArbitraryTablePropertiesIT method userSetGetTablePropertyWithoutPermission.

// Tests set and get of user added arbitrary properties using a non-root account without permissions to alter tables
@Test
public void userSetGetTablePropertyWithoutPermission() throws Exception {
    log.debug("Starting userSetGetTablePropertyWithoutPermission test ------------------------");
    // Make a test username and password
    ClusterUser user = getUser(1);
    String testUser = user.getPrincipal();
    AuthenticationToken testToken = user.getToken();
    // Create a root user and create the table
    // Create a test user and grant that user permission to alter the table
    final String tableName = getUniqueNames(1)[0];
    final Connector c = getConnector();
    c.securityOperations().createLocalUser(testUser, (testToken instanceof PasswordToken ? (PasswordToken) testToken : null));
    c.tableOperations().create(tableName);
    // Set variables for the property name to use and the initial value
    String propertyName = "table.custom.description";
    String description1 = "Description";
    // Make sure the property name is valid
    Assert.assertTrue(Property.isValidPropertyKey(propertyName));
    // Getting a fresh token will ensure we're logged in as this user (if necessary)
    Connector testConn = c.getInstance().getConnector(testUser, user.getToken());
    // If able to set it, the test fails, since permission was never granted
    try {
        testConn.tableOperations().setProperty(tableName, propertyName, description1);
        Assert.fail("Was able to set property without permissions");
    } catch (AccumuloSecurityException e) {
    }
    // Loop through properties to make sure the new property is not added to the list
    int count = 0;
    for (Entry<String, String> property : testConn.tableOperations().getProperties(tableName)) {
        if (property.getKey().equals(propertyName))
            count++;
    }
    Assert.assertEquals(count, 0);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) ClusterUser(org.apache.accumulo.cluster.ClusterUser) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Test(org.junit.Test)

Aggregations

ClusterUser (org.apache.accumulo.cluster.ClusterUser)36 Connector (org.apache.accumulo.core.client.Connector)22 Test (org.junit.Test)21 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)19 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)10 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)10 KerberosToken (org.apache.accumulo.core.client.security.tokens.KerberosToken)9 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)7 Before (org.junit.Before)7 Client (org.apache.accumulo.proxy.thrift.AccumuloProxy.Client)6 IOException (java.io.IOException)5 ByteBuffer (java.nio.ByteBuffer)5 Scanner (org.apache.accumulo.core.client.Scanner)5 Configuration (org.apache.hadoop.conf.Configuration)5 File (java.io.File)4 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)4 ClusterControl (org.apache.accumulo.cluster.ClusterControl)3 BatchWriter (org.apache.accumulo.core.client.BatchWriter)3 Key (org.apache.accumulo.core.data.Key)3 Mutation (org.apache.accumulo.core.data.Mutation)3