Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Customizing suffix of the assumed role ARN for auditing purpose? #38

Open
mumoshu opened this issue Feb 20, 2018 · 12 comments
Open

Customizing suffix of the assumed role ARN for auditing purpose? #38

mumoshu opened this issue Feb 20, 2018 · 12 comments
Milestone

Comments

@mumoshu
Copy link

mumoshu commented Feb 20, 2018

Hi! Thanks for starting & maintaining this great project 👍

I recently realized that running get-caller-identity with the kiam-provided AWS credentials produce:

$ aws sts get-caller-identity --region ap-northeast-1
{
    "Account": "$myaccountid",
    "UserId": "AROAICVHQ4GZUSQIQRRHY:kiam-kiam",
    "Arn": "arn:aws:sts::$myaccountid:assumed-role/my-k8s-service-role/kiam-kiam"
}

my-k8s-service-role is from the pod annotation and kiam-kiam seems to be coming from kiam.

I couldn't find whether it is hard-coded into kiam or not.
Anyway, it would be great if I could configure the part to e.g. kiam-$mycluster-$ns-$pod_name so that it looks kiam-mycluster-kube-system-mytestpod which would add more traceability via CloudTrail logs. More concretely, it would be nice if I could trace from CloudTrail logs which pod in which cluster/namespace called which AWS API.

@mumoshu
Copy link
Author

mumoshu commented Feb 20, 2018

Seems like these are where it is set:

sessionName: fmt.Sprintf("kiam-%s", sessionName),

credentialsCache := sts.DefaultCache(stsGateway, config.SessionName, arnResolver)

kingpin.Flag("session", "Session name used when creating STS Tokens.").Default("kiam").StringVar(&serverConfig.SessionName)

So, ideally a template to the session flag like --session ${cluster_name}-{{.PodNamespace}}-{{.PodName}} executed with the metadata from the credentials-requestor pod would be great.

Note that ${cluster_name} is not needed to be templated. A cluster provisioning tool knows the cluster name at kiam installation time.

@pingles
Copy link
Contributor

pingles commented Mar 9, 2018

As you say- it's configurable with --session but currently kiam will request credentials (and cache) per-role, so the session would be tied to the originally requesting Pod (if you have the same role used by multiple pods it might be misleading) so given it's current implementation it'd mostly be useful for cluster name.

We re-use credentials as we often have many replicas of deployments/jobs etc. that use the same credentials and this helps reduce the number of AWS calls we make.

I guess another option would be to add an additional annotation that would name the session- then have credentials cached using the role name and session name (so pods in the same deployment/job etc. would share the same?).

@pingles
Copy link
Contributor

pingles commented Mar 9, 2018

Also @mumoshu sorry for only just noticing this issue now :)

@pingles pingles added this to the 3.0 milestone Jun 6, 2018
@pingles
Copy link
Contributor

pingles commented Jun 8, 2018

I had a think about doing this today and I don't think it's feasible without quite a large refactoring/change that would also unlock #14. I'm going to make some sketches and talk about it with people. Hopefully we get a little time to do this soon as it'd improve quite a lot of the code!

@pingles
Copy link
Contributor

pingles commented Aug 2, 2018

I'm going to move this back to 3.1- I'd rather we release with all the stuff that's been done so far and then add this later.

It's a feature which shouldn't rely on changing the behaviour of any existing flags so should be possible to add without breaking the existing behaviour.

@aidansteele
Copy link

@pingles What's the status of this effort? I see 3.0-3.2 have been released since your last message. Is this something that others can help with?

@pingles
Copy link
Contributor

pingles commented Jun 26, 2019 via email

@stefansedich
Copy link
Contributor

stefansedich commented Aug 31, 2020

Was there every any movement on this feature? we really need something like this so that we can have better auditiing of our S3 resources from JupyterHub, if I could apply the username as part of the prefix it could solve this in a simple way.

@pingles I am happy to pick this up if you want to have a chat with any ideas you might have had at the time? my initial thoughts in another pod annotation defining the suffix which can then be applied.

@stefansedich
Copy link
Contributor

As you say- it's configurable with --session but currently kiam will request credentials (and cache) per-role, so the session would be tied to the originally requesting Pod (if you have the same role used by multiple pods it might be misleading) so given it's current implementation it'd mostly be useful for cluster name.

We re-use credentials as we often have many replicas of deployments/jobs etc. that use the same credentials and this helps reduce the number of AWS calls we make.

I guess another option would be to add an additional annotation that would name the session- then have credentials cached using the role name and session name (so pods in the same deployment/job etc. would share the same?).

Have been digging into this @pingles and have come to the same conclusion, supporting this is going to require a new annotation but also change the cache key to have to include the role and session name.

Now before I go down this long dirty road just want to check in to see that this feature would be welcomed or if there is other work going on that could make the caching changes simpler.

My current thought is that the cache key would become some concatenation of <role-name>|<role-session-name> which would allow us to have as many role/role-session-name combos as we want.

Would be interested to hear your thoughts?

@stefansedich
Copy link
Contributor

@pingles as talked about in #399 adding my 2c here.

I would like to see it work using a pod template like we do today for the role and soon the extrernal ID, however the idea you mentioned to support templates could also be a viable alternative option if we could support both however I imagine from an implementation perspective and since we are already adding extrernal-id support might be easiest to just go with the annotation?

@bburky
Copy link

bburky commented Feb 17, 2021

I see #430 references this and was merged, what is the status of this now?

Another nice feature would be to allow specifying the tags used during AssumeRole. AWS allows parameterizing IAM policies based on the role's tags. If it were possible to provide the namespace as a tag, it would allow writing some extremely generic IAM policies parameterized based on namespace.

"Condition": {
    "StringEquals": {"aws:ResourceTag/namespace": "${aws:PrincipalTag/namespace}"}
}

Maybe this is a separate feature request, let me know if this needs a different ticket.

@stefansedich
Copy link
Contributor

I see #430 references this and was merged, what is the status of this now?

Another nice feature would be to allow specifying the tags used during AssumeRole. AWS allows parameterizing IAM policies based on the role's tags. If it were possible to provide the namespace as a tag, it would allow writing some extremely generic IAM policies parameterized based on namespace.

"Condition": {
    "StringEquals": {"aws:ResourceTag/namespace": "${aws:PrincipalTag/namespace}"}
}

Maybe this is a separate feature request, let me know if this needs a different ticket.

@bburky this sounds interesting and would not be overly difficult to add with the refactoring that was done to support session-name and external-id, I imagine we could just add support for session-tags as another pod annotation which are used when assuming the role.

I think another feature request is a good route here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants