论坛风格切换切换到宽版
  • 1224阅读
  • 4回复

[问题求助]请教:对局域网用户的管理问题! [复制链接]

上一主题 下一主题
离线ebengbu.
 
发帖
2059
C币
-60701
威望
375
贡献值
2
银元
-1
铜钱
4670
人人网人气币
0
只看楼主 倒序阅读 使用道具 楼主  发表于: 2009-05-01
双端口网关,eth0连接内网,eth1连接外.网,现在要实现当内网用户需要访问外网的时候先要进.行一.个web认证,当认证成功后再对其IP进行转发。同时该用户的信息该如何察看了,是不是会生成一个文本日志记载了?如果是的话,请问放在哪里?          婚庆

评价一下你浏览此帖子的感受

精彩

感动

搞笑

开心

愤怒

无聊

灌水
发帖
2099
C币
-235665
威望
403
贡献值
1
银元
-1
铜钱
4673
人人网人气币
0
只看该作者 沙发  发表于: 2010-04-13
如何在Linux中设置Squid的用户认证存取控制?

http://www.linuxforum.net Jephe Wu (2001-04-21 18:21:46)

内核版本: Linux 2.2
Squid版本: Squid-2.3.stable2
(http://www.squid-cache.org/Versions/v2/2.3/squid-2.3.STABLE2-src.tar.gz)
发行版本: Redhat Linux 6.0

1. 下载,编译,安装Squid略
注意:运行squid作为nobody,不能用root.

假定squid home目录为/usr/local/squid/
假定squid source目录在/tmp/squid-2.3.STABLE2

2. # cd /tmp/squid-2.3.STABLE2/auth_modules/NCSA     
   # make ncsa_auth

3. 拷贝生成的执行文件ncsa_auth到squid执行文件目录
  # cp ncsa_auth /usr/local/squid/bin

4. 从Apache软件包中得到程序htpasswd

5.用htpasswd生成供Squid利用的用户名和密码认证数据库文件

#htpasswd -c /usr/local/squid/etc/passwd 

6. 加其它更多的用户
#htpasswd /usr/loal/squid/etc/passwd 

7. 修改squid.conf,enable ncsa_auth用户认证功能
[root@linux etc]# more squid.conf | grep ncsa_auth
 authenticate_program /usr/local/squid/bin/ncsa_auth /usr/local/squid/etc/passwd

8.修改ACL部分,象下面这样:
[root@linux etc]# more squid.conf | grep jephe
acl isd proxy_auth jephe bob jicon
http_access allow isd

离线卡西亚.
发帖
2146
C币
-60466
威望
407
贡献值
1
银元
-1
铜钱
4829
人人网人气币
0
只看该作者 板凳  发表于: 2010-04-13
SMB proxy authentication module
Current version : 0.05
Released on : 28 September 1999
Author : Richard Huveneers
License : GNU GPL

smb_auth is a proxy authentication module. With smb_auth you can authenticate proxy users against an SMB server like Windows NT or Samba.

Download
The current version is smb_auth-0.05.tar.gz.
Highlights of new features:


Easier debugging (finally!)
More flexibility
Improved documentation
Requirements
Squid 2.0 or above, or another proxy server with the same authentication module interface.
Squid 1.1 with Arjan de Vet's patch works fine too.
smb_auth needs Samba to talk SMB. If you don't have Samba installed on your proxy server, download and install Samba now. You don't need to start the Samba daemons, smb_auth only uses the Samba client utilities.
Note to Samba 2.0 users: The -E option of smbclient does not work properly in Samba 2.0.3 and earlier, which breaks smb_auth. This has been fixed in Samba 2.0.4, so make sure you are using Samba 2.0.4 or later (the command "smbclient -h" shows the version number). If you prefer not to upgrade to Samba 2.0.4, you can apply this patch which fixes the bug.

Installation
Check the Makefile. Make sure that SAMBAPREFIX and INSTALLBIN are set correctly before running make.
Run "make", then "make install". This will install smb_auth and smb_auth.sh in the INSTALLBIN directory.
Primary domain controller setup
To get proxy access control by user and group, smb_auth reads the file \netlogon\proxyauth on one of the domain controllers using the supplied credentials. If reading this file returns "allow" then access will be allowed, otherwise denied.

Create a file named "proxyauth" on the NETLOGON share of the primary domain controller. In case you have one or more backup domain controllers, I'm assuming you are replicating this share to the backup domain controllers. If you prefer, you can change the location of this file by using the -S option of smb_auth (see below).
Put just the one word "allow" in this file.
Assign "Read" access to the "proxyauth" file to all users or group which you want to allow access to the proxy.
If you want to allow access from multiple domains to your proxy, repeat the above steps for the other domains.
Configure Squid
You need to configure Squid for proxy authentication. If you have problems doing this, have a look at the FAQ. While reading the FAQ, replace ncsa_auth with smb_auth. Please pay attention to the REQUIRED keyword in the proxy_auth acl. As an example, here are the relevant lines of my own squid.conf file:

    authenticate_program /usr/local/bin/smb_auth -W MEDIA@VANTAGE
    acl domainusers proxy_auth REQUIRED
    http_access allow domainusers

smb_auth has several options. Most people will call smb_auth like this:

    smb_auth -W domainname

where domainname is the name of your domain. By default, smb_auth tries to find a domain controller by broadcasting on the primary network interface. If you want to broadcast on another interface (for instance, if you have two ethernet interfaces installed), use:

    smb_auth -W domainname -B <broadcast IP address>;

If you really want to specify the IP address of a domain controller yourself, use:

    smb_auth -W domainname -U <IP address>;

This might even work with a WINS server (untested, feedback appreciated). If you have several domains from which you want to allow access to your proxy, just add them:

    smb_auth -W domain1 -W domain2 -W domain3 ...

in this case all users (except those of domain1) have to specify their username as domainname\username when authenticating. If your users are lazy, you can abbreviate the domainnames like this:

    smb_auth -W domain1 -W domain2 -w d2 -W domain3 -w d3 ..

then users of domain2 can authenticate with d2\username instead of domain2\username. You can also specify different broadcast addresses etc. per domain. Note that you don't need an abbreviation for the first domain since omitting a domainname implies authenticating against the first domain.

If you want to authenticate users of domain1 against a domain controller of domain2 (you must have a trust relationship between domain1 and domain2) then you can use the -P option. This is called pass-through authentication and is useful to manage access from multiple domains to the proxy server centrally (using a single proxyauth file):

    smb_auth -W domain1 -P domain2 -W domain2 ..

If you want to change the location of the proxyauth file (for instance because your NETLOGON share is located on a FAT filesystem) then you can use the -S option to specify a different share (make sure you are replicating this share to the backup domain controllers):

    smb_auth -W domain -S share

You can also change the name of the proxyauth file and store it in a sub-directory of the share by appending the full pathname of the proxyauth file to the sharename. You may use both forward slashes and backslashes to separate directories and you may (not required) prepend a (back)slash to the sharename:

    smb_auth -W domain -S /share/path/to/proxyauth


Troubleshooting
You can run smb_auth on the command-line using the same options as in your squid.conf. To debug authentication you can additionally use the -d option which will print debug information after each step, so you can determine which step is failing.
Do not use the -d option in your squid.conf, this corrupts the communication between Squid and smb_auth.
You need to feed one username and password (separated by a space character) to smb_auth's standard input. After authenticating this username and password, smb_auth will continue accepting such username/password combinations until you close it's standard input by pressing Ctrl-D.

Here's the output of a succesful authentication, so you know how the output should look like:


# smb_auth -W MEDIA@VANTAGE -d
richard xxxxxxxx
Domain name: MEDIA@VANTAGE
Pass-through authentication: no
Query address options:
Domain controller IP address: 192.168.1.2
Domain controller NETBIOS name: VEGA
Contents of //VEGA/NETLOGON/proxyauth: allow
OK

Still having problems?
Please e-mail me if you have problems compiling, installing or configuring smb_auth. Suggestions are welcome too.
If somebody could comment on NT licensing issues of smb_auth, that would be more than welcome.

TODO
These are the items currently on my todo list. If you need another feature currently not available, just let me know. I will add it to this list and who knows, it might even get implemented.

research if smbclient does encrypted passwords on demand or needs smb.conf option or something else.
research if Samba 2.0 is able to retrieve NT group membership directly
re-code the shell script in C. I used a shell script mainly to speedup development.
add a netbios name cache. This feature needs the previous one and will speed up smb_auth considerably.
research if linking smb_auth with the Samba code is worth the trouble.

离线chinablue.
发帖
2151
C币
-235260
威望
390
贡献值
1
银元
-3
铜钱
4734
人人网人气币
0
只看该作者 地板  发表于: 2010-04-13
灌水呀 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


5.2 用户认证设置
缺省的,squid本身不带任何认证程序,但是我们可以通过外部认证程序来实现用户认证。一般说来有以下的认证程序:

1.LDAP认证:你可以访问以下资源来获取更多的有用信息。
http://www.geocities.com/ResearchTriangle/Thinktank/5292/projects/ldap/
http://home.iae.nl/users/devet/squid/proxy_auth/contrib/ldap_auth.tar.gz

2.SMB认证:可以实现基于NT和samba的用户认证。更多的信息请访问以下资源。
http://www.hacom.nl/~richard/software/smb_auth.html

3.基于mysql的用户认证。
http://home.iae.nl/users/devet/squid/proxy_auth/contrib/mysql_auth.c

4.基于sock5密码用户认证。
http://nucleo.freeservers.com/

5.基于Radius 的用户认证。
http://home.iae.nl/users/devet/squid/proxy_auth/contrib/auth.pl

但是我们一般常用的是用ncsa实现的认证和用smb_auth实现的基于NT和samba的用户认证。下面我们就来讲这两种认证方法的具体实现。

5.2.1 ncsa用户认证的实现
ncsa是squid源代码包自带的认证程序之一,下面我们以squid-2.3.STABLE2版本为例讲述ncsa的安装和配置。
1.从www.squid-cache.org下载squid源代码包squid-2.3.STABLE2-src.tar.gz并放到/tmp目录下。
2.用tar解开:
tar xvzf squid-2.3.STABLE2-src.tar.gz
%make
%make install
3.然后,进入/tmp/squid-2.3.STABLE2/auth_modules/NCSA目录。
% make
% make install
编译成功后,会生成ncsa_auth的可执行文件。
4.拷贝生成的执行文件ncsa_auth到/usr/bin目录
cp ncsa_auth /usr/bin/bin
5.修改squid.conf中的相关选项如下所示:
authenticate_program /usr/local/squid/bin/ncsa_auth /usr/bin/passwd
6.定义相关的用户类
acl auth_user proxy_auth REQUIRED
注意,REQUIRED关键字指明了接收所有合法用户的访问。
7.设置http_access
http_access allow auth_user
注意,如果你在改行中指定了多个允许访问的用户类的话,应该把要认证的用户类放在第一个。如下所示:
错误的配置:http_access allow auth_user all manager
正确的配置:http_access allow auth_user manager all
8.利用apache携带的工具软件htpasswd在/usr/local/squid/etc下生成密码文件并添加相应的用户信息。一般说来,该密码文件每行包含一个用户的用户信息,即用户名和密码。
用htpasswd生成密码文件passwd并添加用户bye。
htpasswd -c /usr/local/squid/etc/passwd bye
然后重新启动squid,密码认证已经生效。

5.2.2 smb用户认证的实现
国内介绍并使用ncsa实现用户认证的文章不多,而使用smb_auth和samba实现基于NT的用户认证我还没有看到过,下面我们就来看一看在squid中实现基于NT的用户认证。
当前smb_auth的最高版本是smb_auth-0.05,你可以在以下地址下载。当然,squid的源代码包中也包含smb_auth,但是是0.02版的。
http://www.hacom.nl/~richard/software/smb_auth-0.05.tar.gz
smb_auth的主页地址是http://www.hacom.nl/~richard/software/smb_auth.html
1.系统需求:
squid2.0以上版本。
安装samba2.0.4以上版本。你并不需要运行samba服务,因为smb_auth只用到了 samba的客户端软件。
2.下载smb_auth-0.05.tar.gz并复制到/tmp.
3.tar xvzf smb_auth-0.05.tar.gz
4.根据你的要求修改Makefile中的SAMBAPREFIX和INSTALLBIN参数。SAMBAPREFIX指定了你的samba安装路径,INSTALLBIN指明了smb_auth的安装路径。我们指定:
SAMBAPREFIX=/usr,INSTALLBIN=/usr/bin.
5.make
6.make install,成功后会在INSTALLBIN指定路径中生成可执行文件smb_auth.
7.按下列步骤设置你要用于认证的主域控制器:
首先在NETLOG共享目录中建立一个“proxy”文件,该文件只包含一个“allow”的字符串,一般说来,该NETLOG目录位于\winnt\system32\Repl\import\scripts目录中;然后,设置所有你想让其访问squid的用户和用户组拥有对该文件的读的权力。
8.修改squid.conf中的相关选项如下所示:
authenticate_program /usr/local/squid/bin/smb_auth your_domain_name
9.定义相关的用户类
acl auth_user proxy_auth REQUIRED
注意,REQUIRED关键字指明了接收所有合法用户的访问。
10.设置http_access
http_access allow auth_user
注意,如果你在改行中指定了多个允许访问的用户类的话,应该把要认证的用户类放在第一个。如下所示:
错误的配置:http_access allow auth_user all manager
正确的配置:http_access allow auth_user manager all
如果一切正确的话,然后重新启动squid,密码认证已经生效。
说明:smb_auth的调用方法:
1.smb_auth -W your_domain_name
用your_domain_name指定你的域名。smb_auth将进行广播寻找该主域控制器。
2.smb_auth -W your_domain_name -B <ip>;
如果你有多个网络接口,可以用-B 指定用于广播的网络接口的ip地址。
3.smb_auth -W your_domain_name -U <ip>;
也可以用-U直接指定该主域控制器的ip地址。
4.smb_auth -W your_domain_name -S share
可以用-S指定一个不同于NETLOG的共享目录。

5.2.3squid.conf中关于认证的其他设置
1.authenticate_children
说明:设置认证子进程的数目。缺省为5个。如果你处于一个繁忙的网络环境中,你可以适当增大该值。
2.authenticate_ttl
说明:设置一次认证的有效期,缺省是3600秒。
3.proxy_auth_realm
说明:设置用户登录认证时向用户显示的域名。

5.3透明代理的设置
关于透明代理的概念我们已经在第一节将过了,下面我们看一下怎么样在squid中实现透明代理。
透明代理的实现需要在Linux 2.0.29以上,但是Linux 2.0.30并不支持该功能,好在我们现在使用的通常是2.2.X以上的版本,所以不必担心这个问题。下面我们就用ipchains+squid来实现透明代理。在开始之前需要说明的是,目前我们只能实现支持HTTP的透明代理,但是也不必太担心,因为我们之所以使用代理,目的是利用squid的缓存来提高Web的访问速度,至于提供内部非法ip地址的访问及提高网络安全性,我们可以用ipchains来解决。
实现环境:RedHat6.x+squid2.2.x+ipchains
5.3.1 linux的相关配置
确定你的内核已经配置了以下特性:

Network firewalls
[ ] Socket Filtering

Unix domain sockets

TCP/IP networking
[ ] IP: multicasting
[ ] IP: advanced router
[ ] IP: kernel level autoconfiguration

IP: firewalling
[ ] IP: firewall packet netlink device

IP: always defragment (required for masquerading)

IP: transparent proxy support
如果没有,请你重新编译内核。一般在RedHat6.x以上,系统已经缺省配置了这些特性。

5.3.2squid的相关配置选项
设置squid.conf中的相关选项,如下所示:
http_port 3218
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
说明:
1.http_port 3128
在本例中,我们假设squid的HTTP监听端口为3128,即squid缺省设置值。然后,把所有来自于客户端web请求的包(即目标端口为80)重定向到3128端口。
2.httpd_accel_host virtual
httpd_accel_port 80
这两个选项本来是用来定义squid加速模式的。在这里我们用virtual来指定为虚拟主机模式。80端口为要加速的请求端口。采用这种模式时,squid就取消了缓存及ICP功能,假如你需要这些功能,这必须设置httpd_accel_with_proxy选项。
3.httpd_accel_with_proxy on
该选项在透明代理模式下是必须设置成on的。在该模式下,squid既是web请求的加速器,又是缓存代理服务器。
4.httpd_accel_uses_host_header on
在透明代理模式下,如果你想让你代理服务器的缓存功能正确工作的话,你必须将该选项设为on。设为on时,squid会把存储的对象加上主机名而不是ip地址作为索引。这一点在你想建立代理服务器阵列时显得尤为重要。

5.3.3 ipchains的相关配置
ipchains在这里所起的作用是端口重定向。我们可以使用下列语句实现将目标端口为80端口的TCP包重定向到3128端口。

#接收所有的回送包
/sbin/ipchains -A input -j ACCEPT -i lo
#将目标端口为80端口的TCP包重定向到3128端口
/sbin/ipchains -A input -p tcp -d 0.0.0.0/0 80 -j REDIRECT 80

当然在这以前,我们必须用下面的语句打开包转发功能。
echo 1 >; /proc/sys/net/ipv4/ip_forward

第六节 本章小节
在本章的开始,我们讨论了代理服务器的概念,代理服务器的分类;然后,我们把注意力集中在squid,讲述了如何安装和配置squid;最后我们讲了一些squid配置中的高级话题,即实现用户认证的两种方法,透明代理的实现等。当然,还有一些高级话题本章没有讲到,如代理阵列的实现,加速模式的运用等等。但是,我们不可能把所有东西都讲完讲全,希望读者能举一反三,自己去摸索,去尝试。


离线wuyangbo11.
发帖
2038
C币
-235209
威望
394
贡献值
1
银元
-3
铜钱
4624
人人网人气币
0
只看该作者 4楼 发表于: 2010-04-13
谢谢这位老大,我好好研究研究!
快速回复
限100 字节
如果您提交过一次失败了,可以用”恢复数据”来恢复帖子内容
 
上一个 下一个