SELinux’ 2011/07 releases now stable

A few minutes ago, I stabilized both the 2.20110726 policies as well as the SELinux userspace utilities that were stable (upstream) on 20110727. With the change, I also updated the Gentoo SELinux Handbook with the changes I presented on our gentoo-hardened mailinglist. After some time, I’ll remove the now obsoleted older policies and userspace utilities to keep the tree in a sane state.

There are a few policy packages whose stabilized version isn’t the latest (cfr earlier post), those are due within the proper designated period (about 1 month).

Posted in Hardened, SELinux | Leave a comment

Gentoo Hardened SELinux policies, rev 5

I’ve pushed out selinux-base-policy version 2.20110726-r5 to the hardened-dev overlay. It does not hold huge changes, most of them are rewrites or updates on pre-existing patches (on the SELinux policies) to make them conform the refpolicy naming conventions and other guidelines. It includes preliminary support for the XDG Specification although changes there are still going to occur (as the policy is still under development). Other updates are primarily on the policies for user applications (pan, mozilla, skype), portage and asterisk.

In related news, the Gentoo Hardened SELinux FAQ is updated with two entries:

  1. Portage fails to label files because “setfiles” does not work anymore, and
  2. Applications do not transition on a nosuid-mounted partition
Posted in Hardened, SELinux | Leave a comment

Upgrading GCC, revisited

Gentoo has, since long, had a GCC Upgrading guide. A long time ago, upgrading GCC required quite a lot of side activities and was often considered a risky upgrade. But times change, and so do the GCC upgrade cycles. Improved compatibility as well as a better understood impact made GCC upgrades a lot less painful. Sadly, our documentation didn’t reflect that as much – the last update on the GCC Upgrade guide was from 2008.

Today, after some clarifications from gentoo-dev, I’ve updated the GCC Upgrading Guide to reflect the improved situation. I’m hoping this will help clear out the uncertainty surrounding GCC upgrades. As always, comments and feedback are always welcome.

Posted in Gentoo | 7 Comments

Mitigating risks, part 5 – application firewalls

The last isolation-related aspect on risk mitigation is called application firewalls. Like more “regular” firewalls, its purpose is to be put in front of a service, controlling which data/connections get through and which don’t. But unlike these regular firewalls, application firewalls work on higher-level protocols (like HTTP, FTP) that deal with user data rather than with connection routing. I’m going to call these firewalls “network firewalls”, although most modern network firewalls have some application firewall functionality as well.

The purpose and necessity of network firewalls is well known and understood: make sure that the service is only accessible from the right location, check if connections aren’t abused (or too many connections are made), etc. But what if the connection itself is valid? After all, most abuse of services is not because they originate from the wrong location or try to access the wrong service. Instead, such abuse comes from valid access to the application, but with less kosher intentions. So what can application firewalls do in this case?

  • Because they perform inspection of the data that is transferred itself, application firewalls can detect malicious data fragments or attempts to abuse the service. These detection rules can be based on general, heuristic rules (well-known examples are detection rules for cross-site scripting attacks (XSS) or SQL Injection) but can also be very specific to a particular application.
  • Because all data is transferred through the firewall and the firewall has knowledge of the application itself, these firewalls offer advanced auditing features since they can detect authentication steps, user data, application-specific transactions and more.
  • With knowledge of the users’ session and behavior (application-level) and origin (network level), application firewalls can detect and prevent unauthorized sessions, such as the case with session hijacking or even man-in-the-middle attacks (based on behavior detection)

Implementing an application firewall however doesn’t only mean that you improve access controls on it. It has other advantages that make application firewalls an important part in many architectures:

  • If all service access is forced through the application firewall (for instance through an IP filter on the service that only allows connections from the application firewalls) you can implement rules that deter known attacks/vulnerabilities without needing to fix the code itself (or if fixing is possible, lower the time pressure). For instance, for Apache-based services, such an application firewall could detect or even change the Range: header on malicious requests to lower the impact of this potentially nasty DoS vulnerability
  • Depending on the complexity, some functional application bug fixing might even be possible. For instance changing content types on requests/replies (HTTP), adding a domain on an FTP accounts’ login statement, …
  • Many application firewalls (or gateways) offer proxy functionality which might improve response times. This is not a sure-given, since most applications are session-aware so the advantage is only for session-agnostic requests (be it static content or specific SQL statements in case of a database firewall). But also in case of session-aware statements can an improvement be found. Consider a database firewall which translates SQL statements from an unsupported application towards better defined statements (for instance using proper indexes or materialized views).
  • In some cases, you might even be able to upgrade a backend of an unsupported application (which previously required an outdated version of that database) by translating the backend requests when they are incompatible with the new backend version. So you can improve integration or support unsupported upgrades.
  • In case of risk reduction, application firewalls also allow you to move a service elsewhere (even in the public cloud) and still keep the access under control.

Of course, it would be TGTBT (Too Good To Be True) if there isn’t an (important) downside: maintaining the application firewall is a daunting task. Because of its flexibility, you’ll need deep knowledge in the application firewall administration and development, keep track of all rules you have (and why you have them), do lots and lots of testing on each rule (since it might affect the functioning of the application) and still be aware that subtle differences introduced by the application firewall rules can pop up unexpectedly. Also, integrating an application firewall is another service between your customer and his service, which might influence performance but also makes the underlying architecture more complex. Finally, you’ll need to consider that an application firewall requires lots of resources (CPU/memory), especially when it needs to perform SSL/TLS termination. Oh, and they’re often expensive too.

Still, even with these downsides, application firewalls are an important part of the service isolation strategy, which is a key aspect in the risk mitigation strategy which this series started with. We’ve focused on three now: service isolation (network-wise), process isolation (through mandatory access control) and now access isolation through application firewalls. And with proper hardening in place, I believe that you have done all you can do to reduce the risks when running unsupported software (apart from upgrading it or switching towards supported software).

If you have other ideas that benefit risk mitigation, with specific focus on unsupported software, I would be glad to hear about them.

Posted in Architecture, Security | Leave a comment

Quickly setup a Gentoo system

In order to verify if the installation instructions in the Gentoo Handbook are still valid, and to allow me to quickly seed new Gentoo installations in a virtual environment, I wrote a very ugly (really) script to automatically “stage” a Gentoo Linux installation in a KVM guest. This is not my intention to make this an “unattended” installation script, it is merely one of the many scripts out there to help some poor developer in working a bit more agile.

I decided to document gensetup as a first step (cfr my earlier Catching up post) in my quest to document how to setup a virtual Gentoo Hardened (with SELinux) virtual architecture. The gensetup tool is just to provide a (semi)automated way to install Gentoo according to the instructions in the Gentoo Handbook. Later, I’ll add documentation for the setup_*.sh scripts that I use to upgrade such a base installation to a specific server/service.

You want a probably better working installation script, check out Andrew Gaffney’s Quickstart for Gentoo. And if you know of other such scripts, I would be glad to hear from them, if not just to keep track of the various similar projects out there.

Edit: The quickstart application does not seem to be maintained anymore. My bad. However, suggestions are made in the comments for more up-to-date systems ;-)

Posted in Gentoo, Hardened | 7 Comments

Power management guide updated

The Gentoo Power Management Guide is now updated. It is a full rewrite, focusing currently on two main toolsets: Laptop Mode Tools and cpufreqd. I was pleasantly surprised by the number of features that the laptop mode tools package provided.

Of course, this does not mean that the guide is now finished. Documentation never is, so do keep on suggesting improvements (and pointing to bugs) in Gentoo’s bugzilla.

Posted in Gentoo | 1 Comment

Mitigating risks, part 4 – Mandatory Access Control

I’ve talked about service isolation earlier and the risks that it helps to mitigate. However, many applications still run as highly privileged accounts, or can be abused to execute more functions than intended. Service isolation doesn’t help there, and system hardening can only go that far. The additional countermeasures that you can take are application firewalls and mandatory access control. And now you know what part 5 will talk about ;-)

Standard access control on most popular operating systems is based on a limited set of privileges (such as read, write and execute) on a limited scale (user, group, everyone else). Recent developments are showing an increase in the privilege flexibility, with the advent of manageable capabilities (Linux/Unix) or Group Policies (Windows). However, these still lack some important features:

  • Users are still able to delegate their privilege to others. A user with read access on a particular file can copy that file to a public readable location so others can read it as well. Privileges on his own files and directories are fully manageable by the owner. For our risk mitigation approach on unsupported software, that means that a vulnerability might be exploited so that the service “leaks” information. It is especially important in an attack that uses a sequence of vulnerabilities (such as in an advanced persistent threat) where low-risk vulnerabilities can be combined into a high-risk exploit.
  • Privileges are still user-level privileges (including technical account users). In case of running services, this almost always means that the process has more privileges than it requires. Some software titles allow for dropping capabilities when not needed anymore. Most however are oblivious of the rights they possess. Abuse of the service (which includes use of features that the service offers but are not allowed policy-wise by the organization) cannot be prevented if hardening doesn’t disable it.
  • Privileges are managed by many actors (such as the system administrators) and are not that easy to audit. Privilege denials are often not audited, causing issues to only come up when they occur, rather then when the attempt to provoke issues is started. In many cases, a malicious (or “playful, inventive”) user starts with investigating and trying out long before a way is found to abuse the service.

In case of a mandatory access control system, a security administrator is responsible for writing and managing a security policy which is enforced by the operating system (well, higher level enforcement would be even better, but is currently not realistic). Once enforced, the policy ensures that privileges are not delegated (unless allowed). Also, in most MAC systems, the policy allows for a much more detailed privilege granularity. And recent server operating systems have support for MAC – I personally work with SELinux for the (GNU/)Linux operating system.

But this more granular flexibility in privileges comes with some costs. First of all, it becomes much more complex to manage the policy. You’ll need highly experienced administrators to work with a MAC-enabled system. Second, a MAC model has a negative influence on performance since the system has to check many more accesses and access rules. To make MAC-enabled systems workable, operating systems offer a default policy which already covers many services. Also, developers on the MAC technology are continuously safe-guarding performance – I personally do not notice a performance degradation when using SELinux, and more realistic benchmarks suggest that the impact of SELinux is between 3% and 12% depending on the policy level.

But what does that mean towards the initial risk list that I identified in the beginning of this article series? Well, directly, very little: mandatory access control in this case is about reducing the impact of security vulnerabilities (and abuse of the service). It will not help you out in other ways. However, there are other things to gain from a mandatory access control than just threat reduction.

An advantage is – again – that you get to know your application well, especially if you had to write a security policy for it. Since you need to define what files it can access, which kind of accesses it is allowed to do, which commands it can execute, etc, it will give you insight in how the application operates. Bugs in the application might be solved faster and you’ll definitely learn more about how the application is integrated. Another one is that most mandatory access control systems have much more detailed auditing capabilities. Attempts to abuse the service will result in denials which are detected and on which you can then take proper action.

Taking a higher-level look at mandatory access control will show you that, in case of risk mitigation, it is much more like service isolation, but then on the operating system level. You isolate the processes, governing the accesses they are allowed to do.

But the one main issue – active exploits on the application service – cannot be hindered by neither service isolation (since the service is still accessible), hardening (although it might help) or mandatory access control (which reduces the actions an exploit can do). To make sure that vulnerabilities are less likely to be exploited, I’ll talk about application firewalls in the next post.

Posted in Architecture, Hardened, Security, SELinux | 1 Comment

Catching up

As mentioned on the gentoo-doc mailinglist, all documentation bugs (that we know of) related to openrc have been fixed. It was already a week like so, but the last dependency on our “tracker” bug was an open one (asking if more needs to be done or not) from which we haven’t received an answer in over a month. So I guess we’re there.

Now, the OpenRC transition wasn’t an easy one documentation-wise. Since there is no full backwards compatibility, all changes would need to be done in an atomic way, but due to resource constraints, the documentation couldn’t catch up on the changes in due time. Luckily, that’s over now and we can hopefully start by improving our documentation once again.

For SELinux too, OpenRC hasn’t been a gift. The latest selinux-base-policy now in the Portage tree (20110726-r4) still includes some fixes to get OpenRC support fully working. However, I’m fairly confident that we will be able to tackle other bugs (if they arise) quickly now, since the basic policy definitions (like support for rc_exec_t) are now in place.

With the major changes done, let’s look at the future. For documentation, I’m now working on a new Power Management Guide whereas for SELinux, I’ll be focusing on the remaining bugs as well as documentation updates (the SELinux Handbook will have some major updates in the hope it becomes more useful and future-proof). Also, for GDP, I’m going to make a suggestion towards the Gentoo Documentation Policy, taking into account that the GDP resources are not as high as at the time the policy was written. Finally, I’m going to update my installation scripts that I use to seed the virtual servers so that I can enhance the SELinux policy testing.

I consider this post to be a checklist – after all, now that I promised that I would do that, I guess I can’t excuse myself from that anymore do I ;-)

Posted in Gentoo | 1 Comment

Mitigating risks, part 3 – hardening

While I’m writing this post, my neighbor is shouting. He’s shouting so hard, that I was almost writing with CAPS on to make sure you could read me. But don’t worry, he’s not fighting – it is how he expresses his (positive) feelings about his religion.

Security is, for some, also a religion. They see risks and vulnerabilities and what not everywhere. They’re always thinking every system in the world is or will be hacked in the near future and are frantically trying to secure every service they are running – and more. But security is also a real-life issue. If you take a look at the compromised GlobalSign website (who mentions that the website is an isolated one – as I described earlier) I hope that you look at security as being a functional requirement in architecturing and design (and not a non-functional one as many frameworks suggest).

And as you can see from the example, isolating services is not sufficient to prevent a successful exploit of an insecure or unsupported software (the reason why I started with this series). One additional measure that you can take is hardening the server and service.

The act of hardening a server and service is to configure the system so that it is as secure as possible, based on configuration entries. Many vendors and projects offer a security guide (like the Gentoo Security Handbook or the Fedora Security Guide) although most of them add this as part of their standard administrative documents (like the PostgreSQL “Server Setup and Operation” chapter).

But for some reason, you’ll find that default installations – even when following the instructions of the vendor – are not as secure as you want it to be. As a matter of fact, if you come in contact with auditors, you’ll probably fail any audit if you use a default installation. To help administrators to secure their services, you will find lots of third party sites offering advice on securing the operating system and the services running on it. These guides are what you will need to “harden” your system.

  • OWASP, which stands for Open Web Application Security Project, hosts some hardening guides and suggestions together with test scenarios. For front-end application servers (mostly web application servers) you will find lots of interesting resources in the OWASP site (and surrounding community).
  • Google is probably the best resource for finding hardening guides for your operating system or service. Just look for “hardening foo” and you will be reading for a week.
  • CISecurity, or “Center for Internet Security”, is another one with a larger portfolio on hardening guides. Not only does it offer these guides (which it calls “benchmarks”), but organizations can also become a member and as such benefit from tooling that CISecurity supports for the validation of benchmarks (i.e. test if the system/deployment is compliant towards a particular benchmark). It does that by developing the benchmarks in a open specification called OVAL (the Open Vulnerability and Assessment Language) and XCCDF (XML Configuration Checklist Data Format). And CISecurity is not the only one there.
  • Another such resource is the National Vulnerability Database (national for US residents, that is ;-) There you can find and download the OVAL/XCCDF resources for various software titles and operating systems. But as you can imagine from the abbreviations, the resources are XML files which are not made to be read by humans.

Although you can use the tool(s) that CISecurity offers, another possibility is to use Open-SCAP, an open source framework for handling SCAP, OVAL, XCCDF and other such open specifications on a system. Its documentation offers a first glance at what it can support.

However, this brings on he disadvantages of hardening services…

  1. Hardening a system and its services is a time consuming job. Its only purpose is to reduce the impact of exploited vulnerabilities and reduce the “attack surface” so that exploits on unused functions are not possible.
  2. Hardening a system and its services can impact the service. Make it too tight, and it might not behave anymore like you want it to.
  3. Also, since there are many, many resources “out there” on hardening, you will have to manage your hardening rules, document them for yourself. It is also advisable to document the rules you are not implementing, if not just for future’s sake.
  4. The hardening guides also require quite some expertise on the service. If you are not experienced with the service but you need to harden it, you can be lucky and just implement what is suggested and hope for the best, but usually you will need to dive deeper in the subject and make (tough) choices.

Although specifications like SCAP exist to help you in your hardening exercises, these are still difficult to manage (do not try to write OVAL/SCAP/XCCDF content in your favorite text editor). Its adoption however by Fedora and RedHat is showing a positive effect on the tools surrounding this specification. I will be writing about SCAP, OVAL and XCCDF later since I too see good use of it in organizations (or even free software projects).

Does that mean that hardening is not beneficial? On the contrary:

  • You gain lots of knowledge in the matter, and also forces you to think about integration aspects. Since you are responsible for the service (or the damage that could be made if the service is exploited) being knowledgeable is definitely a good thing.
  • A considerable amount of vulnerabilities that are and will be reported on the service (check CVE details to find out about publicly known vulnerabilities, documented in the CVE specification) will not have their effect on a well hardened service. Or put another way, you will reduce the number of real vulnerabilities in your service. You will not be able to exclude all vulnerabilities, but the projected number is high – a fully hardened Windows or Linux system can mitigate up to 90% of the exploits on the operating system. It will considerably reduce the risks that you and your organization are taking.
  • A well defined hardening guide will also offer the means to automatically audit or check if the system is still compliant to the hardening setup you envisioned. Scheduled regularly, this will ensure that your configurations are not drifting away, back to a more vulnerable setup, for whatever reason.
  • By removing the functions that the service should not offer, you make sure that the use of the service is per the organizations’ guidelines. (Internal) abuse of the service is made more difficult, so users are forced to take the regular way. Unlike service isolation, which allows you to keep track of data/service flows, hardening makes sure that side-functionality is not used without your consent. Or to put it more blunt, “Yes I know Oracle DB can be used to schedule tasks on the operating system, but no, you’re not allowed to use that function”.

And who knows, perhaps by optimizing the configuration, it might run faster with a lower resource footprint ;-) If it does, that’s perfect, since the next topic on risk mitigation will have a negative influence on performance: mandatory access control.

Posted in Architecture, Security | Leave a comment

Mitigating risks, part 2 – service isolation

Internet: absolute communication, absolute isolation
~Paul Carvel

The quote might be ripped out of its context completely, since it wasn’t made when talking about risks and the assurance you might need to get in order to reduce risks. But it does give a nice introduction to the second part of this article series on risk mitigation. After all, if the unsupported software is offering services to the Internet, you really want to govern the communication and isolate the service.

When you are dealing with a product or software that is unsupported (be it that it will not get any patches and updates from its authors or vendor, or there is no time/budget to support the environment properly), it is in my opinion wise to isolate the service from the rest. My first post on the matter gave a high-level introduction on the risks that you might be taking when you run unsupported (or out-of-support) systems. Service isolation helps in reducing the risks that others have when you run such software on a shared infrastructure (like in the same network or even data centre).

By isolating the unsupported service from the rest, you create a sort-of quarantine environment where sudden mishaps are shielded from interfering with other systems. It provides insurance for others, knowing that their (supported) services cannot be influenced or jeopardized by issues with the unsupported ones. And if these services need to interact with the isolated service, the interface used is known and much more manageable (think about a well-defined TCP connection versus local communication or even Inter-Process Communication). But it goes beyond just providing insurance for others.

Isolation forces you to learn about the application and its interaction with other services. It is this phase that makes it extremely important in an environment, because not knowing how an application works, behaves or interacts creates more problems later when you need to debug issues, troubleshoot performance problems and more. Integration failures, as described in my previous post, can only be dealt with swiftly if you know how the service integrates with others.

Another advantage of proper service isolation is that you can fix its dependencies more easily. Remember that I talked about upgrade difficulties, where a necessary upgrade for one component impacted the functionalities of the other (unsupported) component? With good isolation, the dependencies are more manageable and controllable. Not only are (sub)component upgrades easier to schedule, it is also a lot easier to provide fall-back scenario’s in case problems occur. After all, the isolated service is the only user so you have little to fear if you need to roll-back a change.

But what is proper service isolation?

  • First of all, it means that you focus on running the (unsupported) software alone on an operating system instance. Do not run other services on the same OS, not even if they too are unsupported. The only exception here is if the other services are tightly integrated with your service and cannot be installed on a separate OS. But usually, full service isolation is possible.
  • Next, strip the operating system so it only runs what you need for managing the service. Put primary focus on services that are accepting incoming connections (“listening”) and secondary focus on allowed outgoing protocols/sessions (and the tools that initiate them).
  • See if you can virtualize the environment. In most cases, the service does not require many resources so it would be a waste running it on a dedicated system. However, in my opinion, a much better reason for virtualization is hardware abstraction. Sure, all operating systems tell you that they have some sort of Hardware Abstraction Layer in them and that they can deal with hardware changes without you noticing it. But if you are an administrator, you know this is only partially true. Virtualization offers the advantage that the underlying hardware is virtual and can remain the same, even if you move the virtualized system to a much more powerful host. Another advantage is that you might be able to offload certain necessary services from the OS (like backup) to the host (snapshotting).
  • Shield the operating system, network-wise, from other systems. Yes, that means putting a firewall BEFORE the operating system guest (and definitely not on the OS) which governs all traffic coming in and out of the environment. Only allow connections that are legit. If your organization has a huge network to manage, they might work with network segment filtering instead of IP-level filtering. See if you can get an exception to that – managing the rules should not give too much overhead since the system, being unsupported and all, is a lot less likely to get many connectivity updates.

But before finishing off, a hint about stripping an operating system. Stripping is much more than just removing services that are not used. It also means that you look for services that are needed, and see if you can externalize them. Common examples here are logging (send your logs to a remote system rather than keeping them local), e-mail (use simple “direct-out” mail) and backup (use a locally scheduled backup tool, or even offload to the host in virtualized systems), but many others exist.

Of course, service isolation is not unknown to most people. If you run a large(r) network with Internet-facing services, you probably isolate those in a DMZ environment. That is quite frankly (also) for the same “risk mitigation” reason. In case of a security breach, service unavailability or otherwise, you want to reduce the risk that this fault spreads to other systems (be it getting to internal documents or putting more services down).

Another aspect administrators do with systems in their DMZ is system hardening, which I will talk about in the third part.

Posted in Architecture, Security | Leave a comment