DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Software Design and Architecture
  3. Security
  4. Osgi, security on the fly

Osgi, security on the fly

Slim Ouertani user avatar by
Slim Ouertani
·
Apr. 08, 11 · Interview
Like (0)
Save
Tweet
Share
11.19K Views

Join the DZone community and get the full member experience.

Join For Free
Recently, I got a question on how to disallow bundles to call System.exit method and shutdown the full system. The first solution is to do with an old static java applications :
  • Delegates security to osgi framework :

java -jar framework.jar -init -Djava.security.manager -Djava.security.policy=all.policy
all.policy
grant { permission java.security.AllPermission;
};
  • deny all exit method call, using java security api and deploy it using single bundle with an activator like :

import org.osgi.framework. {BundleActivator ,BundleContext }

class Activator extends BundleActivator {
@throws (classOf[ java.lang.Exception])
def start( context:BundleContext){
System setSecurityManager new SecurityManager() {
override def checkExit( status:Int) {
throw new SecurityException("Reject System.exit(" + status + ")!");
}
}
}
@throws (classOf[ java.lang.Exception])
def stop( context:BundleContext) {}
}
This blog will show how to change security permission on the fly using console and per osgi bundle. Osgi is more flexible than standard java applications and security inside osgi is not an exception. Using Conditional Permission Admin make security more dynamic. To enable security on the fly we will use sosgi secure scala modules. https://github.com/ouertani/sosgi while this module is under development, We can do many thing with it.

Prerequisite :

  • scala-library-2.8.1.jar -> scala language based
  • scalamodules-core_2.8.1-2.0.4-SNAPSHOT.jar -> clever osgi dsl
  • slf4s_2.8.1-1.0.3.jar -> scala logging dsl
  • slf4j-api-1.6.1.jar with implementation as slf4j-simple-1.6.1.jar -> logging facade and implementation
  • sbt-launch-0.7.4.jar -> to compile and package a bundle
  • org.eclipse.osgi_3.6.2.jar -> curently base on equinox and its Command Interpreter

installing :

launch the framework using all.policy file as :

java -Djava.security.manager -Djava.security.policy=all.policy -jar org.eclipse.osgi_3.6.2.R36x_v20110210.jar -console
  • install base bundles like :

  • i file:./admin/scala-library-2.8.1.jar
  • i file:./admin/slf4j-api-1.6.1.jar
  • i file:./admin/slf4j-simple-1.6.1.jar
  • i file:./admin/slf4s_2.8.1-1.0.3.jar
  • i file:./admin/scalamodules-core_2.8.1-2.0.4-SNAPSHOT.jar
  • i file:./admin/osgi_2.8.1-1.0.jar
now for example install a bundles to illustrate usage :
class Activator extends   BundleActivator {
@throws (classOf[ java.lang.Exception])
def start( context:BundleContext){

try{

System exit 0

}catch {
case e => println (e)
}

}
.....

Running :

  • list bundles

osgi> ss

Framework is launched.

id State Bundle
0 ACTIVE org.eclipse.osgi_3.6.2.R36x_v20110210
1 INSTALLED scala-library_2.8.1
2 INSTALLED slf4j.api_1.6.1
3 INSTALLED slf4j.simple_1.6.1
4 INSTALLED com.weiglewilczek.slf4s_1.0.3
5 INSTALLED com.weiglewilczek.scalamodules.core_2.0.4.SNAPSHOT
6 INSTALLED com.ouertani.osgi_1.0.0
7 INSTALLED com.osgi.1e_1.0.0.SNAPSHOT

  • start security bundle
start 6
  • update admin dir
setprop ADMIN_DIR="*/admin/*"

  • init security bundle
sosgi !

  • try to call start bundle 7

start 7
java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
==>great system.exit is not allowed for this bundle.
  • to allow bundle 7 to call exit and shutdown the VM

sosgi + 7 ( java.lang.RuntimePermission ""exitVM.*"" )
  • add permissions to bundle 7

sosgi + 7 (  org.osgi.framework.PackagePermission ""*"" ""import"" )
sosgi + 7 ( java.lang.RuntimePermission ""exitVM.*"" )
  • start bundle 7 or update it

start 7
great ! VM is shuting down

More :

  • display security

sosgi ?
FOR + [generated_1301865364030] If org.osgi.service.condpermadmin.BundleLocationCondition */admin/* Then org.osgi.framework.ServicePermission org.eclipse.osgi.framework.console.CommandProvider register AND java.security.AllPermission * * AND org.osgi.framework.AdminPermission * * AND org.osgi.framework.PackagePermission * * END FI
  • clear all security

sosgi !!
source :http://ouertani.com/2011/04/osgi-security-on-the-fly/
security

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Host Hack Attempt Detection Using ELK
  • Demystifying the Infrastructure as Code Landscape
  • What “The Rings of Power” Taught Me About a Career in Tech
  • The Power of Docker Images: A Comprehensive Guide to Building From Scratch

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: