Search in sources :

Example 6 with RangerPluginConfig

use of org.apache.ranger.authorization.hadoop.config.RangerPluginConfig in project ranger by apache.

the class RangerAdminUserStoreRetriever method init.

@Override
public void init(Map<String, String> options) {
    if (StringUtils.isNotBlank(serviceName) && serviceDef != null && StringUtils.isNotBlank(appId)) {
        RangerPluginConfig pluginConfig = super.pluginConfig;
        if (pluginConfig == null) {
            pluginConfig = new RangerPluginConfig(serviceDef.getName(), serviceName, appId, null, null, null);
        }
        RangerPluginContext pluginContext = getPluginContext();
        RangerAdminClient rangerAdmin = pluginContext.getAdminClient();
        this.adminClient = (rangerAdmin != null) ? rangerAdmin : pluginContext.createAdminClient(pluginConfig);
    } else {
        LOG.error("FATAL: Cannot find service/serviceDef to use for retrieving userstore. Will NOT be able to retrieve userstore.");
    }
}
Also used : RangerPluginConfig(org.apache.ranger.authorization.hadoop.config.RangerPluginConfig) RangerAdminClient(org.apache.ranger.admin.client.RangerAdminClient) RangerPluginContext(org.apache.ranger.plugin.policyengine.RangerPluginContext)

Example 7 with RangerPluginConfig

use of org.apache.ranger.authorization.hadoop.config.RangerPluginConfig in project ranger by apache.

the class PerfTestEngine method init.

public boolean init() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> init()");
    }
    boolean ret = false;
    Gson gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z").setPrettyPrinting().create();
    Reader reader = null;
    ServicePolicies servicePolicies;
    try {
        InputStream in = servicePoliciesFileURL.openStream();
        reader = new InputStreamReader(in, Charset.forName("UTF-8"));
        servicePolicies = gsonBuilder.fromJson(reader, ServicePolicies.class);
        RangerServiceDef serviceDef = servicePolicies.getServiceDef();
        String serviceType = (serviceDef != null) ? serviceDef.getName() : "";
        rangerPluginContext = new RangerPluginContext(new RangerPluginConfig(serviceType, null, "perf-test", null, null, policyEngineOptions));
        rangerPluginContext.getConfig().addResource(configFileURL);
        policyEvaluationEngine = new RangerPolicyEngineImpl(servicePolicies, rangerPluginContext, null);
        ret = true;
    } catch (Exception excp) {
        LOG.error("Error opening service-policies file or loading service-policies from file, URL=" + servicePoliciesFileURL, excp);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception excp) {
                LOG.error("Error closing file", excp);
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== init() : " + ret);
    }
    return ret;
}
Also used : RangerPluginConfig(org.apache.ranger.authorization.hadoop.config.RangerPluginConfig) ServicePolicies(org.apache.ranger.plugin.util.ServicePolicies) InputStreamReader(java.io.InputStreamReader) GsonBuilder(com.google.gson.GsonBuilder) InputStream(java.io.InputStream) Gson(com.google.gson.Gson) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef)

Example 8 with RangerPluginConfig

use of org.apache.ranger.authorization.hadoop.config.RangerPluginConfig in project ranger by apache.

the class RangerPolicyAdminCache method addPolicyAdmin.

private RangerPolicyAdmin addPolicyAdmin(ServicePolicies policies, RangerRoles roles, RangerPolicyEngineOptions options) {
    RangerServiceDef serviceDef = policies.getServiceDef();
    String serviceType = (serviceDef != null) ? serviceDef.getName() : "";
    RangerPluginContext rangerPluginContext = new RangerPluginContext(new RangerPluginConfig(serviceType, null, "ranger-admin", null, null, options));
    return new RangerPolicyAdminImpl(policies, rangerPluginContext, roles);
}
Also used : RangerPluginConfig(org.apache.ranger.authorization.hadoop.config.RangerPluginConfig) RangerPluginContext(org.apache.ranger.plugin.policyengine.RangerPluginContext) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef)

Example 9 with RangerPluginConfig

use of org.apache.ranger.authorization.hadoop.config.RangerPluginConfig in project ranger by apache.

the class TestPolicyEngine method runTests.

private void runTests(InputStreamReader reader, String testName) {
    try {
        PolicyEngineTestCase testCase = gsonBuilder.fromJson(reader, PolicyEngineTestCase.class);
        assertTrue("invalid input: " + testName, testCase != null && testCase.serviceDef != null && testCase.policies != null && testCase.tests != null);
        ServicePolicies servicePolicies = new ServicePolicies();
        servicePolicies.setServiceName(testCase.serviceName);
        servicePolicies.setServiceDef(testCase.serviceDef);
        servicePolicies.setPolicies(testCase.policies);
        RangerPolicyEngineOptions policyEngineOptions = new RangerPolicyEngineOptions();
        RangerPluginContext pluginContext = new RangerPluginContext(new RangerPluginConfig("hbase", null, testName, "cl1", "on-prem", policyEngineOptions));
        RangerPolicyEngine policyEngine = new RangerPolicyEngineImpl(servicePolicies, pluginContext, null);
        RangerAccessResultProcessor auditHandler = new RangerDefaultAuditHandler(pluginContext.getConfig());
        for (TestData test : testCase.tests) {
            RangerAccessResult expected = test.result;
            RangerAccessRequest request = test.request;
            RangerAccessResult result = policyEngine.evaluatePolicies(request, RangerPolicy.POLICY_TYPE_ACCESS, auditHandler);
            assertNotNull("result was null! - " + test.name, result);
            assertEquals("isAllowed mismatched! - " + test.name, expected.getIsAllowed(), result.getIsAllowed());
            assertEquals("isAudited mismatched! - " + test.name, expected.getIsAudited(), result.getIsAudited());
            assertEquals("policyId mismatched! - " + test.name, expected.getPolicyId(), result.getPolicyId());
        }
    } catch (Throwable excp) {
        excp.printStackTrace();
    }
}
Also used : RangerPolicyEngineImpl(org.apache.ranger.plugin.policyengine.RangerPolicyEngineImpl) RangerPluginConfig(org.apache.ranger.authorization.hadoop.config.RangerPluginConfig) ServicePolicies(org.apache.ranger.plugin.util.ServicePolicies) TestData(org.apache.ranger.authorization.hbase.TestPolicyEngine.PolicyEngineTestCase.TestData) RangerAccessResult(org.apache.ranger.plugin.policyengine.RangerAccessResult) RangerPolicyEngine(org.apache.ranger.plugin.policyengine.RangerPolicyEngine) RangerAccessResultProcessor(org.apache.ranger.plugin.policyengine.RangerAccessResultProcessor) RangerPluginContext(org.apache.ranger.plugin.policyengine.RangerPluginContext) RangerDefaultAuditHandler(org.apache.ranger.plugin.audit.RangerDefaultAuditHandler) RangerAccessRequest(org.apache.ranger.plugin.policyengine.RangerAccessRequest) RangerPolicyEngineOptions(org.apache.ranger.plugin.policyengine.RangerPolicyEngineOptions)

Example 10 with RangerPluginConfig

use of org.apache.ranger.authorization.hadoop.config.RangerPluginConfig in project ranger by apache.

the class TestPolicyDb method runTests.

private void runTests(InputStreamReader reader, String testName, RangerServiceDef serviceDef) {
    PolicyDbTestCase testCase = gsonBuilder.fromJson(reader, PolicyDbTestCase.class);
    if (serviceDef != null) {
        // Override serviceDef in the json test-file with a global service-def
        testCase.servicePolicies.setServiceDef(serviceDef);
    }
    assertTrue("invalid input: " + testName, testCase != null && testCase.servicePolicies != null && testCase.tests != null && testCase.servicePolicies.getPolicies() != null);
    RangerPolicyEngineOptions policyEngineOptions = new RangerPolicyEngineOptions();
    policyEngineOptions.evaluatorType = RangerPolicyEvaluator.EVALUATOR_TYPE_OPTIMIZED;
    policyEngineOptions.cacheAuditResults = false;
    policyEngineOptions.disableContextEnrichers = true;
    policyEngineOptions.disableCustomConditions = true;
    RangerPluginContext pluginContext = new RangerPluginContext(new RangerPluginConfig("hive", null, "test-policydb", "cl1", "on-prem", policyEngineOptions));
    RangerPolicyAdmin policyAdmin = new RangerPolicyAdminImpl(testCase.servicePolicies, pluginContext, null);
    for (TestData test : testCase.tests) {
        boolean expected = test.result;
        if (test.allowedPolicies != null) {
            List<RangerPolicy> allowedPolicies = policyAdmin.getAllowedUnzonedPolicies(test.user, test.userGroups, test.accessType);
            assertEquals("allowed-policy count mismatch!", test.allowedPolicies.size(), allowedPolicies.size());
            Set<Long> allowedPolicyIds = new HashSet<>();
            for (RangerPolicy allowedPolicy : allowedPolicies) {
                allowedPolicyIds.add(allowedPolicy.getId());
            }
            assertEquals("allowed-policy list mismatch!", test.allowedPolicies, allowedPolicyIds);
        } else {
            boolean result = policyAdmin.isAccessAllowedByUnzonedPolicies(test.resources, test.user, test.userGroups, test.accessType);
            assertEquals("isAccessAllowed mismatched! - " + test.name, expected, result);
        }
    }
}
Also used : RangerPluginConfig(org.apache.ranger.authorization.hadoop.config.RangerPluginConfig) TestData(org.apache.ranger.biz.TestPolicyDb.PolicyDbTestCase.TestData) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerPluginContext(org.apache.ranger.plugin.policyengine.RangerPluginContext) RangerPolicyEngineOptions(org.apache.ranger.plugin.policyengine.RangerPolicyEngineOptions) HashSet(java.util.HashSet)

Aggregations

RangerPluginConfig (org.apache.ranger.authorization.hadoop.config.RangerPluginConfig)16 RangerPluginContext (org.apache.ranger.plugin.policyengine.RangerPluginContext)6 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)4 GsonBuilder (com.google.gson.GsonBuilder)3 RangerDefaultAuditHandler (org.apache.ranger.plugin.audit.RangerDefaultAuditHandler)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Properties (java.util.Properties)2 RangerAdminClient (org.apache.ranger.admin.client.RangerAdminClient)2 AuditHandler (org.apache.ranger.audit.provider.AuditHandler)2 AuditProviderFactory (org.apache.ranger.audit.provider.AuditProviderFactory)2 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)2 RangerAccessRequest (org.apache.ranger.plugin.policyengine.RangerAccessRequest)2 RangerPolicyEngineImpl (org.apache.ranger.plugin.policyengine.RangerPolicyEngineImpl)2 RangerPolicyEngineOptions (org.apache.ranger.plugin.policyengine.RangerPolicyEngineOptions)2 BeforeClass (org.junit.BeforeClass)2 Gson (com.google.gson.Gson)1 InputStream (java.io.InputStream)1