Alexander, Simo,<div><br></div><div>Thank you very much for this extensive explanation. I'll set it up monday and let you know how it will go.</div><div><br></div><div>Fred</div><div><br><br><div class="gmail_quote">On Sat, Oct 6, 2012 at 8:31 PM, Alexander Bokovoy <span dir="ltr"><<a href="mailto:abokovoy@redhat.com" target="_blank">abokovoy@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Sat, 06 Oct 2012, Fred van Zwieten wrote:<br>
>Hang on..I don't see how this can work (I haven't tried it btw).<br>
><br>
>If I simply copy login to openvpn1 and call openvpn_auth_pam with that file<br>
>as a parameter, how can it magically know to query IPA for the openvpn1<br>
>service as opposed to username/password? Must I not change the openvpn1<br>
>file to have it check for the service?<br>
</div>PAM defines a 'service', equal to the name of /etc/pam.d/<service> file.<br>
An application using PAM starts using PAM functions by defining what<br>
service it will be, then PAM code load definitions of the service from<br>
the /etc/pam.d/<service> file and process them accordingly and apply<br>
them in appropriate stages (authentication, account management, session<br>
management, password checks).<br>
<br>
If your IPA hosts use SSSD daemon (default), then your PAM stack by<br>
default is configured to authenticate against IPA server and use of its<br>
features like Host-based access control (HBAC). You can verify it by<br>
checking /etc/pam.d/system-auth (login PAM service includes this file).<br>
<br>
Let's say, you want to define PAM services 'ovpn_group1' and 'ovpn_group2'<br>
that actually use login PAM service. You can do it following way:<br>
<br>
cd /etc/pam.d<br>
ln -s login ovpn_group1<br>
ln -s login ovpn_group2<br>
<br>
Now you have two configuration files named 'ovpn_group1' and<br>
'ovpn_group2', you need to allow their use in both OpenVPN and in IPA to<br>
limit who can get into use of the service.<br>
<br>
On OpenVPN side you'd have two configuration files and set<br>
plugin openvpn-auth-pam.so ovpn_group1<br>
in the first configuration file and<br>
plugin openvpn-auth-pam.so ovpn_group2<br>
in the second.<br>
<br>
You don't need to add 'check_group' as the check would be done<br>
automatically by pam_sss module using HBAC rules from IPA.<br>
<br>
In IPA you can define HBAC services corresponding to those <service><br>
files. We have predefined some of them, for commonly available on the<br>
machines, but you can expand that list. Go to 'Policy -> Host Base Acces<br>
Control -> HBAC Services' and add two services there, 'ovpn_group1' and<br>
'ovpn_group2'.<br>
<br>
Next, define HBAC rules that reference the services ovpn_group1<br>
and ovpn_group2. Put appropriate groups in the rules as to what users<br>
would be allowed to access them (and on which hosts).<br>
<br>
You need to be aware that IPA HBAC rules are explicit. If there is no<br>
rule that allows access, it is denied. By default there is one rule<br>
called 'allow_all' which is enabled, so access is allowed from any user<br>
to any service on any host. Once you start using explicit HBAC rules,<br>
you'll need to define all of them and then disable 'allow_all' rule<br>
because otherwise it will always match and grant access.<br>
<br>
Here is how this difference is visible. I defined one PAM service,<br>
'test-service' by doing a symlink to login service file and used a<br>
simple program <a href="https://github.com/beatgammit/simple-pam/blob/master/src/test.c" target="_blank">https://github.com/beatgammit/simple-pam/blob/master/src/test.c</a><br>
to test. The program simply initializes PAM stack for specified service<br>
('check_user' in the source above, I only replaced that by<br>
'test-service' in my copy) and then runs a sequence of calls, like any<br>
PAM-enabled application should do (except handling password expiration,<br>
but that is detail here).<br>
<br>
I have defined special HBAC rule in IPA that only allowed users from a group 'test'<br>
to use service 'test-service'. User admin does not belong to that group,<br>
user ab does belong to it.<br>
<br>
First with 'allow_all' rule enabled by default:<br>
-sh-4.2$ ./app admin<br>
Credentials accepted.<br>
Password:<br>
Account is valid.<br>
Authenticated<br>
-sh-4.2$ ./app ab<br>
Credentials accepted.<br>
Password:<br>
Account is valid.<br>
Authenticated<br>
-sh-4.2$<br>
<br>
Now I disabled 'allow_all' rule in the IPA web UI:<br>
$ ./app admin<br>
Credentials accepted.<br>
Password:<br>
Account is valid.<br>
Not Authenticated<br>
-sh-4.2$ ./app ab<br>
Credentials accepted.<br>
Password:<br>
Account is valid.<br>
Authenticated<br>
-sh-4.2$<br>
<br>
You'll see following in the /var/log/secure when 'allow_all' is<br>
disabled:<br>
...<br>
Oct 6 21:16:06 head app: pam_sss(test-service:auth): authentication<br>
success; logname=ab uid=1471000004 euid=1471000004 tty= ruser= rhost=<br>
user=admin<br>
Oct 6 21:16:06 head app: pam_sss(test-service:account): Access denied<br>
for user admin: 6 (Permission denied)<br>
...<br>
Oct 6 21:17:43 head app: pam_unix(test-service:auth): authentication<br>
failure; logname=ab uid=1471000004 euid=1471000004 tty= ruser= rhost=<br>
user=ab<br>
Oct 6 21:17:46 head app: pam_sss(test-service:auth): authentication<br>
success; logname=ab uid=1471000004 euid=1471000004 tty= ruser= rhost=<br>
user=ab<br>
<br>
Authentication went successfully (admin credentials were accepted) but then<br>
account management part of pam_sss applied HBAC rules and found out that<br>
none of the rules was matched, the access was denied.<br>
<br>
That's it, start your OpenVPN instances and they should be able to<br>
log-in only those users who pass HBAC rules for their specific PAM<br>
services.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
>Fred<br>
><br>
>><br>
>><br>
>> On Fri, Oct 5, 2012 at 9:09 PM, Simo Sorce <<a href="mailto:simo@redhat.com">simo@redhat.com</a>> wrote:<br>
>><br>
>>><br>
>>> Fred I suggest you copy the 'login' file into 2 new files: openvpn1 and<br>
>>> openvn2<br>
>>><br>
>>> Then configure the two instance instance with:<br>
>>> plugin openvpn_auth_pam openvpn1<br>
>>> and<br>
>>> plugin openvpn_auth_pam openvpn2<br>
>>> respectively.<br>
>>><br>
>>> Then you can create HBAC rules in IPA using openvpn1 and openvon2 as<br>
>>> service names.<br>
>>><br>
>>> Simo.<br>
>>><br>
>>> On Fri, 2012-10-05 at 20:58 +0200, Fred van Zwieten wrote:<br>
>>> > Dmitri,<br>
>>> ><br>
>>> ><br>
>>> > Well, this is, sort of, the point. I have no experience using pam, so<br>
>>> > I have no idea how to set this up.<br>
>>> ><br>
>>> ><br>
>>> > I have authentication up and running, but, like I said, both OpenVPN<br>
>>> > instances happily authenticate users from both groups of users.<br>
>>> ><br>
>>> ><br>
>>> > In my openvpn config file i have:<br>
>>> ><br>
>>> ><br>
>>> > plugin openvpn_auth_pam login<br>
>>> ><br>
>>> ><br>
>>> > where login is the /etc/pam.d/login file. I have not adjusted this<br>
>>> > file. This is standard file for IPA client.<br>
>>> ><br>
>>> ><br>
>>> > So, my idea was to do this in openvpn config file:<br>
>>> ><br>
>>> ><br>
>>> > plugin openvpn_auth_pam login (can the user authenticate y/n?)<br>
>>> > plugin openvpn_auth_pam check_group name USERNAME group OPENVPN1 (is<br>
>>> > the user member op OPENVPN1 y/n?)<br>
>>> ><br>
>>> ><br>
>>> > plugin openvpn_auth_pam is afaik the only way to get OpenVPN to<br>
>>> > authenticate against IPA. I am not sure how this could be setup to<br>
>>> > work with HBAC..<br>
>>> ><br>
>>> ><br>
>>> > Fred<br>
>>> ><br>
>>> ><br>
>>> > On Fri, Oct 5, 2012 at 8:23 PM, Dmitri Pal <<a href="mailto:dpal@redhat.com">dpal@redhat.com</a>> wrote:<br>
>>> > On 10/05/2012 02:13 PM, Fred van Zwieten wrote:<br>
>>> > > You are completely right :-)<br>
>>> > ><br>
>>> > ><br>
>>> > > Both IPA server and client are RHEL6.3 x86_64 boxes.<br>
>>> > ><br>
>>> > ><br>
>>> > > On the OpenVPN server (which is an IPA client), I have 2<br>
>>> > > OpenVPN instances running, because different users must end<br>
>>> > > up in different subnet's<br>
>>> > ><br>
>>> > ><br>
>>> > > OpenVPN instance 1 listens on port 50000<br>
>>> > > OpenVPN instance 2 listens on port 50001<br>
>>> > ><br>
>>> > ><br>
>>> > > Users for subnet 1 must connect and authenticate on instance<br>
>>> > > 1 (and get an IP in subnet 1)<br>
>>> > > Users for subnet 2 must connect and authenticate on instance<br>
>>> > > 2 (and get an IP in subnet 2)<br>
>>> > ><br>
>>> > ><br>
>>> > > Both OpenVPN instances use the login pam module.<br>
>>> > ><br>
>>> > ><br>
>>> > > In this setup I can not prevent users for subnet 2 to<br>
>>> > > connect and authenticate successfully on OpenVPN instance 1.<br>
>>> > ><br>
>>> > ><br>
>>> > > So, I would like to put the users for OpenVPN instance 1 in<br>
>>> > > group OpenVPN1 en users for OpenVPN instance 2 in group<br>
>>> > > OpenVPN2 on IPA.<br>
>>> > ><br>
>>> > ><br>
>>> > > Next, the OpenVPN daemon must be able to check a user for<br>
>>> > > membership. Is it is not a member, false is returned, and<br>
>>> > > the OpenVMN authentication fails.<br>
>>> > ><br>
>>> > ><br>
>>> > > Documentation for the openvpn_auth_pam is here.<br>
>>> > ><br>
>>> > ><br>
>>> ><br>
>>> ><br>
>>> > OK, makes sense.<br>
>>> > How does you pam configuration look like?<br>
>>> > Especially the accounting part? What modules do you have<br>
>>> > there?<br>
>>> > Can it be PAM module you are using expecting some value that<br>
>>> > need to be configured in openvpn_auth_pam config?<br>
>>> ><br>
>>> > > Fred<br>
>>> > ><br>
>>> > ><br>
>>> > > On Fri, Oct 5, 2012 at 7:50 PM, Dmitri Pal <<a href="mailto:dpal@redhat.com">dpal@redhat.com</a>><br>
>>> > > wrote:<br>
>>> > > On 10/05/2012 01:36 PM, Fred van Zwieten wrote:<br>
>>> > > > Hello,<br>
>>> > > ><br>
>>> > > ><br>
>>> > > > I have a IPA server running. This server has users<br>
>>> > > > who are member to various groups. I want to query<br>
>>> > > > the IPA server from an IPA client to know whether<br>
>>> > > > a user is a member to a group.<br>
>>> > > ><br>
>>> > > ><br>
>>> > > > I want to do this from the OpenVPN service using<br>
>>> > > > the openvpn_auth_pam.so. Normally one uses this<br>
>>> > > > like this:<br>
>>> > > ><br>
>>> > > ><br>
>>> > > > openvpn_auth_pam.so login<br>
>>> > > ><br>
>>> > > ><br>
>>> > > > This queries the PAM login (and thus IPA) is the<br>
>>> > > > username/password from openvpn is valid. the<br>
>>> > > > "login" is /etc/pam.d/login. OpenVPN docs say you<br>
>>> > > > could use other modules instead of login.<br>
>>> > > ><br>
>>> > > ><br>
>>> > > > So, I would like to add the next line:<br>
>>> > > ><br>
>>> > > ><br>
>>> > > > openvpn_auth_pam.so group <username> "openvpn"<br>
>>> > > ><br>
>>> > > ><br>
>>> > > > Where a /etc/pam.d/group file would check whether<br>
>>> > > > the user is member of the group "openvpn". If not,<br>
>>> > > > false is returned and the login attempt (thru<br>
>>> > > > openvpn) fails.<br>
>>> > > ><br>
>>> > > ><br>
>>> > > > Is this possible? If not is there a better way?<br>
>>> > > ><br>
>>> > > ><br>
>>> > > > Fred<br>
>>> > ><br>
>>> > ><br>
>>> > ><br>
>>> > > Can you step up from the implementation and explain<br>
>>> > > what you want to accomplish?<br>
>>> > > It seems that you want to use OpenVPN and do some<br>
>>> > > access control checks when user connects to OpenVPN.<br>
>>> > > Right?<br>
>>> > > If you can describe the flow of operations we might<br>
>>> > > be able guide you to the right solution.<br>
>>> > ><br>
>>> > > Also would be nice to understand what OS OpenVPN is<br>
>>> > > running on.<br>
>>> > ><br>
>>> > > ><br>
>>> > > ><br>
>>> > > ><br>
>>> > > ><br>
>>> > > > _______________________________________________<br>
>>> > > > Freeipa-users mailing list<br>
>>> > > > <a href="mailto:Freeipa-users@redhat.com">Freeipa-users@redhat.com</a><br>
>>> > > ><br>
>>> <a href="https://www.redhat.com/mailman/listinfo/freeipa-users" target="_blank">https://www.redhat.com/mailman/listinfo/freeipa-users</a><br>
>>> > ><br>
>>> > ><br>
>>> > > --<br>
>>> > > Thank you,<br>
>>> > > Dmitri Pal<br>
>>> > ><br>
>>> > > Sr. Engineering Manager for IdM portfolio<br>
>>> > > Red Hat Inc.<br>
>>> > ><br>
>>> > ><br>
>>> > > -------------------------------<br>
>>> > > Looking to carve out IT costs?<br>
>>> > > <a href="http://www.redhat.com/carveoutcosts/" target="_blank">www.redhat.com/carveoutcosts/</a><br>
>>> > ><br>
>>> > ><br>
>>> > ><br>
>>> > ><br>
>>> > ><br>
>>> > ><br>
>>> > > _______________________________________________<br>
>>> > > Freeipa-users mailing list<br>
>>> > > <a href="mailto:Freeipa-users@redhat.com">Freeipa-users@redhat.com</a><br>
>>> > > <a href="https://www.redhat.com/mailman/listinfo/freeipa-users" target="_blank">https://www.redhat.com/mailman/listinfo/freeipa-users</a><br>
>>> ><br>
>>> ><br>
>>> > --<br>
>>> > Thank you,<br>
>>> > Dmitri Pal<br>
>>> ><br>
>>> > Sr. Engineering Manager for IdM portfolio<br>
>>> > Red Hat Inc.<br>
>>> ><br>
>>> ><br>
>>> > -------------------------------<br>
>>> > Looking to carve out IT costs?<br>
>>> > <a href="http://www.redhat.com/carveoutcosts/" target="_blank">www.redhat.com/carveoutcosts/</a><br>
>>> ><br>
>>> ><br>
>>> ><br>
>>> ><br>
>>> > _______________________________________________<br>
>>> > Freeipa-users mailing list<br>
>>> > <a href="mailto:Freeipa-users@redhat.com">Freeipa-users@redhat.com</a><br>
>>> > <a href="https://www.redhat.com/mailman/listinfo/freeipa-users" target="_blank">https://www.redhat.com/mailman/listinfo/freeipa-users</a><br>
>>><br>
>>><br>
>>> --<br>
>>> Simo Sorce * Red Hat, Inc * New York<br>
>>><br>
>>><br>
>><br>
<br>
>_______________________________________________<br>
>Freeipa-users mailing list<br>
><a href="mailto:Freeipa-users@redhat.com">Freeipa-users@redhat.com</a><br>
><a href="https://www.redhat.com/mailman/listinfo/freeipa-users" target="_blank">https://www.redhat.com/mailman/listinfo/freeipa-users</a><br>
<br>
<br>
<br>
<br>
--<br>
</div></div><span class="HOEnZb"><font color="#888888">/ Alexander Bokovoy<br>
</font></span></blockquote></div><br></div>