본문 바로가기
server/Cent_os7

CentOS 7 OvpenVpn Oracle Freeradius 연동


1.FreeRadius 설치 및 rlm_sql_oracle module 설치

 

-기본적으로 rpm 혹은 yum 으로 바로 설치 가능 하나, oracle 연동 모듈을 설치 하기 위해서 ㅅ소스컴파일이 필요함 (freeradius3 이 가장 최신 안정화 버전이나, openvpn 연동을 위해서는freeradius2 를 설치 해야함)

#cd /usr/local/src

# wget ftp://ftp.freeradius.org/pub/freeradius/freeradius-server-2.2.10.tar.gz

#tar xvzf freeradius-server-2.2.10.tar.gz

# cd freeradius-server-2.2.10/

 

-바로 설치시 연동이 정상적으로 불가능 하며, 아래와 같이 configure.in파일을 새로 작성 한다.

(from Atif’s Blog : http://atif-razzaq.blogspot.kr/2011/01/freeradius-with-oracle.html)

 


# cd src/modules/rlm_sql/drivers/rlm_sql_oracle/

# >configure.in

# vi configure.in

 

AC_INIT(sql_oracle.c)

AC_REVISION($Revision: 1.10 $)

AC_DEFUN(modname,[rlm_sql_oracle])

 

fail=

sql_oracle_ldflags=

sql_oracle_cflags=

if test x$with_[]modname != xno; then

 

AC_MSG_CHECKING([for oci.h])

 

dnl #

dnl # See if the user passed in the oracle_home_dir option and

dnl # use that first. If not, use $ORACLE_HOME. If that's

dnl # not defined, give up. There's no point in blindly

dnl # hunting around for Oracle - there's no standard place

dnl # for it. Any sane Oracle user/developer should have $ORACLE_HOME

dnl # defined anyways.

dnl #

 

dnl ############################################################

dnl # Check for command line options

dnl ############################################################

 

dnl extra argument: --with-oracle-version=VER

oracle_version=

AC_ARG_WITH(oracle-version,

[AS_HELP_STRING([--with-oracle-version=VER],

[Version of Oracle to search for. Should be 10 for Oracle 10g and 11 for 11g])],

[case "$withval" in

11)

oracle_version="$withval"

;;

10)

oracle_version="$withval"

;;

*)

AC_MSG_ERROR(Need oracle-version)

;;

esac])

 

dnl extra argument: --with-oracle-include-dir=DIR

oracle_include_dir=

AC_ARG_WITH(oracle-include-dir,

[AS_HELP_STRING([--with-oracle-include-dir=DIR],

[Directory where the Oracle includes may be found. It should be located under ORACLE_HOME if you have client SDK installed. Use --with-oracle-include-dir=yes if you are sure that your compiler include path includes Oracle include dir. Hint: you might try to do: locate oci.h])],

[case "$withval" in

no)

AC_MSG_ERROR(Need oracle-include-dir)

;;

yes)

;;

*)

oracle_include_dir="$withval"

;;

esac])

 

dnl extra argument: --with-oracle-lib-dir=DIR

oracle_lib_dir=

AC_ARG_WITH(oracle-lib-dir,

[AS_HELP_STRING([--with-oracle-lib-dir=DIR],

[Directory where the oracle libraries may be found. It should be located under ORACLE_HOME. iUse --with-oracle-lib-dir=yes if you are sure that your linker will find the necessary Oracle client libs. Hint: you might try to do: locate libclntsh.so])],

[case "$withval" in

no)

AC_MSG_ERROR(Need oracle-lib-dir)

;;

yes)

;;

*)

oracle_lib_dir="$withval"

;;

esac])

 

AC_TRY_COMPILE([#include ],

[ int a = 1;],

ORACLE_INCLUDE=" ",

ORACLE_INCLUDE=

)

 

RLM_SQL_ORA_WORKING_CFLAGS_FOR_LINKING_TEST=

if test "x$ORACLE_INCLUDE" = "x" ; then

old_CFLAGS="$CFLAGS"

CFLAGS="$old_CFLAGS -I$oracle_include_dir"

AC_TRY_COMPILE([#include ],

[ int a = 1;],

ORACLE_INCLUDE="-I$oracle_include_dir",

ORACLE_INCLUDE=

)

 

RLM_SQL_ORA_WORKING_CFLAGS_FOR_LINKING_TEST="$CFLAGS"

CFLAGS="$old_CFLAGS"

fi

 

# Proceed to linking makes only sense if include dir is OK.

if test "x$ORACLE_INCLUDE" != "x" ; then

old_LIBS="$LIBS"

old_CFLAGS="$CFLAGS"

CFLAGS="$RLM_SQL_ORA_WORKING_CFLAGS_FOR_LINKING_TEST"

 

ORACLE_LIBDIR_SWITCH=

if test "x$oracle_lib_dir" != "x" ; then

ORACLE_LIBDIR_SWITCH="-L${oracle_lib_dir} "

fi

if test "x$oracle_version" = "x" ; then

AC_MSG_RESULT(no)

AC_MSG_WARN([oracle version not found. Use --with-oracle-version={10|11}.])

fail="$fail Oracle version"

else

LIBS="$old_LIBS $ORACLE_LIBDIR_SWITCH -lclntsh -lnnz${oracle_version}"

 

AC_TRY_LINK([#include

 

static OCIEnv *p_env;

static OCIError *p_err;

static OCISvcCtx *p_svc;

static OCIStmt *p_sql;

static OCIDefine *p_dfn = (OCIDefine *) 0;

static OCIBind *p_bnd = (OCIBind *) 0;

],

[

int p_bvi;

char p_sli[20];

int rc;

char errbuf[100];

int errcode;

 

rc = OCIInitialize((ub4) OCI_DEFAULT, (dvoid *)0, /* Initialize OCI */

(dvoid * (*)(dvoid *, size_t)) 0,

(dvoid * (*)(dvoid *, dvoid *, size_t))0,

(void (*)(dvoid *, dvoid *)) 0 );

 

],

ORACLE_LIBS="$ORACLE_LIBDIR_SWITCH -lclntsh -lnnz${oracle_version}",

ORACLE_LIBS=

)

 

LIBS="$old_LIBS"

CFLAGS="$old_CFLAGS"

fi

fi

 

if test "x$ORACLE_INCLUDE" = "x"; then

AC_MSG_RESULT(no)

AC_MSG_WARN([oracle headers not found. Use --with-oracle-include-dir=.])

fail="$fail oci.h"

else

sql_oracle_cflags="${sql_oracle_cflags} ${ORACLE_INCLUDE}"

AC_MSG_RESULT(yes)

 

if test "x$ORACLE_LIBS" = "x"; then

AC_MSG_WARN([oracle libraries not found. Use --with-oracle-lib-dir=.])

fail="$fail libclntsh libnnz${oracle_version}"

else

sql_oracle_ldflags="${sql_oracle_ldflags} $ORACLE_LIBS"

AC_MSG_RESULT(yes)

fi

fi

 

targetname=modname

else

targetname=

echo *** module modname is disabled.

fi

 

dnl Don't change this section.

if test "x$fail" != x; then

if test "x${enable_strict_dependencies}" = xyes; then

AC_MSG_ERROR([set --without-]modname[ to disable it explicitly.])

else

AC_MSG_WARN([silently not building ]modname[.])

AC_MSG_WARN([FAILURE: ]modname[ requires:$fail.]);

targetname=

fi

fi

 

AC_SUBST(sql_oracle_ldflags)

AC_SUBST(sql_oracle_cflags)

AC_SUBST(targetname)

AC_OUTPUT(Makefile)

 

 

 

-아래와 같이 컴파일 진행(with-oracle-include-dir--with-oracle-lib-dir 경로는 실제 오라클 설치 경로 확인 후 컴파일 )

#cd /usr/local/src/freeradius-server-2.2.10/

#./configure --with-oracle-version=11 \

--with-oracle-include-dir=/oracle/product/11g/dbhome_1/rdbms/public/ \

--with-oracle-lib-dir=/oracle/product/11g/dbhome_1/lib/

# make && make install

# /sbin/ldconfig -v

 

-아래와 같이 모듈을 확인 해야 함

(만약 생성 실패시src/modules/rlm_sql/drivers/rlm_sql_oracle/config.log 의 로그 파일을 통해서 확인 한다.)

#ls  /usr/local/lib/rlm_sql_oracle*

/usr/local/lib/rlm_sql_oracle-2.2.10.la/usr/local/lib/rlm_sql_oracle.a   /usr/local/lib/rlm_sql_oracle.so

/usr/local/lib/rlm_sql_oracle-2.2.10.so  /usr/local/lib/rlm_sql_oracle.la


- sql.conf 에서 기존mysql 로 되어 있는 설정 oracle 변경 및 스키마 변경에 따른 table 변수 변경


#vi /usr/local/etc/raddb/sql.conf

database = "oracle"

driver = "rlm_sql_${database}"

 

        # Connection info:

        server = "localhost"

        port = 1522

        login = "tbics"

        password = "tbics"

        # Database table configuration for everything except Oracle

        #radius_db = "radius"

        # If you are using Oracle then use this instead

        radius_db = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1522))(CONNECT_DATA=(SID=SNET)))"

 

        # If you want both stop and start records logged to the

        # same SQL table, leave this as is.  If you want them in

        # different tables, put the start table in acct_table1

        # and stop table in acct_table2

        #acct_table1 = "radacct"

        acct_table1 = "TMS_RADACCT"

        #acct_table2 = "radacct"

        acct_table2 = "TMS_RADACCT"

 

        # Allow for storing data after authentication

        #postauth_table = "radpostauth"

        postauth_table = "TMS_RADPOSTAUTH"

 

        #authcheck_table = "radcheck"

        authcheck_table = "TMS_RADCHECK"

        #authreply_table = "radreply"

        authreply_table = "TMS_RADREPLY"

 

        #groupcheck_table = "radgroupcheck"

        groupcheck_table = "TMS_RADGROUPCHECK"

 

        #groupreply_table = "radgroupreply"

        groupreply_table = "TMS_RADGROUPREPLY"

 

        # Table to keep group info

        #usergroup_table = "radusergroup"

        usergroup_table = "TMS_RADUSERGROUP"

 

- radius.conf 파일에서sql.conf 활성화를 위해 주석해제 및 allow_vulnerable_openssl지시자 활성화

#vi /usr/local/etc/raddb/sql.conf

..생략

$INCLUDE sql.conf

 

…생략

 

allow_vulnerable_openssl = yes

 

… 생략 


 

기본 설정중 default파일에서 authorize 관련 부분 file 을 주석 sql 활성화

#vi /usr/local/etc/raddb/sites-enabled/default

.. 생략…

authorize {

.. 생략…

 

#       files

 

        #

        #  Look in an SQL database.  The schema of the database

        #  is meant to mirror the "users" file.

        #

        #  See "Authorization Queries" in sql.conf

        sql

.. 생략…

}

 


-radius 에서libclntsh.so.11.1 정상적으로 인식 하기 위해 LD_LIBRARY_PATH선언

# cd /usr/local/etc/raddb/sql/oracle/

# export LD_LIBRARY_PATH=/oracle/product/11g/dbhome_1/lib/

 

- 아래 파일을 열어서 기본 제공 되는 스키마 테이블 명 /usr/local/etc/raddb/sql.conf 에서 설정한 테이블 명으로 변경후 oracleimport

(기본 테이블명으로 해도 상관 없음) 

#vi /usr/local/etc/raddb/sql/oracle/schema.sql

 

-오라클에서 테스트 유저를insert (아이디 cy 비밀번호 dbpass)

-이제 radius 에서 관리되는 기본 계정은 TMS_RADCHECK 테이블에서 관리 된다.

INSERT INTO "TBICS"."TMS_RADCHECK" (ID, USERNAME, ATTRIBUTE, OP, VALUE) VALUES ('1', 'cy', 'Cleartext-Password', ':=', 'dbpass')


 

- Radius-X로 디버깅 모드 실행후 radtest를 통해서 정상적으로access-accept 되는지 확인 하며, reject 시 디버깅 되는 로그를 확인 한다.

(radtest [유저명] [비밀번호] [radius서버 아이피] [nas-port 번호] [비밀키=>기본testing123으로 되어 있음])

 

# radiusd –X

# radtest cy dbpass localhost 0 testing123

Sending Access-Request of id 243 to 127.0.0.1 port 1812

        User-Name = "cy"

        User-Password = "dbpass"

        NAS-IP-Address = 218.233.105.58

        NAS-Port = 0

        Message-Authenticator = 0x00000000000000000000000000000000

rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=243, length=20


2.openvpn freeradius 연동


- radiusplugin_v2.1a_beta1d을 설치 하여 기존 PAM 인증을 대체 할 수 있도록 모듈 설치 

 

# cd /usr/local/src/

# wget http://www.nongnu.org/radiusplugin/radiusplugin_v2.1a_beta1.tar.gz

 

#yum install libgcrypt*

# tar xvzf radiusplugin_v2.1a_beta1.tar.gz

# cd radiusplugin_v2.1a_beta1/

# make

# cp radiusplugin.cnf /etc/openvpn/

# cp radiusplugin.so /etc/openvpn/

# cd /etc/openvpn

 

- radiusplugin.cnf에서 radius 서버 아이피 및 sharedsecret 설정(sharedsecret기본 설정은 testing123)

# vi /etc/openvpn/radiusplugin.cnf

..생략

server

{

        # The UDP port for radius accounting.

        acctport=1813

        # The UDP port for radius authentication.

        authport=1812

        # The name or ip address of the radius server.

        #name=192.168.0.153

        name=127.0.0.1

        # How many times should the plugin send the if there is no response?

        retry=1

        # How long should the plugin wait for a response?

        wait=1

        # The shared secret.

        sharedsecret=testing123

}

..생략


 

-  /etc/openvpn/server.conf 파일에서 기존 pam 인증 방식에서radius 모듈로 로그인 될 수 있도록 기존 설정 주석 후 모듈 플러그인 지시자 추가

# vi /etc/openvpn/server.conf

 

#plugin /usr/lib64/openvpn/plugins/openvpn-plugin-auth-pam.so login

plugin /etc/openvpn/radiusplugin.so /etc/openvpn/radiusplugin.cnf

 

3.openvpn client 테스트

 

-openvpn 재시작 및 포그라운드 환경의 라디우스 백그라운드 환경으로 실행

 

# systemctl restart openvpn@server.service

 

# ps aux | grep radius | grep –v radius

root     11489  0.0  0.0 167640 23704 pts/0    S+   10:26   0:00 radiusd -X

# kill -9 11489

# radiusd -X > /var/log/radius.log &

# ps -ef | grep radius

root     14477  1412  0 10:58 pts/0    00:00:00 radiusd –X

 

- Client 에서 아래와 같이oracle DBinsert 한 유저로 로그인 시도 후 로그인 확인 만약 로그인 문제가 있다면 /var/log/radius.log 를 통해서 오류 확인

 



3. openvpn 통한 radius 접속 이력 로그 확인

 

- 유저가 접속시 RADACCT 테이블에서 Log형식으로 접속 과 관련된 정보를 확인 할 수 있다. 해당 로그는 시작,종료시insert 되어 있으며 아래 정보는 기본 설정시 insert 되는 정보임.

-         

테이블 column

column 설명

접속시 insert 되는 row 예시

RADACCTID

 

 

ACCTSESSIONID

인증 세션 아이디

0E132E20DB2E1EA535C61BCC204D972D

ACCTUNIQUEID

인증 고유 아이디

d31bd8dd9d3f6777

USERNAME

접속 유저 ID

cy  

GROUPNAME

그룹명(미설정 null)

 

REALM

 

 

NASIPADDRESS

radius ip

127.0.0.1

NASPORTID

radius port

 

NASPORTTYPE

radius type

Virtual 

ACCTSTARTTIME

접속 시작 시간

17/07/25 12:42:12.000000000 +09:00

ACCTSTOPTIME

접속 종료 시간

 

ACCTSESSIONTIME

세션 유지 시간

5601

ACCTAUTHENTIC

 

 

CONNECTINFO_START

 

 

CONNECTINFO_STOP

 

 

ACCTINPUTOCTETS

inputoectet

57891

ACCTOUTPUTOCTETS

outputoectet

54174

CALLEDSTATIONID

실제 클라이언트 아이피

CALLINGSTATIONID

 

 

ACCTTERMINATECAUSE

 

 

SERVICETYPE

 

Outbound-User

FRAMEDPROTOCOL

 

PPP

FRAMEDIPADDRESS

클라이언트가 연결된 사설 아이피

10.1.0.10

ACCTSTARTDELAY

 

0

ACCTSTOPDELAY

 

0

 

반응형

'server > Cent_os7' 카테고리의 다른 글

CentOS 7 OpenVpn install  (0) 2017.07.29
Migrate from FirewallD to Iptables on CentOS 7  (0) 2016.05.08
Centos7 NIC rename  (0) 2016.05.06
Centos7 Net-tools install  (0) 2016.05.06