Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp560628ybi; Fri, 31 May 2019 05:47:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkp6ff8GMJCQlS5dkUjVpC2qd8viWauDB4yBPtcETbC1CQ2huxMfYjMW5p4gd+EdSK6Vvg X-Received: by 2002:a17:902:a415:: with SMTP id p21mr9343777plq.46.1559306857796; Fri, 31 May 2019 05:47:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559306857; cv=none; d=google.com; s=arc-20160816; b=Vpyof7/CgeeAkJ/t40w6C8DPopU1hEtlYlwrmPo4vhlaR3ATHUDyPSJib30oE2RRFO CKr07RaPHTw11K1Cr1rb8BhtNBnRWF/0/tK56hch4c1JOFO2SC9kuQbF73x3bPFOHkVf 9V3fzmpyIbzzgY5nByVGUHSpXTySzaC4dVKtIyJynFabaB+iIvx/s2IO9I5kncyCenq8 Gs1dAZmmU2qSlz6nFpBG2E5gznBHdqgrOne1QdZpNE2dtRJTK4c33Cw4W94tXQdoCeYq EWd6ynuJ7+qyCcnVo5G9/HcBlzQzVAk9DAy9p0esqggTdI8/Rr7lu0AE5raR1oWVo9UB ueyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ZXDOKwkAEMBmiYSeMHCXxPtDvLwnxyJqoeUB0a+jAg8=; b=bGYJBpVLlcJ73lU19RNci4KVsKZB3xsReYjW2o8+168gPHMEpC74BcubYGpKmArg1Z XTGxKDbGFidklMF+2G3Frx4fNG5UMNqHwTxO98dV1eHaXXGyUlSjomP5WXE+LT2jVqGm /VbAypJlFTmPXtH7f5DsDp+aSLGdUtFOvJ27ZIEK+gYLB7eRbDmceFOFtgF+6ubAnGXO BJsclafjsjpEyZrJvkSs+IvvNMmI0Vr+SDYeiPz3RRC6SG1Lja2xkY63i1ADLl7n1DHQ l4/eklkairW/enY0W92RqqXzVjCe8Tf0WZkwh1ufM4FEHFbr34VCYfwRbXzxJlMCHq+3 71Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=Oh5evWeB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 2si5956677pgy.541.2019.05.31.05.47.20; Fri, 31 May 2019 05:47:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=Oh5evWeB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727318AbfEaMpB (ORCPT + 99 others); Fri, 31 May 2019 08:45:01 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:36886 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726555AbfEaMpA (ORCPT ); Fri, 31 May 2019 08:45:00 -0400 Received: by mail-lj1-f196.google.com with SMTP id h19so9483273ljj.4 for ; Fri, 31 May 2019 05:44:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZXDOKwkAEMBmiYSeMHCXxPtDvLwnxyJqoeUB0a+jAg8=; b=Oh5evWeBS0FQ5+SDSVIYDoDosmFdUraAVQSeP13wAG0FfkUCyvKQpzKYfoQx/Fc9jG lSaXqIOqwzoUzI3o8vBwZqtrK4OfHuaXvwJgEezHSUYUzDIRs8JkI5NH1zlR4cxWyQme Jfit8Diw2UqqiuTc+FH74c11TZCrrrdmpj/o5+9/QDcaiVnDEyYq21nnWSIA465u/MU4 +qSUnOUm6rmASeEsGsXm0RP0/aMO/Wsm45X36MGxa7H5G8PkA5ZCJKY5x4qvxmWuxnO8 Qn1PWZvVAf7u20A+XXfB5qKWG2QcdBuOAtm661NoEzPCdGshFZqYQtHFr/60ieylKxGT GHFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZXDOKwkAEMBmiYSeMHCXxPtDvLwnxyJqoeUB0a+jAg8=; b=DSrhNdPHxEoJtlvJGEhBmRRLEU9zBLausXxCcjI9Sy7VvMKOyA29/xh4YW8tu+4YyN rVHCrSWJGis0emQn18GmEBv9qJpYT5p7mJrxFvaDETG6s0zTt+J4MldtkNCwW1tTuVmu 53AGoM22VzJy1zXWVXjmC9gvrZkyst5lqj+fGrSScpPhCH/3gG1iAVdT59McX9Q88T41 Z/dpMMd6tAkBrMKf8URwkERsGMUkRpLUBY80xc5p0mhwWcmIueZI8WugjYSLNBy2rgeT Rvon2fHLtE6WS7Nmylc79hLGf8ff2145SxUQDbjvRJ9QMklfnG4jGcitX4TCwgasKeCX LHsg== X-Gm-Message-State: APjAAAVF6WBuswH93MqM1EXujYD7fd+49D3P04TVBntuj0ASlkgFghS1 cW6343Bqo1Oi09inntgstFYUuLvLBsIog0UkO4BQ X-Received: by 2002:a2e:3e14:: with SMTP id l20mr5891599lja.40.1559306696964; Fri, 31 May 2019 05:44:56 -0700 (PDT) MIME-Version: 1.0 References: <20190529145742.GA8959@cisco> <20190529153427.GB8959@cisco> <20190529222835.GD8959@cisco> <20190530170913.GA16722@mail.hallyn.com> <20190530212900.GC5739@cisco> <20190531002058.tsddah4edcazkuzs@madcap2.tricolour.ca> In-Reply-To: <20190531002058.tsddah4edcazkuzs@madcap2.tricolour.ca> From: Paul Moore Date: Fri, 31 May 2019 08:44:45 -0400 Message-ID: Subject: Re: [PATCH ghak90 V6 02/10] audit: add container id To: Richard Guy Briggs Cc: Tycho Andersen , "Serge E. Hallyn" , containers@lists.linux-foundation.org, linux-api@vger.kernel.org, Linux-Audit Mailing List , linux-fsdevel@vger.kernel.org, LKML , netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, sgrubb@redhat.com, omosnace@redhat.com, dhowells@redhat.com, simo@redhat.com, Eric Paris , ebiederm@xmission.com, nhorman@tuxdriver.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 30, 2019 at 8:21 PM Richard Guy Briggs wrote: > On 2019-05-30 19:26, Paul Moore wrote: > > On Thu, May 30, 2019 at 5:29 PM Tycho Andersen wrote: > > > On Thu, May 30, 2019 at 03:29:32PM -0400, Paul Moore wrote: > > > > > > > > [REMINDER: It is an "*audit* container ID" and not a general > > > > "container ID" ;) Smiley aside, I'm not kidding about that part.] > > > > > > This sort of seems like a distinction without a difference; presumably > > > audit is going to want to differentiate between everything that people > > > in userspace call a container. So you'll have to support all this > > > insanity anyway, even if it's "not a container ID". > > > > That's not quite right. Audit doesn't care about what a container is, > > or is not, it also doesn't care if the "audit container ID" actually > > matches the ID used by the container engine in userspace and I think > > that is a very important line to draw. Audit is simply given a value > > which it calls the "audit container ID", it ensures that the value is > > inherited appropriately (e.g. children inherit their parent's audit > > container ID), and it uses the value in audit records to provide some > > additional context for log analysis. The distinction isn't limited to > > the value itself, but also to how it is used; it is an "audit > > container ID" and not a "container ID" because this value is > > exclusively for use by the audit subsystem. We are very intentionally > > not adding a generic container ID to the kernel. If the kernel does > > ever grow a general purpose container ID we will be one of the first > > ones in line to make use of it, but we are not going to be the ones to > > generically add containers to the kernel. Enough people already hate > > audit ;) > > > > > > I'm not interested in supporting/merging something that isn't useful; > > > > if this doesn't work for your use case then we need to figure out what > > > > would work. It sounds like nested containers are much more common in > > > > the lxc world, can you elaborate a bit more on this? > > > > > > > > As far as the possible solutions you mention above, I'm not sure I > > > > like the per-userns audit container IDs, I'd much rather just emit the > > > > necessary tracking information via the audit record stream and let the > > > > log analysis tools figure it out. However, the bigger question is how > > > > to limit (re)setting the audit container ID when you are in a non-init > > > > userns. For reasons already mentioned, using capable() is a non > > > > starter for everything but the initial userns, and using ns_capable() > > > > is equally poor as it essentially allows any userns the ability to > > > > munge it's audit container ID (obviously not good). It appears we > > > > need a different method for controlling access to the audit container > > > > ID. > > > > > > One option would be to make it a string, and have it be append only. > > > That should be safe with no checks. > > > > > > I know there was a long thread about what type to make this thing. I > > > think you could accomplish the append-only-ness with a u64 if you had > > > some rule about only allowing setting lower order bits than those that > > > are already set. With 4 bits for simplicity: > > > > > > 1100 # initial container id > > > 1100 -> 1011 # not allowed > > > 1100 -> 1101 # allowed, but now 1101 is set in stone since there are > > > # no lower order bits left > > > > > > There are probably fancier ways to do it if you actually understand > > > math :) > > > > ;) > > > > > Since userns nesting is limited to 32 levels (right now, IIRC), and > > > you have 64 bits, this might be reasonable. You could just teach > > > container engines to use the first say N bits for themselves, with a 1 > > > bit for the barrier at the end. > > > > I like the creativity, but I worry that at some point these > > limitations are going to be raised (limits have a funny way of doing > > that over time) and we will be in trouble. I say "trouble" because I > > want to be able to quickly do an audit container ID comparison and > > we're going to pay a penalty for these larger values (we'll need this > > when we add multiple auditd support and the requisite record routing). > > > > Thinking about this makes me also realize we probably need to think a > > bit longer about audit container ID conflicts between orchestrators. > > Right now we just take the value that is given to us by the > > orchestrator, but if we want to allow multiple container orchestrators > > to work without some form of cooperation in userspace (I think we have > > to assume the orchestrators will not talk to each other) we likely > > need to have some way to block reuse of an audit container ID. We > > would either need to prevent the orchestrator from explicitly setting > > an audit container ID to a currently in use value, or instead generate > > the audit container ID in the kernel upon an event triggered by the > > orchestrator (e.g. a write to a /proc file). I suspect we should > > start looking at the idr code, I think we will need to make use of it. > > My first reaction to using the IDR code is that once an idr is given up, > it can be reused. I suppose we request IDRs and then never give them up > to avoid reuse... I'm not sure we ever what to guarantee that an audit container ID won't be reused during the lifetime of the system, it is a discrete integer after all. What I think we do want to guarantee is that we won't allow an unintentional audit container ID collision between different orchestrators; if a single orchestrator wants to reuse an audit container ID then that is its choice. > I already had some ideas of preventing an existing ID from being reused, Cool. I only made the idr suggestion since it is used for PIDs and solves a very similar problem. > but that makes the practice of some container engines injecting > processes into existing containers difficult if not impossible. Yes, we'll need some provision to indicate which orchestrator "controls" that particular audit container ID, and allow that orchestrator to reuse that particular audit container ID (until all those containers disappear and the audit container ID is given back to the pool). -- paul moore www.paul-moore.com