Description
In kubernetes, a service account with automountServiceAccountToken: false
does not automatically mount the token into pods created by the deployment.
In order to accommodate this, you need to create a service account which has automountServiceAccountToken: true
if you'd like a pod to be able to use it. Being set to true
is the default behavior for a service account, which allows any pod in that namespace which requests that service account to automount.
Instead, I would think it's probably a more advisable security practice to instead create a service account with automountServiceAccountToken: false
and then in the deployment created by OpenFaaS, set automountServiceAccountToken: true
for the pod.
This way, regardless of whether or not you want a service account to amount on pods by default, OF will automount regardless. Right now, if you don't automount by default OF doesn't let you specify that you want the pod to automount at all.
Expected Behaviour
Normally when I create service accounts I set automount to false, and then set automount to true on the pods that will need it.
Current Behaviour
Right now pods do not specify that they would like a token automounted, so if you don't make the service account automount itself, the pod will not attempt to mount it.
Truth table
SA Type | SA automount | Has Annotation? | Pod Automount | Is Automounted? |
---|---|---|---|---|
default | default (true) | false | inherited | true |
custom | true | false | inherited | true |
custom | true | true | inherited | true |
custom | false | false | inherited | false |
custom | false | true | inherited | false |
Are you a GitHub Sponsor (Yes/No?)
Check at: https://github.com/sponsors/openfaas
- Yes
- No
List All Possible Solutions and Workarounds
- You could just ignore it, as a service account should generally be on a per-function basis. But, I'd say automounting off is a perfectly reasonable setting.
- You could make a function set
automountServiceAccountToken
totrue
when there is a value forcom.openfaas.serviceaccount
.
Whether or not functions should even have a default service account, and that it should be automounted by default is a different question.
Which Solution Do You Recommend?
The latter. Automount being off by default for a service account, and then opted-in specifically by pods seems easier to reason about, as well as my gut tells me there's possible security smells from having automount on all service accounts in a namespace by default.
Truth table
SA Type | SA automount | Has Annotation? | Pod Automount | Is Automounted? |
---|---|---|---|---|
default | default (true) | false | inherited | true |
custom | true | false | inherited | true |
custom | true | true | true | true |
custom | false | false | inherited | false |
custom | false | true | true | true |
Steps to Reproduce (for bugs)
- Create a service account with automount set to false
- There is no way to configure the pod to use the service account
Context
Trying to make a function that uses the k8s api.
Your Environment
-
FaaS-CLI version ( Full output from:
faas-cli version
): -
Docker version
docker version
(e.g. Docker 17.0.05 ): -
What version and distriubtion of Kubernetes are you using?
kubectl version
-
Operating System and version (e.g. Linux, Windows, MacOS):
-
Link to your project or a code example to reproduce issue:
-
What network driver are you using and what CIDR? i.e. Weave net / Flannel
Activity