You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by ff...@apache.org on 2015/07/02 07:57:37 UTC
karaf git commit: [KARAF-3823]introduce
karaf.secured.command.compulsory.roles system property
Repository: karaf
Updated Branches:
refs/heads/karaf-2.x e95d0dea5 -> 648f860b3
[KARAF-3823]introduce karaf.secured.command.compulsory.roles system property
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/648f860b
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/648f860b
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/648f860b
Branch: refs/heads/karaf-2.x
Commit: 648f860b3da95a2d8d06923130af06b5f41775a0
Parents: e95d0de
Author: Freeman Fang <fr...@gmail.com>
Authored: Thu Jul 2 13:56:48 2015 +0800
Committer: Freeman Fang <fr...@gmail.com>
Committed: Thu Jul 2 13:56:48 2015 +0800
----------------------------------------------------------------------
.../distribution/text/etc/system.properties | 9 +++++++-
.../service/guard/impl/GuardProxyCatalog.java | 24 +++++++++++++++++---
2 files changed, 29 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/648f860b/assemblies/apache-karaf/src/main/distribution/text/etc/system.properties
----------------------------------------------------------------------
diff --git a/assemblies/apache-karaf/src/main/distribution/text/etc/system.properties b/assemblies/apache-karaf/src/main/distribution/text/etc/system.properties
index 89f3947..f12ecb9 100644
--- a/assemblies/apache-karaf/src/main/distribution/text/etc/system.properties
+++ b/assemblies/apache-karaf/src/main/distribution/text/etc/system.properties
@@ -110,6 +110,13 @@ org.apache.aries.proxy.weaving.disabled = org.objectweb.asm.*,org.slf4j.*,org.ap
karaf.secured.services=(&(osgi.command.scope=*)(osgi.command.function=*))
#
+# By default, if there's no ACL policy for a certain karaf command, this command is allowed to access
+# without the RBAC. We can change this behavior by enable the following property, which means
+# if a karaf command has no corresponding ACL then access it must have one of the karaf.secured.command.compulsory.roles
+#
+#karaf.secured.command.compulsory.roles=admin
+
+#
# Security properties
#
#java.security.policy=${karaf.home}/etc/all.policy
@@ -127,4 +134,4 @@ karaf.secured.services=(&(osgi.command.scope=*)(osgi.command.function=*))
# Even using a single instance, Karaf creates the lock file
# You can specify the location of the lock file using the
# karaf.lock.dir=/path/to/the/directory/containing/the/lock
-#
\ No newline at end of file
+#
http://git-wip-us.apache.org/repos/asf/karaf/blob/648f860b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java
----------------------------------------------------------------------
diff --git a/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java
index 396a768..b6344b5 100644
--- a/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java
+++ b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java
@@ -57,6 +57,7 @@ import org.slf4j.LoggerFactory;
public class GuardProxyCatalog implements ServiceListener {
public static final String KARAF_SECURED_SERVICES_SYSPROP = "karaf.secured.services";
public static final String SERVICE_GUARD_ROLES_PROPERTY = "org.apache.karaf.service.guard.roles";
+ public static final String KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY = "karaf.secured.command.compulsory.roles";
static final String PROXY_CREATOR_THREAD_NAME = "Secure OSGi Service Proxy Creator";
static final String PROXY_SERVICE_KEY = "." + GuardProxyCatalog.class.getName(); // The only currently used value is Boolean.TRUE
@@ -74,15 +75,24 @@ public class GuardProxyCatalog implements ServiceListener {
final ServiceTracker<ProxyManager, ProxyManager> proxyManagerTracker;
final ConcurrentMap<Long, ServiceRegistrationHolder> proxyMap = new ConcurrentHashMap<Long, ServiceRegistrationHolder>();
final BlockingQueue<CreateProxyRunnable> createProxyQueue = new LinkedBlockingQueue<CreateProxyRunnable>();
+ final String compulsoryRoles;
// These two variables control the proxy creator thread, which is started as soon as a ProxyManager Service
// becomes available.
volatile boolean runProxyCreator = true;
volatile Thread proxyCreatorThread = null;
+
+
GuardProxyCatalog(BundleContext bc) throws Exception {
LOG.trace("Starting GuardProxyCatalog");
myBundleContext = bc;
+
+ compulsoryRoles = System.getProperty(GuardProxyCatalog.KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY);
+ if (compulsoryRoles == null) {
+ //default behavior as before, no compulsory roles for a karaf command without the ACL
+ LOG.info("No compulsory roles for a karaf command without the ACL as its system property is not set: {}", GuardProxyCatalog.KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY);
+ }
// The service listener is used to update/unregister proxies if the backing service changes/goes away
bc.addServiceListener(this);
@@ -483,8 +493,9 @@ public class GuardProxyCatalog implements ServiceListener {
// This can probably be optimized. Maybe we can cache the config object relevant instead of
// walking through all of the ones that have 'service.guard'.
+ Object guardFilter = null;
for (Configuration config : getServiceGuardConfigs()) {
- Object guardFilter = config.getProperties().get(SERVICE_GUARD_KEY);
+ guardFilter = config.getProperties().get(SERVICE_GUARD_KEY);
if (guardFilter instanceof String) {
Filter filter = myBundleContext.createFilter((String) guardFilter);
if (filter.match(serviceReference)) {
@@ -504,8 +515,15 @@ public class GuardProxyCatalog implements ServiceListener {
}
if (!foundMatchingConfig) {
- // No mappings for this service, anyone can invoke
- return null;
+ if (compulsoryRoles != null && (guardFilter instanceof String)
+ && ((String)guardFilter).indexOf("osgi.command.scope") > 0
+ && ((String)guardFilter).indexOf("osgi.command.functio") > 0) {
+ //use compulsoryRoles roles for those karaf command without any ACL
+ roleMappings.put(Specificity.NAME_MATCH, ACLConfigurationParser.parseRoles(compulsoryRoles));
+ } else {
+ // No mappings for this service, anyone can invoke
+ return null;
+ }
}
if (roleMappings.size() == 0) {