All of lore.kernel.org
 help / color / mirror / Atom feed
* RE: ipsec, netlabels, secmark- How about a little usability?
@ 2006-09-19 21:19 Venkat Yekkirala
  2006-09-20  1:35 ` Joshua Brindle
  0 siblings, 1 reply; 23+ messages in thread
From: Venkat Yekkirala @ 2006-09-19 21:19 UTC (permalink / raw)
  To: dwalsh; +Cc: selinux

> We have been having some meetings to discuss how we can use 
> this stuff 
> in the real world (IE Non MLS), and I think the current 
> implementation 
> is coming up short.  The discussions I have seen have talked 
> about using 
> getpeercon to look at the other end of the connections, but 
> this is not 
> in the spirit of SELinux where modification of the 
> applications should 
> not be necessary to secure the environment.
> 

I would like to start off with a reference to the Labeled Networking Design
doc at http://marc.theaimsgroup.com/?l=linux-netdev&m=115136637800361&w=2

While secmark as currently implemented upstream "marks" packets,
the secid reconciliation patches being considered for upstream
turn secmark contexts that are defined using iptables, into contexts
on the respective "flow control points". This is a significant shift
in the paradigm and the benefits will be obvious in the later part of
the discussion:

Example (INCOMING PACKETS):

iptables -t mangle -A INPUT -p tcp --dport 22 -m state --state NEW -j
SEL_SSHD
iptables -t mangle -A SEL_SSHD -j SECMARK --selctx
system_u:object_r:sshd_t:s0
iptables -t mangle -A SEL_SSHD -j ACCEPT

The above is really defining the context on an "entry point".

Any packets not labeled externally using labeled IPSec, or CIPSO and
"flowing in" thru that entry point will assume the "entry point" context,
but only by virtue of the packets coming in thru that "entry point".

So, what happens if an externally labeled packet (e.g.: Labeled IPSec)
comes in thru the above entry point? First of all, a check is made to
see if a packet so labeled using IPSec (unlabeled if no IPSec) can
"flow in" thru the "entry point". If it can, and if there's an
IPSec label on the packet, a transition sid is computed between the
"entry point" label and the IPSec label and the packet will be marked
with this transition sid. The transition label will either be the IPSec
label (default) or any other label as defined by SELinux policy transition
rules.

The socket is then checked for packet.recv access to the packet before
the socket can receive the packet.

Example (OUTGOING PACKETS):

iptables -t mangle -A OUTPUT -p tcp --dport 22 -m state --state NEW -j
SEL_SSH_CLIENT
iptables -t mangle -A SEL_SSH_CLIENT -j SECMARK --selctx
system_u:object_r:ssh_client_t:s0
iptables -t mangle -A SEL_SSH_CLIENT -j ACCEPT

The above is really defining the context on an "exit point".

A locally generated packet will normally assume the label of the socket.
Next,
a check is made to see if the packet can "flow out" thru IPSec (unlabeled if
not using Labeled IPSec). If the packet uses labeled IPSec, a transition sid
is computed between the socket label and the IPSec label. The transition
label
will be the IPSec label (default) or any other label as defined by SELinux
policy rules.

The packet is then checked for "flow out" access to the "exit point"
defined using iptables output rules above.

> 
> Lets look at some real world situations where having better 
> controls on 
> the network would work and someone explain to me how Joe Average 
> SysAdmin will set them up.

I will try to show elements of policy for the below example, but
turning it into something useable by Joe Average will obviously
involve integration and policy abstractions that are currently
outside the scope of this discussion. I will let "policy experts"
out there to weigh in here with suggestions and ideas.

PERFORMANCE:

There were some concerns about iptables performance. While
I haven't done any testing in this regard, I would think that it would
atleast compare to the "compat" case where the contexts are looked up on
the node, netif, port individually. Also, bear in mind that the labeling
rules for "entry" and "exit" points as shown above could be placed AFTER
all other normal iptables rules that could drop a packet, so I do not
understand why a packet now has to go thru 400 or so more rules than
otherwise,
before being dropped.

I would imagine that iptabels lookups would be much more efficient than
the current individual lookups on node/netif/port. Another optimizing factor
would be that INPUT/FORWARD rules could be used instead of PREROUTING to
delay jumping to the (CONN)SECMARK target(s). The idea is that labeling
could come AFTER all the drop checks. i.e. one could replace appropriate
ACCEPTs with a jump to the appropriate labeling chain that in turn would
call into (CONN)SECMARK, for example.

> 
> 
> 1.  By default httpd has to be able to talk to itself in order to do 
> gracefull shutdown,
> service httpd graceful.
> 
> So I end up adding a rule allowing httpd to name_connect to the 
> httpd_port_t.    But I really only want to allow this for 
> localhost.  IE 
> I don't want to allow my httpd to name_connect to other 
> machines httpd 
> ports?  I can't do this now.

1. Define "exit" and "entry" point contexts, rather the "connection" context
   (specifically an "outgoing connection") in this case:

iptables -t mangle -A POSTROUTING -o lo -p tcp --sport 80 --dport 80 -m
state --state NEW -j SEL_HTTPD2HTTPD
iptables -t mangle -A SEL_HTTPD2HTTPD -j SECMARK --selctx
system_u:object_r:httpd2httpd_t:s0
iptables -t mangle -A SEL_HTTPD2HTTPD -j CONNSECMARK --save
iptables -t mangle -A SEL_HTTPD2HTTPD -j ACCEPT

# Common rules which copy connection labels to established
# and related packets.
iptables -t mangle -A INPUT -m state --state ESTABLISHED,RELATED -j
CONNSECMARK --restore
iptables -t mangle -A OUTPUT -m state --state ESTABLISHED,RELATED -j
CONNSECMARK --restore

2. Allow the "httpd_t" packets to exit thru the "exit point"

allow httpd_t httpd2httpd_t:packet { flow_out };

NOTE: Packet goes over loopback at this time.

3. Packet didn't use IPSec, so it is "unlabeled" in that "external
    labeling" sense. Allow the non-IPSec packets thru the "entry point".

allow unlabeled_t httpd2httpd_t:packet { flow_in };

NOTE1: If using Labeled IPSec SAs, "unlabeled_t" above would be substituted
with the Type associated with the IPSec SAs here.

NOTE2: Packet is labeled with httpd2httpd_t at this point.

4. Finally, allow the httpd_t socket to receive the packets.

allow httpd_t httpd2http_t:packet { recv };

I applied sorta linear thinking in the above, but the rules could perhaps
be optimized into a smaller rule set particularly in conjunction with
rules for other services.

Anyone see any unintended flows in the above?

Also, since I happened to reuse secmark with a shift in paradigm, the
current naming might be a little bit awkward or even confusing.

I am not well versed in the current policy design as far as useability
is concerned but I would think that the above could be made "useable" for
Joe Average by doing some smart policy interfaces, etc. Policy guys, please
weigh in here.

> 
> 2.  I as a sysadm have setup a apache web site that allows 
> connections 
> from the outside and needs to connect to three mysql servers on my 
> internal network. So I need to allow it to connect to those three 
> machines on the internal network only.  How am I as the 
> Sysadm going to 
> set this up.

You would pretty much do the same as in the previous scenario except
you would also allow connection packets (NEW, ESTABLISHED, RELATED)
from httpd_t to those 3 servers (or a subset of these as can be defined
by standard iptables selection criteria) by defining appropriate
"connection contexts" (which encompass the entry and exit contexts
as described above).

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: ipsec, netlabels, secmark- How about a little usability?
@ 2006-09-20 13:02 Venkat Yekkirala
  0 siblings, 0 replies; 23+ messages in thread
From: Venkat Yekkirala @ 2006-09-20 13:02 UTC (permalink / raw)
  To: Joshua Brindle; +Cc: dwalsh, selinux

> > So, what happens if an externally labeled packet (e.g.: 
> Labeled IPSec)
> > comes in thru the above entry point? First of all, a check 
> is made to
> > see if a packet so labeled using IPSec (unlabeled if no IPSec) can
> > "flow in" thru the "entry point". If it can, and if there's an
> > IPSec label on the packet, a transition sid is computed between the
> > "entry point" label and the IPSec label and the packet will 
> be marked
> > with this transition sid. The transition label will either 
> be the IPSec
> > label (default) or any other label as defined by SELinux 
> policy transition
> > rules.
> >
> >   
> What if there are 2 external labels (ipsec and cipso) ?

A "cipso label" will be constructed using the transition label,
determined in the above process, or in it's absence (i.e., no labeled IPSec)
the "entry point" label, as the base sid. A check is made to see
if a packet with this "cipso label" can "flow in" thru
the transition label (or the "entry point" label if no labeled IPSec)
and if it can, then the packet is marked with this cipso label.

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: ipsec, netlabels, secmark- How about a little usability?
@ 2006-09-14 22:52 Venkat Yekkirala
  2006-09-15  9:00 ` Stuart James
  0 siblings, 1 reply; 23+ messages in thread
From: Venkat Yekkirala @ 2006-09-14 22:52 UTC (permalink / raw)
  To: Stephen Smalley, James Antill
  Cc: Christopher J. PeBenito, Joshua Brindle, SE Linux, jmorris

> > > > 1.  By default httpd has to be able to talk to itself 
> in order to do 
> > > > gracefull shutdown,
> > > > service httpd graceful.
> > > >
> > > > So I end up adding a rule allowing httpd to name_connect to the 
> > > > httpd_port_t.    But I really only want to allow this 
> for localhost.  
> > > > IE I don't want to allow my httpd to name_connect to 
> other machines 
> > > > httpd ports?  I can't do this now.
> > > >
> > > you can with secmark can't you?
> > > iptables -I -p tcp -d localhost -s localhost -i lo 
> --dport 80 -j SECMARK 
> > > --selctx system_u:object_r:httpd_client_packet_t
> > 
> >  This one rule, both allows httpd_t to connect to localhost:80 and
> > disallows it from connecting to anything-else:80 ?
> > 
> >  From the documentation --selctx just sets the "SELinux security
> > context" ... so you presumably _also_ need some bit of 
> policy code that
> > says "httpd_t can only name_bind(?) with httpd_client_packet_t"?
> 
> The iptables rule only deals with labeling the packet with a 
> type.  The
> policy deals with what domains can send/recv a given packet via allow
> rules like:
> 	allow httpd_t http_client_packet_t:packet { send recv };
> encapsulated in interfaces like:
> 	corenet_sendrecv_http_client_packet(httpd_t)
> 
> But the problem I see with the above example is that refpolicy already
> generates a netfilter contexts entry that maps _everything_ going to
> port 80 with http_client_packet_t, so we would need to delete 
> that entry
> to make the above work, or use a different type
> (http_client_packet_lo_t) and only allow httpd_t to send it, not the
> generic http_client_packet_t.  All of which gets back to proper
> integration.

In the secid patch sent to netdev last week, all packets leaving httpd
would be labeled with the label of the source socket (httpd_t). This
label is currently overridable by the above "secmark" rule, but we could
alternatively allow a packet to retain the label if it already has one,
in which case, the allow rule would be like:

allow httpd_t httpd_t:packet { send recv};

Comments?

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: ipsec, netlabels, secmark- How about a little usability?
@ 2006-09-14 14:52 Stuart James
  0 siblings, 0 replies; 23+ messages in thread
From: Stuart James @ 2006-09-14 14:52 UTC (permalink / raw)
  To: selinux

On Thu, 14 Sep 2006 08:52:34 -0400
Daniel J Walsh <dwalsh@redhat.com> wrote:

> We have been having some meetings to discuss how we can use this
> stuff in the real world (IE Non MLS), and I think the current
> implementation is coming up short.  The discussions I have seen have
> talked about using getpeercon to look at the other end of the
> connections, but this is not in the spirit of SELinux where
> modification of the applications should not be necessary to secure
> the environment.
> 
> 
> Lets look at some real world situations where having better controls
> on the network would work and someone explain to me how Joe Average 
> SysAdmin will set them up.
> 

> 
> =======================================================
> 
> If someone was to pass a law and make me the King of SELinux, The way 
> this would happen is that iptables would be extended to add a -t 
> SecurityContext flag, which I then could simple SELinux rules to set 
> this up in a lanquage that most Sysadmins of Linux boxes could
> readily understand.
> 

If I understand it correctly, secmark is an additional type of
selinux context that needs to be modified in the selinux policy
to add the ability for the iptables rule to function correctly? 

Is there currently a way of labeling the type of iptable ruleset? such
as if i were to create a chain called "iptables -N mychain", could i
then label then chain when creating it, such as with 
"iptables -A mychain -p tcp -m tcp --dport 80 -j SecurityContext"
and would SecurityContext take over from the -j ACCEPT ?

As i was looking through the
http://people.redhat.com/jmorris/selinux/secmark/ this tends to make
agree with your statement of having the ability to add the context into
the iptables rule, is this a current ability of iptables or only on
patched systems?

Another issue which has arisen while moving from Fedora core 3 to
above, was prior to newer versions of kernel / openswan and iptables,
if you were using the IPsec device as also a Masquerading device,
complex rulesets to exclude masquerading to destination networks
provided by the ipsec tunnel have to be specified specifically as
ACCEPT for POSTROUTING prior to POSTROUTING of outbound traffic
destined to the internet. 

Assuming now you have ipsec tunnels to 192.168.0.0/16
For example now we currently use this on FC4/5

-A POSTROUTING -d 192.168.0.0/16 -o eth0 -j ACCEPT

Prior to Fedora core 4
-A POSTROUTING -s x.x.x.x/24 -d !
192.168.0.0/255.255.0.0 -o eth0 -j MASQUERADE

Assuming now you tunnels to 192.168.0.0/16 and 10.10.10.0/24
The following works on FC4/5, not on FC3
-A POSTROUTING -d 192.168.0.0/16 -o eth0 -j ACCEPT
-A POSTROUTING -d 10.10.10.0/24 -o eth0 -j ACCEPT

And on FC3 you are limited to
-A POSTROUTING -s x.x.x.x/24 -d !
192.168.0.0/255.255.0.0 -o eth0 -j MASQUERADE
-A POSTROUTING -s x.x.x.x/24 -d !
192.168.0.0/255.255.0.0 -o eth0 -j MASQUERADE


Although this is an improvement with the older way, if you had
multiple ipsec connections to more then just the 192.168.0.0/16
network your initial POSTROUTING rule would match, and traffic destined
for say 10.10.10.0/24 for would also get masqueraded to the internet

With the current distribution of Fedora latest selinux policy two IPsec
devices connected running in enforcing mode will not talk across the
network. I have added these audit2allows to my policy for it to work
but unfortunately i will have to redo it to provide you with the
correct avc messages to hopefully get ipsec(openswan) running in
enforcing mode for fc5 and above, as currently if you were trying to
set it up it would not work as required.


-- 
Stuart James
Systems Administrator
DDI - (44) 0 1723 300205
RHCE - RHEL4
CERT# 804005316914471 

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 23+ messages in thread
* ipsec, netlabels, secmark- How about a little usability?
@ 2006-09-14 12:52 Daniel J Walsh
  2006-09-14 13:50 ` Joshua Brindle
  0 siblings, 1 reply; 23+ messages in thread
From: Daniel J Walsh @ 2006-09-14 12:52 UTC (permalink / raw)
  To: SE Linux

We have been having some meetings to discuss how we can use this stuff 
in the real world (IE Non MLS), and I think the current implementation 
is coming up short.  The discussions I have seen have talked about using 
getpeercon to look at the other end of the connections, but this is not 
in the spirit of SELinux where modification of the applications should 
not be necessary to secure the environment.


Lets look at some real world situations where having better controls on 
the network would work and someone explain to me how Joe Average 
SysAdmin will set them up.


1.  By default httpd has to be able to talk to itself in order to do 
gracefull shutdown,
service httpd graceful.

So I end up adding a rule allowing httpd to name_connect to the 
httpd_port_t.    But I really only want to allow this for localhost.  IE 
I don't want to allow my httpd to name_connect to other machines httpd 
ports?  I can't do this now.

2.  I as a sysadm have setup a apache web site that allows connections 
from the outside and needs to connect to three mysql servers on my 
internal network. So I need to allow it to connect to those three 
machines on the internal network only.  How am I as the Sysadm going to 
set this up.

3.  I want to setup two machines in my environment with bind running on 
them.  One, Machine A,  is a bind master the other, Machine B,  is a 
bind slave.  I want to allow bind zone transfer from Machine A to 
Machine B, but I want to guarantee that the process kicking off the zone 
transfer on Machine A is running as named_t and the process receiving 
the zone transfer on Machine B is running as named_t. 
How do I do that?

4.  I have a machine that is running two bind domains, one on my 
internal network needs to listen on eth0, the other on the externel 
network needs to listen on eth1.  How do I set this up?

=======================================================

If someone was to pass a law and make me the King of SELinux, The way 
this would happen is that iptables would be extended to add a -t 
SecurityContext flag, which I then could simple SELinux rules to set 
this up in a lanquage that most Sysadmins of Linux boxes could readily 
understand.





--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2006-09-20 14:46 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-19 21:19 ipsec, netlabels, secmark- How about a little usability? Venkat Yekkirala
2006-09-20  1:35 ` Joshua Brindle
  -- strict thread matches above, loose matches on Subject: below --
2006-09-20 13:02 Venkat Yekkirala
2006-09-14 22:52 Venkat Yekkirala
2006-09-15  9:00 ` Stuart James
2006-09-14 14:52 Stuart James
2006-09-14 12:52 Daniel J Walsh
2006-09-14 13:50 ` Joshua Brindle
2006-09-14 13:55   ` Joshua Brindle
2006-09-14 14:43   ` Stephen Smalley
2006-09-15 15:36     ` Daniel J Walsh
2006-09-14 16:02   ` James Antill
2006-09-14 16:49     ` Stephen Smalley
2006-09-14 17:24       ` James Antill
2006-09-14 19:45         ` Stephen Smalley
2006-09-19 20:13           ` Karl MacMillan
2006-09-19 20:35             ` Christopher J. PeBenito
2006-09-19 21:12               ` Karl MacMillan
2006-09-19 20:47       ` Karl MacMillan
2006-09-20 13:30         ` Christopher J. PeBenito
2006-09-20 13:45           ` James Morris
2006-09-20 14:27             ` Christopher J. PeBenito
2006-09-20 14:45               ` James Morris

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.