Getting Started with LXC container

Photo by Alexandre Debiève on Unsplash

The first question would have raised in the mind What is LXC?

It is the userspace interface for the Linux kernel containment features.

Through simple steps, we will be to create and manage the application containers.

It is open source, licensed under GNU LGPLv2.1+, standard 2-clause BSD and GNU GPLv2. We can install the LXC directly from the Linux distribution repository. It will install all the required packages into the machine. To install the LXC you should have rights in the particular machine. Run the below command from your terminal,

sudo apt-get install lxc

Now that LXC is installed into your system, you can verify the installation by running the given below command,

 lxc-checkconfig

It will give you the below information

Kernel configuration not found at /proc/config.gz; searching…
Kernel configuration found at /boot/config-3.19.0–25-generic
— — Namespaces — -
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled
Multiple /dev/pts instances: enabled
 — — Control groups — -
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled
 — — Misc — -
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled
Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig

We will be creating the Linux containers as unprivileged in this article, for privilledged may look forward on my future articles. You have installed only in the root, you will be able to create the container only when you in the root. If other users tried to create the container directly it will fail. To allow any particular user to create privilege first we need to make sure the user has uid and gid map defined in /etc/subuid and /etc/subgid andwe need to add the user to the file /etc/lxc/lxc-usernet . By default, your user isn’t allowed to create any network device on the host, to change that, add

your-username veth lxcbr0 10

This means that “your-username” is allowed to create up to 10 veth devices connected to the lxcbr0 bridge.

And now, create your first container with:

lxc-create -t download -n my-container

The download template will show you a list of distributions, versions, and architectures to choose from. A good example would be “ubuntu”, “bionic” (18.04 LTS) and “i386”. or you can give the below command directly

lxc-create -t ubuntu -n my-container

It will install the latest ubuntu directly from the Ubuntu distributions.

A few seconds later your container will be created and you can start it with:

lxc-start -n my-container -d

You can then confirm its status with either of:

lxc-info -n my-container
lxc-ls -f

And get a shell inside it with:

lxc-attach -n my-container

Stopping it can be done with:

lxc-stop -n my-container

And finally removing it with:

lxc-destroy -n my-container

Hope it helps. Feel free to comment below if you find any discrepancies. For more information check out the official website Linux Containers.

Cheers,

Hari

Secure from clickjacking using X-Frame-Options in Apache

Cyber attacks have been a huge concern for many of the Internet company, most hackers try to attack the system or a network and grab the information using various methods to steal, alter and destroy data. According to Testbytesarticle on cyber attacks on Indiaprovide you the insight and lack of security in India.

In this article will provide the insight of securing the application which is running in the Apache to avoid the attack like clickjacking.

X-Frame-Options

Definition: The X-Frame-Options is HTTP response header is used to indicate whether or not a browser should be allowed to render a page in a <frame><iframe>or <object> .

Prevent from cyber attacks: clickjacking

Three Possible directives:

X-Frame-Options: deny
X-Frame-Options: sameorigin
X-Frame-Options: allow-from https://example.com/

Configuring Apache:

To append the frame options for the request from the same origin as the page itself.

Header always set X-Frame-Options "SAMEORIGIN"

To deny the request from other sites

Header always set X-Frame-Options “deny”

To allow from the specific site not allowing other sites

Header always set X-Frame-Options "allow-from https://example.com/"

Hope this helps!

Cheers,

Hari

Create a table using jqGrid

Photo by Lorenzo Cafaro on Pexels.com

Have you ever wonder showing and manipulating the tabular data without doing so much of coding or calling the server for each operation, make it happen within the client side. Well, jqGrid is the easiest way to start exploring your play.

What is the jqGrid?

jqGrid is the Ajax-enabled javascript. It provides the solutions for creating the table and manipulating the data in the client side and it can be integrated with any server-side technology.

It will load the data dynamically through Ajax callbacks.

jqGrid uses a jQuery JavaScript Library.

This example shows how we can load JSON data from Server.

HTML Code

 … 
<table id=”list1"></table> 
<div id=”pager1"></div>

JavaScript code

… 
jQuery(“#list1”).jqGrid(
{ 
url:’{URL}', 
datatype: “json”, 
colNames:[‘SNo’,’Date’, ‘Name’, ‘Age’,’Sex’,’Location’,’Notes’], 
colModel:[ 
{name:’sno’,index:’sno’, width:50}, 
{name:’date’,index:’date’, width:80},
{name:’name’,index:’name asc, invdate’, width:100}, 
{name:’age’,index:’age’, width:50, align:”right”}, 
{name:’sex’,index:’sex’, width:60, align:”right”},
{name:’location’,index:’location’, width:75, align:”right”},
{name:’note’,index:’note’, width:150, sortable:false} ],
rowNum:10, 
rowList:[10,20,30], 
pager: ‘#pager1’,
sortname: ‘sno’,
viewrecords: true, 
sortorder: “desc”, 
caption:”Create Example”
 });
 jQuery(“#list1”).jqGrid(‘navGrid’,’#pager1',{edit:false,add:false,del:false}); 

The above example replaces your API call in place of {URL}. In the data type, if the response is returned from the server is JSON then mention it as JSON. (It can also handle XML, Array).

The setup and configuration of the grid are managed by the setting options for the grid. Like in the above example we have used rowNum, rowList, pager, sort name, view records, caption, etc.

Hope it helps.

Cheers,

Hari

Enabling the Hibernate Logs

Question:

How do you configure Hibernate so that it writes the executed SQL statements and used bind parameters to the log file?

Solution:

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n


log4j.appender.widgety=org.apache.log4j.ConsoleAppender
log4j.appender.widgety.Target=System.out
log4j.appender.widgety.layout=org.apache.log4j.PatternLayout
log4j.appender.widgety.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n


### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

#log4j.rootLogger=DEBUG, INFO, warn, stdout
log4j.rootLogger=warn, stdout

log4j.logger.org.hibernate=warn
#log4j.logger.org.hibernate=debug

### log level for the this project - change this to "info" to kill the debug messages
log4j.logger.org.apache.wookie=info, widgety
log4j.logger.org.directwebremoting.impl.DefaultCreatorManager=info, widgety
#com.mchange.v2=debug widgety

log4j.category.org.directwebremoting=warn
log4j.additivity.org.directwebremoting=false

### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug

### log just the SQL
#log4j.logger.org.hibernate.SQL=debug

### log JDBC bind parameters ###
#log4j.logger.org.hibernate.type=info
#log4j.logger.org.hibernate.type=debug

### log schema export/update ###
l#og4j.logger.org.hibernate.tool.hbm2ddl=debug

### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug

### log cache activity ###
#log4j.logger.org.hibernate.cache=debug

### log transaction activity
#log4j.logger.org.hibernate.transaction=debug

### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug

### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace

Hope it helps!

Cheers,

Hari

She.. 

I have never  been into the ocean in my life,  always been in the shore hearing to each and everyone experienced of being there in and out of it. However, I constantly had an imagination of getting into it, to feel the breeze.   And it never happened until one day she shows up in the shore and waving her hand walking towards me with a cunning smile on her face.  She Came over to me and held my hand took me into the ocean. Bang! Everything has changed; she showed me the rupture of the ocean. And It did awaken our soul and made warm fuzzy feeling all over.  While we were in the shore our days always been short,  once we are into the  ocean days started getting prolonged. The kind of feel we had never been in before it was ecstasy. While in the ocean, we weren’t traveling at all,  we were stagnated at one place where things are cozy and comfy. The time started to flow; my day started with her and ended with her. When we started to travel as we were idle more than we thought,  things were getting worse: of course, we had a small bump  then and there but we never ever thought of getting out to the ocean. Nevertheless, it had happened one huge bump came in our way, and it threw me out of the ocean. Now I’m back in the shore gazing at the people,  all alone with a lot of questions running in my mind without any answers.  Why I was thrown out of the ocean? Why she Came and took me into an ocean? Out of the blue why she shows up?  Never-ending questions come up in my mind. Days of our life may vanish, but it will never dies.  

Cheers!