Skip to content

Track which user created resources #13925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

smarterclayton
Copy link
Contributor

@smarterclayton smarterclayton commented Sep 14, 2015

Adds creationUserName which records the creating user in the resource
for use in audit scenarios. Set by the system automatically to the user
name returned by the authentication plugin. Clients must assume that the
name value may be machine-readable and therefore is not guaranteed to be
a pretty name.

Fixes #13306


This change is Reviewable

@smarterclayton
Copy link
Contributor Author

@kubernetes/kube-api - the proposal didn't get many comments but this adds a new metadata field to track created users.

@derekwaynecarr
Copy link
Member

I assume CreationUserName is preferred over Creator because it aligns with CreationTimestamp?

@@ -25,6 +25,9 @@ import (
// FillObjectMetaSystemFields populates fields that are managed by the system on ObjectMeta.
func FillObjectMetaSystemFields(ctx Context, meta *ObjectMeta) {
meta.CreationTimestamp = util.Now()
if user, ok := UserFrom(ctx); ok {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would there never be a user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I don't want to create new names even if the english is slightly
weird. We're fairly good at "" in our API - "creation" is
the concept, "type" is "UserName", "Timestamp", "PeriodInSeconds", "Name",
"Ref"

On Mon, Sep 14, 2015 at 1:41 PM, Derek Carr [email protected]
wrote:

In pkg/api/meta.go
#13925 (comment)
:

@@ -25,6 +25,9 @@ import (
// FillObjectMetaSystemFields populates fields that are managed by the system on ObjectMeta.
func FillObjectMetaSystemFields(ctx Context, meta *ObjectMeta) {
meta.CreationTimestamp = util.Now()

  • if user, ok := UserFrom(ctx); ok {

When would there never be a user?


Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/13925/files#r39422744.

Clayton Coleman | Lead Engineer, OpenShift

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could not be a user if it's an object created before this change went
in, created by a core system process (like endpoints and namespaces created
by the master on startup), or created by direct edit in etcd that does not
require authentication. Or a cluster that doesn't require authentication
or doesn't pass that info to Kube.

On Mon, Sep 14, 2015 at 2:08 PM, Clayton Coleman [email protected]
wrote:

Yes, I don't want to create new names even if the english is slightly
weird. We're fairly good at "" in our API - "creation" is
the concept, "type" is "UserName", "Timestamp", "PeriodInSeconds", "Name",
"Ref"

On Mon, Sep 14, 2015 at 1:41 PM, Derek Carr [email protected]
wrote:

In pkg/api/meta.go
#13925 (comment)
:

@@ -25,6 +25,9 @@ import (
// FillObjectMetaSystemFields populates fields that are managed by the system on ObjectMeta.
func FillObjectMetaSystemFields(ctx Context, meta *ObjectMeta) {
meta.CreationTimestamp = util.Now()

  • if user, ok := UserFrom(ctx); ok {

When would there never be a user?


Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/13925/files#r39422744.

Clayton Coleman | Lead Engineer, OpenShift

Clayton Coleman | Lead Engineer, OpenShift

@k8s-github-robot k8s-github-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 14, 2015
@smarterclayton
Copy link
Contributor Author

ok to test

@smarterclayton
Copy link
Contributor Author

@bgrant0607 let me know if the naming makes sense here

@bgrant0607 bgrant0607 assigned erictune and unassigned bgrant0607 Sep 16, 2015
@bgrant0607
Copy link
Member

I understand that you want a field that can't be set/modified by the client, as opposed to an annotation. I'm fine with that.

CreationUserName seems fine with respect to the field naming conventions.

I also like that CreationUserName makes it clear that it's a user name and not, for instance, a controller name.

What I don't know is what our plans for User concepts/APIs are. Is "UserName" consistent with our current thinking in that direction? @erictune? @liggitt? @derekwaynecarr?

@@ -273,6 +273,12 @@ func ValidateObjectMetaUpdate(new, old *api.ObjectMeta) errs.ValidationErrorList
} else {
new.CreationTimestamp = old.CreationTimestamp
}
// ignore changes to user name
if len(old.CreationUserName) == 0 {
old.CreationUserName = new.CreationUserName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was empty before, it seems weird to allow it to be updated later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was to allow an automated process to update it for legacy data. So
someone upgrading from Kube 1.0 would be able to be assigned the value. I
can disable the ability to set it post creation, which means we have no API
path to ever set that value and would have to write directly to etcd.
Allowing it to be set from empty to something post create has potential for
abuse.

On Sep 16, 2015, at 9:47 AM, David Eads [email protected] wrote:

In pkg/api/validation/validation.go
#13925 (comment):

@@ -273,6 +273,12 @@ func ValidateObjectMetaUpdate(new, old *api.ObjectMeta) errs.ValidationErrorList
} else {
new.CreationTimestamp = old.CreationTimestamp
}

  • // ignore changes to user name
  • if len(old.CreationUserName) == 0 {
  • old.CreationUserName = new.CreationUserName
    

If it was empty before, it seems weird to allow it to be updated later.


Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/13925/files#r39630766.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for making it immutable by default

@smarterclayton
Copy link
Contributor Author

On Sep 16, 2015, at 1:24 AM, Brian Grant [email protected] wrote:

I understand that you want a field that can't be set/modified by the
client, as opposed to an annotation. I'm fine with that.

CreationUserName seems fine with respect to the field naming conventions.

I also like that CreationUserName makes it clear that it's a user name and
not, for instance, a controller name.

What I don't know is what our plans for User concepts/APIs are. Is
"UserName" consistent with our current thinking in that direction? @erictune
https://github.com/erictune? @liggitt https://github.com/liggitt?
@derekwaynecarr https://github.com/derekwaynecarr?

As defined in our authentication patterns we settled on UserName as the
unique in space name for a user. We don't have a way to enforce uniqueness
for time and space today within Kube (in Openshift we do) because
underlying auth providers are responsible for that (as defined by their
system). An admin is free to let their username not be stable if they
like. I would maybe argue in the future to expand this to include userUID,
but not required for step one.


Reply to this email directly or view it on GitHub
#13925 (comment)
.

@liggitt
Copy link
Member

liggitt commented Sep 16, 2015

CreationUserName seems ok. The user.Info interface has both Name() and UID(). Do we want to preserve both (that gets us point in time uniqueness as well).

@smarterclayton
Copy link
Contributor Author

I wanted to make the minimal change here to start down the path. If
everyone is ok with UID(), we can add it. On the other hand, we can easily
add it later.

On Wed, Sep 16, 2015 at 12:57 PM, Jordan Liggitt [email protected]
wrote:

CreationUserName seems ok. The user.Info interface has both Name() and
UID(). Do we want to preserve both (that gets us point in time uniqueness
as well).


Reply to this email directly or view it on GitHub
#13925 (comment)
.

Clayton Coleman | Lead Engineer, OpenShift

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 17, 2015
@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Sep 18, 2015
Adds `creationUserName` which records the creating user in the resource
for use in audit scenarios. Set by the system automatically to the user
name returned by the authentication plugin. Clients must assume that the
name value may be machine-readable and therefore is not guaranteed to be
a pretty name.
@smarterclayton
Copy link
Contributor Author

Rebased. This is as minimal a change as I can make that provides real value. Do we have consensus on creationUserName as the name? I think we can add creationUserUID in the future. Other thoughts?

@deads2k
Copy link
Contributor

deads2k commented Sep 18, 2015

code lgtm.

I like username as a starting point.

@erictune
Copy link
Contributor

@saad-ali because he ❤️ events.

@smarterclayton
Copy link
Contributor Author

Downside is that is a lot more events. Also, today at least events are owned by a namespace so they can be deleted when the namespace is deleted.

@erictune
Copy link
Contributor

It may be worth comparing with other IaaS/PaaS APIs which are mature enough
to have well-developed audit capabilities. I picked cloud foundry and
openstack for comparison.

On Thu, Dec 24, 2015 at 8:35 PM, Clayton Coleman [email protected]
wrote:

Downside is that is a lot more events. Also, today at least events are
owned by a namespace so they can be deleted when the namespace is deleted.


Reply to this email directly or view it on GitHub
#13925 (comment)
.

@smarterclayton
Copy link
Contributor Author

smarterclayton commented Dec 26, 2015 via email

@cameronbrunner
Copy link
Contributor

Just curious how this request is progressing. Specifically the created-by-user is of great interest but not for an audit perspective but more as a pod attribute. As discussed in #19079 (and sorry for those who have read both of these comments!) I am interested in this as we are working on integrating our scheduler (Grid Engine) with kubernetes and from our past experience user ownership of compute tasks is important when organizations implement resource allocation policies. It would be useful for us to be able to quota against users, favor pods created by one user over another, and group pods of certain users under hierarchical organizational groups. With our scheduler we could do just about all of this now in kubernetes if there was a user tag on resources.

@erictune
Copy link
Contributor

@cameronbrunner Resources are often created by controllers in kubernetes, not end-users. Before we can have this feature in a useful way, we would need to implement acting-as #16933.

@cameronbrunner
Copy link
Contributor

@erictune Thanks for the reference to #16933 thats definitely covering the ownership issue with resource creation inside of controllers in general. I was thinking I was going to have to have to do something on my own here so its good to see that people have already been thinking about this:)

@fejta
Copy link
Contributor

fejta commented Apr 26, 2016

This PR has had no meaningful activity for multiple months. If it is still valid please rebase, push a new commit and reopen the PR. Thanks!

@fejta fejta closed this Apr 26, 2016
@davidopp
Copy link
Contributor

Why did we drop this? It seems useful.

@davidopp davidopp reopened this Apr 26, 2016
@k8s-bot
Copy link

k8s-bot commented Apr 26, 2016

GCE e2e build/test failed for commit a3d32f9.

Please reference the list of currently known flakes when examining this failure. If you request a re-test, you must reference the issue describing the flake.

@aanm
Copy link
Contributor

aanm commented May 13, 2016

@erictune @smarterclayton Since #23549 was merged, what is the current progress with this PR? Let me know if I can help with anything.

@bgrant0607
Copy link
Member

cc @mikedanese

@erictune erictune added the sig/auth Categorizes an issue or PR as relevant to SIG Auth. label Jun 30, 2016
@erictune
Copy link
Contributor

#27087 will add a detailed audit log.

We should see how many use cases that satisfies (I know it does not satisfy @cameronbrunner use case, but want to see how many other need this after we have an audit log).

Also, submitting this before we have implemented controllers that use "acting-as" will mean that we have to do a breaking change once we add "acting-as" support. So, we should do that first, and then reevaluate this.

@erictune
Copy link
Contributor

@aanm It would be helpful if you could describe in detail how you would use this field.

@aanm
Copy link
Contributor

aanm commented Jul 4, 2016

@erictune It would help to allow or deny network traffic from/to a particular user.

@tgraf
Copy link
Contributor

tgraf commented Jul 4, 2016

@erictune The use case is derived from the Net-SIG NetworkPolicy decision which now allows ingress rules based on PodSelector. We would like to allow for the creation of rules based on who has created/is running a particular pod.

@erictune
Copy link
Contributor

erictune commented Jul 6, 2016

Why not do this based on the service account of the pod? This allows two good things:

  • a single human can create different pods with different network policies
  • multiple humans can collaborate in the management of pods for an important service.

@soltysh
Copy link
Contributor

soltysh commented Jul 7, 2016

@sttts fyi

@k8s-bot
Copy link

k8s-bot commented Aug 30, 2016

Can one of the admins verify that this patch is reasonable to test? If so, please reply "ok to test".
(Note: "add to whitelist" is no longer supported. Please update configurations in kubernetes/test-infra/jenkins/job-configs/kubernetes-jenkins-pull instead.)

This message will repeat several times in short succession due to jenkinsci/ghprb-plugin#292. Sorry.

@k8s-github-robot
Copy link

This PR hasn't been active in 90 days. Closing this PR. Please reopen if you would like to work towards merging this change, if/when the PR is ready for the next round of review.

cc @erictune @smarterclayton

You can add 'keep-open' label to prevent this from happening again, or add a comment to keep it open another 90 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api Indicates an issue on api area. area/apiserver area/security kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. sig/auth Categorizes an issue or PR as relevant to SIG Auth. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.