Добрый день, дорогие друзья!!!Прошу вас помоч с одним вопросом:
Каким образом можно ограничить доступ в сеть по Openvpn(доступ по ключами сертификатам), например, чтобы пользоматель имел доступ только одному отдельному ресурсу, а не ко всем ресурсам сети.... Спасибо.....
> Добрый день, дорогие друзья!!!
> Прошу вас помоч с одним вопросом:
> Каким образом можно ограничить доступ в сеть по Openvpn(доступ по ключами сертификатам),
> например, чтобы пользоматель имел доступ только одному отдельному ресурсу, а
> не ко всем ресурсам сети.... Спасибо.....Только правилами firewall.
Я делал так.
вешал скрипт который добавляет и удаляет правила на client-connet и client-disconnetпри запуске этих скриптов в переменных окружения можно достать все необходимые данные
ну и добавляются и удаляются правила в цепочке OPENVPN, которая специально создана для трафика идущего в впн.
Вот пример скрипта#!/bin/bash
_script_type=$script_type
_common_name=$common_name
_dev=$dev
_remote_ip=$ifconfig_pool_remote_ip
_local_ip=$ifconfig_local
_timestamp=$time_unix
_time=$time_ascii
_username=$username
_username=$(echo $_username | tr [:upper:] [:lower:])
_out_dev=br0
_lan_ip="192.168.20.0/22"
VPN_CHAIN="OPENVPN"
DEBUG=0function log(){
echo "$_time [CONNECT_SCRIPT] $*"
}function debug(){
if [ "${DEBUG}" == "1" ]; then
log "debug $*"
fi
}function in_users(){
local user=$1
local in_arr=1
local i
for i in ${Users[@]}; do
if [ "$i" = "${user}" ]; then
in_arr=0
break
fi
donereturn ${in_arr}
}function in_admins(){
local user=$1
local in_arr=1
local i
for i in ${Admins[@]}; do
if [ "$i" = "${user}" ]; then
in_arr=0
break
fi
done
return ${in_arr}
}function check_chain(){
[ -z "$1" ] && return 1
iptables -L $1 >/dev/null 2>&1
return $?
}function add_user_rules(){
debug "iptables -N ${_username}"
iptables -N ${_username}
debug "iptables -A ${_username} -i ${_out_dev} -o ${_dev} -m state --state ESTABLISHED,RELATED -j ACCEPT"
iptables -A ${_username} -i ${_out_dev} -o ${_dev} -m state --state ESTABLISHED,RELATED -j ACCEPT
debug "iptables -A ${_username} -i ${_dev} -o ${_out_dev} -p tcp -s ${_remote_ip} -d ${_lan_ip} --dport 3389 -j ACCEPT"
iptables -A ${_username} -i ${_dev} -o ${_out_dev} -p tcp -s ${_remote_ip} -d ${_lan_ip} --dport 3389 -j ACCEPT
debug "iptables -A ${VPN_CHAIN} -i ${_dev} -s ${_remote_ip} -j ${_username}"
iptables -A ${VPN_CHAIN} -i ${_dev} -s ${_remote_ip} -j ${_username}
debug "iptables -A ${VPN_CHAIN} -o ${_dev} -d ${_remote_ip} -j ${_username}"
iptables -A ${VPN_CHAIN} -o ${_dev} -d ${_remote_ip} -j ${_username}
}function add_admin_rules(){
debug "iptables -N ${_username}"
iptables -N ${_username}
debu "iptables -A ${_username} -i ${_out_dev} -o ${_dev} -m state --state ESTABLISHED,RELATED -j ACCEPT"
iptables -A ${_username} -i ${_out_dev} -o ${_dev} -m state --state ESTABLISHED,RELATED -j ACCEPT
debug "iptables -A ${_username} -i ${_dev} -o ${_out_dev} -s ${_remote_ip} -d ${_lan_ip} -j ACCEPT"
iptables -A ${_username} -i ${_dev} -o ${_out_dev} -s ${_remote_ip} -d ${_lan_ip} -j ACCEPT
debug "iptables -A ${VPN_CHAIN} -i ${_dev} -s ${_remote_ip} -j ${_username}"
iptables -A ${VPN_CHAIN} -i ${_dev} -s ${_remote_ip} -j ${_username}
debug "iptables -A ${VPN_CHAIN} -o ${_dev} -d ${_remote_ip} -j ${_username}"
iptables -A ${VPN_CHAIN} -o ${_dev} -d ${_remote_ip} -j ${_username}
}function add_user_test1(){
debug "iptables -N ${_username}"
iptables -N ${_username}
debug "iptables -A ${_username} -i ${_out_dev} -o ${_dev} -d ${_remote_ip} -m state --state ESTABLISHED,RELATED -j ACCEPT"
iptables -A ${_username} -i ${_out_dev} -o ${_dev} -d ${_remote_ip} -m state --state ESTABLISHED,RELATED -j ACCEPT
debug "iptables -A ${_username} -i ${_dev} -o ${_out_dev} -p tcp -s ${_remote_ip} -d 192.168.20.20 --dport 3389 -j ACCEPT"
iptables -A ${_username} -i ${_dev} -o ${_out_dev} -p tcp -s ${_remote_ip} -d 192.168.20.20 --dport 3389 -j ACCEPT
debug "iptables -A ${_username} -i ${_dev} -o ${_out_dev} -p tcp -s ${_remote_ip} -d 192.168.20.18 --dport 3389 -j ACCEPT"
iptables -A ${_username} -i ${_dev} -o ${_out_dev} -p tcp -s ${_remote_ip} -d 192.168.20.18 --dport 3389 -j ACCEPT
debug "iptables -A ${VPN_CHAIN} -i ${_dev} -s ${_remote_ip} -j ${_username}"
iptables -A ${VPN_CHAIN} -i ${_dev} -s ${_remote_ip} -j ${_username}
debug "iptables -A ${VPN_CHAIN} -o ${_dev} -d ${_remote_ip} -j ${_username}"
iptables -A ${VPN_CHAIN} -o ${_dev} -d ${_remote_ip} -j ${_username}
}function add_user_test2(){
iptables -N ${_username}
iptables -A ${_username} -i ${_out_dev} -o ${_dev} -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A ${_username} -i ${_dev} -o ${_out_dev} -s ${_remote_ip} -d ${_lan_ip} -j ACCEPT
iptables -A ${VPN_CHAIN} -i ${_dev} -s ${_remote_ip} -j ${_username}
iptables -A ${VPN_CHAIN} -o ${_dev} -d ${_remote_ip} -j ${_username}
}function del_rules(){
debug "iptables -D ${VPN_CHAIN} -i ${_dev} -s ${_remote_ip} -j ${_username}"
iptables -D ${VPN_CHAIN} -i ${_dev} -s ${_remote_ip} -j ${_username}
debug "iptables -D ${VPN_CHAIN} -o ${_dev} -d ${_remote_ip} -j ${_username}"
iptables -D ${VPN_CHAIN} -o ${_dev} -d ${_remote_ip} -j ${_username}
debug "iptables -F ${_username}"
iptables -F ${_username}
debug "iptables -X ${_username}"
iptables -X ${_username}
}# Ограниченные пользователи
Users=(
test1
)# Администраторы
Admins=(
test2
)
debug $_username
debug $_remote_ip
debug $_dev
debug $VPN_CHAINcase $_script_type in
client-connect)
log "Connect user=$_username with remote vpn ip=$_remote_ip"if check_chain ${_username}; then
log "Rules for user ${_username} exists. Delete it before create"
del_rules
fi
if in_admins ${_username}; then
log "Add admins rules for user $_username"
add_admin_rules
elif in_users ${_username}; then
log "Add user $_username rules for user $_username"
eval add_user_${_username}
else
log "Add users rules for user $_username"
add_user_rules
fi
;;
client-disconnect)
log "Disconnect user=$_username with remote vpn ip=$_remote_ip"
del_rules
;;
*)
log "Unknow parameters"
;;
esacкод конечно не супер, но работает.
Писалось под CentOS6, там в iptables нет опции проверки наличия правила, поэтому через костыли. На fedora можно проверять наличие правила через ключ, что намного упростит скрипт.
можно и без скрипта.
Привязать к пользователю IP, на IP навешать фиксированные ограничения.
> можно и без скрипта.
> Привязать к пользователю IP, на IP навешать фиксированные ограничения.Спасибо , можете по подробнее описать привязку пользователя к ip для ограничений в openvpn...
>> можно и без скрипта.
>> Привязать к пользователю IP, на IP навешать фиксированные ограничения.
> Спасибо , можете по подробнее описать привязку пользователя к ip для ограничений
> в openvpn...В конфиге у меня это расписано.
Думаю, в документации - тоже.# To assign specific IP addresses to specific
# clients or if a connecting client has a private
# subnet behind it that should also have VPN access,
# use the subdirectory "ccd" for client-specific
# configuration files (see man page for more info).
client-config-dir ccd
# в указанной директории создаете файлик с именем, совпадающим с CommonName сертификата пользователя. В файлик пишете:push-reset
ifconfig-push 1.2.3.4 255.255.255.0
>[оверквотинг удален]
> # To assign specific IP addresses to specific
> # clients or if a connecting client has a private
> # subnet behind it that should also have VPN access,
> # use the subdirectory "ccd" for client-specific
> # configuration files (see man page for more info).
> client-config-dir ccd
> # в указанной директории создаете файлик с именем, совпадающим с CommonName сертификата
> пользователя. В файлик пишете:
> push-reset
> ifconfig-push 1.2.3.4 255.255.255.0Только тут есть один нюанс, а именно в назначении клиентам адреса при топологии net30.
Читайте тут https://forums.openvpn.net/topic12470.html и https://community.openvpn.net/openvpn/wiki/Openvpn23ManPage
Лично я предпочитаю --topology subnet
> Лично я предпочитаю --topology subnetЯ предпочитаю device tap
>> Лично я предпочитаю --topology subnet
> Я предпочитаю device tapВсем огромное спасибо...